我正在尝试创建一个将符号常量扩展为case
语句的宏,如下所示:
// #define WM_PAINT 0x000F
LRESULT CALLBACK WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
BIND_MSG(WM_PAINT)
// -> case WM_PAINT: Wnd_Main_WM_PAINT (hWnd, wParam, lParam); break;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
我试了很多东西。我得到的最佳工作宏是:
#define BIND_MSG(msg) case (msg): Wnd_Main_##msg (hWnd, wParam, lParam); break;
但是这个宏不会扩展到Wnd_Main_WM_PAINT
,而是扩展到Wnd_Main_0x000F
。当我尝试Wnd_Main_ ## #msg
代替Wnd_Main_##msg
时,我不会Wnd_Main_WM_PAINT
,而是Wnd_Main_
。是否有可能将Wnd_Main_
与符号常量WM_PAINT
的名称连接起来?
(抱歉,屏幕截图是德语.Visual Studio说,标识符Wnd_Main_0x000F
未定义。)