我使用以下代码创建静态控件:
hWnd = CreateWindowExW( 0,
L"STATIC",
Content.c_str(),
SS_LEFT | WS_VISIBLE | WS_CHILD /*| SS_SUNKEN*/,
200,
120,
120,
40,
hWndParent,
NULL,
hInstance,
NULL);
如果我SS_SUNKEN
在上面的创建代码中启用样式,创建的静态控件就会出现下沉成功。
但是,我要做的是在创建后更改控件样式。
我试过这个:
void BaseWindowClass::AddStyle(DWORD NewStyle)
{
// NewStyle = 0x00001000 = SS_SUNKEN
LONG oldstyle, changedstyle;
oldstyle=SetWindowLongW(hWnd, GWL_STYLE, changedstyle=GetWindowLongW(hWnd, GWL_STYLE) | NewStyle);
UpdateWindowStyles();
// oldstyle = 0x50000000
// changedstyle = 0x50001000 (everything looks normal)
}
void BaseWindowClass::UpdateWindowStyles()
{
BOOL success;
success=SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
// success = 0x00000001 (non-zero: SetWindowPos sucseeded)
}
文档:
SetWindowLong()
SetWindowPos()
我打电话SetWindowPos()
后打电话SetWindowLongW()
,因为在 SetWindowLong 的文档中,它说:
某些窗口数据被缓存,因此您使用 SetWindowLong 所做的更改在调用 SetWindowPos 函数之前不会生效。具体来说,如果您更改任何框架样式,则必须使用 SWP_FRAMECHANGED 标志调用 SetWindowPos 才能正确更新缓存。
而且,在 SetWindowPos 的文档中,它说:
如果您使用 SetWindowLong 更改了某些窗口数据,则必须调用 SetWindowPos 才能使更改生效。对 uFlags 使用以下组合: SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED。
即使在更改之后SetWindowLongW()
,SetWindowPos()
我的静态控件的样式也不会改变。
我做错了什么,或者我错过了什么?