static HWND SaveDlgFocus(HWND hDlg) { HWND hWnd; hWnd = GetFocus(); if (hWnd && IsChild(hDlg,hWnd)) SetDialogFocus(hDlg,hWnd); else SetDialogFocus(hDlg,0); return hWnd; }
/* * Main BrowseInfo callback to set the initial directory and populate the edit control */ INT CALLBACK BrowseInfoCallback(HWND hDlg, UINT message, LPARAM lParam, LPARAM pData) { char dir[MAX_PATH]; wchar_t* wpath; LPITEMIDLIST pidl; switch(message) { case BFFM_INITIALIZED: pOrgBrowseWndproc = (WNDPROC)SetWindowLongPtr(hDlg, GWLP_WNDPROC, (LONG_PTR)BrowseDlgCallback); // Windows hides the full path in the edit box by default, which is bull. // Get a handle to the edit control to fix that hBrowseEdit = FindWindowExA(hDlg, NULL, "Edit", NULL); SetWindowTextU(hBrowseEdit, szFolderPath); SetDialogFocus(hDlg, hBrowseEdit); // On Windows 7, MinGW only properly selects the specified folder when using a pidl wpath = utf8_to_wchar(szFolderPath); pidl = SHSimpleIDListFromPath(wpath); safe_free(wpath); // NB: see http://connect.microsoft.com/VisualStudio/feedback/details/518103/bffm-setselection-does-not-work-with-shbrowseforfolder-on-windows-7 // for details as to why we send BFFM_SETSELECTION twice. SendMessageW(hDlg, BFFM_SETSELECTION, (WPARAM)FALSE, (LPARAM)pidl); Sleep(100); PostMessageW(hDlg, BFFM_SETSELECTION, (WPARAM)FALSE, (LPARAM)pidl); break; case BFFM_SELCHANGED: // Update the status if (SHGetPathFromIDListU((LPITEMIDLIST)lParam, dir)) { SendMessageLU(hDlg, BFFM_SETSTATUSTEXT, 0, dir); SetWindowTextU(hBrowseEdit, dir); } break; } return 0; }
void Items(HWND hwnd, int on) { const HWND hCloseBtn = GetDlgItem(hwnd, IDCANCEL); const HWND hTestBtn = GetDlgItem(hwnd, IDC_TEST); const HMENU hMenu = g_sdata.menu; const UINT mf = (!on ? MF_GRAYED : MF_ENABLED); const UINT nmf = (!on ? MF_ENABLED : MF_GRAYED); const bool compsuccess = !g_sdata.retcode && on; if(!on) g_sdata.focused_hwnd = GetFocus(); if(compsuccess || !on) { EnableWindow(hTestBtn, on); EnableToolBarButton(IDM_TEST, on); EnableMenuItem(hMenu, IDM_TEST, mf); } EnableMenuItem(hMenu, IDM_CANCEL, nmf); EnableWindow(hCloseBtn, on); static const PACKEDCMDID_T cmds [] = { PACKCMDID(IDM_EXIT), PACKCMDID(IDM_LOADSCRIPT), PACKCMDID(IDM_EDITSCRIPT), PACKCMDID(IDM_COPY), PACKCMDID(IDM_COPYSELECTED), PACKCMDID(IDM_SAVE), PACKCMDID(IDM_CLEARLOG), PACKCMDID(IDM_BROWSESCR), PACKCMDID(IDM_COMPRESSOR), PACKCMDID(IDM_COMPRESSOR_SUBMENU), PACKCMDID(IDM_RECOMPILE), PACKCMDID(IDM_RECOMPILE_TEST) }; for (UINT i = 0; i < COUNTOF(cmds); ++i) { UINT id = UNPACKCMDID(cmds[i]); EnableMenuItem(hMenu, id, mf); if (IDM_COPYSELECTED != id && IDM_COMPRESSOR_SUBMENU != id) EnableToolBarButton(id, on); } HWND hFocus = g_sdata.focused_hwnd, hOptimal = hTestBtn; if (on && hCloseBtn == hFocus) hFocus = hOptimal; if (!IsWindowEnabled(hFocus)) hFocus = GetDlgItem(hwnd, IDC_LOGWIN); SetDialogFocus(hwnd, hOptimal); SetDialogFocus(hwnd, hFocus); }
static HWND DlgSetFocus(HWND hWnd) { HWND hDlg; HWND hChild; hDlg = GetParent(hWnd); hChild = 0; if(hDlg) { hChild = GetDialogFocus(hDlg); SetDialogFocus(hDlg,hWnd); SetFocus(hWnd); } return hChild; }