我使用以下代码创建静态控件:
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
上面的创建代码中的style,创建的静态控件成功出现凹陷。
但是,我想做的是在创建后更改控件样式。
我试过这个:
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)
}
文档:
设置窗口长() http://msdn.microsoft.com/en-us/library/windows/desktop/ms633591%28v=vs.85%29.aspx
设置窗口位置() http://msdn.microsoft.com/en-us/library/windows/desktop/ms633545%28v=vs.85%29.aspx
I call SetWindowPos()
打电话后SetWindowLongW()
因为在 SetWindowLong 的文档中,它说:
某些窗口数据会被缓存,因此使用 SetWindowLong 所做的更改只有在调用 SetWindowPos 函数后才会生效。具体来说,如果更改任何框架样式,则必须使用 SWP_FRAMECHANGED 标志调用 SetWindowPos 才能正确更新缓存。
而且,在 SetWindowPos 的文档中,它说:
如果您使用 SetWindowLong 更改了某些窗口数据,则必须调用 SetWindowPos 才能使更改生效。对 uFlags 使用以下组合:SWP_NOMOVE | SWP_NOMOVE | SWP_NOMOVE | SWP_NOMOVE SWP_NOSIZE | SWP_NOSIZE SWP_NOZORDER | SWP_NOZORDER SWP_FRAMECHANGED。
即使改变之后SetWindowLongW()
and SetWindowPos()
我的静态控件的样式没有改变。
我做错了什么,或者我错过了什么?