Implementation of a floating window similar to FlashGet

Source: Internet
Author: User

First, Introduction:

Like FlashGet, Thunder, BT and so have floating windows, can be detailed to display the details of the download, the type of window has a few features: 1, the window has no title bar, the window size as large as the bitmap. 2, front end display. 3, in the customer area, press the left mouse button can drag the location of the window. 4, can change the transparency of the window. 5, double-click the main window can be activated, and display. Below is a description of each feature implementation for the type of window.

Second, the code detailed description:

1, the window has no title bar, the window size and bitmap as large. Creates a dialog resource, sets the popup type, and cancels the title bar property. Insert a picture control above, set to the imported bitmap.

//得到位图
  CBitmap m_Bitmap;
  HBITMAP hBitmap = m_Logo.GetBitmap();
  ASSERT(hBitmap);
  //得到位图的信息
  m_Bitmap.Attach(hBitmap);
  BITMAP bmp;
  m_Bitmap.GetBitmap(&bmp);
  //得到位图的大小
  int nX = bmp.bmWidth;
  int nY = bmp.bmHeight;
  //根据位图的大小移动窗口
  MoveWindow(0,0,nX,nY);
  m_Logo.MoveWindow(0,0,nX,nY);
  CenterWindow();

2, front end display.//通过SetWindowsPos函数将窗口前端显示。
  ::SetWindowPos(m_hWnd,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE);

3, in the customer area, press the left mouse button can drag the location of the window. Respond to the Wm_hittest function, when the left mouse button is pressed and in the client area, return htcaption, deceive windows, to achieve the same as in the title bar dragging the window effect.UINT CFloatWnd::OnNcHitTest(CPoint pt)
{
  UINT nHitTest = CDialog::OnNcHitTest(pt);
  if (nHitTest == HTCLIENT && ::GetAsyncKeyState(MK_LBUTTON) < 0) // 如果鼠标左键按下,GetAsyncKeyState函数的返回值小于0
    nHitTest = HTCAPTION;
  return nHitTest;
}

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.