以CodeBlocks为IDE,在wxWidgets中实现窗体透明效果

VC中实现窗体的半透明很是酷毙,也想使用wxWidgets来实现这一效果,经过苦苦搜索始终没有找到解决办法,只好引入API了,经过一段时间的摸索终于搞出来了,感觉还不错,记录下来吧!

 

以下是需要添加的代码(详细代码见附件工程):

1、添加支持API的头文件

 

#include "windows.h"

 

2、实现透明效果的代码:

HWND hwnd = (HWND)GetHandle();
HINSTANCE hInst = LoadLibrary(wxT("User32.DLL"));
if(hInst)
{
    long exStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
    exStyle |= WS_EX_LAYERED;
    SetWindowLong(hwnd, GWL_EXSTYLE, exStyle);

    typedef BOOL (WINAPI *MYFUNC)(HWND,COLORREF,BYTE,DWORD);
    MYFUNC fun = NULL;
    fun=(MYFUNC)GetProcAddress(hInst, "SetLayeredWindowAttributes");
    if(fun)fun(hwnd,0,128,2);
    FreeLibrary(hInst);
};

 

 

 

参考:

 

 

1http://blog.163.com/ar_cn/blog/static/145383085200842711948510/

2http://www.vckbase.com/index.php/wv/186