前言

将代码拆分了一下, 如果处理更多的消息也不怕看的眼花
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. 4种Java引用浅解

    近期研究Java Cache实现,发现使用到了软引用(SoftReference),不太理解,查阅了JDK文档.代码以及几篇文章.做个小结,如有错误,欢迎指正. 之所以想学习一下Java的几种引用类型 ...

  2. 微信网页签名失败(invalid signature)

    签名失败,建议按以下步骤排查 确认签名算法正确,可用 http://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=jsapisign 页面工具进行校验. 确认con ...

  3. Ext JS学习第十六天 事件机制event(一)

    此文用来记录学习笔记: 休息了好几天,从今天开始继续保持更新,鞭策自己学习 今天我们来说一说什么是事件,对于事件,相信你一定不陌生, 基本事件是什么?就类似于click.keypress.focus. ...

  4. CSS中的repeat

    Repeat-x是横向铺满,就是图片会横向重复,直到铺满. Repeat-y是纵向铺满,就是让图片纵向重复,直到铺满. 如果不想让重复,就直接为:no-repeat.

  5. 自定义cell时,在宽的手机上显示太窄解决办法

    1.工程设置要如下:见第二个红框,清除launch screan file 后面的内容 2.自定义的cell要设置auto layout 和size clases

  6. 如何通过java反射将数据库表生成实体类?

    首先有几点声明: 1.代码是在别人的基础进行改写的: 2.大家有什么改进的意见可以告诉我,也可以自己改好共享给其他人: 3.刚刚毕业,水平有限,肯定有许多不足之处: 4.希望刚刚学习java的同学能有 ...

  7. vs2010中iostream.h出错

    使用 #include <iostream> using namespace std; 替代 VS2010删除了所有非标准库,保留了C++标准库,iostream.h是以前旧版的库,VS2 ...

  8. C陷阱与缺陷(二)

    第二章 语法陷阱 2.1 理解函数声明 (*(void(*)())0)();任何C变量的声明都由两部分组成:类型以及一组类似表达式的声明符.一旦我们知道了如何声明一个给定类型的变量,那么该类型的类型转 ...

  9. 用SQL实现统计报表中的"小计"与"合计"的方法详解

    本篇文章是对使用SQL实现统计报表中的"小计"与"合计"的方法进行了详细的分析介绍,需要的朋友参考下   客户提出需求,针对某一列分组加上小计,合计汇总.网上找 ...

  10. 设计模式多线程方面之Thread-Per-Message 模式

    Thread-Per-Message模式是一个很简单但很常应用的模式,尤其是在GUI程式中,我们举个例子,当您设计一个文件编辑器时,您可能像这样注册一个开启档案的事件处理:  menuOpenFile ...