Implementation of floating windows similar to flashget

Source: Internet
Author: User
Tags knowledge base

I. Introduction:

Floating windows such as flashget, thunder, and Bt can display detailed download information. This type of window has the following features: 1. The window has no title bar, the size of the window is as large as that of the bitmap. 2. Front-end display. 3. Click the left mouse button in the customer area to drag the window. 4. The window transparency can be changed. 5. Double-click to activate and display the main window. The following describes the implementation of each function of the window of this type.

Ii. Code details:

1. The window has no title bar, and the size of the window is as large as that of the bitmap. Create a dialog box resource, set it to the popup type, and cancel the title bar attribute. Insert an image control on it and set it to the imported bitmap.

// Obtain the bitmap cbitmap m_bitmap; hbitmap = m_logo.getbitmap (); Assert (hbitmap); // obtain the bitmap information m_bitmap.attach (hbitmap); bitmap BMP; m_bitmap.getbitmap (& BMP ); // obtain the bitmap size int Nx = BMP. bmwidth; int ny = BMP. bmheight; // move the window movewindow (, NX, NY) based on the bitmap size; m_logo.movewindow (, NX, NY); centerwindow ();

2. Front-end display.

// Display the front-end of the window through the setwindowspos function. : Setwindowpos (m_hwnd, hwnd_topmost, 0, 0, 0, swp_nomove | swp_nosize );

3. Click the left mouse button in the customer area to drag the window. In response to the wm_hittest function, when the left mouse button is pressed and in the customer zone, htcaption is returned, deceiving windows to achieve the same effect as dragging the window in the title bar.

Uint cfloatwnd: onnchittest (cpoint pt) {uint nhittest = cdialog: onnchittest (PT); If (nhittest = htclient &: getasynckeystate (mk_lbutton) <0) // If you press the left mouse button, the return value of the getasynckeystate function is less than 0 nhittest = htcaption; return nhittest ;}

4. Change the transparency of the window. Set the window style to ws_ex_layered and call the setlayeredwindowattributes function to change the window transparency. Ws_ex_layered may not be defined. We can directly set the value to 0x80000.

// Add the ws_ex_layered extension property setwindowlong (m_hwnd, gwl_exstyle, getwindowlong (this-> getsafehwnd (), gwl_exstyle) ^ 0x80000 );


Bool setlayeredwindowattributes (hwnd, colorref crkey, byte balpha, DWORD dwflags );
Hwnd is the window to be changed. When dwflags is lwa_alpha (0x2), The crkey parameter is useless, balpha is transparent, and the value ranges from 0 ~ In the range of 255. This function is to be loaded from user. dll.

// Update the window Transparency Code, where itransparent is transparency. Void cfloatwnd: onupdatetransparent (INT itransparent) {hinstance hinst = loadlibrary ("user32.dll"); If (hinst) {typedef bool (winapi * slwa) (hwnd, colorref, byte, DWORD); slwa pfun = NULL; // get setlayeredwindowattributes function pointer pfun = (slwa) getprocaddress (hinst, "setlayeredwindowattributes"); If (pfun) {pfun (m_hwnd, 0, itransparent, 2) ;}freelibrary (hinst );}}

5. Double-click to activate and display the main window. Due to the influence of the wm_hittest message, when we double-click the mouse, the message wm_nclbuttondblclk is generated instead of the wm_lbuttondblclk message.

Void cfloatwnd: onnclbuttondblclk (uint nflags, cpoint point) {// todo: add your message handler code here and/or call default cwnd * pparent = getparent (); assert (pparent); // display window if (! Pparent-> iswindowvisible () pparent-> showwindow (sw_show); // set the window to the front pparent-> setforegroundwindow (); cdialog: onnclbuttondblclk (nflags, point );}

Some code has been written to adjust the transparency of Slider for your reference.

Void cmaindlg: onhscroll (uint nsbcode, uint NPOs, cscrollbar * pscrollbar) {// todo: add your message handler code here and/or call default // get the Slider's position int icurpos = m_slider.getpos (); // obtain the maximum and minimum values, and page size int Nmax = m_slider.getrangemax (); int Nmin = m_slider.getrangemin (); int npagesize = callback (); Switch (nsbcode) {Case sb_lineleft: If (icurpos> Nmin) icurpos --; break; Case sb_lineright: If (icurpos <Nmax) icurpos ++; break; Case sb_pageleft: If (icurpos> Nmin) icurpos = max (Nmin, icurpos-npagesize ); break; Case sb_pageright: If (icurpos <Nmax) icurpos = min (Nmax, icurpos + npagesize); break; case when: icurpos = NPOs; break; Case sb_thumbposition: icurpos = NPOs; break;} // set the slider position m_slider.setpos (icurpos); // update the transparency pfloatwnd-> onupdatetransparent (icurpos); cdialog: onhscroll (nsbcode, NPOs, pscrollbar );}

As for the right-click menu of the window, display and hide the window, exit the program and other simple code I will not introduce much.

3. The program has been compiled and debugged in Windows XP SP2 and Visual C ++ 6.0.

Download source code!

From: VC Knowledge Base

Related Article

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.