WinMain

#include <windows.h> #include <stdio.h> LRESULT CALLBACK DriftProc( 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 wndClass; wndClass.cbClsExtra = 0; wndClass.cbWndExtra = 0; wndClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); wndClass.hCursor = LoadCursor(hInstance,IDC_APPSTARTING); wndClass.hIcon = LoadIcon(hInstance,IDI_APPLICATION); wndClass.hInstance = hInstance; wndClass.lpfnWndProc = DriftProc; wndClass.lpszClassName = "GoOnDrift"; wndClass.lpszMenuName = NULL; wndClass.style = CS_HREDRAW | CS_VREDRAW; //注册窗口类 RegisterClass(&wndClass); //创建窗口 HWND hwnd; hwnd = CreateWindow("GoOnDrift","凤凰花开的路口",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT, NULL,NULL,hInstance,NULL); //显示更新窗口 ShowWindow(hwnd,SW_NORMAL); UpdateWindow(hwnd); //消息循环 MSG msg; while(GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return 0; } LRESULT CALLBACK DriftProc( HWND hwnd, // handle to window UINT uMsg, // message identifier WPARAM wParam, // first message parameter LPARAM lParam // second message parameter ) { char huakaiBuf[100] = "时光的河入海流,终于我们分头走,没有哪个港口,是永远的停留"; char huakaiMBuf[100] = "也许值得纪念的事情不多,至少还有这段记忆够深刻"; switch(uMsg) { case WM_PAINT: HDC hdc; PAINTSTRUCT ps; hdc = BeginPaint(hwnd,&ps); TextOut(hdc,0,0,huakaiBuf,strlen(huakaiBuf)); EndPaint(hwnd,&ps); break; case WM_CHAR: char keyBuf[100]; sprintf(keyBuf,"The Key is %d ",wParam); MessageBox(hwnd,keyBuf,"按键",MB_OK); break; case WM_LBUTTONDOWN: MessageBox(hwnd,"Mouse Clicked","鼠标",MB_OK); HDC hDc; hDc = GetDC(hwnd); TextOut(hDc,0,50,huakaiMBuf,strlen(huakaiMBuf)); ReleaseDC(hwnd,hDc); break; case WM_CLOSE: if(IDYES == MessageBox(hwnd,"真的退出?","选择",MB_YESNO)) { DestroyWindow(hwnd); } break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd,uMsg,wParam,lParam); } return 0; }

你可能感兴趣的:(command,null,application,callback,include,winapi)