终于又掌握了几个API,这几个API很常用。。。每掌握一个API,我都感觉到爽到极点
主角函数:
BOOL SetLayeredWindowAttributes(
HWND hwnd, // 应用目标窗口的句柄
COLORREF crKey, // 掩码的颜色,可以用RGB(r,g,b)来指定
BYTE bAlpha, // 掩码颜色部分的Alpha值,0是全透明,255是xx不透明
DWORD dwFlags // 透明方式
);
这个函数只在Windows2000及以上版本才支持。MSDN对要求的描述如下
<Requirements>
Windows NT/2000/XP: Included in Windows 2000 and later.
Windows 95/98/Me: Unsupported.
Header: Declared in Winuser.h; include Windows.h.
Library: User32.lib.
所以调用前需引用User32.DLL动态链接库!
声明一个自定义设置窗体透明的过程函数:
void chuangtitouming(char jubing[100], int toumingdu);
//参数一:窗体标题
//参数二:透明度
xx窗体透明函数:
chuangtitouming("zhuru",100);
//参数一:窗体标题
//参数二:透明度
//**********************************************************************************************************
//***************************底部加入自定义设置窗体透明的函数过程:***********************
void chuangtitouming(char jubing[100], int toumingdu)
{
//**************************************************************
//*****************引用动态链接库user32.dll***********************
typedef BOOL (WINAPI *lpfnSetLayeredWindowAttributes)(HWND hwnd,
COLORREF crKey,
BYTE bAlpha,
DWORD dwFlags); //声明指向函数的指针变量
lpfnSetLayeredWindowAttributes SetLayeredWindowAttributes; //用这个函数的指针声明变量
HMODULE hUser32 = GetModuleHandle("user32.dll"); //声明用于存放动态链接库句柄的变量
SetLayeredWindowAttributes = (lpfnSetLayeredWindowAttributes)GetProcAddress(hUser32,"SetLayeredWindowAttributes");
//把得到动态链接库DLL文件中的函数地址赋值给变量SetLayeredWindowAttributes
//**************************************************************
//*****************窗体透明设置过程***********************
#define LWA_COLORKEY 0x00000002 //设置透明风格为2 窗体透明
#define WS_EX_LAYERED 0x00080000 //窗口样式:带系统菜单的窗口
HWND a;
int b;
a = ::FindWindow(NULL,jubing); //获取窗口句柄
b = ::GetWindowLong(a, GWL_EXSTYLE); //在该程序中要不要都无所谓的
//获得窗口风格
//参数一:窗口句柄
//参数二:获取的风格种类,扩展窗口风格,可翻阅MSND里的窗口样式GWL_EXSTYLE
::SetWindowLong(a, GWL_EXSTYLE, b | WS_EX_LAYERED);
//设置窗体风格
//参数一:窗口句柄
//参数二:指定设置窗体的值,选择GWL_EXSTYLE表示设定扩展窗口风格。
//参数三:将设定窗口风格的值 ,可翻阅MSND里的窗口样式GWL_EXSTYLE
SetLayeredWindowAttributes(a , 0, toumingdu, LWA_COLORKEY);
//设置窗体透明
//参数一:窗口句柄
//参数二:掩码的颜色,可以用RGB(r,g,b)来指定 ,不设置可为0
//参数三:透明度值,0是全透明,255是xx不透明
//参数四:透明风格。设为 1是标题透明, 2 为窗体透明, 3为窗体和标题共同透明
}