当我尝试在窗口过程中使用HANDLE_MSG宏时,出现以下错误:


  错误:标识符“ HANDLE_0xXXXX”未定义


其中0xXXXX取决于我作为宏参数发送的消息(WM_CLOSE为0x0010,WM_DESTROY为0x0002,依此类推)。

谷歌搜索帮助时,我什至没有发现类似问题的任何提及。

我正在Windows 8上使用Visual Studio 2013 Preview用于Windows桌面(尽管VS 2012 Express for WD也是如此)。

一个代码片段:

#include "Precompiled Headers.hpp"    // includes i. a. Windows.h and windowsx.h

#include "MainWindowProcedure.hpp"

LRESULT __stdcall MainWindowProcedure(HWND mainWindow,
                                      UINT receivedMessage,
                                      WPARAM wordParameter,
                                      LPARAM longParameter)
{

    switch (receivedMessage)
    {

        HANDLE_MSG(mainWindow, WM_CLOSE, MainWindowOnClose);

        ...

        default:
            return DefWindowProc(mainWindow,
                                 receivedMessage,
                                 wParam,
                                 lParam);
        break;

    }

    return 0;

}

void MainWindowOnClose(HWND mainWindow)
{

    DestroyWindow(mainWindow);

}

最佳答案

我遇到了同样的问题,只是像下面三个示例所示扩展了Macro。

     //HANDLE_MSG(hwnd, WM_INITDIALOG, OnInitDialog);
case (WM_INITDIALOG) : return HANDLE_WM_INITDIALOG((hwnd), (wParam), (lParam), (OnInitDialog));
    //HANDLE_MSG(hwnd, WM_COMMAND, OnCommand);
case (WM_COMMAND) : return HANDLE_WM_COMMAND((hwnd), (wParam), (lParam), (OnCommand));
    //HANDLE_MSG(hwnd, WM_PAINT, OnPaint);
case (WM_PAINT) : return HANDLE_WM_PAINT((hwnd), (wParam), (lParam), (OnPaint));

10-07 13:38