API模板

 1 #include <windows.h>
 2 #include <windowsx.h>
 3 
 4 #define DIVISIONS 5
 5 
 6 LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
 7 
 8 int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
 9                     PSTR szCmdLine, int iCmdShow)
10 {
11      static TCHAR szAppName[] = TEXT ("Checker2") ;
12      HWND         hwnd ;
13      MSG          msg ;
14      WNDCLASS     wndclass ;
15 
16      wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
17      wndclass.lpfnWndProc   = WndProc ;
18      wndclass.cbClsExtra    = 0 ;
19      wndclass.cbWndExtra    = 0 ;
20      wndclass.hInstance     = hInstance ;
21      wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
22      wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
23      wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
24      wndclass.lpszMenuName  = NULL ;
25      wndclass.lpszClassName = szAppName ;
26      
27      if (!RegisterClass (&wndclass))
28      {
29           MessageBox (NULL, TEXT ("Program requires Windows NT!"), 
30                       szAppName, MB_ICONERROR) ;
31           return 0 ;
32      }
33      
34      hwnd = CreateWindow (szAppName, TEXT ("Checker2 Mouse Hit-Test Demo"),
35                           WS_OVERLAPPEDWINDOW,
36                           CW_USEDEFAULT, CW_USEDEFAULT,
37                           CW_USEDEFAULT, CW_USEDEFAULT,
38                           NULL, NULL, hInstance, NULL) ;
39      
40      ShowWindow (hwnd, iCmdShow) ;
41      UpdateWindow (hwnd) ;
42      
43      while (GetMessage (&msg, NULL, 0, 0))
44      {
45           TranslateMessage (&msg) ;
46           DispatchMessage (&msg) ;
47      }
48      return msg.wParam ;
49 }
50 
51 LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
52 {
1   EndPaint (hwnd, &ps) ;
2           return 0 ;
3                
4      case WM_DESTROY :
5           PostQuitMessage (0) ;
6           return 0 ;
7      }
8      return DefWindowProc (hwnd, message, wParam, lParam) ;
9 }
原文地址:https://www.cnblogs.com/Zblogs/p/3262183.html