📄 win.c
字号:
/* desktop window */ check_parents( desktop, 0, 0, 0, 0, 0, 0 ); ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)hwndMain2 ); ok( !ret, "Set GWL_HWNDPARENT succeeded on desktop" ); check_parents( desktop, 0, 0, 0, 0, 0, 0 ); ok( !SetParent( desktop, hwndMain ), "SetParent succeeded on desktop" ); check_parents( desktop, 0, 0, 0, 0, 0, 0 ); /* normal child window */ test = create_tool_window( WS_CHILD, hwndMain ); trace( "created child %p\n", test ); ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)hwndMain2 ); ok( ret == hwndMain, "GWL_HWNDPARENT return value %p expected %p", ret, hwndMain ); check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 ); ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)child ); ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p", ret, hwndMain2 ); check_parents( test, child, child, child, 0, hwndMain, hwndMain ); ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)desktop ); ok( ret == child, "GWL_HWNDPARENT return value %p expected %p", ret, child ); check_parents( test, desktop, 0, desktop, 0, test, desktop ); /* window is now child of desktop so GWL_HWNDPARENT changes owner from now on */ ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)child ); ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0", ret ); check_parents( test, desktop, child, desktop, child, test, desktop ); ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, 0 ); ok( ret == child, "GWL_HWNDPARENT return value %p expected %p", ret, child ); check_parents( test, desktop, 0, desktop, 0, test, desktop ); DestroyWindow( test ); /* not owned top-level window */ test = create_tool_window( 0, 0 ); trace( "created top-level %p\n", test ); ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)hwndMain2 ); ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0", ret ); check_parents( test, desktop, hwndMain2, 0, hwndMain2, test, test ); ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)child ); ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p", ret, hwndMain2 ); check_parents( test, desktop, child, 0, child, test, test ); ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, 0 ); ok( ret == child, "GWL_HWNDPARENT return value %p expected %p", ret, child ); check_parents( test, desktop, 0, 0, 0, test, test ); DestroyWindow( test ); /* not owned popup */ test = create_tool_window( WS_POPUP, 0 ); trace( "created popup %p\n", test ); ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)hwndMain2 ); ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0", ret ); check_parents( test, desktop, hwndMain2, hwndMain2, hwndMain2, test, hwndMain2 ); ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)child ); ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p", ret, hwndMain2 ); check_parents( test, desktop, child, child, child, test, hwndMain ); ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, 0 ); ok( ret == child, "GWL_HWNDPARENT return value %p expected %p", ret, child ); check_parents( test, desktop, 0, 0, 0, test, test ); DestroyWindow( test ); /* normal child window */ test = create_tool_window( WS_CHILD, hwndMain ); trace( "created child %p\n", test ); ret = SetParent( test, desktop ); ok( ret == hwndMain, "SetParent return value %p expected %p", ret, hwndMain ); check_parents( test, desktop, 0, desktop, 0, test, desktop ); ret = SetParent( test, child ); ok( ret == desktop, "SetParent return value %p expected %p", ret, desktop ); check_parents( test, child, child, child, 0, hwndMain, hwndMain ); ret = SetParent( test, hwndMain2 ); ok( ret == child, "SetParent return value %p expected %p", ret, child ); check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 ); DestroyWindow( test ); /* not owned top-level window */ test = create_tool_window( 0, 0 ); trace( "created top-level %p\n", test ); ret = SetParent( test, child ); ok( ret == desktop, "SetParent return value %p expected %p", ret, desktop ); check_parents( test, child, child, 0, 0, hwndMain, test ); DestroyWindow( test ); /* owned popup */ test = create_tool_window( WS_POPUP, hwndMain2 ); trace( "created owned popup %p\n", test ); ret = SetParent( test, child ); ok( ret == desktop, "SetParent return value %p expected %p", ret, desktop ); check_parents( test, child, child, hwndMain2, hwndMain2, hwndMain, hwndMain2 ); ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (ULONG_PTR)hwndMain ); ok( ret == child, "GWL_HWNDPARENT return value %p expected %p", ret, child ); check_parents( test, hwndMain, hwndMain, hwndMain2, hwndMain2, hwndMain, hwndMain2 ); DestroyWindow( test ); /**************** test owner destruction *******************/ /* owned child popup */ owner = create_tool_window( 0, 0 ); test = create_tool_window( WS_POPUP, owner ); trace( "created owner %p and popup %p\n", owner, test ); ret = SetParent( test, child ); ok( ret == desktop, "SetParent return value %p expected %p", ret, desktop ); check_parents( test, child, child, owner, owner, hwndMain, owner ); /* window is now child of 'child' but owned by 'owner' */ DestroyWindow( owner ); ok( IsWindow(test), "Window %p destroyed by owner destruction", test ); check_parents( test, child, child, owner, owner, hwndMain, owner ); ok( !IsWindow(owner), "Owner %p not destroyed", owner ); DestroyWindow(test); /* owned top-level popup */ owner = create_tool_window( 0, 0 ); test = create_tool_window( WS_POPUP, owner ); trace( "created owner %p and popup %p\n", owner, test ); check_parents( test, desktop, owner, owner, owner, test, owner ); DestroyWindow( owner ); ok( !IsWindow(test), "Window %p not destroyed by owner destruction", test ); /* top-level popup owned by child */ owner = create_tool_window( WS_CHILD, hwndMain2 ); test = create_tool_window( WS_POPUP, 0 ); trace( "created owner %p and popup %p\n", owner, test ); ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (ULONG_PTR)owner ); ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0", ret ); check_parents( test, desktop, owner, owner, owner, test, hwndMain2 ); DestroyWindow( owner ); ok( IsWindow(test), "Window %p destroyed by owner destruction", test ); ok( !IsWindow(owner), "Owner %p not destroyed", owner ); check_parents( test, desktop, owner, owner, owner, test, owner ); DestroyWindow(test); /* final cleanup */ DestroyWindow(child);}static BOOL RegisterWindowClasses(void){ WNDCLASSA cls; cls.style = 0; cls.lpfnWndProc = DefWindowProcA; cls.cbClsExtra = 0; cls.cbWndExtra = 0; cls.hInstance = GetModuleHandleA(0); cls.hIcon = 0; cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW); cls.hbrBackground = GetStockObject(WHITE_BRUSH); cls.lpszMenuName = NULL; cls.lpszClassName = "MainWindowClass"; if(!RegisterClassA(&cls)) return FALSE; cls.style = 0; cls.lpfnWndProc = DefWindowProcA; cls.cbClsExtra = 0; cls.cbWndExtra = 0; cls.hInstance = GetModuleHandleA(0); cls.hIcon = 0; cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW); cls.hbrBackground = GetStockObject(WHITE_BRUSH); cls.lpszMenuName = NULL; cls.lpszClassName = "ToolWindowClass"; if(!RegisterClassA(&cls)) return FALSE; return TRUE;}START_TEST(win){ pGetAncestor = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetAncestor" ); if (!RegisterWindowClasses()) assert(0); hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window", WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP, 100, 100, 200, 200, 0, 0, 0, NULL); hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2", WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP, 100, 100, 200, 200, 0, 0, 0, NULL); assert( hwndMain ); assert( hwndMain2 ); test_parent_owner();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -