UpdateLayeredWindow方式实现异型窗口
2015-02-02 16:33
573 查看
使用该种方法要注意几个问题:
1. 窗口属性必须是Top Window,子窗口(Win8之前的操作系统)不支持实现异形窗口
2. Layer Window没有WM_PAINT消息,需要自己调用OnPaint
3. 窗口属性可设置为
WS_POPUP | WS_VISIBLE, WS_EX_TOOLWINDOW | WS_EX_LAYERED
实现代码:
1. 窗口属性必须是Top Window,子窗口(Win8之前的操作系统)不支持实现异形窗口
2. Layer Window没有WM_PAINT消息,需要自己调用OnPaint
3. 窗口属性可设置为
WS_POPUP | WS_VISIBLE, WS_EX_TOOLWINDOW | WS_EX_LAYERED
实现代码:
CDC hdc = GetDC(); // Get the display device context (DC) CDC hdcSrc = CreateCompatibleDC(hdc); // creates a memory device context (DC) compatible with the display device context CRect rc; GetClientRect(&rc); // 创建DIB BITMAPINFO bmInfo; ZeroMemory (&bmInfo, sizeof(bmInfo)); bmInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmInfo.bmiHeader.biWidth = rc.Width(); bmInfo.bmiHeader.biHeight = rc.Height(); bmInfo.bmiHeader.biPlanes = 1; bmInfo.bmiHeader.biBitCount = 32; UINT* pBits = NULL; CBitmap hBmp = CreateDIBSection (hdcSrc, (BITMAPINFO*)&bmInfo, DIB_RGB_COLORS, (void**)&pBits, NULL, 0); HBITMAP hBmpOld = hdcSrc.SelectBitmap(hBmp); RECT rcDraw = {0, 0, c_n_popwnd_width, c_n_popwnd_height}; BLENDFUNCTION blendFunction; blendFunction.AlphaFormat = AC_SRC_ALPHA; blendFunction.BlendFlags = 0; blendFunction.BlendOp = AC_SRC_OVER; blendFunction.SourceConstantAlpha = 255; POINT pptDst = {m_ptWnd.x, m_ptWnd.y}; SIZE pDesSize = {c_n_popwnd_width, c_n_popwnd_height}; POINT ptSrc = { 0, 0 }; //////////////////////////////// m_bmpBkg.StretchBlt(hdcSrc, 0, 0, rc.Width(), rc.Height(), 0); // 这里是要绘制的异形窗口背景 BOOL bRet = ::UpdateLayeredWindow(m_hWnd, NULL, &pptDst, &pDesSize, hdcSrc, &ptSrc, CLR_NONE, &blendFunction, ULW_ALPHA); hdcSrc.SelectBitmap(hBmpOld); ReleaseDC(hdc);
相关文章推荐
- [用UpdateLayeredWindow实现任意异形窗口]
- GDI+ / PNG 实现半透明窗口,正常情况下没有问题 将系统设置为16位色后UpdateLayeredWindow函数失败,GetLastError返回8(ERROR_NOT_ENOUGH_MEMORY)
- UpdateLayeredWindow 绘制异型窗口
- UpdateLayeredWindow实现自定义透明窗口
- Layered windows and UpdateLayeredWindow 分层窗口
- 一个用UpdateLayeredWindow实现窗体半透明的delphi的代码
- GDI+ 透明窗口.UpdateLayeredWindow
- VC++调用UpdateLayeredWindow实现半透明窗体【转】
- UpdateLayeredWindow 失败导致透明gdi+ 窗口没有被显示
- 用SetLayeredWindowAttributes实现窗口透明
- 用SetLayeredWindowAttributes实现窗口透明
- c# UpdateLayeredWindow异形窗口
- VC++调用UpdateLayeredWindow实现半透明窗体【转】
- GDI+ 透明窗口.UpdateLayeredWindow
- Layered windows and UpdateLayeredWindow 分层窗口
- 透明窗口(窗口上面文字图片等内容不透明)的实现(使用SetLayeredWindowAttributes API函数)
- android PopupWindow 和 Activity弹出窗口实现方式
- 使用SetLayeredWindowAttributes API 实现透明窗口
- 一个用UpdateLayeredWindow实现窗体半透明的delphi的代码-The realization of a form with translucent UpdateLayeredWindow code delphi
- 利用BMP通道和UpdateLayeredWindow制作边缘透明不规则窗口