|
楼主 |
发表于 2011-12-6 12:07:08
|
显示全部楼层
#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK WinProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show state
)
{
WNDCLASS winclass;
winclass.cbClsExtra=0;
winclass.cbWndExtra=0;
winclass.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
winclass.hCursor=LoadCursor(NULL,IDC_CROSS);
winclass.hIcon=LoadIcon(NULL,IDI_ERROR);
winclass.hInstance=hInstance;
winclass.lpfnWndProc=WinProc;
winclass.lpszClassName="Win";
winclass.lpszMenuName=NULL;
winclass.style=CS_HREDRAW|CS_VREDRAW;
RegisterClass(&winclass);
HWND hwnd;
hwnd=CreateWindow("Win","FirstWin",WS_OVERLAPPEDWINDOW,0,0,400,600,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WinProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
switch(uMsg)
{
case WM_PAINT:
HDC hdc;
PAINTSTRUCT ps;
hdc=BeginPaint(hwnd,&ps);
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(MessageBox(hwnd,"程序退出","是否退出程序",MB_YESNO))
DestroyWindow(hwnd);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"oye","click once again",MB_OK);
break;
case WM_CHAR:
MessageBox(hwnd,"oo","try again",MB_OK);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default: DefWindowProc(hwnd,uMsg,wParam,lParam);
break;
}
return 0;
}
就这么多 |
|