CreateDialog创建非模态对话框时 其内部 会发送几条消息例如: WM_INITDIALOGWM_SETFONT  DS_SETFONT , DS_SHELLFONT.

所以如果在另一个CallWndProc中调用CreateDailog时,有可能发生递归调用情况。

例如:你用 ::SetWindowsHookEx(WH_CALLWNDPROC, CallWndProc, NULL, thread_id) 的 CallWndProc里调用 CreateDailog时,就会发生递归的情况,最好的做法是利用一个变量来标识是否已经创建对话框

LRESULT CALLBACK CallWndProc(
_In_ int nCode,
_In_ WPARAM wParam,
_In_ LPARAM lParam
)
{
CWPSTRUCT * pMsg = (CWPSTRUCT *)lParam;
if (!g_my_wnd)
{
static bool created = false;
if (!created)
{
created = true;
g_my_wnd = CreateDialog(g_inst, MAKEINTRESOURCE(IDD_DIALOG_MAIN), NULL, DialogProc);
}
OutputDebugStr(L"CreateDialog sucess %d", pMsg->message);
::ShowWindow(g_my_wnd, SW_SHOW);
} return CallNextHookEx(g_hhook_wnd_proc, nCode, wParam, lParam);
}

  

04-25 17:44