From 433df0d5d8763e24772e60168bb8f1a664bd9ed8 Mon Sep 17 00:00:00 2001 From: Huw Davies Date: Tue, 28 Oct 2014 15:01:18 +0000 Subject: [PATCH] comctl32: Enable the appropriate wizard buttons before sending DM_SETDEFID. --- dlls/comctl32/propsheet.c | 21 +++++---------------- dlls/comctl32/tests/propsheet.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/dlls/comctl32/propsheet.c b/dlls/comctl32/propsheet.c index 0dd1ca74109..5de0debabc5 100644 --- a/dlls/comctl32/propsheet.c +++ b/dlls/comctl32/propsheet.c @@ -2430,15 +2430,16 @@ static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags) HWND hwndBack = GetDlgItem(hwndDlg, IDC_BACK_BUTTON); HWND hwndNext = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON); HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON); + BOOL enable_finish = ((dwFlags & PSWIZB_FINISH) || psInfo->hasFinish) && !(dwFlags & PSWIZB_DISABLEDFINISH); TRACE("%d\n", dwFlags); - EnableWindow(hwndBack, FALSE); - EnableWindow(hwndNext, FALSE); - EnableWindow(hwndFinish, FALSE); + EnableWindow(hwndBack, dwFlags & PSWIZB_BACK); + EnableWindow(hwndNext, dwFlags & PSWIZB_NEXT); + EnableWindow(hwndFinish, enable_finish); /* set the default pushbutton to an enabled button */ - if (((dwFlags & PSWIZB_FINISH) || psInfo->hasFinish) && !(dwFlags & PSWIZB_DISABLEDFINISH)) + if (enable_finish) SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0); else if (dwFlags & PSWIZB_NEXT) SendMessageW(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0); @@ -2447,13 +2448,6 @@ static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags) else SendMessageW(hwndDlg, DM_SETDEFID, IDCANCEL, 0); - - if (dwFlags & PSWIZB_BACK) - EnableWindow(hwndBack, TRUE); - - if (dwFlags & PSWIZB_NEXT) - EnableWindow(hwndNext, TRUE); - if (!psInfo->hasFinish) { if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH)) @@ -2463,9 +2457,6 @@ static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags) /* Show the Finish button */ ShowWindow(hwndFinish, SW_SHOW); - - if (!(dwFlags & PSWIZB_DISABLEDFINISH)) - EnableWindow(hwndFinish, TRUE); } else { @@ -2475,8 +2466,6 @@ static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags) ShowWindow(hwndNext, SW_SHOW); } } - else if (!(dwFlags & PSWIZB_DISABLEDFINISH)) - EnableWindow(hwndFinish, TRUE); } /****************************************************************************** diff --git a/dlls/comctl32/tests/propsheet.c b/dlls/comctl32/tests/propsheet.c index d3112d5e443..2797e944830 100644 --- a/dlls/comctl32/tests/propsheet.c +++ b/dlls/comctl32/tests/propsheet.c @@ -279,6 +279,37 @@ static INT_PTR CALLBACK nav_page_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM return FALSE; } +static WNDPROC old_nav_dialog_proc; + +static LRESULT CALLBACK new_nav_dialog_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp ) +{ + switch (msg) + { + case DM_SETDEFID: + ok( IsWindowEnabled( GetDlgItem(hwnd, wp) ), "button is not enabled\n" ); + break; + } + return CallWindowProcW( old_nav_dialog_proc, hwnd, msg, wp, lp ); +} + +static LRESULT CALLBACK hook_proc( int code, WPARAM wp, LPARAM lp ) +{ + static BOOL done; + if (code == HCBT_CREATEWND) + { + CBT_CREATEWNDW *c = (CBT_CREATEWNDW *)lp; + + /* The first dialog created will be the parent dialog */ + if (!done && c->lpcs->lpszClass == MAKEINTRESOURCEW(WC_DIALOG)) + { + old_nav_dialog_proc = (WNDPROC)SetWindowLongPtrW( (HWND)wp, GWLP_WNDPROC, (LONG_PTR)new_nav_dialog_proc ); + done = TRUE; + } + } + + return CallNextHookEx( NULL, code, wp, lp ); +} + static void test_wiznavigation(void) { HPROPSHEETPAGE hpsp[4]; @@ -291,6 +322,10 @@ static void test_wiznavigation(void) BOOL hwndtoindex_supported = TRUE; const INT nextID = 12324; const INT backID = 12323; + HHOOK hook; + + /* set up a hook proc in order to subclass the main dialog early on */ + hook = SetWindowsHookExW( WH_CBT, hook_proc, NULL, GetCurrentThreadId() ); /* create the property sheet pages */ memset(psp, 0, sizeof(PROPSHEETPAGEA) * 4); @@ -400,6 +435,7 @@ static void test_wiznavigation(void) ok(defidres == MAKELRESULT(nextID, DC_HASDEFID), "Expected default button ID to be %d, is %d\n", nextID, LOWORD(defidres)); DestroyWindow(hdlg); + UnhookWindowsHookEx( hook ); } static void test_buttons(void) -- 2.11.4.GIT