我希望他的背景是透明的黄色,就是透过他能看到后面的东西,请问该怎么做?
谢谢

解决方案 »

  1.   

    UpdateLayeredWindow
    The UpdateLayeredWindow function updates the position, size, shape, content, and translucency of a layered window. BOOL UpdateLayeredWindow(
      HWND hwnd,             // handle to layered window
      HDC hdcDst,            // handle to screen DC
      POINT *pptDst,         // new screen position
      SIZE *psize,           // new size of the layered window
      HDC hdcSrc,            // handle to surface DC
      POINT *pptSrc,         // layer position
      COLORREF crKey,        // color key
      BLENDFUNCTION *pblend, // blend function
      DWORD dwFlags          // options
    );
      

  2.   

    一个简单的方法:(只在win2000下有效)
    先把窗体设置成黄色的SetBkColor
    然后使用SetWindowAttribute(好象是这个,记不清了,自己再查查吧)
      

  3.   

    拷过去就用:
    SetWindowLong(this->GetSafeHwnd(),GWL_EXSTYLE, GetWindowLong(this->GetSafeHwnd(),GWL_EXSTYLE)^0x80000);
    HINSTANCE hInst = LoadLibrary("User32.DLL"); 
    if(hInst) 
    {
      typedef BOOL (WINAPI *MYFUNC)WND,COLORREF,BYTE,DWORD); 
      MYFUNC fun = NULL;//取得SetLayeredWindowAttributes函数指针 
      fun=(MYFUNC)GetProcAddress(hInst, "SetLayeredWindowAttributes");
      if(fun)
      fun(this->GetSafeHwnd(),0,128,2);//第三个参数是 透明程序
      FreeLibrary(hInst); 
    }
      

  4.   

    typedef BOOL (WINAPI* lpfnSetLayeredWindowAttributes)(HWND hWnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags);
    HMODULE m_hDll = ::LoadLibrary(_T("USER32.dll"));
    HWND hwnd = this->m_hWnd;
    if(m_hDll)
    {
        ::SetWindowLong(hwnd, GWL_EXSTYLE, ::GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED);
        lpfnSetLayeredWindowAttributes pFn = NULL;
        pFn = (lpfnSetLayeredWindowAttributes)::GetProcAddress(m_hDll, "SetLayeredWindowAttributes");
        if(pFn)
        {
            pFn(hwnd, 0, (255 * 70) / 100, LWA_ALPHA);
        }
        ::FreeLibrary(m_hDll);
    }
    其中的70是透明的程度,有效范围是0 - 100。如果你的SDK没有更新,那么你还需要在对话框的头文件中添加如下的代码:#ifndef WS_EX_LAYERED
    #define WS_EX_LAYERED           0x00080000
    #define LWA_COLORKEY            0x00000001
    #define LWA_ALPHA               0x00000002
    #endif
    很不幸,这个函数只在WIN200/XP下才有效
      

  5.   

    void Target::CreateTarget(LPCTSTR lpTitle, CWnd* pWnd)
    {
    //取得屏幕的高和宽,用于创建跨整个屏幕的窗口
    cxScreen=::GetSystemMetrics(SM_CXSCREEN);
    cyScreen=::GetSystemMetrics(SM_CYSCREEN);
    //用CWnd::CreateEx创建一个透明的窗口,WS_EX_TOPMOST使窗口总是在最顶层
    CreateEx(WS_EX_TOPMOST,
    AfxRegisterWndClass(0,AfxGetApp()->LoadStandardCursor(IDC_ARROW)),
    "Target", WS_POPUP, 0, 0, cxScreen, cyScreen,
    NULL, NULL, NULL );
    //pDC用于开始测量时绘制辅助标志
    pDC=GetDC();
    //bSecond用于标识是否已经点击了一次
    bSecond=FALSE;
    //pWndParent保存父窗口的指针
    pWndParent=pWnd;
    //创建一个MemDC临时存放整个屏幕的画面,用于刷新屏幕
    MemDC.CreateCompatibleDC(pDC);
    CBitmap Bitmap;
    Bitmap.CreateCompatibleBitmap(pDC,cxScreen,cyScreen);
    //确定MemDC的大小
    MemDC.SelectObject(&Bitmap);
    //将这个屏幕的都存入MemDC
    MemDC.BitBlt(0,0,cxScreen,cyScreen,pDC,0,0,SRCCOPY);
    //将临时图片删除
    ::DeleteObject(Bitmap.m_hObject);
    }