CRect rectClient;
    GetClientRect(&rectClient);

    HDC hdc = ::GetDC(m_hWnd);

    BOOL fFade = FALSE;
    HWND hwnd;
    SIZE size;
    POINT ptSrc = {0, 0};
    BLENDFUNCTION blend;

    // Be nice and respect the user's wishes: Do they want the fade?
    SystemParametersInfo(SPI_GETSELECTIONFADE, 0, &fFade, 0);
    if (!fFade)
        return;
    hwnd = CreateWindowEx(WS_EX_LAYERED | // Layered Windows
WS_EX_TRANSPARENT | // Don't hittest this window
WS_EX_TOPMOST | WS_EX_TOOLWINDOW, 
"Button", NULL, WS_POPUP | WS_VISIBLE, rectClient.left,
rectClient.top, 0, 0, NULL, (HMENU)0, AfxGetInstanceHandle(), NULL);
    size.cx = rectClient.Width();
    size.cy = rectClient.Height();
    
    blend.BlendOp = AC_SRC_OVER;
    blend.BlendFlags = 0;
    blend.AlphaFormat = 0;
    blend.SourceConstantAlpha = gbAlpha;

    UpdateLayeredWindow(hwnd, NULL, NULL, &size, hdc, &ptSrc, 0,
&blend, ULW_ALPHA);
    // Finally set the animation timer
    ::SetTimer(hwnd, IDT_FADE, 25, NULL);
::ReleaseDC(m_hWnd, hdc);上面的代码是成功的,但是我一旦把:UpdateLayeredWindow(hwnd, NULL, NULL, &size, hdc, &ptSrc, 0,
&blend, ULW_ALPHA);换做UpdateLayeredWindow(m_hWnd, NULL, NULL, &size, hdc, &ptSrc, 0,
&blend, ULW_ALPHA);之后就不行了,@err,hr说参数错误,搞不懂是为什么?为什么参数参数1不能是本窗口呢??(说明一下,m_hWnd是具有WS_EX_LAYERED这个style的)

解决方案 »

  1.   

    hwnd 
    [in] Handle to a layered window. A layered window is created by specifying WS_EX_LAYERED when creating the window with the CreateWindowEx function. 
      

  2.   

    你的本窗口即m_hWnd有WS_EX_LAYERED风格属性吗?
      

  3.   

    Sorry,没有看到你下面说的,检查一下其它参数是否有效,比如后面的参数是否有效size, hdc, ptSrc
      

  4.   

    size的值用GetWindowRect获取的区域的值设置试试看