产生半透明的对话框和窗口没有闪烁
问题 AnimateWindow () API AW_BLEND参数 应该消失在windows顺利。基本上,它有两个缺点: 文本和ListView控件(和其他)并没有呈现 正确地在淡入。你不能指定一个半透明的窗口,即。后, 动画,是不透明的窗口。 点击“不”在示例项目展示了这两个问题。 解决方法? 似乎有一个简单的解决方法:添加 WS_EX_LAYERED扩展风格的窗口和调用 与所需的alpha值,SetLayeredWindowAttributes () 描述在MSDN Library和各种各样的其他来源。 不幸的是,这没有奏效,至少在我的XP专业版系统。的代码 产生一个非常讨厌的闪烁:窗口区域 最初的黑色。 解决方案 下面的代码展示了如何在一个对话框消失predefinded 没有闪烁的半透明: 隐藏,收缩,复制Code
INT_PTR CALLBACK DialogProc(
HWND hwndDlg, // handle to dialog box
UINT uMsg, // message
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
RECT rcDesktop;
RECT rcMe;
BYTE bTranslucency;
const DWORD ANIMATION_MILLIS = 200;
const BYTE TRANSLUCENCY = 192;
const BYTE TRANSLUCENCY_STEP = 16;
const DWORD TRANSLUCENCY_TIMEOUT
= TRANSLUCENCY_STEP * ANIMATION_MILLIS / TRANSLUCENCY;
switch (uMsg) {
case WM_INITDIALOG:
// Make it a layered window.
::SetWindowLong(hwndDlg, GWL_EXSTYLE,
::GetWindowLong(hwndDlg, GWL_EXSTYLE) | WS_EX_LAYERED);
// Completely transparent window - note the third parameter
::SetLayeredWindowAttributes(hwndDlg, 0, 0, LWA_ALPHA);
// Show it _first_
::ShowWindow(hwndDlg, SW_SHOW);
// Redraw contents NOW - no flickering since the window's not visible
::RedrawWindow(hwndDlg, NULL, NULL, RDW_UPDATENOW);
// Normally, you would use a timer here...
for (bTranslucency = 0; bTranslucency < TRANSLUCENCY;
bTranslucency+=TRANSLUCENCY_STEP) {
// Adjust the translucency
::SetLayeredWindowAttributes(hwndDlg, 0, bTranslucency, LWA_ALPHA);
// Wait
::Sleep(TRANSLUCENCY_TIMEOUT);
}
// Set the final translucency
::SetLayeredWindowAttributes(hwndDlg, 0, bTranslucency, LWA_ALPHA);
break;
}
return 0;
}
注意,调用显示窗口()通常是做的 CreateDialogXXX如果对话框模板()函数 WS_VISIBLE风格。对于我们的目的,我们要做的是对的 在应对WM_INITDIALOG消息。 本文转载于:http://www.diyabc.com/frontweb/news12415.html

浙公网安备 33010602011771号