From: Andrew Nguyen <arethusa26@gmail.com> Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=23326 --- dlls/comdlg32/printdlg.c | 77 ++++++++++++++++++++++++++-------- dlls/comdlg32/tests/printdlg.c | 74 ++++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+), 17 deletions(-) diff --git a/dlls/comdlg32/printdlg.c b/dlls/comdlg32/printdlg.c index 6fed7f124b0..b798e74de6d 100644 --- a/dlls/comdlg32/printdlg.c +++ b/dlls/comdlg32/printdlg.c @@ -2073,6 +2073,7 @@ static INT_PTR CALLBACK PrintDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { PRINT_PTRA* PrintStructures; + DWORD hook_flags; INT_PTR res = FALSE; if (uMsg!=WM_INITDIALOG) { @@ -2087,21 +2088,40 @@ static INT_PTR CALLBACK PrintDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, EndDialog(hDlg,FALSE); return FALSE; } - res = PRINTDLG_WMInitDialog(hDlg, PrintStructures); + res = PRINTDLG_WMInitDialog(hDlg, PrintStructures); + + hook_flags = PrintStructures->lpPrintDlg->Flags & + (PD_PRINTSETUP | PD_ENABLEPRINTHOOK | PD_ENABLESETUPHOOK); + + if (hook_flags == PD_ENABLEPRINTHOOK) { + res = PrintStructures->lpPrintDlg->lpfnPrintHook( + hDlg, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg + ); + } else if (hook_flags == (PD_PRINTSETUP | PD_ENABLESETUPHOOK)) { + res = PrintStructures->lpPrintDlg->lpfnSetupHook( + hDlg, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg + ); + } - if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) - res = PrintStructures->lpPrintDlg->lpfnPrintHook( - hDlg, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg - ); - return res; + return res; } - if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) { - res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam, - lParam); - if(res) return res; + hook_flags = PrintStructures->lpPrintDlg->Flags & + (PD_PRINTSETUP | PD_ENABLEPRINTHOOK | PD_ENABLESETUPHOOK); + + if (hook_flags == PD_ENABLEPRINTHOOK) { + res = PrintStructures->lpPrintDlg->lpfnPrintHook( + hDlg, uMsg, wParam, lParam + ); + } else if (hook_flags == (PD_PRINTSETUP | PD_ENABLESETUPHOOK)) { + res = PrintStructures->lpPrintDlg->lpfnSetupHook( + hDlg, uMsg, wParam, lParam + ); } + if(res) + return res; + switch (uMsg) { case WM_COMMAND: return PRINTDLG_WMCommandA(hDlg, wParam, PrintStructures); @@ -2122,6 +2142,7 @@ static INT_PTR CALLBACK PrintDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { PRINT_PTRW* PrintStructures; + DWORD hook_flags; INT_PTR res = FALSE; if (uMsg!=WM_INITDIALOG) { @@ -2136,18 +2157,40 @@ static INT_PTR CALLBACK PrintDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam, EndDialog(hDlg,FALSE); return FALSE; } - res = PRINTDLG_WMInitDialogW(hDlg, PrintStructures); + res = PRINTDLG_WMInitDialogW(hDlg, PrintStructures); + + hook_flags = PrintStructures->lpPrintDlg->Flags & + (PD_PRINTSETUP | PD_ENABLEPRINTHOOK | PD_ENABLESETUPHOOK); + + if (hook_flags == PD_ENABLEPRINTHOOK) { + res = PrintStructures->lpPrintDlg->lpfnPrintHook( + hDlg, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg + ); + } else if (hook_flags == (PD_PRINTSETUP | PD_ENABLESETUPHOOK)) { + res = PrintStructures->lpPrintDlg->lpfnSetupHook( + hDlg, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg + ); + } - if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) - res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg); - return res; + return res; } - if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) { - res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam, lParam); - if(res) return res; + hook_flags = PrintStructures->lpPrintDlg->Flags & + (PD_PRINTSETUP | PD_ENABLEPRINTHOOK | PD_ENABLESETUPHOOK); + + if (hook_flags == PD_ENABLEPRINTHOOK) { + res = PrintStructures->lpPrintDlg->lpfnPrintHook( + hDlg, uMsg, wParam, lParam + ); + } else if (hook_flags == (PD_PRINTSETUP | PD_ENABLESETUPHOOK)) { + res = PrintStructures->lpPrintDlg->lpfnSetupHook( + hDlg, uMsg, wParam, lParam + ); } + if(res) + return res; + switch (uMsg) { case WM_COMMAND: return PRINTDLG_WMCommandW(hDlg, wParam, PrintStructures); diff --git a/dlls/comdlg32/tests/printdlg.c b/dlls/comdlg32/tests/printdlg.c index c17d8153e7c..8412892b349 100644 --- a/dlls/comdlg32/tests/printdlg.c +++ b/dlls/comdlg32/tests/printdlg.c @@ -147,6 +147,12 @@ static UINT_PTR CALLBACK printer_properties_hook_procA(HWND hdlg, UINT msg, WPAR return 0; } +static UINT_PTR CALLBACK check_hook_proc_not_called(HWND hdlg, UINT msg, WPARAM wp, LPARAM lp) +{ + ok(0, "Hook proc should not be called\n"); + return 0; +} + static UINT_PTR CALLBACK check_hook_proc_msg_handlingA(HWND hdlg, UINT msg, WPARAM wp, LPARAM lp) { if (msg == WM_INITDIALOG) @@ -346,6 +352,40 @@ static void test_PrintDlgA(void) ok(res, "PrintDlg error %#lx\n", CommDlgExtendedError()); ok(hook_inited, "expected hook procedure to be called with WM_INITDIALOG\n"); + /* Validate some message handling behaviors of a setup dialog hook. */ + ZeroMemory(pDlg, sizeof(*pDlg)); + hook_inited = FALSE; + pDlg->lStructSize = sizeof(*pDlg); + pDlg->Flags = PD_PRINTSETUP | PD_ENABLESETUPHOOK; + pDlg->lpfnSetupHook = check_hook_proc_msg_handlingA; + pDlg->lCustData = (LPARAM)&hook_inited; + res = PrintDlgA(pDlg); + ok(res, "PrintDlg error %#lx\n", CommDlgExtendedError()); + ok(hook_inited, "expected hook procedure to be called with WM_INITDIALOG\n"); + + /* If both hooks are specified, only the appropriate one for the specified mode is invoked. */ + ZeroMemory(pDlg, sizeof(*pDlg)); + hook_inited = FALSE; + pDlg->lStructSize = sizeof(*pDlg); + pDlg->Flags = PD_ENABLEPRINTHOOK | PD_ENABLESETUPHOOK; + pDlg->lpfnPrintHook = check_hook_proc_msg_handlingA; + pDlg->lpfnSetupHook = check_hook_proc_not_called; + pDlg->lCustData = (LPARAM)&hook_inited; + res = PrintDlgA(pDlg); + ok(res, "PrintDlg error %#lx\n", CommDlgExtendedError()); + ok(hook_inited, "expected hook procedure to be called with WM_INITDIALOG\n"); + + ZeroMemory(pDlg, sizeof(*pDlg)); + hook_inited = FALSE; + pDlg->lStructSize = sizeof(*pDlg); + pDlg->Flags = PD_PRINTSETUP | PD_ENABLEPRINTHOOK | PD_ENABLESETUPHOOK; + pDlg->lpfnPrintHook = check_hook_proc_not_called; + pDlg->lpfnSetupHook = check_hook_proc_msg_handlingA; + pDlg->lCustData = (LPARAM)&hook_inited; + res = PrintDlgA(pDlg); + ok(res, "PrintDlg error %#lx\n", CommDlgExtendedError()); + ok(hook_inited, "expected hook procedure to be called with WM_INITDIALOG\n"); + free(pDlg); } @@ -437,6 +477,40 @@ void test_PrintDlgW(void) res = PrintDlgW(&pd); ok(res, "PrintDlg error %#lx\n", CommDlgExtendedError()); ok(hook_inited, "expected hook procedure to be called with WM_INITDIALOG\n"); + + /* Validate some message handling behaviors of a setup dialog hook. */ + ZeroMemory(&pd, sizeof(pd)); + hook_inited = FALSE; + pd.lStructSize = sizeof(pd); + pd.Flags = PD_PRINTSETUP | PD_ENABLESETUPHOOK; + pd.lpfnSetupHook = check_hook_proc_msg_handlingW; + pd.lCustData = (LPARAM)&hook_inited; + res = PrintDlgW(&pd); + ok(res, "PrintDlg error %#lx\n", CommDlgExtendedError()); + ok(hook_inited, "expected hook procedure to be called with WM_INITDIALOG\n"); + + /* If both hooks are specified, only the appropriate one for the specified mode is invoked. */ + ZeroMemory(&pd, sizeof(pd)); + hook_inited = FALSE; + pd.lStructSize = sizeof(pd); + pd.Flags = PD_ENABLEPRINTHOOK | PD_ENABLESETUPHOOK; + pd.lpfnPrintHook = check_hook_proc_msg_handlingW; + pd.lpfnSetupHook = check_hook_proc_not_called; + pd.lCustData = (LPARAM)&hook_inited; + res = PrintDlgW(&pd); + ok(res, "PrintDlg error %#lx\n", CommDlgExtendedError()); + ok(hook_inited, "expected hook procedure to be called with WM_INITDIALOG\n"); + + ZeroMemory(&pd, sizeof(pd)); + hook_inited = FALSE; + pd.lStructSize = sizeof(pd); + pd.Flags = PD_PRINTSETUP | PD_ENABLEPRINTHOOK | PD_ENABLESETUPHOOK; + pd.lpfnPrintHook = check_hook_proc_not_called; + pd.lpfnSetupHook = check_hook_proc_msg_handlingW; + pd.lCustData = (LPARAM)&hook_inited; + res = PrintDlgW(&pd); + ok(res, "PrintDlg error %#lx\n", CommDlgExtendedError()); + ok(hook_inited, "expected hook procedure to be called with WM_INITDIALOG\n"); } /* ########################### */ -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/11087