標籤:none ati use over 表單 info 技術 patch one
源碼
1 #include<Windows.h> 2 3 LRESULT CALLBACK WindProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); 4 5 int WinMain(HINSTANCE hInst, HINSTANCE tmp, LPSTR szCmd, int nShow) 6 { 7 WNDCLASS WndClass; 8 TCHAR* ClassName = TEXT("MyClass"); 9 HWND hwnd;10 MSG msg;11 12 WndClass.cbClsExtra = 0;13 WndClass.cbWndExtra = 0;14 WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);15 WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);16 WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);17 WndClass.hInstance = hInst;18 WndClass.lpfnWndProc = WindProc;19 WndClass.lpszClassName = ClassName;20 WndClass.lpszMenuName = NULL;21 WndClass.style = CS_VREDRAW | CS_HREDRAW;22 23 if (!RegisterClass(&WndClass))24 {25 MessageBox(NULL, TEXT("Gegister Class Fail!!"), TEXT("error"), MB_OK);26 return 0;27 }28 29 hwnd = CreateWindow(ClassName, TEXT("Hello"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 500, 300, NULL, NULL, hInst, NULL);30 if (hwnd == NULL)31 {32 MessageBox(NULL, TEXT("Create Window Fail!!"), TEXT("error"), MB_OK);33 return 0;34 }35 ShowWindow(hwnd, nShow);36 UpdateWindow(hwnd);37 38 while (GetMessage(&msg,NULL,0,0))39 {40 TranslateMessage(&msg);41 DispatchMessage(&msg);42 }43 44 return 0;45 }46 47 LRESULT CALLBACK WindProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)48 {49 switch (message)50 {51 case WM_DESTROY:52 PostQuitMessage(0);//發送WM_QUIT訊息53 return 0;54 default:55 break;56 }57 58 return DefWindowProc(hwnd, message, wParam, lParam);59 }
View Code
WIndows表單程式的一生 ,大部分時間都在訊息迴圈中度過。
05 Windows編程——Windows程式架構