界面_制作ttplayer式的不规则形状的窗口

王朝other·作者佚名  2006-01-10
窄屏简体版  字體: |||超大  

制作ttplayer式的不规则形状的窗口

结合半透明窗口的实现,更好的理解 SetLayeredWindowAttributes() 函数的功能

SetLayeredWindowAttributes的函数原型如下:

BOOL SetLayeredWindowAttributes(

HWND hwnd, // handle to the layered window

COLORREF crKey, // specifies the color key

BYTE bAlpha, // value for the blend function

DWORD dwFlags // action

);

dwFlags = 1 窗体上由 crKey 颜色部分将被透明掉

dwFlags = 2 窗体呈半透明,程度由 bAlpha 决定,当 bAlpha = 0 时,变成全透明

dwFlags = 3 两者效果兼有

////////////////////////////////////////////////////////////

制作一张背景透明的图片

将窗口大小设成图像大小

在 OnPaint() 中,画出该图片

////////////////////////////////////////////////////////////

在窗口创建后,给窗口加入 WS_EX_LAYERED 扩展

#define WS_EX_LAYERED 0x80000

int ...Wnd::OnCreate(LPCREATESTRUCT lpCreateStruct)

{

if (CWnd::OnCreate(lpCreateStruct) == -1)

return -1;

//将窗口大小设成图片大小

this->MoveWindow( 100 , 100 , imageWidth , imageHeight );

////////////////////////////////////////////////////////////

//加入WS_EX_LAYERED扩展属性

//设置为透明窗口类型

SetWindowLong( this->GetSafeHwnd(), GWL_EXSTYLE ,

GetWindowLong( this->GetSafeHwnd() , GWL_EXSTYLE ) ^ 0x80000 );

HMODULE hUser32 = LoadLibrary("User32.DLL");

if( hUser32 )

{

typedef BOOL (WINAPI *MYFUNC)(HWND,COLORREF,BYTE,DWORD);

MYFUNC fun = NULL;

//取得SetLayeredWindowAttributes函数指针

fun=(MYFUNC)GetProcAddress( hUser32, "SetLayeredWindowAttributes" );

if( fun )

fun( this->GetSafeHwnd() , 0 , 100 , 1 );

FreeLibrary( hUser32 );

}

////////////////////////////////////////////////////////////

return 0;

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航