/** * @file XTPWindowPos.cpp * * @copyright * (c) 1998-2025 Codejock Software, All Rights Reserved. * * This source file is the property of Codejock Software and must not be * redistributed by any means without the explicit written permission of * Codejock Software. * * The use of this source code is governed by the terms and conditions specified * in the Toolkit Pro license agreement. Codejock Software grants you, as a * single software developer, the limited right to use this software on one * computer only. * * Contact Information: * support@codejock.com * http://www.codejock.com * */ #include "stdafx.h" #include "Common/XTPTypeId.h" #include "Common/XTPVC80Helpers.h" // Visual Studio 2005 helper functions #include "Common/XTPFramework.h" #include "Common/XTPSystemHelpers.h" #include "Common/XTPSynchro.h" #include "Common/XTPApplication.h" #include "Common/XTPSingleton.h" #include "Common/XTPGdiObjects.h" #include "Common/XTPDrawHelpers.h" #include "Controls/Util/XTPWindowPos.h" #include "Controls/Util/XTPRegistryManager.h" const TCHAR XTP_REG_SETTINGS[] = _T("Settings"); const TCHAR XTP_REG_WNDPOS[] = _T("Window Position"); #include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" #ifdef _DEBUG # define new DEBUG_NEW # undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CXTPWindowPos ///////////////////////////////////////////////////////////////////////////// CXTPWindowPos::CXTPWindowPos() { _ASSERTE(sizeof(CXTPWindowPos) == sizeof(WINDOWPLACEMENT)); memset((LPWINDOWPLACEMENT)this, 0, sizeof(WINDOWPLACEMENT)); length = sizeof(WINDOWPLACEMENT); showCmd = SW_SHOW; } BOOL CXTPWindowPos::SaveWindowPos(CWnd* pWnd, LPCTSTR lpszWndPos /*=NULL*/, LPCTSTR lpszSection /*=NULL*/) { _ASSERTE(pWnd); // must be valid. if (!pWnd) return FALSE; if (::IsWindow(pWnd->m_hWnd)) { if (pWnd->GetWindowPlacement(this)) { LPWINDOWPLACEMENT wndPlacement = static_cast(this); wndPlacement->ptMinPosition = XTP_UNDPI_POINT(wndPlacement->ptMinPosition); wndPlacement->ptMaxPosition = XTP_UNDPI_POINT(wndPlacement->ptMaxPosition); wndPlacement->rcNormalPosition = XTP_UNDPI_RECT(wndPlacement->rcNormalPosition); CString strSection; if (lpszSection) strSection = lpszSection; else strSection = XTP_REG_SETTINGS; CString strEntry; if (lpszWndPos) strEntry = lpszWndPos; else strEntry = XTP_REG_WNDPOS; // Make sure we don't pop up // minimized the next time if (showCmd != SW_SHOWMAXIMIZED) { showCmd = SW_SHOWNORMAL; } CXTPRegistryManager regManager; regManager.WriteProfileBinary(strSection, strEntry, reinterpret_cast((LPWINDOWPLACEMENT)this), sizeof(WINDOWPLACEMENT)); return TRUE; } } return FALSE; } BOOL CXTPWindowPos::LoadWindowPos(CWnd* pWnd, LPCTSTR lpszWndPos /*=NULL*/, LPCTSTR lpszSection /*=NULL*/) { _ASSERTE(pWnd); // must be valid. if (::IsWindow(pWnd->m_hWnd)) { if (LoadWindowPos(lpszWndPos, lpszSection)) { LPWINDOWPLACEMENT wndPlacement = static_cast(this); wndPlacement->ptMinPosition = XTP_DPI_POINT(wndPlacement->ptMinPosition); wndPlacement->ptMaxPosition = XTP_DPI_POINT(wndPlacement->ptMaxPosition); wndPlacement->rcNormalPosition = XTP_DPI_RECT(wndPlacement->rcNormalPosition); pWnd->SetWindowPlacement(this); return TRUE; } } return FALSE; } BOOL CXTPWindowPos::LoadWindowPos(LPCTSTR lpszWndPos /*=NULL*/, LPCTSTR lpszSection /*=NULL*/) { UINT nSize = 0; LPBYTE pbtData = 0; CString strSection; if (lpszSection) strSection = lpszSection; else strSection = XTP_REG_SETTINGS; CString strEntry; if (lpszWndPos) strEntry = lpszWndPos; else strEntry = XTP_REG_WNDPOS; CXTPRegistryManager regManager; if (!regManager.GetProfileBinary(strSection, strEntry, &pbtData, &nSize)) { return FALSE; } BOOL bResult = FALSE; if (nSize == sizeof(WINDOWPLACEMENT)) { MEMCPY_S((void*)&*((LPWINDOWPLACEMENT)this), pbtData, (DWORD)sizeof(WINDOWPLACEMENT)); bResult = TRUE; } delete[] pbtData; return bResult; }