win32 controls (QWinHost) not painted on layered (ie. semi-transparent) widget (WS_EX_LAYERED)

StackOverflow https://stackoverflow.com/questions/11880888

I ported a win32 control using QWinHost, and put it on a layered (semi-transparent) widget. When I set WS_EX_LAYERED flag, then paint not occurred for win32 ported control.

SetWindowLong(winId(),
           GWL_EXSTYLE,
           GetWindowLong(winId(), GWL_EXSTYLE) | *WS_EX_LAYERED*);
有帮助吗?

解决方案

You need to tell Windows how to paint the layered window. MSDN says that there are two ways; you almost certainly want SetLayeredWindowAttributes since you don't want to alter the control's painting code.

So after

SetWindowLong(winId(),
           GWL_EXSTYLE,
           GetWindowLong(winId(), GWL_EXSTYLE) | WS_EX_LAYERED);

add

SetLayeredWindowAttributes(winId(), RGB(0,0,0), bAlpha, LWA_ALPHA);

(Adjusted, of course, for your needs).

Note that the layered window must be a top-level window on Windows 7 below; only Windows 8 and above support layered child windows.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top