Original link: http://blog.csdn.net/tangaowen/article/details/5108980
How to pop a window bubble
Recently encountered in the work of such a requirement, is the need to a window from the lower right corner of the taskbar slowly up to the top of the taskbar, and now there are a lot of software has such bubbles, such as: Sogou Input method of the Entry Update window, such as CSDN advertising window and so on.
1. First move the window that will pop up to the taskbar (current screen) below
2. Then, get the height of the taskbar (essentially a window) so you know where the window will end up.
3. Then calculate where the window will end up: Calculation formula: dwmaxheight= Current screen height-top of taskbar window +/-Moderate offset value
4. Set a timer
5. In the Timer response window, call MoveWindow or SetWindowPos function to reduce a fixed y-coordinate value each time Dwincreatmentvalue
A few things about the timer response:
1. If the Top<=dwmaxheight Description window of the rising window has surfaced to a predetermined position, this time
KillTimer
2. If the top>dwmaxheight of the rising window, the description has not reached the predetermined position, this time
Processing based on the value of the top+dwincreatmentvalue of the rising window
(1) The Top+dwincreatmentvalue<=dwmaxheight of the rising window, stating that this time do not increase
Dwincreatmentvalue so many values can be raised to a predetermined position, this time
Let the top=dwmaxheight of the rising window, and then setwindowpos to the predetermined position, and then
KillTimer
(2) The top+dwincreatmentvalue>dwmaxheight of the rising window, indicating that this time is not
Rise to the predetermined position, so direct: Rising window Rect+dwincreatmentvalue
The SetWindowPos then moves the window up dwincreatementvalue position.
Here is the relevant code:
1. Declare two member variables in a class:
[CPP]View Plaincopy
- The time interval at which the window floats
- DWORD M_nuptimespan;
- Height of each ascent
- DWORD M_nincrementheight;
- Limit value of Ascent
- DWORD M_nmintop;
2. In the constructor of the class, initialize these values:
[CPP]View Plaincopy
- m_nincrementheight=2;
- m_nuptimespan=1*10;
3. Write the function of the entire window as Startmove
[CPP]View Plaincopy
- Start Moving up
- void Startmove (void)
- {
- //Get the area range of the current window
- CRect Windowrect;
- :: GetWindowRect (GetSafeHwnd (), &windowrect);
- //Get wide screen height
- int screenwidth=getsystemmetrics (sm_cxscreen);
- int screenheith=getsystemmetrics (sm_cyscreen);
- //Move the current window to the place below the screen
- MoveWindow (Screenwidth-windowrect.width () -2,screenheith,windowrect.width (), Windowrect.height ());
- //Test
- Invalidate (FALSE);
- ShowWindow (SW_SHOWNORMAL);
- //Sticky
- :: SetWindowPos (This->getsafehwnd (), hwnd_topmost,0,0,0,0,swp_nomove| Swp_nosize);
- //Get taskbar window
- cwnd* CWD = NULL;
- RECT RT;
- hwnd hwnd =:: FindWindow (_t ("Shell_traywnd"), NULL);
- if (HWND)
- {
- CWD = Cwnd::fromhandle (hwnd);
- }
- Cwd->getwindowrect (&RT);
- M_nmintop=rt.top-windowrect.height ()-2;
- //Rise timer Settings
- SetTimer (Tm_startup,m_nuptimespan,null);
- }
Implementation of 4.OnTimer functions
[CPP]View Plaincopy
- void OnTimer (uint_ptr nidevent)
- {
- //If the limit value is already above, then the description has completely floated up
- CRect Windowrect;
- :: GetWindowRect (GetSafeHwnd (), &windowrect);
- if (windowrect.top<=m_nmintop)
- {
- Invalidate (FALSE);
- ShowWindow (SW_SHOWNORMAL);
- UpdateWindow ();
- //Sticky
- This->setforegroundwindow ();
- :: SetWindowPos (This->getsafehwnd (), hwnd_topmost,0,0,0,0,swp_nomove| Swp_nosize);
- KillTimer (Tm_startup);
- }
- //otherwise
- Else
- {
- int iheight=windowrect.height ();
- Windowrect.top-=m_nincrementheight;
- if (windowrect.top<m_nmintop)
- {
- Windowrect.top=m_nmintop;
- Windowrect.bottom=windowrect.top+iheight;
- MoveWindow (&windowrect);
- //Sticky
- This->setforegroundwindow ();
- :: SetWindowPos (This->getsafehwnd (), hwnd_topmost,0,0,0,0,swp_nomove| Swp_nosize);
- KillTimer (Tm_startup);
- }
- Else
- {
- Windowrect.bottom-=m_nincrementheight;
- MoveWindow (&windowrect);
- }
- }
- Cdialog::ontimer (nidevent);
- }
http://blog.csdn.net/huasonl88/article/details/8705558
How to eject a window bubble (use timer to move up)