void RestoreWindowPlacement(HWND hWnd, int showCmd) { if (!hWnd) return; // If window is maximized, set the "restore" window position if (showCmd == SW_MAXIMIZE) { WINDOWPLACEMENT wp; wp.length = sizeof(WINDOWPLACEMENT); wp.flags = 0; wp.showCmd = SW_MAXIMIZE; wp.ptMinPosition.x = -1; wp.ptMinPosition.y = -1; wp.ptMaxPosition.x = -1; wp.ptMaxPosition.y = -1; wp.rcNormalPosition.left = CW_USEDEFAULT; wp.rcNormalPosition.top = CW_USEDEFAULT; wp.rcNormalPosition.right = CW_USEDEFAULT; wp.rcNormalPosition.bottom = CW_USEDEFAULT; GetRegistryInt(PREF_WINPOS_FOLDER, PREF_RESTORE_LEFT, NULL, (int&)wp.rcNormalPosition.left); GetRegistryInt(PREF_WINPOS_FOLDER, PREF_RESTORE_TOP, NULL, (int&)wp.rcNormalPosition.top); GetRegistryInt(PREF_WINPOS_FOLDER, PREF_RESTORE_RIGHT, NULL, (int&)wp.rcNormalPosition.right); GetRegistryInt(PREF_WINPOS_FOLDER, PREF_RESTORE_BOTTOM, NULL, (int&)wp.rcNormalPosition.bottom); // This returns an error code, but not sure what we could do on an error SetWindowPlacement(hWnd, &wp); } ShowWindow(hWnd, showCmd); }
// Initialization helper -- // Loads the Restores data and positions the window in its previously saved state void cef_main_window::RestoreWindowPlacement(int showCmd) { if (showCmd == SW_MAXIMIZE) { WINDOWPLACEMENT wp; ::ZeroMemory(&wp, sizeof (wp)); wp.length = sizeof(WINDOWPLACEMENT); wp.flags = 0; wp.showCmd = SW_MAXIMIZE; wp.ptMinPosition.x = -1; wp.ptMinPosition.y = -1; wp.ptMaxPosition.x = -1; wp.ptMaxPosition.y = -1; wp.rcNormalPosition.left = CW_USEDEFAULT; wp.rcNormalPosition.top = CW_USEDEFAULT; wp.rcNormalPosition.right = CW_USEDEFAULT; wp.rcNormalPosition.bottom = CW_USEDEFAULT; GetRegistryInt(::kWindowPostionFolder, ::kPrefRestoreLeft, NULL, (int&)wp.rcNormalPosition.left); GetRegistryInt(::kWindowPostionFolder, ::kPrefRestoreTop, NULL, (int&)wp.rcNormalPosition.top); GetRegistryInt(::kWindowPostionFolder, ::kPrefRestoreRight, NULL, (int&)wp.rcNormalPosition.right); GetRegistryInt(::kWindowPostionFolder, ::kPrefRestoreBottom, NULL, (int&)wp.rcNormalPosition.bottom); // This returns FALSE on failure but not sure what we could do in that case SetWindowPlacement(&wp); } ShowWindow(showCmd); }
void CCommands::SetApplicationObject (IApplication * pApplication) { // This function assumes pApplication has already been AddRef'd // for us, which CDSAddIn did in it's QueryInterface call // just before it called us. m_pApplication = pApplication; if (! m_pApplication) return; // Create Application event handlers XApplicationEventsObj::CreateInstance (&m_pApplicationEventsObj); if (! m_pApplicationEventsObj) { ReportInternalError ("XApplicationEventsObj::CreateInstance"); return; } m_pApplicationEventsObj->AddRef (); m_pApplicationEventsObj->Connect (m_pApplication); m_pApplicationEventsObj->m_pCommands = this; #ifdef NEVER // Create Debugger event handler CComPtr < IDispatch > pDebugger; if (SUCCEEDED (m_pApplication->get_Debugger (&pDebugger)) && pDebugger != NULL) { XDebuggerEventsObj::CreateInstance (&m_pDebuggerEventsObj); m_pDebuggerEventsObj->AddRef (); m_pDebuggerEventsObj->Connect (pDebugger); m_pDebuggerEventsObj->m_pCommands = this; } #endif // Get settings from registry HKEY_CURRENT_USER\Software\Vim\VisVim HKEY hAppKey = GetAppKey ("Vim"); if (hAppKey) { HKEY hSectionKey = GetSectionKey (hAppKey, "VisVim"); if (hSectionKey) { g_bEnableVim = GetRegistryInt (hSectionKey, "EnableVim", g_bEnableVim); g_bDevStudioEditor = GetRegistryInt(hSectionKey,"DevStudioEditor", g_bDevStudioEditor); g_ChangeDir = GetRegistryInt (hSectionKey, "ChangeDir", g_ChangeDir); RegCloseKey (hSectionKey); } RegCloseKey (hAppKey); } }
BOOL GetRegistryInt(HKEY root, const CString & path, const CString & var, DWORD & val) { CString s; s = path; s += _T("\\"); s += var; return GetRegistryInt(root, s, val); } // GetRegistryInt
int RegistryVar::getInt(UINT id, int def, HKEY root) { DWORD value; CString pathname; pathname.LoadString(id); if(!GetRegistryInt(root, pathname, value)) return def; return (int)value; }
BOOL GetRegistryInt(HKEY root, const CString & path, UINT var, DWORD & val) { CString s; s = path; s += _T("\\"); CString t; t.LoadString(var); s += t; return GetRegistryInt(root, s, val); } // GetRegistryInt
BOOL RegistryVar::getInt(UINT id, DWORD & value, DWORD def, HKEY root) { DWORD v; CString pathname; pathname.LoadString(id); if(!GetRegistryInt(root, pathname, v)) { /* use default */ value = def; if(::GetLastError() == ERROR_FILE_NOT_FOUND) return TRUE; return FALSE; } /* use default */ value = v; return TRUE; }
void RestoreWindowRect(int& left, int& top, int& width, int& height, int& showCmd) { // Start with Registry data GetRegistryInt(PREF_WINPOS_FOLDER, PREF_LEFT, NULL, left); GetRegistryInt(PREF_WINPOS_FOLDER, PREF_TOP, NULL, top); GetRegistryInt(PREF_WINPOS_FOLDER, PREF_WIDTH, NULL, width); GetRegistryInt(PREF_WINPOS_FOLDER, PREF_HEIGHT, NULL, height); GetRegistryInt(PREF_WINPOS_FOLDER, PREF_SHOWSTATE, NULL, showCmd); // If window size has changed, we may need to alter window size HMONITOR hMonitor; MONITORINFO mi; RECT rcOrig, rcMax; // Get the nearest monitor to the passed rect rcOrig.left = left; rcOrig.top = top; rcOrig.right = left + width; rcOrig.bottom = top + height; hMonitor = MonitorFromRect(&rcOrig, MONITOR_DEFAULTTONEAREST); // Get the monitor rect mi.cbSize = sizeof(mi); GetMonitorInfo(hMonitor, &mi); rcMax = mi.rcMonitor; if (showCmd == SW_MAXIMIZE) { // For maximized case, just use monitor dimensions left = rcMax.left; top = rcMax.top; width = rcMax.right - rcMax.left; height = rcMax.bottom - rcMax.top; } else { // For non-maximized case, adjust window to fit on screen // make sure width fits int rcMaxWidth = static_cast<int>(rcMax.right - rcMax.left); if (width > rcMaxWidth) width = rcMaxWidth; // make sure left is on screen if (left < rcMax.left) left = static_cast<int>(rcMax.left); // make sure right is on screen if ((left + width) > rcMax.right) left = static_cast<int>(rcMax.right) - width; // make sure height fits int rcMaxHeight = static_cast<int>(rcMax.bottom - rcMax.top); if (height > rcMaxHeight) height = rcMaxHeight; // make sure top is on screen if (top < rcMax.top) top = static_cast<int>(rcMax.top); // make sure bottom is on screen if ((top + height) > rcMax.bottom) top = static_cast<int>(rcMax.bottom) - height; } }
BOOL GetRegistryWindowPlacement(HKEY root, const CString & var, WINDOWPLACEMENT * wp) { ASSERT(wp != NULL); BOOL ok = TRUE; DWORD val; //================ // length // flags //================ if(!GetRegistryInt(root, var, IDS_KEY_PLACEMENT_FLAGS, val)) return FALSE; // no data wp->length = sizeof(WINDOWPLACEMENT); wp->flags = val; //================ // showCmd //================ ok &= GetRegistryInt(root, var, IDS_KEY_PLACEMENT_SHOWCMD, val); wp->showCmd = val; //================ // ptMinPosition.x //================ ok &= GetRegistryInt(root, var, IDS_KEY_PLACEMENT_MINPOSITION_X, val); wp->ptMinPosition.x = val; //================ // ptMinMposition.y //================ ok &= GetRegistryInt(root, var, IDS_KEY_PLACEMENT_MINPOSITION_Y, val); wp->ptMinPosition.y = val; //================ // ptMaxPosition.x //================ ok &= GetRegistryInt(root, var, IDS_KEY_PLACEMENT_MAXPOSITION_X, val); wp->ptMaxPosition.x = val; //================ // ptMaxMposition.y //================ ok &= GetRegistryInt(root, var, IDS_KEY_PLACEMENT_MAXPOSITION_Y, val); wp->ptMaxPosition.y = val; //================ // rcNormalPosition.left //================ ok &= GetRegistryInt(root, var, IDS_KEY_PLACEMENT_NORMAL_LEFT, val); wp->rcNormalPosition.left = val; //================ // rcNormalPosition.top //================ ok &= GetRegistryInt(root, var, IDS_KEY_PLACEMENT_NORMAL_TOP, val); wp->rcNormalPosition.top = val; //================ // rcNormalPosition.right //================ ok &= GetRegistryInt(root, var, IDS_KEY_PLACEMENT_NORMAL_RIGHT, val); wp->rcNormalPosition.right = val; //================ // rcNormalPosition.bottom //================ ok &= GetRegistryInt(root, var, IDS_KEY_PLACEMENT_NORMAL_BOTTOM, val); wp->rcNormalPosition.bottom = val; return ok; } // GetRegistryWindowPlacement