我使用以下代码创建静态控件:
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()
我在调用 SetWindowLongW()
之后调用了 SetWindowPos()
,因为在 SetWindowLong 的文档中,它说:
Certain window data is cached, so changes you make using SetWindowLong will not take effect until you call the SetWindowPos function. Specifically, if you change any of the frame styles, you must call SetWindowPos with the SWP_FRAMECHANGED flag for the cache to be updated properly.
并且,在 SetWindowPos 的文档中,它说:
If you have changed certain window data using SetWindowLong, you must call SetWindowPos for the changes to take effect. Use the following combination for uFlags: SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED.
即使在更改 SetWindowLongW()
和 SetWindowPos()
之后,我的静态控件的样式也没有改变。
我做错了什么,或者我错过了什么?
最佳答案
SS_SUNKEN
有效地在扩展样式 (GWL_EXSTYLE
) 窗口中设置 WS_EX_STATICEDGE
,因此您可以更新 GWL_EXSTYLE
适本地重新定位,就像你目前所做的那样。
关于c++ - `SetWindowLong()` 函数不执行 't change window style even after calling ` SetWindowPos()`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17896059/