1) Пробовал перехватывать сообщение WM_MOVE | Код | #define CAPTIONBAR_HEIGHT 22 #define MINIMAL_GAP 20
LRESULT CMainDlg::OnMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
CRect rectDesktop; SystemParametersInfo(SPI_GETWORKAREA, 0, &rectDesktop, 0); ULONG desktopWidth = rectDesktop.right - rectDesktop.left; ULONG desktopHeight = rectDesktop.bottom - rectDesktop.top;
UINT xPos = (int)(short) LOWORD(lParam); // horizontal position UINT yPos = (int)(short) HIWORD(lParam); // vertical position
CRect windowRect; GetWindowRect(&windowRect); UINT width = windowRect.right - windowRect.left; UINT height = windowRect.bottom - windowRect.top;
if (xPos < MINIMAL_GAP && xPos > 0) { windowRect.left = 0; windowRect.right = width; MoveWindow(&windowRect); } else if (xPos + width > desktopWidth - MINIMAL_GAP && xPos + width < desktopWidth) {
windowRect.left = desktopWidth - width; windowRect.right = desktopWidth; MoveWindow(&windowRect); }
if (yPos - CAPTIONBAR_HEIGHT < MINIMAL_GAP && yPos - CAPTIONBAR_HEIGHT > 0) {
windowRect.top = 0; windowRect.bottom = height; MoveWindow(&windowRect); } else if (yPos - CAPTIONBAR_HEIGHT + height > desktopHeight - MINIMAL_GAP && yPos - CAPTIONBAR_HEIGHT + height < desktopHeight) {
windowRect.top = desktopHeight - height; windowRect.bottom = desktopHeight; MoveWindow(&windowRect); } return 0; }
|
Но т.к. WM_MOVE посылается уже после перехода окна в новое положение, то наблюдается дрожжание окна. 2) WM_MOVING посылается все время, пока окно находится в движении, пробовал так | Код | LRESULT CMainDialog::OnMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { CRect rectDesktop; SystemParametersInfo(SPI_GETWORKAREA, 0, &rectDesktop, 0); ULONG desktopWidth = rectDesktop.right - rectDesktop.left; ULONG desktopHeight = rectDesktop.bottom - rectDesktop.top;
UINT oldX = x; UINT oldY = y;
RECT* windowRect = (RECT*)lParam; x = windowRect->left; y = windowRect->top; width = windowRect->right - windowRect->left; height = windowRect->bottom - windowRect->top;
if (x < 10 && x > 1) { windowRect->left = 1; windowRect->right = width + 1; x = windowRect->left; } else if (x + width > desktopWidth - 25 && x + width < desktopWidth) {
windowRect->left = desktopWidth - width; windowRect->right = desktopWidth; x = windowRect->left; }
if (y - 22 < 25 && y - 22 > 0) {
windowRect->top = 0; windowRect->bottom = height; y = windowRect->top; } else if (y - 22 + height > desktopHeight - 25 && y - 22 + height < desktopHeight) {
windowRect->top = desktopHeight - height; windowRect->bottom = desktopHeight; y = windowRect->top; } return TRUE; }
|
Теперь окно прилепает к краям рабочего стола, не дрожжит... но отлипает с большим трудом, только если "хорошенько" дернуть мышкой! Никак не могу добиться правильной логики
|