Create a message window for MSN and QQ using VC ++

Source: Internet
Author: User

Create a message window for MSN and QQ using VC ++
Anyone who has used QQ and MSN chat tools knows that as long as a friend goes online, a prompt window will be displayed at the position of the tray, in the form of a pull curtain or fade-in or fade-out; think about how to add a beautiful Prompt window for your program?

1. Create an MSN curtain window

Divided into three parts: 1. Display of the window; 2. stay of the window; 3. Disappear of the window;
If this happens, the system requires three timers for separate control. The defined timer is as follows:

# Define id_timer_pop_window 1
# Define id_timer_dispaly_delay 2
# Define id_timer_close_window 3

A window can be inherited from cwnd, and can also be derived from cframewnd. This is not the main problem. The key is how you handle messages of wm_paint, wm_mousemove, and wm_timer. In general, I use onpaint () to display images and process timer messages in wm_timer. The following code is used in the Timer:

Cmsgwnd: cmsgwnd ()
{
...
Settimer (id_tiemr_pop_window, 20, null );
...
}

Void cmsgwnd: ontimer (uint nidevent)
{
Static int nheight = 0;
Int Cy = getsystemmetrics (sm_cyscreen );
Int Cx = getsystemmetrics (sm_cxscreen );
Rect;
Systemparametersinfo (spi_getworkarea, 0, & rect, 0 );
Int y = rect. bottom-rect.top;
Int x = rect. right-rect.left;
X = x-WIN_WIDTH;

Switch (nidevent)
{
Case id_timer_pop_window:
If (nheight <= win_height)
{
++ Nheight;
Movewindow (X, Y-nheight, win_width, win_height );
Invalidate (false );
}
Else
{
Killtimer (id_timer_pop_window );
Settimer (id_timer_display_delay, 5000, null );
}
Break;
Case id_timer_close_window:
If (nheight> = 0)
{
Nheight --;
Movewindow (X, Y-nheight, win_width, nheight );
}
Else
{
Killtimer (id_timer_close_window );
Sendmessage (wm_close );
}
Break;
Case id_timer_display_delay:
Killtimer (id_timer_display_delay );
Settimer (id_timer_close_window, 20, null );
Break;
}
Cwnd: ontimer (nidevent );
}

Control the display process of the window based on the length of the timer you set;
Ii. Implement QQ fade-out display

Actually, an API function is used: animatewindow. The following describes the function:

Bool animatewindow (
Hwnd, // handle to the window to animate
DWORD dwtime, // duration of Animation
DWORD dwflags // animation type
);

The first two parameters of the above function can be understood at a Glance. Needless to say, the last parameter dwflags sets the animation window style:

Various logos:

Description
Aw_slide uses slide animation. By default, roll animation is used.
This flag is ignored when used with the aw_center flag.
Aw_activate activates the window. Do not use this flag with aw_hide.
Aw_blend uses a fade effect. This flag can be used only if hwnd is a top-level window.
Aw_hide hides the window. By default, the window is shown.
Aw_center makes the window appear to collapse inward if the aw_hide flag is used or expand outward
If the aw_hide flag is not used.
Aw_hor_positive animate the window from left to right. This flag can be used with roll or slide animation. It is ignored when used with the aw_center flag.
Aw_hor_negative animate the window from right to left. This flag can be used with roll or slide animation.
It is ignored when used with the aw_center flag.
Aw_ver_positive animate the window from top to bottom. This flag can be used with roll or slide animation.
It is ignored when used with the aw_center flag.
Aw_ver_negative animate the window from bottom to top. This flag can be used with roll or slide animation.
It is ignored when used with the aw_center flag.

The above content is excerpted from msdn. to fade in and out, aw_belnd is used.

3. Code displayed in the control window

Cmainframe: oncreate (...)
{
//...
Animatewindow (getsafehwnd (), 1000, aw_center | aw_blend );
//...
}

4. Closed code

Cmainframe: onclose (..)
{
Animatewindow (getsafehwnd (), 1000, aw_hide | aw_center | aw_blend );
}

In fact, animatewindow only uses the windows method. If you want more personalized window effects, you should write more code.

V. Conclusion

In fact, in the prompt window of MSN, if you want to use a complex background and effect, there is still a problem of refreshing the screen, and there should be no flash refresh. due to the time-consuming promotion, the shortcomings are inevitable. At the same time, the above Code also referred to a part of the previous vckbase technical documentation. Thank you!

If you have any questions, please contact us! Make progress together!

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.