我在做UI的时候,主界面用了WM_SYSCOMMAND消息,但发现用了之后主界面的菜单没反应了,请问怎么解决?在WM_SYSCOMMAND的处理函数中,我返回了DefWindowProc(hwnd, WM_SYSCOMMAND, wParam,lParam);所以没有其他问题,就是菜单没反应。谢谢。

解决方案 »

  1.   

    //对话框消息处理宏
    #define HANDLE_DLGMSG(hwnd, message, fn) \
    case (message): return (SetDlgMsgResult(hwnd, uMsg,\
    HANDLE_##message((hwnd), (wParam), (lParam), (fn))))int Main_OnSysCommand(HWND hwnd, int wParam, int lParam, UINT codeNotify) 
    {
    switch (wParam)
    {
    case SC_CLOSE:
    EndDialog(hwnd, wParam);
    break;
    case SC_DEFAULT:
    break;
    case SC_MINIMIZE:
    break;
    case SC_MOUSEMENU:
    break;
    case SC_KEYMENU:
    break;
    }
    // Any WM_SYSCOMMAND messages not handled by the application 
    // must be passed to DefWindowProc*/
    return DefWindowProc(hwnd, WM_SYSCOMMAND, wParam,lParam);
    }
    //------------------------------------------------------------------------------
    // main proc function
    //------------------------------------------------------------------------------
    int WINAPI MainProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
        switch (uMsg) 
        {   
    HANDLE_DLGMSG(hwnd, WM_INITDIALOG, Main_OnInitDialog);
    HANDLE_DLGMSG(hwnd, WM_SIZE, Main_OnSize);
    HANDLE_DLGMSG(hwnd, WM_COMMAND, Main_OnCommand);
    HANDLE_DLGMSG(hwnd, WM_SYSCOMMAND, Main_OnSysCommand);
        }
        return 0;
    }  
    关键部分只有这些,谢谢~
      

  2.   

    菜单响应的应该是WM_COMMAND 详看MSDN上的WM_SYSCOMMAND说明WM_SYSCOMMAND
    A window receives this message when the user chooses a command from the window menu (formerly known as the system or control menu) or when the user chooses the maximize button, minimize button, restore button, or close button.WM_SYSCOMMAND 
    uCmdType = wParam;        // type of system command requested 
    xPos = LOWORD(lParam);    // horizontal position, in screen coordinates 
    yPos = HIWORD(lParam);    // vertical position, in screen coordinates 
     
    Parameters
    uCmdType 
    Specifies the type of system command requested. This parameter can be one of the following values. Value Meaning 
    SC_CLOSE Closes the window. 
    SC_CONTEXTHELP Changes the cursor to a question  with a pointer. If the user then clicks a control in the dialog box, the control receives a WM_HELP message. 
    SC_DEFAULT Selects the default item; the user double-clicked the window menu. 
    SC_HOTKEY Activates the window associated with the application-specified hot key. The low-order word of lParam identifies the window to activate. 
    SC_HSCROLL Scrolls horizontally. 
    SC_KEYMENU Retrieves the window menu as a result of a keystroke. 
    SC_MAXIMIZE Maximizes the window. 
    SC_MINIMIZE Minimizes the window. 
    SC_MONITORPOWER   Sets the state of the display. This command supports devices that have power-saving features, such as a battery-powered personal computer.
    lParam can have the following values:1 means the display is going to low power.2 means the display is being shut off.
     
    SC_MOUSEMENU Retrieves the window menu as a result of a mouse click. 
    SC_MOVE Moves the window. 
    SC_NEXTWINDOW Moves to the next window. 
    SC_PREVWINDOW Moves to the previous window. 
    SC_RESTORE Restores the window to its normal position and size. 
    SC_SCREENSAVE Executes the screen saver application specified in the [boot] section of the SYSTEM.INI file. 
    SC_SIZE Sizes the window. 
    SC_TASKLIST Activates the Start menu. 
    SC_VSCROLL Scrolls vertically.