Как анимированно свернуть окно в трей?
От: GOGIH  
Дата: 30.03.05 22:42
Оценка:
Как сделать чтобы при минимизации окно не просто скрывать и показывать иконку в трее, а анимированно сворачивать его в трей?
Re: Как анимированно свернуть окно в трей?
От: Sergeant Украина www.photomirror.com.ua
Дата: 31.03.05 08:05
Оценка:
Здравствуйте, GOGIH, Вы писали:

GOG>Как сделать чтобы при минимизации окно не просто скрывать и показывать иконку в трее, а анимированно сворачивать его в трей?


http://www.rsdn.ru/Forum/?mid=1015062&flat=0
Автор: Кодёнок
Дата: 08.02.05
Курить я буду, но пить не брошу.
Re: Как анимированно свернуть окно в трей?
От: kam Россия  
Дата: 31.03.05 08:29
Оценка: 1 (1)
Здравствуйте, GOGIH, Вы писали:

GOG>Как сделать чтобы при минимизации окно не просто скрывать и показывать иконку в трее, а анимированно сворачивать его в трей?


#define DEFAULT_RECT_WIDTH 150
#define DEFAULT_RECT_HEIGHT 30

BOOL GetTrayWndRect(RECT& TrayRect) 
{
    // try to find task bar window
    HWND hShellTray = ::FindWindowEx(NULL, NULL, _T("Shell_TrayWnd"), NULL);

    if (hShellTray) 
    {
        // try to find system tray window
        HWND hTrayNotify = ::FindWindowEx(hShellTray, NULL, _T("TrayNotifyWnd"), NULL);

        if (hTrayNotify) 
        {
            // try to find the toolbar containing the icons
            HWND hToolbar = ::FindWindowEx(hTrayNotify, NULL, _T("ToolbarWindow32"), NULL);

            if (hToolbar)
            {
                if (::GetWindowRect(hToolbar, &TrayRect)) 
                {
                    // last step is to make the rectangle the size of a single icon
                    TrayRect.left = TrayRect.right - ::GetSystemMetrics(SM_CXSMICON);
                    TrayRect.top = TrayRect.bottom - ::GetSystemMetrics(SM_CYSMICON);
                    return(TRUE);
                }
            }
        }
    }
    
    // failed to get the taskbar or system tray windows
    // let's try to find out which edge the taskbar is attached to
    // -> we then know, that the system tray is either to the right or at
    // the bottom -- this is enough information to make a pretty good guess
    APPBARDATA appBarData = { 0 };
    appBarData.cbSize = sizeof(appBarData);

    if (SHAppBarMessage(ABM_GETTASKBARPOS,&appBarData)) 
    {
        switch(appBarData.uEdge) 
        {
        case ABE_LEFT:
        case ABE_RIGHT:
            // We want to minimize to the bottom of the taskbar
            TrayRect.top = appBarData.rc.bottom - 100;
            TrayRect.bottom = appBarData.rc.bottom - 16;
            TrayRect.left = appBarData.rc.left;
            TrayRect.right = appBarData.rc.right;
            break;
            
        case ABE_TOP:
        case ABE_BOTTOM:
            // We want to minimize to the right of the taskbar
            TrayRect.top = appBarData.rc.top;
            TrayRect.bottom = appBarData.rc.bottom;
            TrayRect.left = appBarData.rc.right - 100;
            TrayRect.right = appBarData.rc.right - 16;
            break;
        }
        
        return(TRUE);
    }
    
    // failed to retrieve the edge the taskbar is attached to -- let's do a
    // bit more guessing...
    hShellTray = ::FindWindowEx(NULL, NULL, _T("Shell_TrayWnd"), NULL);

    if (hShellTray) 
    {
        if (::GetWindowRect(hShellTray, &TrayRect)) 
        {
            if (TrayRect.right - TrayRect.left > DEFAULT_RECT_WIDTH)
                TrayRect.left = TrayRect.right - DEFAULT_RECT_WIDTH;

            if (TrayRect.bottom - TrayRect.top > DEFAULT_RECT_HEIGHT)
                TrayRect.top = TrayRect.bottom - DEFAULT_RECT_HEIGHT;
            
            return(TRUE);
        }
    }
    
    // OK. Haven't found a thing. Provide a default rect based on the
    // current work area
    ::SystemParametersInfo(SPI_GETWORKAREA, 0, &TrayRect, 0);
    TrayRect.left = TrayRect.right - DEFAULT_RECT_WIDTH;
    TrayRect.top = TrayRect.bottom - DEFAULT_RECT_HEIGHT;
    
    return(TRUE);
}

BOOL DoAnimation() 
{
    ANIMATIONINFO ai = { 0 };
    ai.cbSize = sizeof(ai);
    
    if (::SystemParametersInfo(SPI_GETANIMATION, sizeof(ai), &ai, 0))
        return(0 != ai.iMinAnimate);
    
    return(FALSE);
}

#ifndef IDANI_CAPTION
//#pragma INFO_MSG("IDANI_CAPTION not defined -- manually set to 3")
#define IDANI_CAPTION 3
#endif  // !IDANI_CAPTION

void MinToTray(const HWND hWnd) 
{
    if (DoAnimation() && ::IsWindowVisible(hWnd)) 
    {
        RECT rcFrom = { 0 }, rcTo = { 0 };
    
        ::GetWindowRect(hWnd, &rcFrom);
        GetTrayWndRect(rcTo);
        
        ::DrawAnimatedRects(hWnd, IDANI_CAPTION, &rcFrom, &rcTo);
    }
    
    ::ShowWindow(hWnd, SW_HIDE);
}

void RestoreFromTray(const HWND hWnd, BOOL bForceMax) 
{
    if (DoAnimation()) 
    {
        RECT rcFrom = { 0 }, rcTo = { 0 };

        GetTrayWndRect(rcFrom);
        ::GetWindowRect(hWnd, &rcTo);
        
        ::DrawAnimatedRects(hWnd, IDANI_CAPTION, &rcFrom, &rcTo);
    }
    
    BOOL bZoomed = (IsZoomed(hWnd) || bForceMax);

    ::ShowWindow(hWnd, bZoomed ? SW_SHOWMAXIMIZED : SW_RESTORE);
    ::SetActiveWindow(hWnd);
    ::SetForegroundWindow(hWnd);
}
Re[2]: Как анимированно свернуть окно в трей?
От: sercher Украина  
Дата: 31.03.05 08:49
Оценка: +1
В WindowsXP работать не будет. Там между TrayNotifyWnd и ToolbarWindow32 есть ещё SysPager
Re[3]: Как анимированно свернуть окно в трей?
От: AlexEagle Украина http://www.vik.oil
Дата: 31.03.05 09:08
Оценка:
Здравствуйте, sercher, Вы писали:


S> В WindowsXP работать не будет. Там между TrayNotifyWnd и ToolbarWindow32 есть ещё SysPager


Рекомендации ??
Re[4]: Как анимированно свернуть окно в трей?
От: kam Россия  
Дата: 31.03.05 09:13
Оценка:
Здравствуйте, AlexEagle, Вы писали:

AE>Здравствуйте, sercher, Вы писали:



S>> В WindowsXP работать не будет. Там между TrayNotifyWnd и ToolbarWindow32 есть ещё SysPager


AE>Рекомендации ??


Какие, к черту рекомендации?
Проверять версию OS?
Искать окно другим способом?

        if (hTrayNotify) 
        {

            // <- Вот здесь?!   :-\ 

            // try to find the toolbar containing the icons
            HWND hToolbar = ::FindWindowEx(hTrayNotify, NULL, _T("ToolbarWindow32"), NULL);



--
kam
Re[5]: Как анимированно свернуть окно в трей?
От: AlexEagle Украина http://www.vik.oil
Дата: 31.03.05 09:53
Оценка: +1
Здравствуйте, kam, Вы писали:

kam>Какие, к черту рекомендации?


фи как грубо
Re[5]: Как анимированно свернуть окно в трей?
От: sercher Украина  
Дата: 31.03.05 10:01
Оценка:
Здравствуйте, kam, Вы писали:

kam>Здравствуйте, AlexEagle, Вы писали:


AE>>Здравствуйте, sercher, Вы писали:



S>>> В WindowsXP работать не будет. Там между TrayNotifyWnd и ToolbarWindow32 есть ещё SysPager


AE>>Рекомендации ??


kam>Какие, к черту рекомендации?

kam>Проверять версию OS?
kam>Искать окно другим способом?

Я думаю лучше рекурсивный поиск EnumChildWindows() начиная от TrayNotifyWnd или Shell_TrayWnd ...
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.