敬请高手指点一二
这是课本的API程序。就是它了: #include<windows.h> #include<stdlib.h> #include<string.h> LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage, UINT wParam,LONG lParam); BOOL InitWindowsClass(HINSTANCE hInstance); BOOL InitWindows(HINSTANCE hInstance,int nCmdShow);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) { MSG Message; if(! InitWindowsClass(hInstance)) return FALSE; if(! InitWindows(hInstance,nCmdShow)) return FALSE; while(GetMessage(&Message,0,0,0)) { TranslateMessage(&Message); DispatchMessage(&Message); } return Message.wParam; }
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,UINT wParam,LONG lParam) { static long nXChar,nCaps,nYChar; HDC hDC; short x; TEXTMETRIC tm; short LnCount=6; PAINTSTRUCT PtStr; static char *textbuf[]= { "This is the first line", "This is the second line", "This is the third line", "This is the fourth line", "this is the fifth line", "this is the sixth line" }; switch(iMessage) { case WM_CREATE: hDC=GetDC(hWnd); GetTextMetrics(hDC,&tm); nXChar=tm.tmAveCharWidth; nYChar=tm.tmHeight+tm.tmExternalLeading; ReleaseDC(hWnd,hDC); return 0; case WM_PAINT: hDC=BeginPaint(hWnd,&PtStr); for( x=0;x<LnCount;x=x+1) TextOut(hDC,nXChar,nYChar*(1+x),textbuf[x],lstrlen(textbuf[x])); EndPaint(hWnd,&PtStr); return 0;
case WM_DESTROY: PostQuitMessage(0); return 0; default: return (DefWindowProc(hWnd,iMessage,wParam,lParam)); } } BOOL InitWindowsClass(HINSTANCE hInstance) { WNDCLASS WndClass; WndClass.cbClsExtra=0; WndClass.cbWndExtra=0; WndClass.hbrBackground=(HBRUSH)(GetStockObject(WHITE_BRUSH)); WndClass.hCursor=LoadCursor(NULL,IDC_ARROW); WndClass.hIcon=LoadIcon(NULL,"END"); WndClass.hInstance=hInstance; WndClass.lpfnWndProc=WndProc; WndClass.lpszClassName="WinText"; WndClass.lpszMenuName=NULL; WndClass.style=CS_HREDRAW|CS_VREDRAW; return RegisterClass(&WndClass); } BOOL InitWindows (HINSTANCE hInstance,int nCmdShow) { HWND hWnd; hWnd=CreateWindow("WinText", "文本显示例程序", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); if (! hWnd) return FALSE; ShowWindow(hWnd,nCmdShow); UpdateWindow(hWnd); return TRUE; }
另外还有: #include<windows.h> #include<stdlib.h> #include<string.h> BOOL InitWindowsClass(HINSTANCE hInstance); BOOL InitWindows(HINSTANCE hInstance,int nCmdShow); int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdline,int nCmdShow) { MSG Message; if(! InitWindowsClass(hInstance)) return FALSE; if (! InitWindows(hInstance,nCmdShow)) return FALSE; while(GetMessage(&Message,0,0,0)) { TranslateMessage(&Message); DispatchMessage(&Message); } return Message.wParam; }
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage, UINT wParam,LONG lParam) { WORD x,y; HCURSOR hCursor; switch(iMessage) { case WM_MOUSEMOVE: x=LOWORD(lParam); y=HIWORD(lParam); if (x>=50&&x<=400&&y>=50&&y<=300) { if (x>=50&&x<=100&&y>=50&&y<=100) { hCursor=LoadCursor(NULL,IDC_CROSS); SetCursor(hCursor); }
if (x>=150&&x<=2000&&y>=50&&y<=100) { hCursor=LoadCursor(NULL,IDC_HELP); SetCursor(hCursor); } if (x>=50&&x<=100&&y>=100&&y<=150) { hCursor=LoadCursor(NULL,IDC_SIZENESW); SetCursor(hCursor); } if (x>=100&&x<=250&&y>=100&&y<=150) { hCursor=LoadCursor(NULL,IDC_SIZENS); SetCursor(hCursor); } if (x>=250&&x<=400&&y>=100&&y<=150) { hCursor=LoadCursor(NULL,IDC_SIZENWSE); SetCursor(hCursor); } if (x>=100&&x<=150&&y>=150&&y<=300) { hCursor=LoadCursor(NULL,IDC_SIZEWE); SetCursor(hCursor); } if (x>=100&&x<=250&&y>=150&&y<=300) { hCursor=LoadCursor(NULL,IDC_UPARROW); SetCursor(hCursor); } if (x>=250&&x<=400&&y>=150&&y<=300) { hCursor=LoadCursor(NULL,IDC_WAIT); SetCursor(hCursor); } /*if (x>=100&&x<=150&&y>=50&&y<=100) { hCursor=LoadCursor(NULL,IDC_SIZEALL); SetCursor(hCursor); } if (x>=100&&x<=150&&y>=50&&y<=100) { hCursor=LoadCursor(NULL,IDC_SIZEALL); SetCursor(hCursor); }*/ } else { hCursor=LoadCursor(NULL,IDC_ARROW); SetCursor(hCursor); } return 0; case WM_DESTROY: PostQuitMessage(0); return 0; default: return(DefWindowProc(hWnd,iMessage,wParam,lParam)); }
}
BOOL InitWindowProc(HINSTANCE hInstance) { WNDCLASS WndClass; WndClass.cbClsExtra=0; WndClass.cbWndExtra=0; WndClass.hbrBackground=(HBRUSH)(GetStockObject(WHITE_BRUSH)); WndClass.hCursor=LoadCursor(NULL,IDC_ARROW); WndClass.hIcon=LoadIcon(NULL,"END"); WndClass.hInstance=hInstance; WndClass.lpfnWndProc=WndProc; WndClass.lpszClassName="WinMouse"; WndClass.lpszMenuName=NULL; WndClass.style=CS_HREDRAW|CS_VREDRAW; return RegisterClass(&WndClass); }
BOOL InitWindoews(HINSTANCE hInstance,int nCmdShow) { HWND hWnd; hWnd=CreateWindow("WinMouse", "鼠标及光标形状设置及示例", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); if(! hWnd) return FALSE; ShowWindow(hWnd,nCmdShow); UpdateWindow(hWnd); return TRUE; }