2 const DWORD style = wnd.GetWindowLong(GWL_STYLE), exstyle = wnd.GetWindowLong(GWL_EXSTYLE);
3 return AdjustWindowRectEx(&rc,style,(style & WS_POPUP) ? wnd.GetMenu() != NULL : FALSE, exstyle);
7 HMONITOR monitor = MonitorFromRect(rcParent,MONITOR_DEFAULTTONEAREST);
8 MONITORINFO mi = {
sizeof(MONITORINFO)};
9 if (GetMonitorInfo(monitor,&mi)) {
10 const CRect clip = mi.rcWork;
11 if (rc.right > clip.right) rc.OffsetRect(clip.right - rc.right, 0);
12 if (rc.bottom > clip.bottom) rc.OffsetRect(0, clip.bottom - rc.bottom);
13 if (rc.left < clip.left) rc.OffsetRect(clip.left - rc.left, 0);
14 if (rc.top < clip.top) rc.OffsetRect(0, clip.top - rc.top);
20 if (!wnd.GetClientRect(temp))
return FALSE;
21 if (temp.IsRectNull())
return FALSE;
22 if (!wnd.ClientToScreen(temp))
return FALSE;
30 if (!wndParent.GetWindowRect(&parent) || !wnd.GetWindowRect(&child))
return FALSE;
32 CPoint origin = parent.CenterPoint();
33 origin.Offset( - child.Width() / 2, - child.Height() / 2);
34 child.OffsetRect( origin - child.TopLeft() );
44 return wnd.SetWindowPos(NULL,rc,SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
50 return wnd.SetWindowPos(HWND_TOP,rc,SWP_NOSIZE | SWP_SHOWWINDOW);
73 if (m_var.m_width != ~0 && m_var.m_height != ~0) {
74 CRect rect (0,0,m_var.m_width,m_var.m_height);
76 SetWindowPos(p_wnd,NULL,0,0,rect.right-rect.left,rect.bottom-rect.top,SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
85 if (uMsg == WM_SIZE && m_applied) {
87 m_var.m_width = (short)LOWORD(lParam); m_var.m_height = (short)HIWORD(lParam);
102 if (uMsg == WM_INITDIALOG) Apply(hWnd);
114 m_dpiX = m_dpiY = 96;
124 if (m_windows.contains(wnd)) {
125 StoreConfig(wnd); m_windows -= wnd;
133 CWindow wndParent = wnd.GetParent();
134 UINT flags = SWP_NOACTIVATE | SWP_NOZORDER;
137 if (
m_width != sizeInvalid &&
m_height != sizeInvalid && (wnd.GetWindowLong(GWL_STYLE) & WS_SIZEBOX) != 0) {
143 if (wndParent != NULL) {
145 if (GetParentWndRect(wndParent, rcParent)) {
146 if (m_posX != posInvalid && m_posY != posInvalid) {
147 rc.MoveToXY( rcParent.TopLeft() + CPoint(m_posX, m_posY) );
149 CPoint center = rcParent.CenterPoint();
150 rc.MoveToXY( center.x - rc.Width() / 2, center.y - rc.Height() / 2);
159 CRect rcAdjust(0,0,1,1);
160 if (wndParent != NULL) {
162 if (wndParent.GetWindowRect(temp)) rcAdjust = temp;
168 return wnd.SetWindowPos(NULL, rc, flags);
177 if (wnd != state->
m_thisWnd && IsWindowVisible(wnd) ) {
179 if (GetWindowRect(wnd, rc)) {
181 state->
m_match =
true;
return FALSE;
190 EnumThreadWindows(GetCurrentThreadId(), MyEnumChildProc, reinterpret_cast<LPARAM>(&state));
194 return pfc::max_t<int>(GetSystemMetrics(SM_CYCAPTION),1);
197 const int delta = DeOverlapDelta();
199 if (!DeOverlapTest(wnd, rc.TopLeft()))
break;
200 rc.OffsetRect(delta,delta);
207 m_dpiX = DPI.cx; m_dpiY = DPI.cy;
209 m_posX = m_posY = posInvalid;
210 CWindow parent = wnd.GetParent();
211 if (parent != NULL) {
213 if (GetParentWndRect(parent, rcParent)) {
214 m_posX = rc.left - rcParent.left;
215 m_posY = rc.top - rcParent.top;
222 if (StoreConfig(*walk))
break;
228 if (screenDPI.cx == 0 || screenDPI.cy == 0) {
229 PFC_ASSERT(!
"Should not get here - something seriously wrong with the OS");
232 if (m_dpiX != dpiInvalid && m_dpiX != screenDPI.cx) {
234 if (m_posX != posInvalid) m_posX = MulDiv(m_posX, screenDPI.cx, m_dpiX);
236 if (m_dpiY != dpiInvalid && m_dpiY != screenDPI.cy) {
238 if (m_posY != posInvalid) m_posY = MulDiv(m_posY, screenDPI.cy, m_dpiY);
240 m_dpiX = screenDPI.cx;
241 m_dpiY = screenDPI.cy;
245 if (m_dpiX != dpiInvalid) DPI.cx = m_dpiX;
246 if (m_dpiY != dpiInvalid) DPI.cy = m_dpiY;
251 if (!wndParent.IsIconic()) {
252 return wndParent.GetWindowRect(rc);
254 WINDOWPLACEMENT pl = {
sizeof(pl)};
255 if (!wndParent.GetWindowPlacement(&pl))
return FALSE;
256 rc = pl.rcNormalPosition;
266 posInvalid = 0x80000000,
267 sizeInvalid = 0xFFFFFFFF,
273 stream >> value.m_width >> value.m_height;
275 stream >> value.m_posX >> value.m_posY >> value.m_dpiX >> value.m_dpiY;
276 }
catch(exception_io_data) {
283 return stream << value.m_width << value.m_height << value.m_posX << value.m_posY << value.m_dpiX << value.m_dpiY;
299 if (uMsg == WM_CREATE || uMsg == WM_INITDIALOG) {
302 m_var.AddWindow(m_wnd);
303 }
else if (uMsg == WM_DESTROY) {
304 PFC_ASSERT( hWnd == m_wnd );
313 m_var.RemoveWindow(m_wnd);
BOOL ProcessWindowMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT &lResult)
static void AdjustRectToScreenArea(CRect &rc, CRect rcParent)
pfc::avltree_t< CWindow > m_windows
static BOOL GetParentWndRect(CWindow wndParent, CRect &rc)
static BOOL GetClientRectAsSC(CWindow wnd, CRect &rc)
void AddWindow(CWindow wnd)
BOOL ProcessWindowMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT &lResult)
BOOL ProcessWindowMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT &lResult)
cfgDialogPosition & m_var
static int DeOverlapDelta()
typedef BOOL(WINAPI *pPowerSetRequest_t)(__in HANDLE PowerRequest
static BOOL AdjustWindowRectHelper(CWindow wnd, CRect &rc)
FB2K_STREAM_WRITER_OVERLOAD(cfgDialogPositionData)
void RemoveWindow(CWindow wnd)
static void DeOverlap(CWindow wnd, CRect &rc)
BOOL StoreConfig(CWindow wnd)
void get_data_raw(stream_writer *p_stream, abort_callback &p_abort)
Retrieves state of the variable. Called only from main thread, when writing configuration file...
static BOOL ShowWindowCentered(CWindow wnd, CWindow wndParent)
void set_data_raw(stream_reader *p_stream, t_size p_sizehint, abort_callback &p_abort)
Sets state of the variable. Called only from main thread, when reading configuration file...
cfgDialogPosition(const GUID &id)
void get_data_raw(stream_writer *p_stream, abort_callback &p_abort)
Retrieves state of the variable. Called only from main thread, when writing configuration file...
void set_data_raw(stream_reader *p_stream, t_size p_sizehint, abort_callback &p_abort)
Sets state of the variable. Called only from main thread, when reading configuration file...
static BOOL CALLBACK MyEnumChildProc(HWND wnd, LPARAM param)
static bool DeOverlapTest(CWindow wnd, CPoint topLeft)
void OverrideDefaultSize(t_uint32 width, t_uint32 height)
~cfgDialogPositionTracker()
cfgWindowSize(const GUID &p_guid)
static BOOL CenterWindowAbove(CWindow wnd, CWindow wndParent)
static BOOL CenterWindowGetRect(CWindow wnd, CWindow wndParent, CRect &out)
Base class for configuration variable classes; provides self-registration mechaisms and methods to se...
cfgDialogPositionTracker(cfgDialogPosition &p_var)
FB2K_STREAM_READER_OVERLOAD(cfgDialogPositionData)
cfgWindowSizeTracker(cfgWindowSize &p_var)
BOOL ApplyConfig(CWindow wnd)
cfgDialogSizeTracker(cfgWindowSize &p_var)