static void test_SaveRestoreFocus(void) { HWND hDlg; HRSRC hResource; HANDLE hTemplate; DLGTEMPLATE* pTemplate; LONG_PTR foundId; HWND foundHwnd; /* create the dialog */ hResource = FindResourceA(g_hinst, "MULTI_EDIT_DIALOG", RT_DIALOG); hTemplate = LoadResource(g_hinst, hResource); pTemplate = LockResource(hTemplate); hDlg = CreateDialogIndirectParamA(g_hinst, pTemplate, NULL, messageBoxFontDlgWinProc, 0); ok (hDlg != 0, "Failed to create test dialog.\n"); foundId = GetWindowLongPtr(GetFocus(), GWLP_ID); ok (foundId == 1000, "First edit box should have gained focus on dialog creation. Expected: %d, Found: %ld\n", 1000, foundId); /* de- then reactivate the dialog */ SendMessage(hDlg, WM_ACTIVATE, MAKEWPARAM(WA_INACTIVE, 0), 0); SendMessage(hDlg, WM_ACTIVATE, MAKEWPARAM(WA_ACTIVE, 0), 0); foundId = GetWindowLongPtr(GetFocus(), GWLP_ID); ok (foundId == 1000, "First edit box should have regained focus after dialog reactivation. Expected: %d, Found: %ld\n", 1000, foundId); /* select the next tabbable item */ SetFocus(GetNextDlgTabItem(hDlg, GetFocus(), FALSE)); foundId = GetWindowLongPtr(GetFocus(), GWLP_ID); ok (foundId == 1001, "Second edit box should have gained focus. Expected: %d, Found: %ld\n", 1001, foundId); /* de- then reactivate the dialog */ SendMessage(hDlg, WM_ACTIVATE, MAKEWPARAM(WA_INACTIVE, 0), 0); SendMessage(hDlg, WM_ACTIVATE, MAKEWPARAM(WA_ACTIVE, 0), 0); foundId = GetWindowLongPtr(GetFocus(), GWLP_ID); ok (foundId == 1001, "Second edit box should have gained focus after dialog reactivation. Expected: %d, Found: %ld\n", 1001, foundId); /* disable the 2nd box */ EnableWindow(GetFocus(), FALSE); foundHwnd = GetFocus(); ok (foundHwnd == NULL, "Second edit box should have lost focus after being disabled. Expected: %p, Found: %p\n", NULL, foundHwnd); /* de- then reactivate the dialog */ SendMessage(hDlg, WM_ACTIVATE, MAKEWPARAM(WA_INACTIVE, 0), 0); SendMessage(hDlg, WM_ACTIVATE, MAKEWPARAM(WA_ACTIVE, 0), 0); foundHwnd = GetFocus(); ok (foundHwnd == NULL, "No controls should have gained focus after dialog reactivation. Expected: %p, Found: %p\n", NULL, foundHwnd); /* clean up */ DestroyWindow(hDlg); }
static RETERR16 VCP_UI_CopyStart(void) { LPCVOID template32; char buf[256]; /* plenty */ BOOL dirty; DWORD len; /* FIXME: should be registered at DLL startup instead */ VCP_UI_RegisterProgressClass(); if (!(VCP_UI_GetDialogTemplate(&template32))) return VCPN_FAIL; if (vn_num > 10) /* hack */ { hDlgCopy = CreateDialogIndirectParamA(SETUPAPI_hInstance, template32, 0, VCP_UI_FileCopyDlgProc, 0); if (!hDlgCopy) return VCPN_FAIL; SetDlgItemTextA(hDlgCopy, SOURCESTRORD, "Scanning ..."); SetDlgItemTextA(hDlgCopy, DESTSTRORD, "NOT_IMPLEMENTED_YET"); } strcpy(buf, REG_INSTALLEDFILES); if (RegCreateKeyA(HKEY_LOCAL_MACHINE, buf, &hKeyFiles)) return VCPN_FAIL; strcat(buf, REGPART_RENAME); if (RegCreateKeyA(HKEY_LOCAL_MACHINE, buf, &hKeyRename)) return VCPN_FAIL; if (RegCreateKeyA(HKEY_LOCAL_MACHINE, REG_VERSIONCONFLICT, &hKeyConflict)) return VCPN_FAIL; len = 1; if (!(RegQueryValueExA(hKeyConflict, "Dirty", NULL, 0, (LPBYTE)&dirty, &len))) { /* FIXME: what does SETUPX.DLL do in this case ? */ MESSAGE("Warning: another program using SETUPX is already running ! Failed.\n"); return VCPN_FAIL; } dirty = TRUE; if (RegSetValueExA(hKeyConflict, "Dirty", 0, REG_BINARY, (LPBYTE)&dirty, 1)) return VCPN_FAIL; len = 12; if (!(RegQueryValueExA(hKeyConflict, "BackupDirectory", NULL, 0, (LPBYTE)BackupDir, &len))) strcpy(BackupDir, "VCM"); /* create C:\WINDOWS\[BackupDir] and set registry key to it */ GetWindowsDirectoryA(buf, 256); strcat(buf, "\\"); strcat(buf, BackupDir); if (!(CreateDirectoryA(buf, NULL))) return VCPN_FAIL; if (RegSetValueExA(hKeyConflict, "BackupDirectory", 0, REG_SZ, (LPBYTE)buf, strlen(buf)+1)) return VCPN_FAIL; RegCloseKey(hKeyConflict); return VCPN_OK; }
static void FindFilterStrings(int enableKeywordFiltering, int current, HWND hWndParent, const OptionsPageData *page) { TCHAR pluginName[MAX_PATH]; HWND hWnd = 0; if (enableKeywordFiltering) { if (current) hWnd = page->hwnd; else { hWnd = CreateDialogIndirectParamA(page->hInst, page->pTemplate, hWndParent, page->dlgProc, page->dwInitParam); //create the options dialog page so we can parse it ShowWindow(hWnd, SW_HIDE); //make sure it's hidden } } DWORD key = GetPluginPageHash(page); //get the plugin page hash char *temp = GetPluginNameByInstance(page->hInst); GetDialogStrings(enableKeywordFiltering, key, GetPluginName(page->hInst, pluginName, SIZEOF(pluginName)), hWnd, page->ptszGroup, page->ptszTitle, page->ptszTab, _A2T(temp)); if (enableKeywordFiltering && !current) DestroyWindow(hWnd); //destroy the page, we're done with it }
static INT_PTR CALLBACK OptionsDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) { OptionsPageData *opd; OptionsDlgData *dat = (OptionsDlgData*)GetWindowLongPtr(hdlg, GWLP_USERDATA); HWND hwndTree = GetDlgItem(hdlg, IDC_PAGETREE); switch (message) { case WM_CTLCOLORSTATIC: switch (GetDlgCtrlID((HWND)lParam)) { case IDC_WHITERECT: case IDC_KEYWORD_FILTER: SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW)); return (INT_PTR)GetSysColorBrush(COLOR_WINDOW); } break; case WM_INITDIALOG: TranslateDialogDefault(hdlg); if (!ServiceExists(MS_MODERNOPT_SHOW)) ShowWindow(GetDlgItem(hdlg, IDC_MODERN), FALSE); { PROPSHEETHEADER *psh = (PROPSHEETHEADER*)lParam; OPENOPTIONSDIALOG *ood = (OPENOPTIONSDIALOG*)psh->pStartPage; COMBOBOXINFO cbi; cbi.cbSize = sizeof(COMBOBOXINFO); GetComboBoxInfo(GetDlgItem(hdlg, IDC_KEYWORD_FILTER), &cbi); mir_subclassWindow(cbi.hwndItem, OptionsFilterSubclassProc); if (IsAeroMode()) { mir_subclassWindow(cbi.hwndCombo, AeroPaintSubclassProc); mir_subclassWindow(cbi.hwndItem, AeroPaintSubclassProc); } Utils_RestoreWindowPositionNoSize(hdlg, NULL, "Options", ""); Window_SetIcon_IcoLib(hdlg, SKINICON_OTHER_OPTIONS); EnableWindow(GetDlgItem(hdlg, IDC_APPLY), FALSE); dat = new OptionsDlgData; SetWindowLongPtr(hdlg, GWLP_USERDATA, (LONG_PTR)dat); SetWindowText(hdlg, psh->pszCaption); LOGFONT lf; dat->hBoldFont = (HFONT)SendDlgItemMessage(hdlg, IDC_APPLY, WM_GETFONT, 0, 0); GetObject(dat->hBoldFont, sizeof(lf), &lf); lf.lfWeight = FW_BOLD; dat->hBoldFont = CreateFontIndirect(&lf); dat->hPluginLoad = HookEventMessage(ME_SYSTEM_MODULELOAD, hdlg, HM_MODULELOAD); dat->hPluginUnload = HookEventMessage(ME_SYSTEM_MODULEUNLOAD, hdlg, HM_MODULEUNLOAD); dat->currentPage = -1; ptrT lastPage, lastGroup, lastTab; if (ood->pszPage == NULL) { lastPage = db_get_tsa(NULL, "Options", "LastPage"); if (ood->pszGroup == NULL) lastGroup = db_get_tsa(NULL, "Options", "LastGroup"); else lastGroup = mir_a2t(ood->pszGroup); } else { lastPage = mir_a2t(ood->pszPage); lastGroup = mir_a2t(ood->pszGroup); } if (ood->pszTab == NULL) lastTab = db_get_tsa(NULL, "Options", "LastTab"); else lastTab = mir_a2t(ood->pszTab); OPTIONSDIALOGPAGE *odp = (OPTIONSDIALOGPAGE*)psh->ppsp; for (UINT i = 0; i < psh->nPages; i++, odp++) { opd = (OptionsPageData*)mir_calloc(sizeof(OptionsPageData)); if (!LoadOptionsPage(odp, opd)) { mir_free(opd); continue; } dat->arOpd.insert(opd); if (!lstrcmp(lastPage, odp->ptszTitle) && !lstrcmpnull(lastGroup, odp->ptszGroup)) if ((ood->pszTab == NULL && dat->currentPage == -1) || !lstrcmpnull(lastTab, odp->ptszTab)) dat->currentPage = (int)i; } GetWindowRect(GetDlgItem(hdlg, IDC_STNOPAGE), &dat->rcDisplay); MapWindowPoints(NULL, hdlg, (LPPOINT)&dat->rcDisplay, 2); // Add an item to count in height TCITEM tie; tie.mask = TCIF_TEXT | TCIF_IMAGE; tie.iImage = -1; tie.pszText = _T("X"); TabCtrl_InsertItem(GetDlgItem(hdlg, IDC_TAB), 0, &tie); GetWindowRect(GetDlgItem(hdlg, IDC_TAB), &dat->rcTab); MapWindowPoints(NULL, hdlg, (LPPOINT)&dat->rcTab, 2); TabCtrl_AdjustRect(GetDlgItem(hdlg, IDC_TAB), FALSE, &dat->rcTab); FillFilterCombo(hdlg, dat); PostMessage(hdlg, DM_REBUILDPAGETREE, 0, 0); } return TRUE; case DM_REBUILDPAGETREE: RebuildPageTree(hdlg, dat); break; case HM_MODULELOAD: LoadOptionsModule(hdlg, dat, (HINSTANCE)lParam); break; case HM_MODULEUNLOAD: UnloadOptionsModule(hdlg, dat, (HINSTANCE)lParam); break; case PSM_CHANGED: EnableWindow(GetDlgItem(hdlg, IDC_APPLY), TRUE); opd = dat->getCurrent(); if (opd) opd->changed = 1; return TRUE; case PSM_GETBOLDFONT: SetWindowLongPtr(hdlg, DWLP_MSGRESULT, (LONG_PTR)dat->hBoldFont); return TRUE; case WM_NOTIFY: switch (wParam) { case IDC_TAB: case IDC_PAGETREE: switch (((LPNMHDR)lParam)->code) { case TVN_ITEMEXPANDING: SetWindowLongPtr(hdlg, DWLP_MSGRESULT, FALSE); return TRUE; case TCN_SELCHANGING: case TVN_SELCHANGING: opd = dat->getCurrent(); if (opd && opd->hwnd != NULL) { PSHNOTIFY pshn; pshn.hdr.code = PSN_KILLACTIVE; pshn.hdr.hwndFrom = dat->arOpd[dat->currentPage]->hwnd; pshn.hdr.idFrom = 0; pshn.lParam = 0; if (SendMessage(dat->arOpd[dat->currentPage]->hwnd, WM_NOTIFY, 0, (LPARAM)&pshn)) { SetWindowLongPtr(hdlg, DWLP_MSGRESULT, TRUE); return TRUE; } } break; case TCN_SELCHANGE: case TVN_SELCHANGED: ShowWindow(GetDlgItem(hdlg, IDC_STNOPAGE), SW_HIDE); opd = dat->getCurrent(); if (opd && opd->hwnd != NULL) ShowWindow(opd->hwnd, SW_HIDE); if (wParam != IDC_TAB) { TVITEM tvi; tvi.hItem = dat->hCurrentPage = TreeView_GetSelection(hwndTree); if (tvi.hItem == NULL) { ShowWindow(GetDlgItem(hdlg, IDC_TAB), SW_HIDE); break; } tvi.mask = TVIF_HANDLE | TVIF_PARAM; TreeView_GetItem(hwndTree, &tvi); dat->currentPage = tvi.lParam; ShowWindow(GetDlgItem(hdlg, IDC_TAB), SW_HIDE); } else { TCITEM tie; tie.mask = TCIF_PARAM; TabCtrl_GetItem(GetDlgItem(hdlg, IDC_TAB), TabCtrl_GetCurSel(GetDlgItem(hdlg, IDC_TAB)), &tie); dat->currentPage = tie.lParam; TVITEM tvi; tvi.hItem = dat->hCurrentPage; tvi.mask = TVIF_PARAM; tvi.lParam = dat->currentPage; TreeView_SetItem(hwndTree, &tvi); } opd = dat->getCurrent(); if (opd == NULL) { ShowWindow(GetDlgItem(hdlg, IDC_STNOPAGE), SW_SHOW); break; } if (opd->hwnd == NULL) { opd->hwnd = CreateDialogIndirectParamA(opd->hInst, opd->pTemplate, hdlg, opd->dlgProc, opd->dwInitParam); if (opd->flags & ODPF_BOLDGROUPS) EnumChildWindows(opd->hwnd, BoldGroupTitlesEnumChildren, (LPARAM)dat->hBoldFont); RECT rcPage; GetClientRect(opd->hwnd, &rcPage); int w = opd->width = rcPage.right; int h = opd->height = rcPage.bottom; RECT rc; GetWindowRect(opd->hwnd, &rc); opd->offsetX = 0; opd->offsetY = 0; opd->insideTab = IsInsideTab(hdlg, dat, dat->currentPage); if (opd->insideTab) { SetWindowPos(opd->hwnd, HWND_TOP, (dat->rcTab.left + dat->rcTab.right - w) >> 1, dat->rcTab.top, w, h, 0); ThemeDialogBackground(opd->hwnd, TRUE); } else { SetWindowPos(opd->hwnd, HWND_TOP, (dat->rcDisplay.left + dat->rcDisplay.right - w) >> 1, (dat->rcDisplay.top + dat->rcDisplay.bottom - h) >> 1, w, h, 0); ThemeDialogBackground(opd->hwnd, FALSE); } } if (wParam != IDC_TAB) { opd->insideTab = IsInsideTab(hdlg, dat, dat->currentPage); if (opd->insideTab) { // Make tabbed pane int pages = 0, sel = 0; HWND hwndTab = GetDlgItem(hdlg, IDC_TAB); TabCtrl_DeleteAllItems(hwndTab); TCITEM tie; tie.mask = TCIF_TEXT | TCIF_IMAGE | TCIF_PARAM; tie.iImage = -1; for (int i = 0; i < dat->arOpd.getCount(); i++) { if (!CheckPageShow(hdlg, dat, i)) continue; OptionsPageData *p = dat->arOpd[i]; if (lstrcmp(opd->ptszTitle, p->ptszTitle) || lstrcmpnull(opd->ptszGroup, p->ptszGroup)) continue; tie.pszText = TranslateTH(p->hLangpack, p->ptszTab); tie.lParam = i; TabCtrl_InsertItem(hwndTab, pages, &tie); if (!lstrcmp(opd->ptszTab, p->ptszTab)) sel = pages; pages++; } TabCtrl_SetCurSel(hwndTab, sel); ShowWindow(hwndTab, opd->insideTab ? SW_SHOW : SW_HIDE); } if (opd->insideTab) ThemeDialogBackground(opd->hwnd, TRUE); else ThemeDialogBackground(opd->hwnd, FALSE); } ShowWindow(opd->hwnd, SW_SHOW); if (((LPNMTREEVIEW)lParam)->action == TVC_BYMOUSE) PostMessage(hdlg, DM_FOCUSPAGE, 0, 0); else SetFocus(hwndTree); }
static void test_initial_focus(void) { /* Test 1: * This test intentionally returns FALSE in response to WM_INITDIALOG * without setting focus to a control. This is not allowed according to * MSDN, but it is exactly what MFC's CFormView does. * * Since the WM_INITDIALOG handler returns FALSE without setting the focus, * the focus should initially be NULL. Later, when we manually set focus to * the dialog, the default handler should set focus to the first control that * is "visible, not disabled, and has the WS_TABSTOP style" (MSDN). Because the * second radio button has been checked, it should be the first control * that meets these criteria and should receive the focus. */ g_bInitialFocusInitDlgResult = FALSE; g_hwndInitialFocusT1 = (HWND) -1; g_hwndInitialFocusT2 = (HWND) -1; g_styleInitialFocusT1 = -1; g_styleInitialFocusT2 = -1; DialogBoxA(g_hinst, "RADIO_TEST_DIALOG", NULL, delayFocusDlgWinProc); ok (((g_styleInitialFocusT1 & WS_TABSTOP) == 0), "Error in wrc - Detected WS_TABSTOP as default style for GROUPBOX\n"); ok (((g_styleInitialFocusT2 & WS_VISIBLE) == 0), "Modal dialogs should not be shown until the message queue first goes empty\n"); ok ((g_hwndInitialFocusT1 == NULL), "Error in initial focus when WM_INITDIALOG returned FALSE: " "Expected NULL focus, got %s (%p).\n", GetHwndString(g_hwndInitialFocusT1), g_hwndInitialFocusT1); ok ((g_hwndInitialFocusT2 == g_hwndButton2), "Error after first SetFocus() when WM_INITDIALOG returned FALSE: " "Expected the second button (%p), got %s (%p).\n", g_hwndButton2, GetHwndString(g_hwndInitialFocusT2), g_hwndInitialFocusT2); /* Test 2: * This is the same as above, except WM_INITDIALOG is made to return TRUE. * This should cause the focus to go to the second radio button right away * and stay there (until the user indicates otherwise). */ g_bInitialFocusInitDlgResult = TRUE; g_hwndInitialFocusT1 = (HWND) -1; g_hwndInitialFocusT2 = (HWND) -1; g_styleInitialFocusT1 = -1; g_styleInitialFocusT2 = -1; DialogBoxA(g_hinst, "RADIO_TEST_DIALOG", NULL, delayFocusDlgWinProc); ok ((g_hwndInitialFocusT1 == g_hwndButton2), "Error in initial focus when WM_INITDIALOG returned TRUE: " "Expected the second button (%p), got %s (%p).\n", g_hwndButton2, GetHwndString(g_hwndInitialFocusT1), g_hwndInitialFocusT1); ok ((g_hwndInitialFocusT2 == g_hwndButton2), "Error after first SetFocus() when WM_INITDIALOG returned TRUE: " "Expected the second button (%p), got %s (%p).\n", g_hwndButton2, GetHwndString(g_hwndInitialFocusT2), g_hwndInitialFocusT2); /* Test 3: * If the dialog has DS_CONTROL and it's not visible then we shouldn't change focus */ { HWND hDlg; HRSRC hResource; HANDLE hTemplate; DLGTEMPLATE* pTemplate; hResource = FindResourceA(g_hinst,"FOCUS_TEST_DIALOG", RT_DIALOG); hTemplate = LoadResource(g_hinst, hResource); pTemplate = LockResource(hTemplate); g_hwndInitialFocusT1 = 0; hDlg = CreateDialogIndirectParamA(g_hinst, pTemplate, NULL, focusDlgWinProc, 0); ok (hDlg != 0, "Failed to create test dialog.\n"); ok ((g_hwndInitialFocusT1 == 0), "Focus should not be set for an invisible DS_CONTROL dialog %p.\n", g_hwndInitialFocusT1); DestroyWindow(hDlg); } }
/*********************************************************************** * COMDLG32_FR_DoFindReplace [internal] * Actual load and creation of the Find/Replace dialog. * RETURNS * Window handle to created dialog:Success * NULL:Failure */ static HWND COMDLG32_FR_DoFindReplace( COMDLG32_FR_Data *pdata /* [in] Internal data structure */ ) { HWND hdlgwnd = 0; HGLOBAL loadrc; DWORD error; LPDLGTEMPLATEW rcs; TRACE("hInst=%p, Flags=%08x\n", pdata->fr.hInstance, pdata->fr.Flags); if(!(pdata->fr.Flags & FR_ENABLETEMPLATEHANDLE)) { HMODULE hmod = COMDLG32_hInstance; HRSRC htemplate; if(pdata->fr.Flags & FR_ENABLETEMPLATE) { hmod = pdata->fr.hInstance; if(pdata->fr.Flags & FR_WINE_UNICODE) { htemplate = FindResourceW(hmod, (LPCWSTR)pdata->fr.lpTemplateName, (LPWSTR)RT_DIALOG); } else { htemplate = FindResourceA(hmod, pdata->fr.lpTemplateName, (LPCSTR)RT_DIALOG); } } else { int rcid = pdata->fr.Flags & FR_WINE_REPLACE ? REPLACEDLGORD : FINDDLGORD; htemplate = FindResourceA(hmod, MAKEINTRESOURCEA(rcid), (LPCSTR)RT_DIALOG); } if(!htemplate) { error = CDERR_FINDRESFAILURE; goto cleanup; } loadrc = LoadResource(hmod, htemplate); } else { loadrc = (HGLOBAL)pdata->fr.hInstance; } if(!loadrc) { error = CDERR_LOADRESFAILURE; goto cleanup; } if((rcs = (LPDLGTEMPLATEW)LockResource(loadrc)) == NULL) { error = CDERR_LOCKRESFAILURE; goto cleanup; } hdlgwnd = CreateDialogIndirectParamA(COMDLG32_hInstance, rcs, pdata->fr.hwndOwner, COMDLG32_FindReplaceDlgProc, (LPARAM)pdata); if(!hdlgwnd) { error = CDERR_DIALOGFAILURE; cleanup: COMDLG32_SetCommDlgExtendedError(error); HeapFree(GetProcessHeap(), 0, pdata); } return hdlgwnd; }