Поиск:

Ответ в темуСоздание новой темы Создание опроса
> Прилипание окна, Прилипание окна к краям рабочего стола 
:(
    Опции темы
zhekha
Дата 5.9.2007, 06:40 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 48
Регистрация: 19.10.2005

Репутация: нет
Всего: нет



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;
}

Теперь окно прилепает к краям рабочего стола, не дрожжит... но отлипает с большим трудом, только если "хорошенько" дернуть мышкой!

Никак не могу добиться правильной логики
PM MAIL   Вверх
  
Ответ в темуСоздание новой темы Создание опроса
0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | Visual C++/MFC/WTL | Следующая тема »


 




[ Время генерации скрипта: 0.0369 ]   [ Использовано запросов: 22 ]   [ GZIP включён ]


Реклама на сайте     Информационное спонсорство

 
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности     Powered by Invision Power Board(R) 1.3 © 2003  IPS, Inc.