static INT_PTR AssertInsideScreen(WPARAM wParam, LPARAM lParam) { LPRECT rc = (LPRECT) wParam; if (rc == NULL) return -1; RECT rcScreen; SystemParametersInfo(SPI_GETWORKAREA, 0, &rcScreen, FALSE); if (MonitorFromRect(rc, MONITOR_DEFAULTTONULL)) return 0; MONITORINFO mi = {0}; HMONITOR hMonitor = MonitorFromRect(rc, MONITOR_DEFAULTTONEAREST); mi.cbSize = sizeof(mi); if (GetMonitorInfo(hMonitor, &mi)) rcScreen = mi.rcWork; if (rc->top >= rcScreen.bottom) OffsetRect(rc, 0, rcScreen.bottom - rc->bottom); else if (rc->bottom <= rcScreen.top) OffsetRect(rc, 0, rcScreen.top - rc->top); if (rc->left >= rcScreen.right) OffsetRect(rc, rcScreen.right - rc->right, 0); else if (rc->right <= rcScreen.left) OffsetRect(rc, rcScreen.left - rc->left, 0); return 1; }
MIR_CORE_DLL(int) Utils_AssertInsideScreen(RECT *rc) { if (rc == NULL) return -1; RECT rcScreen; SystemParametersInfo(SPI_GETWORKAREA, 0, &rcScreen, FALSE); if (MonitorFromRect(rc, MONITOR_DEFAULTTONULL)) return 0; MONITORINFO mi = { 0 }; HMONITOR hMonitor = MonitorFromRect(rc, MONITOR_DEFAULTTONEAREST); mi.cbSize = sizeof(mi); if (GetMonitorInfo(hMonitor, &mi)) rcScreen = mi.rcWork; if (rc->top >= rcScreen.bottom) OffsetRect(rc, 0, rcScreen.bottom - rc->bottom); else if (rc->bottom <= rcScreen.top) OffsetRect(rc, 0, rcScreen.top - rc->top); if (rc->left >= rcScreen.right) OffsetRect(rc, rcScreen.right - rc->right, 0); else if (rc->right <= rcScreen.left) OffsetRect(rc, rcScreen.left - rc->left, 0); return 1; }
int clamp_window(RECT *rwin) { HMONITOR hmon; hmon=MonitorFromRect(rwin,MONITOR_DEFAULTTONEAREST); if(hmon){ MONITORINFO mi; mi.cbSize=sizeof(mi); if(GetMonitorInfo(hmon,&mi)){ int x,y,cx,cy; RECT rmon; rmon=mi.rcWork; x=rwin->left; y=rwin->top; cx=rwin->right-rwin->left; cy=rwin->bottom-rwin->top; if(x<rmon.left) x=rmon.left; if(y<rmon.top) y=rmon.top; if(cx>(rmon.right-rmon.left)) cx=rmon.right-rmon.left; if(cy>(rmon.bottom-rmon.top)) cy=rmon.bottom-rmon.top; if((x+cx)>rmon.right) x=rmon.right-cx; if((y+cy)>rmon.bottom) y=rmon.bottom-cy; rwin->left=x; rwin->top=y; rwin->right=x+cx; rwin->bottom=y+cy; } } return 0; }
void GetBestOverlapWithMonitors(LPRECT rect) { int rcLeft, rcTop; int rcWidth, rcHeight; RECT rcMon; HMONITOR hMon = MonitorFromRect(rect, MONITOR_DEFAULTTONEAREST); MONITORINFO info; info.cbSize = sizeof(info); GetMonitorInfo(hMon, &info); rcMon = info.rcMonitor; rcLeft = rect->left; rcTop = rect->top; rcWidth = (rect->right - rect->left); rcHeight = (rect->bottom - rect->top); if (rcLeft < rcMon.left) rcLeft = rcMon.left; if (rcTop < rcMon.top) rcTop = rcMon.top; if (rcLeft > (rcMon.right - rcWidth)) rcLeft = (rcMon.right - rcWidth); if (rcTop > (rcMon.bottom - rcHeight)) rcTop = (rcMon.bottom - rcHeight); OffsetRect(rect, (rcLeft-rect->left), (rcTop-rect->top)); }
VOID PhSaveWindowPlacementToSetting( _In_opt_ PWSTR PositionSettingName, _In_opt_ PWSTR SizeSettingName, _In_ HWND WindowHandle ) { WINDOWPLACEMENT placement = { sizeof(placement) }; PH_RECTANGLE windowRectangle; MONITORINFO monitorInfo = { sizeof(MONITORINFO) }; GetWindowPlacement(WindowHandle, &placement); windowRectangle = PhRectToRectangle(placement.rcNormalPosition); // The rectangle is in workspace coordinates. Convert the values back to screen coordinates. if (GetMonitorInfo(MonitorFromRect(&placement.rcNormalPosition, MONITOR_DEFAULTTOPRIMARY), &monitorInfo)) { windowRectangle.Left += monitorInfo.rcWork.left - monitorInfo.rcMonitor.left; windowRectangle.Top += monitorInfo.rcWork.top - monitorInfo.rcMonitor.top; } if (PositionSettingName) PhSetIntegerPairSetting(PositionSettingName, windowRectangle.Position); if (SizeSettingName) PhSetScalableIntegerPairSetting2(SizeSettingName, windowRectangle.Size); }
void CDpiAware::GetCenteredRect(HWND hWnd, RECT& rcCentered) { bool lbCentered = false; HMONITOR hMon; if (hWnd) hMon = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST); else hMon = MonitorFromRect(&rcCentered, MONITOR_DEFAULTTONEAREST); MONITORINFO mi = {}; GetNearestMonitorInfo(&mi, NULL, hWnd ? NULL : &rcCentered, hWnd); int iWidth = rcCentered.right - rcCentered.left; int iHeight = rcCentered.bottom - rcCentered.top; RECT rcNew = { (mi.rcWork.left + mi.rcWork.right - iWidth)/2, (mi.rcWork.top + mi.rcWork.bottom - iHeight)/2 }; rcNew.right = rcNew.left + iWidth; rcNew.bottom = rcNew.top + iHeight; rcCentered = rcNew; }
void reopen_console (void) { HWND hwnd; if (realconsole) return; if (consoleopen >= 0) return; hwnd = myGetConsoleWindow (); if (hwnd) { int newpos = 1; int x, y, w, h; if (!regqueryint (NULL, _T("LoggerPosX"), &x)) newpos = 0; if (!regqueryint (NULL, _T("LoggerPosY"), &y)) newpos = 0; if (!regqueryint (NULL, _T("LoggerPosW"), &w)) newpos = 0; if (!regqueryint (NULL, _T("LoggerPosH"), &h)) newpos = 0; if (newpos) { RECT rc; rc.left = x; rc.top = y; rc.right = x + w; rc.bottom = y + h; if (MonitorFromRect (&rc, MONITOR_DEFAULTTONULL) != NULL) { SetForegroundWindow (hwnd); SetWindowPos (hwnd, HWND_TOP, x, y, w, h, SWP_NOACTIVATE); } } } }
bool grib_pi::QualifyCtrlBarPosition( wxPoint position, wxSize size ) { // Make sure drag bar (title bar) or grabber always screen bool b_reset_pos = false; #ifdef __WXMSW__ // Support MultiMonitor setups which an allow negative window positions. // If the requested window does not intersect any installed monitor, // then default to simple primary monitor positioning. RECT frame_title_rect; frame_title_rect.left = position.x; frame_title_rect.top = position.y; frame_title_rect.right = position.x + size.x; frame_title_rect.bottom = m_DialogStyle == ATTACHED_HAS_CAPTION ? position.y + 30 : position.y + size.y; if(NULL == MonitorFromRect(&frame_title_rect, MONITOR_DEFAULTTONULL)) b_reset_pos = true; #else wxRect window_title_rect; // conservative estimate window_title_rect.x = position.x; window_title_rect.y = position.y; window_title_rect.width = size.x; window_title_rect.height = m_DialogStyle == ATTACHED_HAS_CAPTION ? 30 : size.y; wxRect ClientRect = wxGetClientDisplayRect(); if(!ClientRect.Intersects(window_title_rect)) b_reset_pos = true; #endif return !b_reset_pos; }
static void hippo_platform_impl_get_screen_info(HippoPlatform *platform, HippoRectangle *monitor_rect_p, HippoRectangle *tray_icon_rect_p, HippoOrientation *tray_icon_orientation_p) { APPBARDATA abd; abd.cbSize = sizeof(abd); if (!SHAppBarMessage(ABM_GETTASKBARPOS, &abd)) { g_warning("Failed to get task bar extents"); return; } HippoOrientation orientation; switch (abd.uEdge) { case ABE_BOTTOM: case ABE_TOP: orientation = HIPPO_ORIENTATION_HORIZONTAL; break; case ABE_LEFT: case ABE_RIGHT: orientation = HIPPO_ORIENTATION_VERTICAL; break; default: g_warning("unknown tray icon orientation"); break; } if (tray_icon_orientation_p) *tray_icon_orientation_p = orientation; RECT iconTrayRect; if (!find_icon_tray_rect(&iconTrayRect, orientation)) { // If this starts happening regularly, we can refine // this code to make a better guess at that point. iconTrayRect = abd.rc; } if (tray_icon_rect_p) { tray_icon_rect_p->x = iconTrayRect.left; tray_icon_rect_p->width = iconTrayRect.right - iconTrayRect.left; tray_icon_rect_p->y = iconTrayRect.top; tray_icon_rect_p->height = iconTrayRect.bottom - iconTrayRect.top; } if (monitor_rect_p) { HMONITOR monitor = MonitorFromRect(&iconTrayRect, MONITOR_DEFAULTTONEAREST); MONITORINFO monitorInfo; monitorInfo.cbSize = sizeof(monitorInfo); if (GetMonitorInfo(monitor, &monitorInfo)) { monitor_rect_p->x = monitorInfo.rcWork.left; monitor_rect_p->y = monitorInfo.rcWork.top; monitor_rect_p->width = monitorInfo.rcWork.right - monitorInfo.rcWork.left; monitor_rect_p->height = monitorInfo.rcWork.bottom - monitorInfo.rcWork.top; } else { g_warning("GetMonitorInfo failed"); // Shouldn't happen, don't both with a fallback } } }
/*********************************************************************** * MonitorFromPoint (USER32.@) */ HMONITOR WINAPI MonitorFromPoint( POINT pt, DWORD flags ) { RECT rect; SetRect( &rect, pt.x, pt.y, pt.x + 1, pt.y + 1 ); return MonitorFromRect( &rect, flags ); }
void ResizeTo(HWND hwnd, int width, int height) { HWND root_wnd = ::GetAncestor(hwnd, GA_ROOT); // Retrieve current window placement information. WINDOWPLACEMENT placement; ::GetWindowPlacement(root_wnd, &placement); if(placement.showCmd == SW_MAXIMIZE) return; HMONITOR monitor = MonitorFromRect(&placement.rcNormalPosition, MONITOR_DEFAULTTONEAREST); MONITORINFO info; info.cbSize = sizeof(info); GetMonitorInfo(monitor, &info); if (width < 100) width = 100; else if (width > info.rcWork.right - info.rcWork.left) width = info.rcWork.right - info.rcWork.left; if (height < 100) height = 100; else if (height > info.rcWork.bottom - info.rcWork.top) height = info.rcWork.bottom - info.rcWork.top; ::SetWindowPos(root_wnd, NULL, 0, 0, width, height, SWP_NOMOVE | SWP_NOZORDER); if (placement.showCmd == SW_MINIMIZE) ::ShowWindow(root_wnd, SW_RESTORE); }
/*********************************************************************** * MonitorFromWindow (USER32.@) */ HMONITOR WINAPI MonitorFromWindow(HWND hWnd, DWORD dwFlags) { RECT rect; WINDOWPLACEMENT wp; TRACE("(%p, 0x%08x)\n", hWnd, dwFlags); if (IsIconic(hWnd) && GetWindowPlacement(hWnd, &wp)) return MonitorFromRect( &wp.rcNormalPosition, dwFlags ); if (GetWindowRect( hWnd, &rect )) return MonitorFromRect( &rect, dwFlags ); if (!(dwFlags & (MONITOR_DEFAULTTOPRIMARY|MONITOR_DEFAULTTONEAREST))) return 0; /* retrieve the primary */ SetRect( &rect, 0, 0, 1, 1 ); return MonitorFromRect( &rect, dwFlags ); }
RectI GetWorkAreaRect(RectI rect) { MONITORINFO mi = { 0 }; mi.cbSize = sizeof mi; HMONITOR monitor = MonitorFromRect(&rect.ToRECT(), MONITOR_DEFAULTTONEAREST); BOOL ok = GetMonitorInfo(monitor, &mi); if (!ok) SystemParametersInfo(SPI_GETWORKAREA, 0, &mi.rcWork, 0); return RectI::FromRECT(mi.rcWork); }
MONITORINFO GetMonitorInformation(HWND handle) { HMONITOR monitor; MONITORINFO mi; RECT rect; GetWindowRect(handle, &rect); monitor = MonitorFromRect(&rect, MONITOR_DEFAULTTONEAREST); mi.cbSize = sizeof mi; GetMonitorInfo(monitor, &mi); return mi; }
CRect CCherryNotificationDialog::GetAnchorRect(UINT nWidth, UINT nHeight) { CRect rect; APPBARDATA appBarData; appBarData.cbSize = sizeof(APPBARDATA); if (!SHAppBarMessage(ABM_GETTASKBARPOS, &appBarData)) return rect; // TASKBAR 가 위치한 모니터의 핸들 얻어옴 HMONITOR hMonitor = MonitorFromRect(&appBarData.rc, MONITOR_DEFAULTTOPRIMARY); MONITORINFO monitorInfo; monitorInfo.cbSize = sizeof(MONITORINFO); GetMonitorInfo(hMonitor, &monitorInfo); CRect workRect(monitorInfo.rcWork); CPoint point; switch (appBarData.uEdge) { case ABE_LEFT: rect.SetRect( appBarData.rc.right, appBarData.rc.bottom - SCROLLBAR_WIDTH - nHeight, appBarData.rc.right + nWidth, appBarData.rc.bottom - SCROLLBAR_WIDTH); break; case ABE_TOP: rect.SetRect( appBarData.rc.right - SCROLLBAR_WIDTH - nWidth, appBarData.rc.bottom, appBarData.rc.right - SCROLLBAR_WIDTH, appBarData.rc.bottom + nHeight); break; case ABE_RIGHT: rect.SetRect( appBarData.rc.left - nWidth, appBarData.rc.bottom - SCROLLBAR_WIDTH - nHeight, appBarData.rc.left, appBarData.rc.bottom - SCROLLBAR_WIDTH); break; case ABE_BOTTOM: rect.SetRect( appBarData.rc.right - SCROLLBAR_WIDTH - nWidth, appBarData.rc.top - nHeight, appBarData.rc.right - SCROLLBAR_WIDTH, appBarData.rc.top); break; } return rect; }
int set_window_pos(HWND hwnd,int x,int y,int w,int h,int max) { int result=FALSE; HMONITOR hmon; MONITORINFO mi; RECT rect; rect.left=x; rect.top=y; rect.right=x+w; rect.bottom=y+h; hmon=MonitorFromRect(&rect,MONITOR_DEFAULTTONEAREST); mi.cbSize=sizeof(mi); if(GetMonitorInfo(hmon,&mi)){ int cw,ch; rect=mi.rcWork; cw=w; ch=h; if(0==cw) cw=100; if(0==ch) ch=100; if((x+cw)>rect.right) x=rect.right-cw; if(x<rect.left) x=rect.left; if((y+ch)>rect.bottom) y=rect.bottom-ch; if(y<rect.top) y=rect.top; if(w>0 && h>0){ int rw,rh; rw=rect.right-rect.left; rh=rect.bottom-rect.top; if(w>rw) w=rw; if(h>rh) h=rh; if(w<25) w=25; if(h<25) h=25; } { int flags=SWP_NOZORDER; if(max) flags|=SW_MAXIMIZE; if(w==0 || h==0) flags|=SWP_NOSIZE; SetWindowPos(hwnd,NULL,x,y,w,h,flags); } result=TRUE; } return result; }
gfx::Rect GetMonitorBoundsForRect(const gfx::Rect& rect) { RECT p_rect = rect.ToRECT(); HMONITOR monitor = MonitorFromRect(&p_rect, MONITOR_DEFAULTTONEAREST); if(monitor) { MONITORINFO mi = { 0 }; mi.cbSize = sizeof(mi); GetMonitorInfo(monitor, &mi); return gfx::Rect(mi.rcWork); } NOTREACHED(); return gfx::Rect(); }
// Get the desktop dimensions - for the monitor containing most of the active window //----------------------------------------------------------------------------- void CPUTWindowWin::GetDesktopDimensions(int *pX, int *pY, int *pWidth, int *pHeight) { RECT windowRect; GetWindowRect(mhWnd, &windowRect); HMONITOR hMonitor = MonitorFromRect(&windowRect, MONITOR_DEFAULTTONEAREST); MONITORINFO monitorInfo; monitorInfo.cbSize = sizeof(monitorInfo); GetMonitorInfo(hMonitor, &monitorInfo); *pX = monitorInfo.rcMonitor.left; *pY = monitorInfo.rcMonitor.top; *pWidth = monitorInfo.rcMonitor.right - monitorInfo.rcMonitor.left; *pHeight = monitorInfo.rcMonitor.bottom - monitorInfo.rcMonitor.top; }
HMONITOR GetNearestMonitorInfo(MONITORINFO* pmi /*= NULL*/, HMONITOR hDefault /*= NULL*/, LPCRECT prcWnd /*= NULL*/, HWND hWnd /*= NULL*/) { HMONITOR hMon = NULL; MONITORINFO mi = {0}; if (hDefault) { mi.cbSize = sizeof(mi); if (GetMonitorInfo(hDefault, &mi)) { hMon = hDefault; } else { _ASSERTE(FALSE && "GetMonitorInfo(hDefault) failed"); mi.cbSize = 0; } } if (!hMon) { if (prcWnd) { hMon = MonitorFromRect(prcWnd, MONITOR_DEFAULTTONEAREST); } else if (hWnd) { hMon = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST); } if (hMon) { mi.cbSize = sizeof(mi); if (!GetMonitorInfo(hMon, &mi)) { _ASSERTE(FALSE && "GetMonitorInfo(hDefault) failed"); mi.cbSize = 0; } } } if (!hMon) { _ASSERTE(FALSE && "Nor RECT neither HWND was succeeded, defaulting to PRIMARY"); hMon = GetPrimaryMonitorInfo(&mi); } if (pmi) *pmi = mi; return hMon; }
static void MoveOnScreen(RECT* rect) { HMONITOR hMonitor; MONITORINFO mi; /* find the nearest monitor ... */ hMonitor = MonitorFromRect(rect, MONITOR_DEFAULTTONEAREST); /* ... and move it into the work area (ie excluding task bar)*/ mi.cbSize = sizeof(mi); GetMonitorInfo(hMonitor, &mi); ShiftBetween(&rect->left, &rect->right, mi.rcWork.left, mi.rcWork.right); ShiftBetween(&rect->top, &rect->bottom, mi.rcWork.top, mi.rcWork.bottom); }
static bool test_rect(const RECT * rc) { RECT clip = {}; if (EnumDisplayMonitors(NULL,NULL,__MonitorEnumProc,(LPARAM)&clip)) { const LONG sanitycheck = 4; const LONG cwidth = clip.right - clip.left; const LONG cheight = clip.bottom - clip.top; const LONG width = rc->right - rc->left; const LONG height = rc->bottom - rc->top; if (width > cwidth * sanitycheck || height > cheight * sanitycheck) return false; } return MonitorFromRect(rc,MONITOR_DEFAULTTONULL) != NULL; }
bool CCommonAppUtils::IsFullscreenWindowActive() { HWND hwnd = GetForegroundWindow(); RECT rcWindow; GetWindowRect(hwnd, &rcWindow); HMONITOR hm = MonitorFromRect(&rcWindow, MONITOR_DEFAULTTONULL); if (!hm) return false; MONITORINFO mi = { sizeof(mi) }; GetMonitorInfo(hm, &mi); return !!EqualRect(&rcWindow, &mi.rcMonitor); }
std::shared_ptr<osd_monitor_info> monitor_from_rect(const osd_rect& rect) override { if (!m_initialized) return nullptr; RECT p; p.top = rect.top(); p.left = rect.left(); p.bottom = rect.bottom(); p.right = rect.right(); auto nearest = monitor_from_handle(reinterpret_cast<std::uintptr_t>(MonitorFromRect(&p, MONITOR_DEFAULTTONEAREST))); assert(nearest != nullptr); return nearest; }
/*********************************************************************** * MonitorFromWindow (USER32.@) */ HMONITOR WINAPI MonitorFromWindow(HWND hWnd, DWORD dwFlags) { WINDOWPLACEMENT wp; if (dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST)) return xPRIMARY_MONITOR; if (IsIconic(hWnd) ? GetWindowPlacement(hWnd, &wp) : GetWindowRect(hWnd, &wp.rcNormalPosition)) { return MonitorFromRect(&wp.rcNormalPosition, dwFlags); } return NULL; }
HMONITOR CMonitorInfo::GetFullScreenRect(HWND hWnd, CRect& rc) { CRect wr; ::GetWindowRect(hWnd, wr); // try to get screen size from monitor API in case we're dual-monitor MONITORINFO mi; mi.cbSize = sizeof(mi); HMONITOR hMon = MonitorFromRect(wr, MONITOR_DEFAULTTONEAREST); if (hMon != NULL && GetMonitorInfo(hMon, &mi)) { rc = mi.rcMonitor; } else { // fall back to older API rc = CRect(0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)); } return(hMon); }
int get_nearest_monitor(int x,int y,int width,int height,RECT *rect) { HMONITOR hmon; MONITORINFO mi; RECT r={0}; r.left=x; r.top=y; r.right=x+width; r.bottom=y+height; hmon=MonitorFromRect(&r,MONITOR_DEFAULTTONEAREST); mi.cbSize=sizeof(mi); if(GetMonitorInfo(hmon,&mi)){ *rect=mi.rcWork; return TRUE; } return FALSE; }
//-------------------------------------------------------------- // find monitor and adapter based on window rect void mgWinServices::findAdapter() { // fiond the monitor containing the window RECT windowRect; windowRect.left = m_windowX != CW_USEDEFAULT ? m_windowX : 0; windowRect.top = m_windowY != CW_USEDEFAULT ? m_windowY : 0; windowRect.right = windowRect.left + m_windowWidth; windowRect.bottom = windowRect.top + m_windowHeight; HMONITOR monitor = MonitorFromRect(&windowRect, MONITOR_DEFAULTTONEAREST); MONITORINFOEX monitorInfo; memset(&monitorInfo, 0, sizeof(monitorInfo)); monitorInfo.cbSize = sizeof(monitorInfo); GetMonitorInfo(monitor, &monitorInfo); m_monitorDevice = monitorInfo.szDevice; mgDebug("running on monitor=%s", (const char*) m_monitorDevice); }
void CDpiAware::UpdateStartupInfo(CEStartupEnv* pStartEnv) { if (!pStartEnv) return; pStartEnv->bIsPerMonitorDpi = IsPerMonitorDpi(); for (INT_PTR i = ((int)pStartEnv->nMonitorsCount)-1; i >= 0; i--) { HMONITOR hMon = MonitorFromRect(&pStartEnv->Monitors[i].rcMonitor, MONITOR_DEFAULTTONEAREST); if (!hMon) continue; for (int j = MDT_Effective_DPI; j <= MDT_Raw_DPI; j++) { DpiValue dpi; QueryDpiForMonitor(hMon, &dpi, (MonitorDpiType)j); pStartEnv->Monitors[i].dpis[j+1].x = dpi.Xdpi; pStartEnv->Monitors[i].dpis[j+1].y = dpi.Xdpi; } } }
win_monitor_info *winwindow_video_window_monitor(win_window_info *window, const RECT *proposed) { win_monitor_info *monitor; // in window mode, find the nearest if (!window->fullscreen) { if (proposed != NULL) monitor = winvideo_monitor_from_handle(MonitorFromRect(proposed, MONITOR_DEFAULTTONEAREST)); else monitor = winvideo_monitor_from_handle(MonitorFromWindow(window->hwnd, MONITOR_DEFAULTTONEAREST)); } // in full screen, just use the configured monitor else monitor = window->monitor; // make sure we're up-to-date winvideo_monitor_refresh(monitor); return monitor; }
void CResizableStandAloneDialog::OnMoving(UINT fwSide, LPRECT pRect) { m_bVertical = m_bHorizontal = false; if (pRect) { HMONITOR hMonitor = MonitorFromRect(pRect, MONITOR_DEFAULTTONEAREST); if (hMonitor) { MONITORINFO minfo = { 0 }; minfo.cbSize = sizeof(minfo); if (GetMonitorInfo(hMonitor, &minfo)) { int width = pRect->right - pRect->left; int heigth = pRect->bottom - pRect->top; if (abs(pRect->left - minfo.rcWork.left) < m_stickySize) { pRect->left = minfo.rcWork.left; pRect->right = pRect->left + width; } if (abs(pRect->right - minfo.rcWork.right) < m_stickySize) { pRect->right = minfo.rcWork.right; pRect->left = pRect->right - width; } if (abs(pRect->top - minfo.rcWork.top) < m_stickySize) { pRect->top = minfo.rcWork.top; pRect->bottom = pRect->top + heigth; } if (abs(pRect->bottom - minfo.rcWork.bottom) < m_stickySize) { pRect->bottom = minfo.rcWork.bottom; pRect->top = pRect->bottom - heigth; } } } } CStandAloneDialogTmpl<CResizableDialog>::OnMoving(fwSide, pRect); }