更改 Win32 窗口的父级时为什么要圆角? [英] Why rounded corners when changing a Win32 window's parent?
问题描述
我正在尝试学习如何使顶级 Win32 窗口成为另一个窗口的子窗口.
I'm trying to learn how to make a top-level Win32 window become a child of another window.
当我改变一个窗口的父级时,我仍然得到丑陋的圆角,就好像它是一个带有圆形标题栏的顶级窗口.为什么?我该如何解决这个问题?(我无法获得 WM_UPDATEUISTATE
的帮助,但我也不知道如何正确使用它.)
When I change a window's parent, I still get ugly rounded corners, as though it was a top-level window with a rounded title bar. Why? And how do I fix this? (I couldn't get WM_UPDATEUISTATE
to help, but I'm not sure how to use it correctly either.)
#include <tchar.h>
#include <windows.h>
#include <commctrl.h>
int _tmain()
{
WNDCLASS wndClass = {
0, &DefWindowProc, 0, 0, NULL, NULL, LoadCursor(NULL, IDC_ARROW),
GetSysColorBrush(COLOR_3DFACE), NULL, TEXT("MyWindowClass")
};
ATOM atom = RegisterClass(&wndClass);
HWND hWnd = CreateWindow(MAKEINTATOM(atom), TEXT("Win"),
WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, NULL, NULL);
HWND hWndChild = CreateWindowEx(WS_EX_CLIENTEDGE,
WC_EDIT, TEXT("Control"), WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10, 10, 86, 24, NULL, NULL, NULL, NULL);
SetParent(hWndChild, hWnd); // Change the parent
SetWindowLong(hWndChild, GWL_STYLE, // Set child styles
GetWindowLong(hWndChild, GWL_STYLE)
& ~(WS_OVERLAPPED | WS_POPUP | WS_CAPTION | WS_SYSMENU |
WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX)
| WS_CHILDWINDOW);
SetWindowPos(hWndChild, NULL, 0, 0, 0, 0, // Refresh
SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE
| SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_FRAMECHANGED);
BOOL bRet;
MSG msg;
while ((bRet = GetMessage(&msg, hWnd, 0, 0)) != 0 && bRet != -1)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
推荐答案
这似乎在原则上是可能的,但实际上很难做到正确"(根据 Raymond 的评论).
It seems like this is possible in principle but difficult to get 'right' practically (according to Raymond's comment).
我发现 SetWindowRgn(hWnd, NULL, TRUE);
可以解决问题,但我认为它不正确——我可能遗漏了其他一些东西.所以正确的解决方案可能是在一开始就正确构造对象.
I found that SetWindowRgn(hWnd, NULL, TRUE);
does the trick, but I don't think it's correct -- there might be other things I've missed. So the correct solution is probably to just construct the object correctly at the beginning.
这篇关于更改 Win32 窗口的父级时为什么要圆角?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!