From: Andrew Nguyen <arethusa26@gmail.com> --- dlls/comdlg32/tests/printdlg.c | 70 ++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/dlls/comdlg32/tests/printdlg.c b/dlls/comdlg32/tests/printdlg.c index 347f7ddd7b1..c17d8153e7c 100644 --- a/dlls/comdlg32/tests/printdlg.c +++ b/dlls/comdlg32/tests/printdlg.c @@ -147,6 +147,29 @@ static UINT_PTR CALLBACK printer_properties_hook_procA(HWND hdlg, UINT msg, WPAR return 0; } +static UINT_PTR CALLBACK check_hook_proc_msg_handlingA(HWND hdlg, UINT msg, WPARAM wp, LPARAM lp) +{ + if (msg == WM_INITDIALOG) + { + PRINTDLGA* dlg = (PRINTDLGA*)lp; + BOOL* hook_inited = (BOOL*)dlg->lCustData; + + *hook_inited = TRUE; + + PostMessageA(hdlg, WM_COMMAND, IDCANCEL, 0); + } + else if (msg == WM_COMMAND && wp == IDCANCEL) + { + PostMessageA(hdlg, WM_COMMAND, IDOK, 0); + + /* Returning a non-zero value for IDCANCEL should prevent the message + * from being processed further. Otherwise, it would result in the + * dialog closing and PrintDlgA returning FALSE. */ + return TRUE; + } + return 0; +} + static void test_PrintDlgA(void) { DWORD res, n_copies = 0; @@ -158,6 +181,7 @@ static void test_PrintDlgA(void) CHAR buffer[MAX_PATH]; LPSTR ptr; DEVMODEA *dm; + BOOL hook_inited; pDlg = malloc((sizeof(PRINTDLGA)) * 2); if (!pDlg) return; @@ -311,6 +335,17 @@ static void test_PrintDlgA(void) GlobalUnlock(pDlg->hDevMode); GlobalFree(pDlg->hDevMode); + /* Validate some message handling behaviors of a print dialog hook. */ + ZeroMemory(pDlg, sizeof(*pDlg)); + hook_inited = FALSE; + pDlg->lStructSize = sizeof(*pDlg); + pDlg->Flags = PD_ENABLEPRINTHOOK; + pDlg->lpfnPrintHook = 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); } @@ -336,11 +371,35 @@ static UINT_PTR CALLBACK printer_properties_hook_procW(HWND hdlg, UINT msg, WPAR return 0; } +static UINT_PTR CALLBACK check_hook_proc_msg_handlingW(HWND hdlg, UINT msg, WPARAM wp, LPARAM lp) +{ + if (msg == WM_INITDIALOG) + { + PRINTDLGW* dlg = (PRINTDLGW*)lp; + BOOL* hook_inited = (BOOL*)dlg->lCustData; + + *hook_inited = TRUE; + + PostMessageW(hdlg, WM_COMMAND, IDCANCEL, 0); + } + else if (msg == WM_COMMAND && wp == IDCANCEL) + { + PostMessageW(hdlg, WM_COMMAND, IDOK, 0); + + /* Returning a non-zero value for IDCANCEL should prevent the message + * from being processed further. Otherwise, it would result in the + * dialog closing and PrintDlgW returning FALSE. */ + return TRUE; + } + return 0; +} + void test_PrintDlgW(void) { PRINTDLGW pd = { 0 }; DEVMODEW* dm; DWORD name_size = 0; + BOOL res, hook_inited; GetDefaultPrinterW(NULL, &name_size); if(name_size == 0) @@ -367,6 +426,17 @@ void test_PrintDlgW(void) ok(dm->dmPaperSize == 888, "expected 888, but got %d.\n", dm->dmPaperSize); GlobalUnlock(pd.hDevMode); GlobalFree(pd.hDevMode); + + /* Validate some message handling behaviors of a print dialog hook. */ + ZeroMemory(&pd, sizeof(pd)); + hook_inited = FALSE; + pd.lStructSize = sizeof(pd); + pd.Flags = PD_ENABLEPRINTHOOK; + pd.lpfnPrintHook = 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