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;
}