How to eject a window bubble (use timer to move up)

Source: Internet
Author: User

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
    1. The time interval at which the window floats
    2. DWORD M_nuptimespan;
    3. Height of each ascent
    4. DWORD M_nincrementheight;
    5. Limit value of Ascent
    6. DWORD M_nmintop;

2. In the constructor of the class, initialize these values:

[CPP]View Plaincopy
    1. m_nincrementheight=2;
    2. m_nuptimespan=1*10;

3. Write the function of the entire window as Startmove

[CPP]View Plaincopy
  1. Start Moving up
  2. void Startmove (void)
  3. {
  4. //Get the area range of the current window
  5. CRect Windowrect;
  6. :: GetWindowRect (GetSafeHwnd (), &windowrect);
  7. //Get wide screen height
  8. int screenwidth=getsystemmetrics (sm_cxscreen);
  9. int screenheith=getsystemmetrics (sm_cyscreen);
  10. //Move the current window to the place below the screen
  11. MoveWindow (Screenwidth-windowrect.width () -2,screenheith,windowrect.width (), Windowrect.height ());
  12. //Test
  13. Invalidate (FALSE);
  14. ShowWindow (SW_SHOWNORMAL);
  15. //Sticky
  16. :: SetWindowPos (This->getsafehwnd (), hwnd_topmost,0,0,0,0,swp_nomove|  Swp_nosize);
  17. //Get taskbar window
  18. cwnd* CWD = NULL;
  19. RECT RT;
  20. hwnd hwnd =:: FindWindow (_t ("Shell_traywnd"), NULL);
  21. if (HWND)
  22. {
  23. CWD = Cwnd::fromhandle (hwnd);
  24. }
  25. Cwd->getwindowrect (&RT);
  26. M_nmintop=rt.top-windowrect.height ()-2;
  27. //Rise timer Settings
  28. SetTimer (Tm_startup,m_nuptimespan,null);
  29. }

Implementation of 4.OnTimer functions

[CPP]View Plaincopy
  1. void OnTimer (uint_ptr nidevent)
  2. {
  3. //If the limit value is already above, then the description has completely floated up
  4. CRect Windowrect;
  5. :: GetWindowRect (GetSafeHwnd (), &windowrect);
  6. if (windowrect.top<=m_nmintop)
  7. {
  8. Invalidate (FALSE);
  9. ShowWindow (SW_SHOWNORMAL);
  10. UpdateWindow ();
  11. //Sticky
  12. This->setforegroundwindow ();
  13. :: SetWindowPos (This->getsafehwnd (), hwnd_topmost,0,0,0,0,swp_nomove|  Swp_nosize);
  14. KillTimer (Tm_startup);
  15. }
  16. //otherwise
  17. Else
  18. {
  19. int iheight=windowrect.height ();
  20. Windowrect.top-=m_nincrementheight;
  21. if (windowrect.top<m_nmintop)
  22. {
  23. Windowrect.top=m_nmintop;
  24. Windowrect.bottom=windowrect.top+iheight;
  25. MoveWindow (&windowrect);
  26. //Sticky
  27. This->setforegroundwindow ();
  28. :: SetWindowPos (This->getsafehwnd (), hwnd_topmost,0,0,0,0,swp_nomove|  Swp_nosize);
  29. KillTimer (Tm_startup);
  30. }
  31. Else
  32. {
  33. Windowrect.bottom-=m_nincrementheight;
  34. MoveWindow (&windowrect);
  35. }
  36. }
  37. Cdialog::ontimer (nidevent);
  38. }

http://blog.csdn.net/huasonl88/article/details/8705558

How to eject a window bubble (use timer to move up)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.