我在vista系统下用VS2008 ,把窗体透明化,用SetLayeredWindowAttributes的ColorKey指定颜色透明,能透明,但透明部分不能穿透到下一层窗口,这同一工程在XP系统下编译运行就可以,这是为什么??望高人指点!!!谢谢!!!

解决方案 »

  1.   

    恩, vista有这个问题, 换个函数, 用bmp来做镂空.
    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); 

    }
      

  2.   

    // Set WS_EX_LAYERED on this window 
    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);
    楼主是这样做的吗?
      

  3.   

    soryy, 代码应该是这样的:
    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();
    }
      

  4.   

    谢谢!!!暂时还是用COLORKEY
      

  5.   

    没懂你的bitmap的镂空是什么意思!这位图是透明的?还是什么颜色的?
      

  6.   

    就是根据图片的左上角颜色或者自己制定颜色, 把bmp含有此颜色的去掉, 形成异形.那个set...在vista是不行. 我以前遇到了.