📄 class.c
字号:
/* Unit test suite for window classes.
*
* Copyright 2002 Mike McCormack
* Copyright 2003 Alexandre Julliard
*
* 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 CS_DROPSHADOW with the MSVC headers */
#define _WIN32_WINNT 0x0501
#include <assert.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include "wine/test.h"
#include "windef.h"
#include "winbase.h"
#include "winreg.h"
#include "wingdi.h"
#include "winuser.h"
#define NUMCLASSWORDS 4
static LRESULT WINAPI ClassTest_WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
return DefWindowProcW (hWnd, msg, wParam, lParam);
}
/***********************************************************************
*/
static void ClassTest(HINSTANCE hInstance, BOOL global)
{
WNDCLASSW cls, wc;
static const WCHAR className[] = {'T','e','s','t','C','l','a','s','s',0};
static const WCHAR winName[] = {'W','i','n','C','l','a','s','s','T','e','s','t',0};
ATOM test_atom;
HWND hTestWnd;
LONG i;
WCHAR str[20];
ATOM classatom;
cls.style = CS_HREDRAW | CS_VREDRAW | (global?CS_GLOBALCLASS:0);
cls.lpfnWndProc = ClassTest_WndProc;
cls.cbClsExtra = NUMCLASSWORDS*sizeof(DWORD);
cls.cbWndExtra = 12;
cls.hInstance = hInstance;
cls.hIcon = LoadIconW (0, (LPWSTR)IDI_APPLICATION);
cls.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
cls.hbrBackground = GetStockObject (WHITE_BRUSH);
cls.lpszMenuName = 0;
cls.lpszClassName = className;
classatom=RegisterClassW(&cls);
if (!classatom && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
return;
ok(classatom, "failed to register class\n");
ok(!RegisterClassW (&cls),
"RegisterClass of the same class should fail for the second time\n");
/* Setup windows */
hTestWnd = CreateWindowW (className, winName,
WS_OVERLAPPEDWINDOW + WS_HSCROLL + WS_VSCROLL,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0,
0, hInstance, 0);
ok(hTestWnd!=0, "Failed to create window\n");
/* test initial values of valid classwords */
for(i=0; i<NUMCLASSWORDS; i++)
{
SetLastError(0);
ok(!GetClassLongW(hTestWnd,i*sizeof (DWORD)),
"GetClassLongW initial value nonzero!\n");
ok(!GetLastError(),
"GetClassLongW failed!\n");
}
#if 0
/*
* GetClassLongW(hTestWnd, NUMCLASSWORDS*sizeof(DWORD))
* does not fail on Win 98, though MSDN says it should
*/
SetLastError(0);
GetClassLongW(hTestWnd, NUMCLASSWORDS*sizeof(DWORD));
ok(GetLastError(),
"GetClassLongW() with invalid offset did not fail\n");
#endif
/* set values of valid class words */
for(i=0; i<NUMCLASSWORDS; i++)
{
SetLastError(0);
ok(!SetClassLongW(hTestWnd,i*sizeof(DWORD),i+1),
"GetClassLongW(%ld) initial value nonzero!\n",i*sizeof(DWORD));
ok(!GetLastError(),
"SetClassLongW(%ld) failed!\n",i*sizeof(DWORD));
}
/* test values of valid classwords that we set */
for(i=0; i<NUMCLASSWORDS; i++)
{
SetLastError(0);
ok( (i+1) == GetClassLongW(hTestWnd,i*sizeof (DWORD)),
"GetClassLongW value doesn't match what was set!\n");
ok(!GetLastError(),
"GetClassLongW failed!\n");
}
/* check GetClassName */
i = GetClassNameW(hTestWnd, str, sizeof(str));
ok(i == lstrlenW(className),
"GetClassName returned incorrect length\n");
ok(!lstrcmpW(className,str),
"GetClassName returned incorrect name for this window's class\n");
/* check GetClassInfo with our hInstance */
if((test_atom = GetClassInfoW(hInstance, str, &wc)))
{
ok(test_atom == classatom,
"class atom did not match\n");
ok(wc.cbClsExtra == cls.cbClsExtra,
"cbClsExtra did not match\n");
ok(wc.cbWndExtra == cls.cbWndExtra,
"cbWndExtra did not match\n");
ok(wc.hbrBackground == cls.hbrBackground,
"hbrBackground did not match\n");
ok(wc.hCursor== cls.hCursor,
"hCursor did not match\n");
ok(wc.hInstance== cls.hInstance,
"hInstance did not match\n");
}
else
ok(FALSE,"GetClassInfo (hinstance) failed!\n");
/* check GetClassInfo with zero hInstance */
if(global)
{
if((test_atom = GetClassInfoW(0, str, &wc)))
{
ok(test_atom == classatom,
"class atom did not match %x != %x\n", test_atom, classatom);
ok(wc.cbClsExtra == cls.cbClsExtra,
"cbClsExtra did not match %x!=%x\n",wc.cbClsExtra,cls.cbClsExtra);
ok(wc.cbWndExtra == cls.cbWndExtra,
"cbWndExtra did not match %x!=%x\n",wc.cbWndExtra,cls.cbWndExtra);
ok(wc.hbrBackground == cls.hbrBackground,
"hbrBackground did not match %p!=%p\n",wc.hbrBackground,cls.hbrBackground);
ok(wc.hCursor== cls.hCursor,
"hCursor did not match %p!=%p\n",wc.hCursor,cls.hCursor);
ok(!wc.hInstance,
"hInstance not zero for global class %p\n",wc.hInstance);
}
else
ok(FALSE,"GetClassInfo (0) failed for global class!\n");
}
else
{
ok(!GetClassInfoW(0, str, &wc),
"GetClassInfo (0) succeeded for local class!\n");
}
ok(!UnregisterClassW(className, hInstance),
"Unregister class succeeded with window existing\n");
ok(DestroyWindow(hTestWnd),
"DestroyWindow() failed!\n");
ok(UnregisterClassW(className, hInstance),
"UnregisterClass() failed\n");
return;
}
static void check_style( const char *name, int must_exist, UINT style, UINT ignore )
{
WNDCLASS wc;
if (GetClassInfo( 0, name, &wc ))
{
ok( !(~wc.style & style & ~ignore), "System class %s is missing bits %x (%08x/%08x)\n",
name, ~wc.style & style, wc.style, style );
ok( !(wc.style & ~style), "System class %s has extra bits %x (%08x/%08x)\n",
name, wc.style & ~style, wc.style, style );
}
else
ok( !must_exist, "System class %s does not exist\n", name );
}
/* test styles of system classes */
static void test_styles(void)
{
/* check style bits */
check_style( "Button", 1, CS_PARENTDC | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW, 0 );
check_style( "ComboBox", 1, CS_PARENTDC | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW, 0 );
check_style( "Edit", 1, CS_PARENTDC | CS_DBLCLKS, 0 );
check_style( "ListBox", 1, CS_PARENTDC | CS_DBLCLKS, CS_PARENTDC /*FIXME*/ );
check_style( "MDIClient", 1, 0, 0 );
check_style( "ScrollBar", 1, CS_PARENTDC | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW, 0 );
check_style( "Static", 1, CS_PARENTDC | CS_DBLCLKS, 0 );
check_style( "ComboLBox", 1, CS_SAVEBITS | CS_DBLCLKS, 0 );
check_style( "DDEMLEvent", 0, 0, 0 );
check_style( "Message", 0, 0, 0 );
check_style( "#32768", 1, CS_DROPSHADOW | CS_SAVEBITS | CS_DBLCLKS, CS_DROPSHADOW ); /* menu */
check_style( "#32769", 1, CS_DBLCLKS, 0 ); /* desktop */
check_style( "#32770", 1, CS_SAVEBITS | CS_DBLCLKS, 0 ); /* dialog */
todo_wine { check_style( "#32771", 1, CS_SAVEBITS | CS_HREDRAW | CS_VREDRAW, 0 ); } /* task switch */
check_style( "#32772", 1, 0, 0 ); /* icon title */
}
static void check_class(HINSTANCE inst, const char *name, const char *menu_name)
{
WNDCLASS wc;
UINT atom = GetClassInfo(inst,name,&wc);
ok( atom, "Class %s %p not found\n", name, inst );
if (atom)
{
if (wc.lpszMenuName && menu_name)
ok( !strcmp( menu_name, wc.lpszMenuName ), "Wrong name %s/%s for class %s %p\n",
wc.lpszMenuName, menu_name, name, inst );
else
ok( !menu_name == !wc.lpszMenuName, "Wrong name %p/%p for class %s %p\n",
wc.lpszMenuName, menu_name, name, inst );
}
}
static void check_instance( const char *name, HINSTANCE inst, HINSTANCE info_inst, HINSTANCE gcl_inst )
{
WNDCLASSA wc;
HWND hwnd;
ok( GetClassInfo( inst, name, &wc ), "Couldn't find class %s inst %p\n", name, inst );
ok( wc.hInstance == info_inst, "Wrong info instance %p/%p for class %s\n",
wc.hInstance, info_inst, name );
hwnd = CreateWindowExA( 0, name, "test_window", 0, 0, 0, 0, 0, 0, 0, inst, 0 );
ok( hwnd != NULL, "Couldn't create window for class %s inst %p\n", name, inst );
ok( (HINSTANCE)GetClassLongPtrA( hwnd, GCLP_HMODULE ) == gcl_inst,
"Wrong GCL instance %p/%p for class %s\n",
(HINSTANCE)GetClassLongPtrA( hwnd, GCLP_HMODULE ), gcl_inst, name );
ok( (HINSTANCE)GetWindowLongPtrA( hwnd, GWLP_HINSTANCE ) == inst,
"Wrong GWL instance %p/%p for window %s\n",
(HINSTANCE)GetWindowLongPtrA( hwnd, GWLP_HINSTANCE ), inst, name );
ok(!UnregisterClassA(name, inst), "UnregisterClassA should fail while exists a class window\n");
ok(GetLastError() == ERROR_CLASS_HAS_WINDOWS, "GetLastError() should be set to ERROR_CLASS_HAS_WINDOWS not %ld\n", GetLastError());
DestroyWindow(hwnd);
}
struct class_info
{
const char *name;
HINSTANCE inst, info_inst, gcl_inst;
};
static DWORD WINAPI thread_proc(void *param)
{
struct class_info *class_info = (struct class_info *)param;
check_instance(class_info->name, class_info->inst, class_info->info_inst, class_info->gcl_inst);
return 0;
}
static void check_thread_instance( const char *name, HINSTANCE inst, HINSTANCE info_inst, HINSTANCE gcl_inst )
{
HANDLE hThread;
DWORD tid;
struct class_info class_info;
class_info.name = name;
class_info.inst = inst;
class_info.info_inst = info_inst;
class_info.gcl_inst = gcl_inst;
hThread = CreateThread(NULL, 0, thread_proc, &class_info, 0, &tid);
ok(hThread != NULL, "CreateThread failed, error %ld\n", GetLastError());
ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
CloseHandle(hThread);
}
/* test various instance parameters */
static void test_instances(void)
{
WNDCLASSA cls, wc;
HWND hwnd, hwnd2;
const char *name = "__test__";
HINSTANCE kernel32 = GetModuleHandleA("kernel32");
HINSTANCE user32 = GetModuleHandleA("user32");
HINSTANCE main_module = GetModuleHandleA(NULL);
memset( &cls, 0, sizeof(cls) );
cls.style = CS_HREDRAW | CS_VREDRAW;
cls.lpfnWndProc = ClassTest_WndProc;
cls.cbClsExtra = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -