前言

将代码拆分了一下, 如果处理更多的消息也不怕看的眼花
SDK编程就是对各种Windows消息的处理

实验工程

  1. /// @file exam_1.cpp
  2. /// @brief 查阅本地MSDN, 手工写SDK程序
  3. #include "common.h"
  4. #include "ErrorProc.h"
  5. #include "WindowProc.h"
  6. int WINAPI WinMain(HINSTANCE hInstance,
  7. HINSTANCE hPrevInstance,
  8. LPSTR lpCmdLine,
  9. int nCmdShow) {
  10. if (!fnRegisterClass(hInstance, hPrevInstance, lpCmdLine, nCmdShow)) {
  11. ShowErrMsg();
  12. goto WINMAIN_END;
  13. }
  14. if (!fnCreateWindow(hInstance, hPrevInstance, lpCmdLine, nCmdShow)) {
  15. ShowErrMsg();
  16. goto WINMAIN_END;
  17. }
  18. MsgLoop();
  19. WINMAIN_END:
  20. return 0;
  21. }
 
  1. /// @file common.h
  2. /// @brief 公用头文件
  3. #ifndef COMMON_H_2016_0128
  4. #define COMMON_H_2016_0128
  5. #define _WIN32_WINDOWS 0x500
  6. #include <windows.h>
  7. #include <tchar.h>
  8. #include <stdlib.h>
  9. #include <stdio.h>
  10. #endif // #ifndef COMMON_H_2016_0128
  1. /// @file ErrorProc.h
  2. /// @brief 错误处理
  3. #ifndef ERRORPROC_H_2016_0128
  4. #define ERRORPROC_H_2016_0128
  5. const TCHAR* StringFormatV(TCHAR* szFormat, ...);
  6. void ShowMsg(const TCHAR* pcMsg);
  7. void ShowErrMsg();
  8. BOOL isQuitProg(HWND hWnd);
  9. #endif // #ifndef ERRORPROC_H_2016_0128
  1. /// @file WindowProc.h
  2. /// @brief 消息处理
  3. /// 消息处理函数命名规范
  4. /// OnX On说明是Windows消息处理函数
  5. /// X是消息 WM_X 去掉 WM_ 之后,按照将X按照匈牙利写法拼在On后面
  6. /// e.g. WM_CLOSE消息处理函数为OnClose
  7. #ifndef WINDOWPROC_H_2016_0128
  8. #define WINDOWPROC_H_2016_0128
  9. #include "common.h"
  10. BOOL fnRegisterClass(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);
  11. BOOL fnCreateWindow(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);
  12. void MsgLoop();
  13. HWND getMainWnd();
  14. HINSTANCE getInstance();
  15. LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  16. LONG fnDispatchMessage(CONST MSG* lpMsg);
  17. BOOL OnKeyDown(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  18. BOOL OnChar(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  19. BOOL OnSysDeadChar(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  20. BOOL OnSysChar(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  21. BOOL OnSysKeyDown(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  22. BOOL OnSysKeyUp(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  23. BOOL OnMouse(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  24. BOOL OnMouseMove(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  25. BOOL OnMouseWheel(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  26. BOOL OnMouseLButtonDown(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  27. BOOL OnMouseLButtonUp(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  28. BOOL OnMouseLButtonDblClk(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  29. BOOL OnMouseRButtonDown(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  30. BOOL OnMouseRButtonUp(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  31. BOOL OnMouseRButtonDblClk(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  32. BOOL OnMouseMButtonDown(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  33. BOOL OnMouseMButtonUp(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  34. BOOL OnMouseMButtonDblClk(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  35. BOOL OnClose(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  36. BOOL OnDestory(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  37. #endif // #ifndef WINDOWPROC_H_2016_0128
  1. /// @file common.cpp
  2. /// @brief 公用头文件对应的实现
  3. #include "common.h"
  1. /// @file ErrorProc.cpp
  2. /// @brief 错误处理实现
  3. #include "common.h"
  4. #include "ErrorProc.h"
  5. #include "WindowProc.h"
  6. BOOL isQuitProg(HWND hWnd) {
  7. BOOL bRc = FALSE;
  8. if (IDYES == MessageBox(hWnd, _T("是否退出?"), _T("提示"), MB_YESNO)) {
  9. bRc = TRUE;
  10. }
  11. return bRc; ///< true is quit prog
  12. }
  13. void ShowErrMsg() {
  14. LPVOID lpMsgBuf = NULL;
  15. FormatMessage(
  16. FORMAT_MESSAGE_ALLOCATE_BUFFER
  17. | FORMAT_MESSAGE_FROM_SYSTEM
  18. | FORMAT_MESSAGE_IGNORE_INSERTS,
  19. NULL,
  20. GetLastError(),
  21. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  22. (LPTSTR)&lpMsgBuf,
  23. 0,
  24. NULL);
  25. MessageBox(getMainWnd(), (LPCTSTR)lpMsgBuf, _T("Error"), MB_OK | MB_ICONINFORMATION);
  26. LocalFree(lpMsgBuf);
  27. }
  28. const TCHAR* StringFormatV(TCHAR* szFormat, ...)
  29. {
  30. /// 在栈空间上拼字符串, 如果new的话, 容易引起内存碎片
  31. /// 运行的次数多了,有可能分配不出内存来
  32. static TCHAR s_cBuf[4096] = {'\0'}; ///< _vsntprintf做了处理, 最多就是打印不全
  33. int iStringLen = 0;
  34. va_list args;
  35. va_start(args, szFormat);
  36. iStringLen = _vsntprintf(s_cBuf, (sizeof(s_cBuf) / sizeof(TCHAR)) - 1, szFormat, args);
  37. va_end(args);
  38. return s_cBuf;
  39. }
  40. void ShowMsg(const TCHAR* pcMsg) {
  41. if (NULL != pcMsg) {
  42. OutputDebugString(pcMsg);
  43. }
  44. }
  1. /// @file WindowProc.cpp
  2. /// @brief Windows消息处理的实现
  3. #include "WindowProc.h"
  4. #include "ErrorProc.h"
  5. static HWND g_hWnd = NULL;
  6. static HINSTANCE g_hInstance = NULL;
  7. HWND getMainWnd() {
  8. return g_hWnd;
  9. }
  10. HINSTANCE getInstance() {
  11. return g_hInstance;
  12. }
  13. BOOL fnRegisterClass(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
  14. /// 设计,注册窗口类
  15. BOOL bRc = TRUE;
  16. ATOM _atom;
  17. WNDCLASS WndClass = {0};
  18. // 拥有了经典样式 CS_DBLCLKS, 才会响应双击操作
  19. WndClass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
  20. WndClass.lpfnWndProc = &WindowProc;
  21. WndClass.cbClsExtra = 0;
  22. WndClass.cbWndExtra = 0;
  23. WndClass.hInstance = hInstance;
  24. WndClass.hIcon = NULL;
  25. WndClass.hCursor = NULL /*LoadCursor(NULL, IDC_ARROW)*/;
  26. WndClass.hbrBackground = (HBRUSH)COLOR_WINDOW;
  27. WndClass.lpszMenuName = NULL;
  28. WndClass.lpszClassName = _T("test class");///< 不能为空
  29. _atom = RegisterClass(&WndClass);
  30. if (0 == _atom) {
  31. bRc = FALSE;
  32. }
  33. g_hInstance = hInstance;
  34. return bRc;
  35. }
  36. BOOL fnCreateWindow(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
  37. /// 创建, 显示窗口
  38. BOOL bRc = TRUE;
  39. g_hWnd = CreateWindow(
  40. _T("test class"),  // pointer to registered class name
  41. _T("test class window"), // pointer to window name
  42. WS_OVERLAPPEDWINDOW,        // window style
  43. 100,                // horizontal position of window
  44. 100,                // vertical position of window
  45. 800,           // window width
  46. 600,          // window height
  47. NULL,      // handle to parent or owner window
  48. NULL,          // handle to menu or child-window identifier
  49. hInstance,     // handle to application instance
  50. NULL        // pointer to window-creation data
  51. );
  52. if (NULL == g_hWnd) {
  53. bRc = FALSE;
  54. goto FNCREATEWINDOW_END;
  55. }
  56. ShowMsg(StringFormatV(_T("g_hWnd = 0x%X\n"), g_hWnd));
  57. ShowWindow(g_hWnd, SW_SHOWNORMAL);
  58. UpdateWindow(g_hWnd);
  59. FNCREATEWINDOW_END:
  60. return bRc;
  61. }
  62. void MsgLoop() {
  63. /// 消息循环
  64. MSG msg;
  65. // GetMessage参数2必须是NULL, 如果是g_hWnd, 会在WM_NCDESTROY后,
  66. // msg子项内容都全变成0, 变成一个死循环
  67. // 如果第2个参数为NULL, 会接收本进程所有窗口(线程)的消息
  68. ShowMsg(_T(">> MsgLoop()\n"));
  69. while (GetMessage(
  70. &msg,         // address of structure with message
  71. NULL,     // handle of window
  72. 0,  // first message
  73. 0   // last message
  74. )) {
  75. TranslateMessage(&msg); ///< 键盘消息到字符消息(多投递一个WM_CHAR消息)
  76. fnDispatchMessage(&msg); ///< DispatchMessage不是必须的,我们也可以自己实现
  77. }
  78. ShowMsg(_T("<< MsgLoop()\n"));
  79. }
  80. LONG fnDispatchMessage(CONST MSG* lpMsg) {
  81. long lRc = 0;
  82. int iLen = 0;
  83. TCHAR cBuf[MAXBYTE] = {_T('\0')};
  84. WNDCLASS WndClass = {0};
  85. if (NULL == lpMsg)
  86. goto FNDISPATCHMESSAGE_END;
  87. iLen = GetClassName(lpMsg->hwnd, cBuf, sizeof(cBuf)/sizeof(TCHAR));
  88. if (iLen <= 0)
  89. goto FNDISPATCHMESSAGE_END;
  90. if (!GetClassInfo(getInstance(), cBuf, &WndClass))
  91. goto FNDISPATCHMESSAGE_END;
  92. if (NULL == WndClass.lpfnWndProc)
  93. goto FNDISPATCHMESSAGE_END;
  94. lRc = WndClass.lpfnWndProc(lpMsg->hwnd, lpMsg->message, lpMsg->wParam, lpMsg->lParam);
  95. FNDISPATCHMESSAGE_END:
  96. return lRc;
  97. }
  98. /**
  99. WM_XXX
  100. 键盘,鼠标,绘制消息
  101. WM_COMMAND
  102. 菜单,快捷键消息
  103. 快捷键消息和键盘消息不同。
  104. 键盘消息是一个一个的按键
  105. 快捷键消息是组合键.
  106. WM_NOTIFY
  107. 子窗口的消息
  108. */
  109. LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  110. BOOL bCallDefWindowProc = TRUE;
  111. LRESULT lRc = 0;
  112. ShowMsg(StringFormatV(_T("uMsg = 0x%X\n"), uMsg));
  113. /// 编码规范, 必须单独封装处理消息的函数OnMsg,
  114. /// 不允许在WindowProc中写具体的消息处理实现
  115. switch (uMsg) {
  116. case WM_KEYDOWN:
  117. bCallDefWindowProc = OnKeyDown(lRc, hwnd, uMsg, wParam, lParam);
  118. break;
  119. case WM_CHAR:
  120. bCallDefWindowProc = OnChar(lRc, hwnd, uMsg, wParam, lParam);
  121. break;
  122. case WM_SYSDEADCHAR:
  123. bCallDefWindowProc = OnSysDeadChar(lRc, hwnd, uMsg, wParam, lParam);
  124. break;
  125. case WM_SYSCHAR:
  126. bCallDefWindowProc = OnSysChar(lRc, hwnd, uMsg, wParam, lParam);
  127. break;
  128. case WM_SYSKEYDOWN:
  129. bCallDefWindowProc = OnSysKeyDown(lRc, hwnd, uMsg, wParam, lParam);
  130. break;
  131. case WM_SYSKEYUP:
  132. bCallDefWindowProc = OnSysKeyUp(lRc, hwnd, uMsg, wParam, lParam);
  133. break;
  134. case WM_MOUSEMOVE:
  135. case WM_MOUSEWHEEL:
  136. case WM_LBUTTONDOWN:
  137. case WM_LBUTTONUP:
  138. case WM_LBUTTONDBLCLK:
  139. case WM_RBUTTONDOWN:
  140. case WM_RBUTTONUP:
  141. case WM_RBUTTONDBLCLK:
  142. case WM_MBUTTONDOWN:
  143. case WM_MBUTTONUP:
  144. case WM_MBUTTONDBLCLK:
  145. bCallDefWindowProc = OnMouse(lRc, hwnd, uMsg, wParam, lParam);
  146. break;
  147. case WM_CLOSE:
  148. bCallDefWindowProc = OnClose(lRc, hwnd, uMsg, wParam, lParam);
  149. break;
  150. case WM_DESTROY:
  151. bCallDefWindowProc = OnDestory(lRc, hwnd, uMsg, wParam, lParam);
  152. break;
  153. default:
  154. break;
  155. }
  156. /// The DefWindowProc function calls the default window procedure
  157. /// to provide default processing for any window messages
  158. /// that an application does not process.
  159. return bCallDefWindowProc ? DefWindowProc(hwnd, uMsg, wParam, lParam) : lRc;
  160. }
  161. BOOL OnKeyDown(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  162. /// 如果不调用 TranslateMessage, 可以自己取按键值
  163. /// 如果调用了 TranslateMessage, 在OnChar中直接取键值
  164. ShowMsg(_T("OnKeyDown\n"));
  165. int nVirtKey = (int) wParam;    // virtual-key code
  166. ULONG ulKeyData = lParam;          // key data
  167. BYTE ucKeyState[256] = {0};
  168. WORD wChar = 0;
  169. int iRc = 0;
  170. /**
  171. lKeyData
  172. Value of lParam. Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag, as shown in the following table. Value Description
  173. 0–15 Specifies the repeat count for the current message. The value is the number of times the keystroke is auto-repeated as a result of the user holding down the key. If the keystroke is held long enough, multiple messages are sent. However, the repeat count is not cumulative.
  174. 16–23 Specifies the scan code. The value depends on the original equipment manufacturer (OEM).
  175. 24 Specifies whether the key is an extended key, such as the right-hand alt and ctrl keys that appear on an enhanced 101- or 102-key keyboard. The value is 1 if it is an extended key; otherwise, it is 0.
  176. 25–28 Reserved; do not use.
  177. 29 Specifies the context code. The value is always 0 for a WM_KEYDOWN message.
  178. 30 Specifies the previous key state. The value is 1 if the key is down before the message is sent, or it is 0 if the key is up.
  179. 31 Specifies the transition state. The value is always 0 for a WM_KEYDOWN message.
  180. */
  181. if (!GetKeyboardState(&ucKeyState[0])) {
  182. goto ONKEYDOWN_END;
  183. }
  184. if (ToAscii(nVirtKey, (ulKeyData >> 16) & 0xff, ucKeyState, &wChar, 0) <= 0) {
  185. goto ONKEYDOWN_END;
  186. }
  187. ShowMsg(StringFormatV(_T("%c "), (TCHAR)wChar));
  188. ONKEYDOWN_END:
  189. lRc = 0;
  190. return TRUE;
  191. }
  192. BOOL OnChar(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  193. ShowMsg(StringFormatV(_T("%c "), (TCHAR)wParam));
  194. lRc = 0;
  195. return TRUE;
  196. }
  197. BOOL OnSysDeadChar(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  198. lRc = 0;
  199. return TRUE;
  200. }
  201. BOOL OnSysChar(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  202. lRc = 0;
  203. return TRUE;
  204. }
  205. BOOL OnSysKeyDown(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  206. /// F10 press down
  207. lRc = 0;
  208. return TRUE;
  209. }
  210. BOOL OnSysKeyUp(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  211. /// F10 press up
  212. lRc = 0;
  213. return TRUE;
  214. }
  215. BOOL OnMouse(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  216. BOOL bRc = FALSE;
  217. //     POINTS pt;
  218. //     UINT uMK = 0; // key flags
  219. //     WORD xPos = 0; // horizontal position of cursor
  220. //     WORD yPos = 0; // vertical position of cursor
  221. if ((uMsg < WM_MOUSEFIRST) || (uMsg > WM_MOUSELAST))
  222. goto ONMOUSE_END;
  223. /**
  224. * Key State Masks for Mouse Messages
  225. #define MK_LBUTTON          0x0001
  226. #define MK_RBUTTON          0x0002
  227. #define MK_SHIFT            0x0004
  228. #define MK_CONTROL          0x0008
  229. #define MK_MBUTTON          0x0010
  230. */
  231. //     uMK = wParam;
  232. //     xPos = LOWORD(lParam);
  233. //     yPos = HIWORD(lParam);
  234. //     pt = MAKEPOINTS(lParam);
  235. switch (uMsg) {
  236. // 移动
  237. case WM_MOUSEMOVE:
  238. bRc = OnMouseMove(lRc, hwnd, uMsg, wParam, lParam);
  239. break;
  240. // 滑过
  241. case WM_MOUSEWHEEL:
  242. bRc = OnMouseWheel(lRc, hwnd, uMsg, wParam, lParam);
  243. break;
  244. // 左键
  245. case WM_LBUTTONDOWN:
  246. bRc = OnMouseLButtonDown(lRc, hwnd, uMsg, wParam, lParam);
  247. break;
  248. case WM_LBUTTONUP:
  249. bRc = OnMouseLButtonUp(lRc, hwnd, uMsg, wParam, lParam);
  250. break;
  251. case WM_LBUTTONDBLCLK:
  252. bRc = OnMouseLButtonDblClk(lRc, hwnd, uMsg, wParam, lParam);
  253. break;
  254. // 右键
  255. case WM_RBUTTONDOWN:
  256. bRc = OnMouseRButtonDown(lRc, hwnd, uMsg, wParam, lParam);
  257. break;
  258. case WM_RBUTTONUP:
  259. bRc = OnMouseRButtonUp(lRc, hwnd, uMsg, wParam, lParam);
  260. break;
  261. case WM_RBUTTONDBLCLK:
  262. bRc = OnMouseRButtonDblClk(lRc, hwnd, uMsg, wParam, lParam);
  263. break;
  264. // 中键
  265. case WM_MBUTTONDOWN:
  266. bRc = OnMouseMButtonDown(lRc, hwnd, uMsg, wParam, lParam);
  267. break;
  268. case WM_MBUTTONUP:
  269. bRc = OnMouseMButtonUp(lRc, hwnd, uMsg, wParam, lParam);
  270. break;
  271. case WM_MBUTTONDBLCLK:
  272. bRc = OnMouseMButtonDblClk(lRc, hwnd, uMsg, wParam, lParam);
  273. break;
  274. default:
  275. break;
  276. }
  277. ONMOUSE_END:
  278. lRc = 0;
  279. return bRc; ///< bCallDefWindowProc
  280. }
  281. BOOL OnMouseMove(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  282. lRc = 0;
  283. return TRUE;
  284. }
  285. BOOL OnMouseWheel(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  286. lRc = 0;
  287. return TRUE;
  288. }
  289. BOOL OnMouseLButtonDown(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  290. ShowMsg(StringFormatV(_T("OnMouseLButtonDown, hwnd = 0x%X\n"), hwnd));
  291. // MessageBox(hwnd, _T("OnMouseLButtonDown"), _T("SDK Frame"), MB_OK);
  292. lRc = 0;
  293. return TRUE;
  294. }
  295. BOOL OnMouseLButtonUp(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  296. ShowMsg(StringFormatV(_T("OnMouseLButtonUp, hwnd = 0x%X\n"), hwnd));
  297. lRc = 0;
  298. return TRUE;
  299. }
  300. BOOL OnMouseLButtonDblClk(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  301. ShowMsg(_T("OnMouseLButtonDblClk\n"));
  302. lRc = 0;
  303. return TRUE;
  304. }
  305. BOOL OnMouseRButtonDown(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  306. lRc = 0;
  307. return TRUE;
  308. }
  309. BOOL OnMouseRButtonUp(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  310. lRc = 0;
  311. return TRUE;
  312. }
  313. BOOL OnMouseRButtonDblClk(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  314. lRc = 0;
  315. return TRUE;
  316. }
  317. BOOL OnMouseMButtonDown(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  318. lRc = 0;
  319. return TRUE;
  320. }
  321. BOOL OnMouseMButtonUp(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  322. lRc = 0;
  323. return TRUE;
  324. }
  325. BOOL OnMouseMButtonDblClk(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  326. lRc = 0;
  327. return TRUE;
  328. }
  329. BOOL OnClose(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  330. lRc = 0;
  331. return isQuitProg(hwnd); ///< bCallDefWindowProc
  332. }
  333. BOOL OnDestory(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  334. lRc = 0;
  335. // WM_QUIT使GetMessage为FALSE, 跳出消息循环的处理
  336. // PostMessage(hwnd, WM_QUIT, 0, 0); ///< ok
  337. PostQuitMessage(0); ///< 也会发送WM_QUIT消息
  338. return TRUE; ///< bCallDefWindowProc
  339. }

http://blog.csdn.net/lostspeed/article/details/50606215

http://blog.csdn.net/lostspeed/article/details/50614423

SDK Hello world(直接使用SDK封装)的更多相关文章

  1. 【Win10 UWP】QQ SDK(二):SDK的回调处理

    上一讲,我们介绍了QQ SDK的使用方法,请看<[Win10 UWP]QQ SDK(一):SDK基本使用方法> 一. 回调的基本形式 从前面的介绍中我们知道,我们的应用和QQ客户端之间需要 ...

  2. 【Win10 UWP】QQ SDK(一):SDK基本使用方法

    每当开发一个应用需要社交分享的应用时,总是心里咯噔一下:到底什么时候分享能加上QQ和微信?除了WP8.0版本的微信SDK,官方似乎从未正面发布过适应时代发展的QQ SDK,就连后台,也没有一个可以创建 ...

  3. iOS开发——iOS10升级极光推送SDK、友盟分享SDK

    前不久升级了Xcode8 ,同时iOS10系统也推送久. 由于公司需要适配iOS 10系统,同时第三方sdk建议升级. 包含替换升级新的SDK和相应的代码修改. 主要分享如何升级极光推送SDK,友盟分 ...

  4. [2015-06-10 20:53:50 - Android SDK] Error when loading the SDK:

    1.错误描述 [2015-06-10 20:53:50 - Android SDK] Error when loading the SDK: Error: Error parsing D:\Andro ...

  5. Android基础之在Eclipes中关联SDK源码和查看SDK源码

    在进行Android应用开发的时候,我们有时候需要查看某个类或接口的源码从而了解如何去使用一个类或者实现一个接口,查看源码有助于我们的学习某个封装的类的底层是如何实现的,这样可以帮助我们掌握类或者接口 ...

  6. 关于js SDK的程序,java SDK的程序

    一:JS SDK 1.修改配置workspace 2.导入 3.Demo.html <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Trans ...

  7. 【微博SDK调用逻辑】微博SDK的调用逻辑,最好自己还是写一个例子,试一下!!!

    逻辑是这样的,谢谢给我讲东西的开发哥哥,嘻嘻~~~  1.点击微博登录,SDK会打开微博客户端,然后点击登陆(如果已经登录了会出现一个当前app跟微博交互的图片界面,然后提示“正在获取授权信息”,如果 ...

  8. iOS——Command-Line 查看当前SDK版本并修改默认SDK版本

    在工作中可能会碰到用命令行编译.打包iOS应用程序的情况(xcodebuild相关命令). 但是由于SDK版本问题,会报错,说某SDK版本不对,可能是因为升级Xcode导致的SDK版本升级,为了避免高 ...

  9. 安装Android SDK时,点击SDK Manager.exe闪退,并且jdk的环境变量是对的。

    前提:我的jdk的环境变量是正确的,同时我的jdk还是1.7应该不是版本太低的原因,同时这个压缩文件是好的,我在其他的电脑上可以运行SDK Manager.exe. 点击SDK Manager.exe ...

  10. 解决Android Studio 3.x版本的安装时没有SDK,运行时出现SDK tools错误

    好久没更新了,最近手机上的闹钟APP没一个好用的,所以想自己写个. 那Android开发环境搭起来,注意先装好jdk. 1.安装Android Studio google的Android开发网站已经有 ...

随机推荐

  1. 猪猪的机器学习笔记(十七)隐马尔科夫模型HMM

    隐马尔科夫模型HMM 作者:樱花猪 摘要: 本文为七月算法(julyedu.com)12月机器学习第十七次课在线笔记.隐马尔可夫模型(Hidden Markov Model,HMM)是统计模型,它用来 ...

  2. BZOJ 2196: [Usaco2011 Mar]Brownie Slicing( 二分答案 )

    二分答案就可以了.... ----------------------------------------------------------------------- #include<cst ...

  3. DLL运行时动态加加载的问题

    1.error C2440: 'initializing' : cannot convert from 'int (__stdcall *)(void)' to 'void (__cdecl *)(c ...

  4. Node.js学习笔记2(安装和配置Node.js)

            1.安装         windows下安装,在http://nodejs.org下载安装包进行安装即可.         linux下安装,使用yum或者下载源码进行编译.     ...

  5. PHPExcel 生成图形报表

    db.php为数据库操作类, $config为数据库配置,PHPExcel版本为PHPExcel_1.8.0,  PHP代码: $dir = dirname(__FILE__); require $d ...

  6. 高质量程序设计指南C/C++语言——C++/C编译预处理

    C++/C的编译预处理器对预编译伪指令进行处理后生成中间文件作为编译器的输入,因此所有的预编译伪指令都不会进入编译阶段.预编译伪指令一般都以#打头,且其前面只能出现空白字符.预编译伪指令不是C++/C ...

  7. spring jdbc 笔记3

    spring JDBC 加入对commons-dbcp  spring-jdbc  spring-tx的依赖 1.数据源的配置 获取数据源在spring中的Bean管理默认已经是单例模式 关闭数据源d ...

  8. 多少遍ner让他加56看6

    http://www.huihui.cn/share/8112372 http://www.huihui.cn/share/8112363 http://www.huihui.cn/share/811 ...

  9. JAVA GUI学习 - 窗体背景图片设置方法:重写paintComponent(Graphics g)方法

    public class BackgroundImage extends JFrame { public BackgroundImage() { this.setTitle("窗体背景图片设 ...

  10. 64位CentOS上编译 Hadoop 2.2.0

    下载了Hadoop预编译好的二进制包,hadoop-2.2.0.tar.gz,启动起来后.总是出现这样的警告: WARN util.NativeCodeLoader: Unable to load n ...