我在vista系统下用VS2008 ,把窗体透明化,用SetLayeredWindowAttributes的ColorKey指定颜色透明,能透明,但透明部分不能穿透到下一层窗口,这同一工程在XP系统下编译运行就可以,这是为什么??望高人指点!!!谢谢!!!
解决方案 »
- 【感谢帖】穿上五条裤衩了,赶紧散分咯
- 32位色情况下粉色的值是多少?
- win32制作动态库的文章或示例代码。
- VC中编辑对话框资源时显示的标尺与运行时屏幕分辨率的比率是多少?
- 一个线程怎样给属性页里的edit框赋值?请各位指教
- Format输出的问题:如何指定输出数字的位数(不足用0补充)。
- 怎么清除串口的发送和接收缓冲区?我用的是MSCOMM控件。请高手帮帮忙,急于交工了!
- 送分 请教CFileDialog 类的问题 在线等
- 我是个初学者,希望和我一样的朋友多多联系QQ78143897
- 请给我出视 两个例子: 同步 socket 和异步 socket 的代码,API的,不要那几个sock类的
- 求解决winpcap的vc源代码报错?
- MFC 在一个工程中使用两个记录集
void CWinerDlg::CreateRegionFromBitmap(HBITMAP hBitmap, COLORREF crTransparentColor, BOOL bUseDefaultTransColor)
{
//Center it on current desktop
GetObject(hBitmap, sizeof(m_Bitmap), &m_Bitmap); // Get info about the bitmap ::SetWindowRgn(this->m_hWnd, m_pOwnerDlg->m_crWinnerRgn, TRUE);
int iX = (GetSystemMetrics(SM_CXSCREEN)) / 2 - (m_Bitmap.bmWidth / 2);
int iY = (GetSystemMetrics(SM_CYSCREEN)) / 2 - (m_Bitmap.bmHeight / 2);
::SetWindowPos(this->m_hWnd, NULL, iX, iY, m_Bitmap.bmWidth, m_Bitmap.bmHeight, NULL);
}
SetWindowLong(hwnd,
GWL_EXSTYLE,
GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED);// Make this window 70% alpha
SetLayeredWindowAttributes(hwnd, 0, (255 * 70) / 100, LWA_ALPHA);
// Remove WS_EX_LAYERED from this window styles
SetWindowLong(hwnd,
GWL_EXSTYLE,
GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED);// Ask the window and its children to repaint
RedrawWindow(hwnd,
NULL,
NULL,
RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
楼主是这样做的吗?
CreateRegionFromBitmap(HBITMAP hBitmap, COLORREF crTransparentColor, BOOL bUseDefaultTransColor)
{
//hBitmap = (HBITMAP)LoadImage(GetModuleHandle(NULL), "res\\MeshGuard.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
if (hBitmap == NULL)
{
OutputDebugString("Not Indicated hBitmap--CRegionCreate::CreateRegionFromBitmap\n");
return;
}
//Get information about the bitmap..
BITMAP Bitmap;
GetObject(hBitmap, sizeof(Bitmap), &Bitmap); // Get info about the bitmap
// Put the bitmap into a memory device context
CPaintDC dc(this);
//get a memory dc object
CDC dcMem;
//create a compatible dc
dcMem.CreateCompatibleDC(&dc); // Select the bitmap into the in-memory DC
//Select the bitmap into the dc
CBitmap* pOldBitmap = dcMem.SelectObject(CBitmap::FromHandle(hBitmap));
//Create a couple of region objects.
CRgn crRgnTmp;
//create an empty region
m_crWinnerRgn.CreateRectRgn(0, 0, 0, 0);
//Create a region from a bitmap with transparency color of Purple
COLORREF crTransparent;
if (bUseDefaultTransColor)
{
crTransparent = dcMem.GetPixel(2, 2);
}
else
{
crTransparent = crTransparentColor;
}
int iX = 0;
for (int iY = 0; iY < Bitmap.bmHeight; iY++)
{
do
{
//skip over transparent pixels at start of lines.
while (iX <= Bitmap.bmWidth && dcMem.GetPixel(iX, iY) == crTransparent)
iX++;
//remember this pixel
int iLeftX = iX;
//now find first non transparent pixel
while (iX <= Bitmap.bmWidth && dcMem.GetPixel(iX, iY) != crTransparent)
++iX;
//create a temp region on this info
crRgnTmp.CreateRectRgn(iLeftX, iY, iX, iY+1);
//combine into main region.
m_crWinnerRgn.CombineRgn(&m_crWinnerRgn, &crRgnTmp, RGN_OR);
//delete the temp region for next pass (otherwise you'll get an ASSERT)
crRgnTmp.DeleteObject();
}while(iX < Bitmap.bmWidth);
iX = 0;
} // Free resources.
dcMem.SelectObject(pOldBitmap); // Put the original bitmap back (prevents memory leaks)
dcMem.DeleteDC();
}