window程序设计默认生成的模板

  1 // me.cpp : 定义应用程序的入口点。
  2 //
  3 
  4 #include "stdafx.h"
  5 #include "me.h"
  6 
  7 #define MAX_LOADSTRING 100
  8 
  9 // 全局变量: 
 10 HINSTANCE hInst;                                       // 当前实例
 11 TCHAR szTitle[MAX_LOADSTRING]=_T("hello");               // 标题栏文本
 12 TCHAR szWindowClass[MAX_LOADSTRING]=_T("HAHA");           // 主窗口类名
 13 
 14 // 此代码模块中包含的函数的前向声明: 
 15 ATOM                MyRegisterClass(HINSTANCE hInstance);
 16 BOOL                InitInstance(HINSTANCE, int);
 17 LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
 18 
 19 
 20 int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
 21                      _In_opt_ HINSTANCE hPrevInstance,
 22                      _In_ LPTSTR    lpCmdLine,
 23                      _In_ int       nCmdShow)
 24 {
 25     
 26     MSG msg;
 27     MyRegisterClass(hInstance);
 28     // 执行应用程序初始化: 
 29     if (!InitInstance (hInstance, nCmdShow))
 30     {
 31         return FALSE;
 32     }
 33     // 主消息循环: 
 34     while (GetMessage(&msg, NULL, 0, 0))
 35     {
 36         
 37             TranslateMessage(&msg);
 38             DispatchMessage(&msg);
 39         
 40     }
 41 
 42     return (int) msg.wParam;
 43 }
 44 
 45 
 46 ATOM MyRegisterClass(HINSTANCE hInstance)
 47 {
 48     WNDCLASSEX wcex;
 49 
 50     wcex.cbSize = sizeof(WNDCLASSEX);
 51 
 52     wcex.style            = CS_HREDRAW | CS_VREDRAW;
 53     wcex.lpfnWndProc    = WndProc;
 54     wcex.cbClsExtra        = 0;
 55     wcex.cbWndExtra        = 0;
 56     wcex.hInstance        = hInstance;
 57     wcex.hIcon = NULL;
 58     wcex.hCursor = NULL;
 59     wcex.hbrBackground    = (HBRUSH)(COLOR_WINDOW+1);
 60     wcex.lpszMenuName = NULL;
 61     wcex.lpszClassName    = szWindowClass;
 62     wcex.hIconSm = NULL;
 63 
 64     return RegisterClassEx(&wcex);
 65 }
 66 
 67 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
 68 {
 69    HWND hWnd;
 70 
 71    hInst = hInstance; // 将实例句柄存储在全局变量中
 72 
 73    hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
 74       0, 0, 200, 200, NULL, NULL, hInstance, NULL);
 75 
 76    if (!hWnd)
 77    {
 78       return FALSE;
 79    }
 80 
 81    ShowWindow(hWnd, nCmdShow);
 82    UpdateWindow(hWnd);
 83 
 84    return TRUE;
 85 }
 86 
 87 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 88 {
 89     int wmId, wmEvent;
 90     PAINTSTRUCT ps;
 91     HDC hdc;
 92 
 93     switch (message)
 94     {
 95     
 96     case WM_PAINT:
 97         hdc = BeginPaint(hWnd, &ps);
 98         // TODO:  在此添加任意绘图代码...
 99         EndPaint(hWnd, &ps);
100         break;
101     case WM_DESTROY:
102         PostQuitMessage(0);
103         break;
104     default:
105         return DefWindowProc(hWnd, message, wParam, lParam);
106     }
107     return 0;
108 }
让数据变得更安全!
原文地址:https://www.cnblogs.com/Alyoyojie/p/5254186.html