MFC如何制作一个透明的窗体

解决方案 »

  1.   

    如果是对话框程序,直接在其属性设置里的"Extended Styles"选项卡的Transparent选项打上钩就可以了.还可以用通用方法:
    在App的InitInstance()里如下做:
    BOOL CTest_2003_2_25App::InitInstance()
    {
    .........
    m_pMainWnd->ModifyStyleEx(0,WS_EX_TRANSPARENT,0);
    return TRUE;
    }
    试一试^-^
    我测试过,可以的。
      

  2.   

    //透明窗体(2000以上)
    第一步 定义功能
    typedef BOOL (FAR PASCAL * FUNC1)(
      HWND hwnd,           // handle to the layered window
      COLORREF crKey,      // specifies the color key
      BYTE bAlpha,         // value for the blend function
      DWORD dwFlags        // action
    );
    第二步 实现代码
    在OnInitDialog中加入下列代码
    .....
     HMODULE hModule = GetModuleHandle("user32.dll");
     FUNC1 SetLayeredWindowAttributes;
     SetLayeredWindowAttributes =  (FUNC1) GetProcAddress (hModule, _T( "SetLayeredWindowAttributes" ) ); // 设置分层扩展标记
     SetWindowLong(GetSafeHwnd(), GWL_EXSTYLE, GetWindowLong(GetSafeHwnd(), GWL_EXSTYLE) | 0x80000L);
     // 70% alpha
     SetLayeredWindowAttributes(GetSafeHwnd(), 0, (255 * 70) / 100, 0x2);
      

  3.   


    直接在在OnInitDialog中加入下列代码就可以了SetWindowLong(this->GetSafeHwnd(),GWL_EXSTYLE,
    GetWindowLong(this->GetSafeHwnd(),GWL_EXSTYLE)^0x80000);
    HINSTANCE hInst = LoadLibrary("User32.DLL"); 
    if(hInst) 

    typedef BOOL (WINAPI *MYFUNC)(HWND,COLORREF,BYTE,DWORD); 
    MYFUNC fun = NULL;
    //取得SetLayeredWindowAttributes函数指针 
    fun=(MYFUNC)GetProcAddress(hInst, "SetLayeredWindowAttributes");
    if(fun)fun(this->GetSafeHwnd(),0,230,2); 
    FreeLibrary(hInst); 
    }