zoukankan      html  css  js  c++  java
  • SDK Hello world(直接使用SDK封装)

    前言

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

    实验工程

    [cpp] view plaincopy在CODE上查看代码片派生到我的代码片
     
    1. /// @file exam_1.cpp  
    2. /// @brief 查阅本地MSDN, 手工写SDK程序  
    3.   
    4. #include "common.h"  
    5.   
    6. #include "ErrorProc.h"  
    7. #include "WindowProc.h"  
    8.   
    9. int WINAPI WinMain(HINSTANCE hInstance,  
    10.                    HINSTANCE hPrevInstance,  
    11.                    LPSTR lpCmdLine,  
    12.                    int nCmdShow) {  
    13.     if (!fnRegisterClass(hInstance, hPrevInstance, lpCmdLine, nCmdShow)) {  
    14.         ShowErrMsg();  
    15.         goto WINMAIN_END;  
    16.     }  
    17.   
    18.     if (!fnCreateWindow(hInstance, hPrevInstance, lpCmdLine, nCmdShow)) {  
    19.         ShowErrMsg();  
    20.         goto WINMAIN_END;  
    21.     }  
    22.       
    23.     MsgLoop();  
    24.       
    25. WINMAIN_END:  
    26.     return 0;  
    27. }  
     
    [cpp] view plaincopy在CODE上查看代码片派生到我的代码片
     
    1. /// @file common.h  
    2. /// @brief 公用头文件  
    3.   
    4. #ifndef COMMON_H_2016_0128  
    5. #define COMMON_H_2016_0128  
    6.   
    7. #define _WIN32_WINDOWS 0x500  
    8.   
    9. #include <windows.h>  
    10. #include <tchar.h>  
    11. #include <stdlib.h>  
    12. #include <stdio.h>  
    13.   
    14. #endif // #ifndef COMMON_H_2016_0128  

    [cpp] view plaincopy在CODE上查看代码片派生到我的代码片
     
    1. /// @file ErrorProc.h  
    2. /// @brief 错误处理  
    3.   
    4. #ifndef ERRORPROC_H_2016_0128  
    5. #define ERRORPROC_H_2016_0128  
    6.   
    7. const TCHAR* StringFormatV(TCHAR* szFormat, ...);  
    8. void ShowMsg(const TCHAR* pcMsg);  
    9. void ShowErrMsg();  
    10. BOOL isQuitProg(HWND hWnd);  
    11.   
    12. #endif // #ifndef ERRORPROC_H_2016_0128  

    [cpp] view plaincopy在CODE上查看代码片派生到我的代码片
     
    1. /// @file WindowProc.h  
    2. /// @brief 消息处理  
    3.   
    4. /// 消息处理函数命名规范  
    5. /// OnX On说明是Windows消息处理函数  
    6. /// X是消息 WM_X 去掉 WM_ 之后,按照将X按照匈牙利写法拼在On后面  
    7. /// e.g. WM_CLOSE消息处理函数为OnClose  
    8.   
    9. #ifndef WINDOWPROC_H_2016_0128  
    10. #define WINDOWPROC_H_2016_0128  
    11.   
    12. #include "common.h"  
    13.   
    14. BOOL fnRegisterClass(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);  
    15. BOOL fnCreateWindow(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);  
    16. void MsgLoop();  
    17. HWND getMainWnd();  
    18. HINSTANCE getInstance();  
    19.   
    20. LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);  
    21. LONG fnDispatchMessage(CONST MSG* lpMsg);  
    22. BOOL OnKeyDown(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);  
    23. BOOL OnChar(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);  
    24. BOOL OnSysDeadChar(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);  
    25. BOOL OnSysChar(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);  
    26. BOOL OnSysKeyDown(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);  
    27. BOOL OnSysKeyUp(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);  
    28.   
    29. BOOL OnMouse(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);  
    30. BOOL OnMouseMove(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);  
    31. BOOL OnMouseWheel(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);  
    32. BOOL OnMouseLButtonDown(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);  
    33. BOOL OnMouseLButtonUp(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);  
    34. BOOL OnMouseLButtonDblClk(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);  
    35. BOOL OnMouseRButtonDown(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);  
    36. BOOL OnMouseRButtonUp(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);  
    37. BOOL OnMouseRButtonDblClk(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);  
    38. BOOL OnMouseMButtonDown(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);  
    39. BOOL OnMouseMButtonUp(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);  
    40. BOOL OnMouseMButtonDblClk(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);  
    41.   
    42. BOOL OnClose(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);  
    43. BOOL OnDestory(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);  
    44.   
    45.   
    46.   
    47. #endif // #ifndef WINDOWPROC_H_2016_0128  

    [cpp] view plaincopy在CODE上查看代码片派生到我的代码片
     
    1. /// @file common.cpp  
    2. /// @brief 公用头文件对应的实现  
    3.   
    4. #include "common.h"  

    [cpp] view plaincopy在CODE上查看代码片派生到我的代码片
     
    1. /// @file ErrorProc.cpp  
    2. /// @brief 错误处理实现  
    3.   
    4. #include "common.h"  
    5. #include "ErrorProc.h"  
    6. #include "WindowProc.h"  
    7.   
    8. BOOL isQuitProg(HWND hWnd) {  
    9.     BOOL bRc = FALSE;  
    10.       
    11.     if (IDYES == MessageBox(hWnd, _T("是否退出?"), _T("提示"), MB_YESNO)) {  
    12.         bRc = TRUE;  
    13.     }  
    14.       
    15.     return bRc; ///< true is quit prog  
    16. }  
    17.   
    18. void ShowErrMsg() {  
    19.     LPVOID lpMsgBuf = NULL;  
    20.       
    21.     FormatMessage(   
    22.         FORMAT_MESSAGE_ALLOCATE_BUFFER   
    23.         | FORMAT_MESSAGE_FROM_SYSTEM  
    24.         | FORMAT_MESSAGE_IGNORE_INSERTS,  
    25.         NULL,  
    26.         GetLastError(),  
    27.         MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language  
    28.         (LPTSTR)&lpMsgBuf,  
    29.         0,  
    30.         NULL);  
    31.       
    32.     MessageBox(getMainWnd(), (LPCTSTR)lpMsgBuf, _T("Error"), MB_OK | MB_ICONINFORMATION);  
    33.     LocalFree(lpMsgBuf);  
    34. }  
    35.   
    36. const TCHAR* StringFormatV(TCHAR* szFormat, ...)  
    37. {  
    38.     /// 在栈空间上拼字符串, 如果new的话, 容易引起内存碎片  
    39.     /// 运行的次数多了,有可能分配不出内存来  
    40.     static TCHAR s_cBuf[4096] = {''}; ///< _vsntprintf做了处理, 最多就是打印不全  
    41.     int iStringLen = 0;  
    42.     va_list args;  
    43.       
    44.     va_start(args, szFormat);  
    45.     iStringLen = _vsntprintf(s_cBuf, (sizeof(s_cBuf) / sizeof(TCHAR)) - 1, szFormat, args);  
    46.     va_end(args);  
    47.       
    48.     return s_cBuf;  
    49. }  
    50.   
    51. void ShowMsg(const TCHAR* pcMsg) {  
    52.     if (NULL != pcMsg) {  
    53.         OutputDebugString(pcMsg);  
    54.     }  
    55. }  

    [cpp] view plaincopy在CODE上查看代码片派生到我的代码片
     
    1. /// @file WindowProc.cpp  
    2. /// @brief Windows消息处理的实现  
    3.   
    4. #include "WindowProc.h"  
    5. #include "ErrorProc.h"  
    6.   
    7. static HWND g_hWnd = NULL;  
    8. static HINSTANCE g_hInstance = NULL;  
    9.   
    10. HWND getMainWnd() {  
    11.     return g_hWnd;  
    12. }  
    13.   
    14. HINSTANCE getInstance() {  
    15.     return g_hInstance;  
    16. }  
    17.   
    18. BOOL fnRegisterClass(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {  
    19.     /// 设计,注册窗口类  
    20.     BOOL bRc = TRUE;  
    21.     ATOM _atom;  
    22.     WNDCLASS WndClass = {0};  
    23.       
    24.     // 拥有了经典样式 CS_DBLCLKS, 才会响应双击操作  
    25.     WndClass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;  
    26.     WndClass.lpfnWndProc = &WindowProc;  
    27.     WndClass.cbClsExtra = 0;  
    28.     WndClass.cbWndExtra = 0;  
    29.     WndClass.hInstance = hInstance;  
    30.     WndClass.hIcon = NULL;  
    31.     WndClass.hCursor = NULL /*LoadCursor(NULL, IDC_ARROW)*/;  
    32.     WndClass.hbrBackground = (HBRUSH)COLOR_WINDOW;  
    33.     WndClass.lpszMenuName = NULL;  
    34.     WndClass.lpszClassName = _T("test class");///< 不能为空  
    35.       
    36.     _atom = RegisterClass(&WndClass);  
    37.     if (0 == _atom) {  
    38.         bRc = FALSE;  
    39.     }  
    40.   
    41.     g_hInstance = hInstance;  
    42.     return bRc;  
    43. }  
    44.   
    45. BOOL fnCreateWindow(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {  
    46.     /// 创建, 显示窗口  
    47.     BOOL bRc = TRUE;  
    48.   
    49.     g_hWnd = CreateWindow(  
    50.         _T("test class"),  // pointer to registered class name  
    51.         _T("test class window"), // pointer to window name  
    52.         WS_OVERLAPPEDWINDOW,        // window style  
    53.         100,                // horizontal position of window  
    54.         100,                // vertical position of window  
    55.         800,           // window width  
    56.         600,          // window height  
    57.         NULL,      // handle to parent or owner window  
    58.         NULL,          // handle to menu or child-window identifier  
    59.         hInstance,     // handle to application instance  
    60.         NULL        // pointer to window-creation data  
    61.         );  
    62.   
    63.     if (NULL == g_hWnd) {  
    64.         bRc = FALSE;  
    65.         goto FNCREATEWINDOW_END;  
    66.     }  
    67.       
    68.     ShowMsg(StringFormatV(_T("g_hWnd = 0x%X "), g_hWnd));  
    69.     ShowWindow(g_hWnd, SW_SHOWNORMAL);  
    70.   
    71.     UpdateWindow(g_hWnd);  
    72.   
    73. FNCREATEWINDOW_END:  
    74.     return bRc;  
    75. }  
    76.   
    77. void MsgLoop() {  
    78.     /// 消息循环  
    79.     MSG msg;  
    80.       
    81.     // GetMessage参数2必须是NULL, 如果是g_hWnd, 会在WM_NCDESTROY后,  
    82.     // msg子项内容都全变成0, 变成一个死循环  
    83.     // 如果第2个参数为NULL, 会接收本进程所有窗口(线程)的消息  
    84.     ShowMsg(_T(">> MsgLoop() "));  
    85.     while (GetMessage(  
    86.         &msg,         // address of structure with message  
    87.         NULL,     // handle of window  
    88.         0,  // first message  
    89.         0   // last message  
    90.         )) {  
    91.         TranslateMessage(&msg); ///< 键盘消息到字符消息(多投递一个WM_CHAR消息)  
    92.         fnDispatchMessage(&msg); ///< DispatchMessage不是必须的,我们也可以自己实现  
    93.     }  
    94.   
    95.     ShowMsg(_T("<< MsgLoop() "));  
    96. }  
    97.   
    98. LONG fnDispatchMessage(CONST MSG* lpMsg) {  
    99.     long lRc = 0;  
    100.     int iLen = 0;  
    101.     TCHAR cBuf[MAXBYTE] = {_T('')};  
    102.     WNDCLASS WndClass = {0};  
    103.   
    104.     if (NULL == lpMsg)  
    105.         goto FNDISPATCHMESSAGE_END;  
    106.   
    107.     iLen = GetClassName(lpMsg->hwnd, cBuf, sizeof(cBuf)/sizeof(TCHAR));  
    108.     if (iLen <= 0)  
    109.         goto FNDISPATCHMESSAGE_END;  
    110.   
    111.     if (!GetClassInfo(getInstance(), cBuf, &WndClass))  
    112.         goto FNDISPATCHMESSAGE_END;  
    113.   
    114.     if (NULL == WndClass.lpfnWndProc)  
    115.         goto FNDISPATCHMESSAGE_END;  
    116.   
    117.     lRc = WndClass.lpfnWndProc(lpMsg->hwnd, lpMsg->message, lpMsg->wParam, lpMsg->lParam);  
    118.   
    119. FNDISPATCHMESSAGE_END:  
    120.     return lRc;  
    121. }  
    122.   
    123. /** 
    124. WM_XXX  
    125. 键盘,鼠标,绘制消息 
    126.  
    127.   WM_COMMAND 
    128.   菜单,快捷键消息 
    129.   快捷键消息和键盘消息不同。 
    130.   键盘消息是一个一个的按键 
    131.   快捷键消息是组合键. 
    132.    
    133.     WM_NOTIFY 
    134.     子窗口的消息 
    135. */  
    136. LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {  
    137.     BOOL bCallDefWindowProc = TRUE;  
    138.     LRESULT lRc = 0;  
    139.   
    140.     ShowMsg(StringFormatV(_T("uMsg = 0x%X "), uMsg));  
    141.   
    142.     /// 编码规范, 必须单独封装处理消息的函数OnMsg,   
    143.     /// 不允许在WindowProc中写具体的消息处理实现  
    144.     switch (uMsg) {  
    145.     case WM_KEYDOWN:  
    146.         bCallDefWindowProc = OnKeyDown(lRc, hwnd, uMsg, wParam, lParam);  
    147.         break;  
    148.           
    149.     case WM_CHAR:  
    150.         bCallDefWindowProc = OnChar(lRc, hwnd, uMsg, wParam, lParam);  
    151.         break;  
    152.   
    153.     case WM_SYSDEADCHAR:  
    154.         bCallDefWindowProc = OnSysDeadChar(lRc, hwnd, uMsg, wParam, lParam);  
    155.         break;  
    156.   
    157.     case WM_SYSCHAR:  
    158.         bCallDefWindowProc = OnSysChar(lRc, hwnd, uMsg, wParam, lParam);  
    159.         break;  
    160.   
    161.     case WM_SYSKEYDOWN:  
    162.         bCallDefWindowProc = OnSysKeyDown(lRc, hwnd, uMsg, wParam, lParam);  
    163.         break;  
    164.   
    165.     case WM_SYSKEYUP:  
    166.         bCallDefWindowProc = OnSysKeyUp(lRc, hwnd, uMsg, wParam, lParam);  
    167.         break;  
    168.   
    169.     case WM_MOUSEMOVE:  
    170.     case WM_MOUSEWHEEL:  
    171.     case WM_LBUTTONDOWN:  
    172.     case WM_LBUTTONUP:  
    173.     case WM_LBUTTONDBLCLK:  
    174.     case WM_RBUTTONDOWN:  
    175.     case WM_RBUTTONUP:  
    176.     case WM_RBUTTONDBLCLK:  
    177.     case WM_MBUTTONDOWN:  
    178.     case WM_MBUTTONUP:  
    179.     case WM_MBUTTONDBLCLK:  
    180.         bCallDefWindowProc = OnMouse(lRc, hwnd, uMsg, wParam, lParam);  
    181.         break;  
    182.   
    183.     case WM_CLOSE:  
    184.         bCallDefWindowProc = OnClose(lRc, hwnd, uMsg, wParam, lParam);  
    185.         break;  
    186.   
    187.     case WM_DESTROY:  
    188.         bCallDefWindowProc = OnDestory(lRc, hwnd, uMsg, wParam, lParam);  
    189.         break;  
    190.           
    191.     default:  
    192.         break;  
    193.     }  
    194.       
    195.     /// The DefWindowProc function calls the default window procedure   
    196.     /// to provide default processing for any window messages   
    197.     /// that an application does not process.   
    198.     return bCallDefWindowProc ? DefWindowProc(hwnd, uMsg, wParam, lParam) : lRc;  
    199. }  
    200.   
    201. BOOL OnKeyDown(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {  
    202.     /// 如果不调用 TranslateMessage, 可以自己取按键值  
    203.     /// 如果调用了 TranslateMessage, 在OnChar中直接取键值  
    204.   
    205.     ShowMsg(_T("OnKeyDown "));  
    206.   
    207.     int nVirtKey = (int) wParam;    // virtual-key code   
    208.     ULONG ulKeyData = lParam;          // key data   
    209.     BYTE ucKeyState[256] = {0};  
    210.     WORD wChar = 0;  
    211.     int iRc = 0;  
    212.     /** 
    213.     lKeyData  
    214.     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  
    215.     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.  
    216.     16–23 Specifies the scan code. The value depends on the original equipment manufacturer (OEM).  
    217.     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.  
    218.     25–28 Reserved; do not use.  
    219.     29 Specifies the context code. The value is always 0 for a WM_KEYDOWN message.  
    220.     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.  
    221.     31 Specifies the transition state. The value is always 0 for a WM_KEYDOWN message.  
    222.     */  
    223.   
    224.     if (!GetKeyboardState(&ucKeyState[0])) {  
    225.         goto ONKEYDOWN_END;  
    226.     }  
    227.   
    228.     if (ToAscii(nVirtKey, (ulKeyData >> 16) & 0xff, ucKeyState, &wChar, 0) <= 0) {  
    229.         goto ONKEYDOWN_END;  
    230.     }  
    231.   
    232.     ShowMsg(StringFormatV(_T("%c "), (TCHAR)wChar));  
    233.   
    234. ONKEYDOWN_END:  
    235.     lRc = 0;  
    236.     return TRUE;  
    237. }  
    238.   
    239. BOOL OnChar(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {  
    240.     ShowMsg(StringFormatV(_T("%c "), (TCHAR)wParam));  
    241.     lRc = 0;  
    242.     return TRUE;  
    243. }  
    244.   
    245. BOOL OnSysDeadChar(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {  
    246.     lRc = 0;  
    247.     return TRUE;  
    248. }  
    249.   
    250. BOOL OnSysChar(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {  
    251.     lRc = 0;  
    252.     return TRUE;  
    253. }  
    254.   
    255. BOOL OnSysKeyDown(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {  
    256.     /// F10 press down  
    257.     lRc = 0;  
    258.     return TRUE;  
    259. }  
    260.   
    261. BOOL OnSysKeyUp(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {  
    262.     /// F10 press up  
    263.     lRc = 0;  
    264.     return TRUE;  
    265. }  
    266.   
    267. BOOL OnMouse(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {  
    268.     BOOL bRc = FALSE;  
    269. //     POINTS pt;  
    270. //     UINT uMK = 0; // key flags   
    271. //     WORD xPos = 0; // horizontal position of cursor   
    272. //     WORD yPos = 0; // vertical position of cursor   
    273.   
    274.     if ((uMsg < WM_MOUSEFIRST) || (uMsg > WM_MOUSELAST))  
    275.         goto ONMOUSE_END;  
    276.   
    277.         /** 
    278.         * Key State Masks for Mouse Messages 
    279.         #define MK_LBUTTON          0x0001 
    280.         #define MK_RBUTTON          0x0002 
    281.         #define MK_SHIFT            0x0004 
    282.         #define MK_CONTROL          0x0008 
    283.         #define MK_MBUTTON          0x0010 
    284.     */  
    285. //     uMK = wParam;  
    286. //     xPos = LOWORD(lParam);  
    287. //     yPos = HIWORD(lParam);  
    288. //     pt = MAKEPOINTS(lParam);  
    289.   
    290.     switch (uMsg) {  
    291.         // 移动  
    292.     case WM_MOUSEMOVE:  
    293.         bRc = OnMouseMove(lRc, hwnd, uMsg, wParam, lParam);  
    294.         break;  
    295.   
    296.         // 滑过  
    297.     case WM_MOUSEWHEEL:  
    298.         bRc = OnMouseWheel(lRc, hwnd, uMsg, wParam, lParam);  
    299.         break;  
    300.   
    301.         // 左键  
    302.     case WM_LBUTTONDOWN:  
    303.         bRc = OnMouseLButtonDown(lRc, hwnd, uMsg, wParam, lParam);  
    304.         break;  
    305.   
    306.     case WM_LBUTTONUP:  
    307.         bRc = OnMouseLButtonUp(lRc, hwnd, uMsg, wParam, lParam);  
    308.         break;  
    309.   
    310.     case WM_LBUTTONDBLCLK:  
    311.         bRc = OnMouseLButtonDblClk(lRc, hwnd, uMsg, wParam, lParam);  
    312.         break;  
    313.   
    314.         // 右键  
    315.     case WM_RBUTTONDOWN:  
    316.         bRc = OnMouseRButtonDown(lRc, hwnd, uMsg, wParam, lParam);  
    317.         break;  
    318.   
    319.     case WM_RBUTTONUP:  
    320.         bRc = OnMouseRButtonUp(lRc, hwnd, uMsg, wParam, lParam);  
    321.         break;  
    322.   
    323.     case WM_RBUTTONDBLCLK:  
    324.         bRc = OnMouseRButtonDblClk(lRc, hwnd, uMsg, wParam, lParam);  
    325.         break;  
    326.   
    327.         // 中键  
    328.     case WM_MBUTTONDOWN:  
    329.         bRc = OnMouseMButtonDown(lRc, hwnd, uMsg, wParam, lParam);  
    330.         break;  
    331.   
    332.     case WM_MBUTTONUP:  
    333.         bRc = OnMouseMButtonUp(lRc, hwnd, uMsg, wParam, lParam);  
    334.         break;  
    335.   
    336.     case WM_MBUTTONDBLCLK:  
    337.         bRc = OnMouseMButtonDblClk(lRc, hwnd, uMsg, wParam, lParam);  
    338.         break;  
    339.   
    340.     default:  
    341.         break;  
    342.     }  
    343.   
    344. ONMOUSE_END:  
    345.     lRc = 0;  
    346.     return bRc; ///< bCallDefWindowProc  
    347. }  
    348.   
    349. BOOL OnMouseMove(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {  
    350.     lRc = 0;  
    351.     return TRUE;  
    352. }  
    353.   
    354. BOOL OnMouseWheel(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {  
    355.     lRc = 0;  
    356.     return TRUE;  
    357. }  
    358.   
    359. BOOL OnMouseLButtonDown(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {  
    360.     ShowMsg(StringFormatV(_T("OnMouseLButtonDown, hwnd = 0x%X "), hwnd));  
    361.     // MessageBox(hwnd, _T("OnMouseLButtonDown"), _T("SDK Frame"), MB_OK);  
    362.     lRc = 0;  
    363.     return TRUE;  
    364. }  
    365.   
    366. BOOL OnMouseLButtonUp(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {  
    367.     ShowMsg(StringFormatV(_T("OnMouseLButtonUp, hwnd = 0x%X "), hwnd));  
    368.     lRc = 0;  
    369.     return TRUE;  
    370. }  
    371.   
    372. BOOL OnMouseLButtonDblClk(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {  
    373.     ShowMsg(_T("OnMouseLButtonDblClk "));  
    374.     lRc = 0;  
    375.     return TRUE;  
    376. }  
    377.   
    378. BOOL OnMouseRButtonDown(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {  
    379.     lRc = 0;  
    380.     return TRUE;  
    381. }  
    382.   
    383. BOOL OnMouseRButtonUp(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {  
    384.     lRc = 0;  
    385.     return TRUE;  
    386. }  
    387.   
    388. BOOL OnMouseRButtonDblClk(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {  
    389.     lRc = 0;  
    390.     return TRUE;  
    391. }  
    392.   
    393. BOOL OnMouseMButtonDown(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {  
    394.     lRc = 0;  
    395.     return TRUE;  
    396. }  
    397.   
    398. BOOL OnMouseMButtonUp(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {  
    399.     lRc = 0;  
    400.     return TRUE;  
    401. }  
    402.   
    403. BOOL OnMouseMButtonDblClk(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {  
    404.     lRc = 0;  
    405.     return TRUE;  
    406. }  
    407.   
    408. BOOL OnClose(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {  
    409.     lRc = 0;  
    410.     return isQuitProg(hwnd); ///< bCallDefWindowProc  
    411. }  
    412.   
    413. BOOL OnDestory(OUT LRESULT& lRc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {  
    414.     lRc = 0;  
    415.     // WM_QUIT使GetMessage为FALSE, 跳出消息循环的处理  
    416.     // PostMessage(hwnd, WM_QUIT, 0, 0); ///< ok  
    417.     PostQuitMessage(0); ///< 也会发送WM_QUIT消息  
    418.   
    419.     return TRUE; ///< bCallDefWindowProc  
    420. }  

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

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

  • 相关阅读:
    读写锁机制原理
    jvm
    (WPF) 再议binding:点击User Control时,User Control变换颜色或做其他的处理。
    (WF)
    (C# ) 解析XML。
    (C#) 调用执行批处理文件
    (WPF, Service) 删除注册表中的USB Enum值.
    (C#) 文件操作
    (C#) Parse xml 时, 返回的node值总是null。
    (PowerShell) Managing Windows Registry
  • 原文地址:https://www.cnblogs.com/findumars/p/5174330.html
Copyright © 2011-2022 走看看