📄 win.c
字号:
/*
* Unit tests for window handling
*
* Copyright 2002 Bill Medland
* Copyright 2002 Alexandre Julliard
* Copyright 2003 Dmitry Timoshkov
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* To get ICON_SMALL2 with the MSVC headers */
#define _WIN32_WINNT 0x0501
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
#include <assert.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include "windef.h"
#include "winbase.h"
#include "wingdi.h"
#include "winuser.h"
#include "wine/test.h"
#ifndef SPI_GETDESKWALLPAPER
#define SPI_GETDESKWALLPAPER 0x0073
#endif
#define MAKEINTATOMA(atom) ((LPCSTR)((ULONG_PTR)((WORD)(atom))))
#define LONG_PTR INT_PTR
#define ULONG_PTR UINT_PTR
void dump_region(HRGN hrgn);
static HWND (WINAPI *pGetAncestor)(HWND,UINT);
static BOOL (WINAPI *pGetWindowInfo)(HWND,WINDOWINFO*);
static BOOL test_lbuttondown_flag;
static HWND hwndMessage;
static HWND hwndMain, hwndMain2;
static HHOOK hhook;
static const char* szAWRClass = "Winsize";
static HMENU hmenu;
#define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
/* try to make sure pending X events have been processed before continuing */
static void flush_events(void)
{
MSG msg;
int diff = 100;
DWORD time = GetTickCount() + diff;
while (diff > 0)
{
MsgWaitForMultipleObjects( 0, NULL, FALSE, diff, QS_ALLINPUT );
while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
diff = time - GetTickCount();
}
}
/* check the values returned by the various parent/owner functions on a given window */
static void check_parents( HWND hwnd, HWND ga_parent, HWND gwl_parent, HWND get_parent,
HWND gw_owner, HWND ga_root, HWND ga_root_owner )
{
HWND res;
if (pGetAncestor)
{
res = pGetAncestor( hwnd, GA_PARENT );
ok( res == ga_parent, "Wrong result for GA_PARENT %p expected %p\n", res, ga_parent );
}
res = (HWND)GetWindowLongPtrA( hwnd, GWLP_HWNDPARENT );
ok( res == gwl_parent, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res, gwl_parent );
res = GetParent( hwnd );
ok( res == get_parent, "Wrong result for GetParent %p expected %p\n", res, get_parent );
res = GetWindow( hwnd, GW_OWNER );
ok( res == gw_owner, "Wrong result for GW_OWNER %p expected %p\n", res, gw_owner );
if (pGetAncestor)
{
res = pGetAncestor( hwnd, GA_ROOT );
ok( res == ga_root, "Wrong result for GA_ROOT %p expected %p\n", res, ga_root );
res = pGetAncestor( hwnd, GA_ROOTOWNER );
ok( res == ga_root_owner, "Wrong result for GA_ROOTOWNER %p expected %p\n", res, ga_root_owner );
}
}
BOOL CALLBACK EnumChildProc( HWND hwndChild, LPARAM lParam)
{
(*(LPINT)lParam)++;
trace("EnumChildProc on %p\n", hwndChild);
if (*(LPINT)lParam > 1) return FALSE;
return TRUE;
}
/* will search for the given window */
BOOL CALLBACK EnumChildProc1( HWND hwndChild, LPARAM lParam)
{
trace("EnumChildProc1 on %p\n", hwndChild);
if ((HWND)lParam == hwndChild) return FALSE;
return TRUE;
}
static HWND create_tool_window( LONG style, HWND parent )
{
HWND ret = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style,
0, 0, 100, 100, parent, 0, 0, NULL );
ok( ret != 0, "Creation failed\n" );
return ret;
}
/* test parent and owner values for various combinations */
static void test_parent_owner(void)
{
LONG style;
HWND test, owner, ret;
HWND desktop = GetDesktopWindow();
HWND child = create_tool_window( WS_CHILD, hwndMain );
INT numChildren;
trace( "main window %p main2 %p desktop %p child %p\n", hwndMain, hwndMain2, desktop, child );
/* child without parent, should fail */
test = CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
WS_CHILD, 0, 0, 100, 100, 0, 0, 0, NULL );
ok( !test, "WS_CHILD without parent created\n" );
/* desktop window */
check_parents( desktop, 0, 0, 0, 0, 0, 0 );
style = GetWindowLongA( desktop, GWL_STYLE );
ok( !SetWindowLongA( desktop, GWL_STYLE, WS_POPUP ), "Set GWL_STYLE on desktop succeeded\n" );
ok( !SetWindowLongA( desktop, GWL_STYLE, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
ok( GetWindowLongA( desktop, GWL_STYLE ) == style, "Desktop style changed\n" );
/* normal child window */
test = create_tool_window( WS_CHILD, hwndMain );
trace( "created child %p\n", test );
check_parents( test, hwndMain, hwndMain, hwndMain, 0, hwndMain, hwndMain );
SetWindowLongA( test, GWL_STYLE, 0 );
check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
SetWindowLongA( test, GWL_STYLE, WS_POPUP );
check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
SetWindowLongA( test, GWL_STYLE, WS_POPUP|WS_CHILD );
check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
SetWindowLongA( test, GWL_STYLE, WS_CHILD );
DestroyWindow( test );
/* normal child window with WS_MAXIMIZE */
test = create_tool_window( WS_CHILD | WS_MAXIMIZE, hwndMain );
DestroyWindow( test );
/* normal child window with WS_THICKFRAME */
test = create_tool_window( WS_CHILD | WS_THICKFRAME, hwndMain );
DestroyWindow( test );
/* popup window with WS_THICKFRAME */
test = create_tool_window( WS_POPUP | WS_THICKFRAME, hwndMain );
DestroyWindow( test );
/* child of desktop */
test = create_tool_window( WS_CHILD, desktop );
trace( "created child of desktop %p\n", test );
check_parents( test, desktop, 0, desktop, 0, test, desktop );
SetWindowLongA( test, GWL_STYLE, WS_POPUP );
check_parents( test, desktop, 0, 0, 0, test, test );
SetWindowLongA( test, GWL_STYLE, 0 );
check_parents( test, desktop, 0, 0, 0, test, test );
DestroyWindow( test );
/* child of desktop with WS_MAXIMIZE */
test = create_tool_window( WS_CHILD | WS_MAXIMIZE, desktop );
DestroyWindow( test );
/* child of desktop with WS_MINIMIZE */
test = create_tool_window( WS_CHILD | WS_MINIMIZE, desktop );
DestroyWindow( test );
/* child of child */
test = create_tool_window( WS_CHILD, child );
trace( "created child of child %p\n", test );
check_parents( test, child, child, child, 0, hwndMain, hwndMain );
SetWindowLongA( test, GWL_STYLE, 0 );
check_parents( test, child, child, 0, 0, hwndMain, test );
SetWindowLongA( test, GWL_STYLE, WS_POPUP );
check_parents( test, child, child, 0, 0, hwndMain, test );
DestroyWindow( test );
/* child of child with WS_MAXIMIZE */
test = create_tool_window( WS_CHILD | WS_MAXIMIZE, child );
DestroyWindow( test );
/* child of child with WS_MINIMIZE */
test = create_tool_window( WS_CHILD | WS_MINIMIZE, child );
DestroyWindow( test );
/* not owned top-level window */
test = create_tool_window( 0, 0 );
trace( "created top-level %p\n", test );
check_parents( test, desktop, 0, 0, 0, test, test );
SetWindowLongA( test, GWL_STYLE, WS_POPUP );
check_parents( test, desktop, 0, 0, 0, test, test );
SetWindowLongA( test, GWL_STYLE, WS_CHILD );
check_parents( test, desktop, 0, desktop, 0, test, desktop );
DestroyWindow( test );
/* not owned top-level window with WS_MAXIMIZE */
test = create_tool_window( WS_MAXIMIZE, 0 );
DestroyWindow( test );
/* owned top-level window */
test = create_tool_window( 0, hwndMain );
trace( "created owned top-level %p\n", test );
check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
SetWindowLongA( test, GWL_STYLE, WS_POPUP );
check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
SetWindowLongA( test, GWL_STYLE, WS_CHILD );
check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
DestroyWindow( test );
/* owned top-level window with WS_MAXIMIZE */
test = create_tool_window( WS_MAXIMIZE, hwndMain );
DestroyWindow( test );
/* not owned popup */
test = create_tool_window( WS_POPUP, 0 );
trace( "created popup %p\n", test );
check_parents( test, desktop, 0, 0, 0, test, test );
SetWindowLongA( test, GWL_STYLE, WS_CHILD );
check_parents( test, desktop, 0, desktop, 0, test, desktop );
SetWindowLongA( test, GWL_STYLE, 0 );
check_parents( test, desktop, 0, 0, 0, test, test );
DestroyWindow( test );
/* not owned popup with WS_MAXIMIZE */
test = create_tool_window( WS_POPUP | WS_MAXIMIZE, 0 );
DestroyWindow( test );
/* owned popup */
test = create_tool_window( WS_POPUP, hwndMain );
trace( "created owned popup %p\n", test );
check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
SetWindowLongA( test, GWL_STYLE, WS_CHILD );
check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
SetWindowLongA( test, GWL_STYLE, 0 );
check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
DestroyWindow( test );
/* owned popup with WS_MAXIMIZE */
test = create_tool_window( WS_POPUP | WS_MAXIMIZE, hwndMain );
DestroyWindow( test );
/* top-level window owned by child (same as owned by top-level) */
test = create_tool_window( 0, child );
trace( "created top-level owned by child %p\n", test );
check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
DestroyWindow( test );
/* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
test = create_tool_window( WS_MAXIMIZE, child );
DestroyWindow( test );
/* popup owned by desktop (same as not owned) */
test = create_tool_window( WS_POPUP, desktop );
trace( "created popup owned by desktop %p\n", test );
check_parents( test, desktop, 0, 0, 0, test, test );
DestroyWindow( test );
/* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
test = create_tool_window( WS_POPUP | WS_MAXIMIZE, desktop );
DestroyWindow( test );
/* popup owned by child (same as owned by top-level) */
test = create_tool_window( WS_POPUP, child );
trace( "created popup owned by child %p\n", test );
check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
DestroyWindow( test );
/* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
test = create_tool_window( WS_POPUP | WS_MAXIMIZE, child );
DestroyWindow( test );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -