XXXXX
C/C++
XXXXX
C#/.net
XXXXX
js
java
java
开发导航 开发导航 www.endv.cn
天云

VC++ MFC应用程序项目文件2.cpp

 

 

  1 //GameServer.cpp: 定义应用程序的入口点。
  2 //
  3 
  4 #include "stdafx.h"
  5 #include "GameServer.h"
  6 
  7 #define MAX_LOADSTRING 100
  8 
  9 // 全局变量: 
 10 HINSTANCE hInst;                                // 当前实例
 11 WCHAR szTitle[MAX_LOADSTRING];                  // 标题栏文本
 12 WCHAR szWindowClass[MAX_LOADSTRING];            // 主窗口类名
 13 
 14 // 此代码模块中包含的函数的前向声明: 
 15 ATOM                MyRegisterClass(HINSTANCE hInstance);
 16 BOOL                InitInstance(HINSTANCE, int);
 17 LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
 18 INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);
 19 
 20 int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
 21                      _In_opt_ HINSTANCE hPrevInstance,
 22                      _In_ LPWSTR    lpCmdLine,
 23                      _In_ int       nCmdShow)
 24 {
 25     UNREFERENCED_PARAMETER(hPrevInstance);
 26     UNREFERENCED_PARAMETER(lpCmdLine);
 27 
 28     // TODO: 在此放置代码。
 29 
 30     // 初始化全局字符串
 31     LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
 32     LoadStringW(hInstance, IDC_GAMESERVER, szWindowClass, MAX_LOADSTRING);
 33     MyRegisterClass(hInstance);
 34 
 35     // 执行应用程序初始化: 
 36     if (!InitInstance (hInstance, nCmdShow))
 37     {
 38         return FALSE;
 39     }
 40 
 41     HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_GAMESERVER));
 42 
 43     MSG msg;
 44 
 45     // 主消息循环: 
 46     while (GetMessage(&msg, nullptr, 0, 0))
 47     {
 48         if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
 49         {
 50             TranslateMessage(&msg);
 51             DispatchMessage(&msg);
 52         }
 53     }
 54 
 55     return (int) msg.wParam;
 56 }
 57 
 58 
 59 
 60 //
 61 //  函数: MyRegisterClass()
 62 //
 63 //  目的: 注册窗口类。
 64 //
 65 ATOM MyRegisterClass(HINSTANCE hInstance)
 66 {
 67     WNDCLASSEXW wcex;
 68 
 69     wcex.cbSize = sizeof(WNDCLASSEX);
 70 
 71     wcex.style          = CS_HREDRAW | CS_VREDRAW;//从这个窗口类派生的窗口具有的风格
 72     wcex.lpfnWndProc    = WndProc;//窗口处理函数的指针, 处理主窗口的消息
 73     wcex.cbClsExtra     = 0;//指定紧跟在窗口类结构后的附加字节数。
 74     wcex.cbWndExtra     = 0;
 75     wcex.hInstance      = hInstance;//本模块的实例句柄。
 76     wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_GAMESERVER));
 77     wcex.hCursor        = LoadCursor(nullptr, IDC_ARROW);//光标的句柄
 78     wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
 79     wcex.lpszMenuName   = MAKEINTRESOURCEW(IDC_GAMESERVER);//指向菜单的指针
 80     wcex.lpszClassName  = szWindowClass;//指向类名称的指针
 81     wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));//和窗口类关联的小图标。如果该值为NULL。则把hIcon中的图标转换成大小合适的小图标
 82 
 83     return RegisterClassExW(&wcex);
 84 }
 85 
 86 //
 87 //   函数: InitInstance(HINSTANCE, int)
 88 //
 89 //   目的: 保存实例句柄并创建主窗口
 90 //
 91 //   注释: 
 92 //
 93 //        在此函数中,我们在全局变量中保存实例句柄并
 94 //        创建和显示主程序窗口。
 95 //
 96 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
 97 {
 98    hInst = hInstance; // 将实例句柄存储在全局变量中
 99 
100    HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
101       CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);
102 
103    if (!hWnd)
104    {
105       return FALSE;
106    }
107 
108    ShowWindow(hWnd, nCmdShow);
109    UpdateWindow(hWnd);
110 
111    return TRUE;
112 }
113 
114 //
115 //  函数: WndProc(HWND, UINT, WPARAM, LPARAM)
116 //
117 //  目的:    处理主窗口的消息。
118 //
119 //  WM_COMMAND  - 处理应用程序菜单
120 //  WM_PAINT    - 绘制主窗口
121 //  WM_DESTROY  - 发送退出消息并返回
122 //
123 //
124 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
125 {
126     switch (message)
127     {
128     case WM_COMMAND:
129         {
130             int wmId = LOWORD(wParam);
131             // 分析菜单选择: 
132             switch (wmId)
133             {
134             case IDM_ABOUT:
135                 DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
136                 break;
137             case IDM_EXIT:
138                 DestroyWindow(hWnd);
139                 break;
140             default:
141                 return DefWindowProc(hWnd, message, wParam, lParam);
142             }
143         }
144         break;
145     case WM_PAINT:
146         {
147             PAINTSTRUCT ps;
148             HDC hdc = BeginPaint(hWnd, &ps);
149             // TODO: 在此处添加使用 hdc 的任何绘图代码...
150             EndPaint(hWnd, &ps);
151         }
152         break;
153     case WM_DESTROY:
154 
155         // 退出程序 窗口销毁后(调用DestroyWindow()后),消息队列得到的消息。 
156 
157         PostQuitMessage(0);
158         break;
159     default:
160 
161         // hWnd 指向接收消息的窗口过程的句柄。
162         // Msg:指定消息类型
163         // wParam:指定其余的、消息特定的信息。该参数的内容与Msg参数值有关
164         // IParam:指定其余的、消息特定的信息。该参数的内容与Msg参数值有关
165         // 返回值:返回值就是消息处理结果,它与发送的消息有关。
166         // 当 DefWindowProc 处理 WM_DESTROY 消息时,它不自动调用 PostQuitMessage
167         return DefWindowProc(hWnd, message, wParam, lParam);
168     }
169     return 0;
170 }
171 
172 // “关于”框的消息处理程序。
173 INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
174 {
175     UNREFERENCED_PARAMETER(lParam);
176     switch (message)
177     {
178     case WM_INITDIALOG:
179         return (INT_PTR)TRUE;
180 
181     case WM_COMMAND:
182         if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
183         {
184             EndDialog(hDlg, LOWORD(wParam));
185             return (INT_PTR)TRUE;
186         }
187         break;
188     }
189     return (INT_PTR)FALSE;
190 }

 

posted @ 2018-01-23 20:16  Endv  阅读(429)  评论(0编辑  收藏  举报