26#include "wine/winternl.h"
30#define DESKTOP_ALL_ACCESS 0x01ff
39 trace(
"could not get info for %p\n",
obj );
44 trace(
"could not get type for %p\n",
obj );
71 HWND hwnd =
CreateWindowExA(0,
"WinStationClass",
"test",
WS_POPUP,0,0,100,100,
GetDesktopWindow(),0,0,0);
72 ok(
hwnd != 0,
"CreateWindow failed\n" );
74 trace(
"thread %p desktop: %p\n",
arg, d1 );
86 trace(
"created desktop %p\n", d2 );
87 ok( d2 != 0,
"CreateDesktop failed\n" );
97 ok( d1 == d2,
"GetThreadDesktop did not return set desktop %p/%p\n", d1, d2 );
126 ok( !
CloseHandle(
w1),
"closing process win station handle succeeded\n" );
134 "handle %p PROTECT_FROM_CLOSE set\n",
w1 );
149 ok(
w2 !=
w1,
"CreateWindowStation returned default handle\n" );
151 ok( !
CloseDesktop( (HDESK)
w2 ),
"CloseDesktop succeeded on win station\n" );
160 win_skip(
"Not enough privileges for CreateWindowStation\n" );
163 ok(
w2 != 0,
"OpenWindowStation failed\n" );
164 ok(
w2 !=
w1,
"OpenWindowStation returned default handle\n" );
168 ok( !
w2,
"open dummy win station succeeded\n" );
178 ok( w3 != 0,
"open foobar station failed\n" );
179 ok( w3 !=
w2,
"open foobar station returned same handle\n" );
184 ok( !w3,
"open foobar station succeeded\n" );
187 ok(
w2 != 0,
"create foobar station failed\n" );
189 ok( w3 != 0,
"create foobar station failed\n" );
208 win_skip(
"Not enough privileges for CreateWindowStation\n" );
212 ok( !
w2,
"open station succeeded\n" );
235 ok( !
w2,
"create station succeeded\n" );
241 ok( !
w2,
"create station succeeded\n" );
248 "GetThreadDesktop returned different handles\n" );
262 win_skip(
"NT4 desktop handle management is completely different\n" );
273 ok(
CloseHandle(d2),
"closing dup desktop handle failed\n" );
276 ok( !d2,
"open dummy desktop succeeded\n" );
281 ok( !d2,
"create empty desktop succeeded\n" );
287 ok( !d2,
"open empty desktop succeeded\n" );
292 ok( !d2,
"create desktop succeeded\n" );
297 ok( !d2,
"open desktop succeeded\n" );
301 ok( d2 != 0,
"create foobar desktop failed\n" );
309 ok( d3 != 0,
"create foobar desktop again failed\n" );
314 ok( d3 != 0,
"open foobar desktop failed\n" );
315 ok( d3 != d2,
"open foobar desktop returned same handle\n" );
320 ok( !d3,
"open foobar desktop succeeded\n" );
322 ok( !
CloseHandle(d1),
"closing thread desktop handle succeeded\n" );
324 ok( d1 == d2,
"got different handles after close\n" );
327 trace(
"thread 1 desktop: %p\n", d1 );
343 trace(
"window_station_callbackA called with argument %s\n", winsta);
351 trace(
"open_window_station_callbackA called with argument %s\n", winsta);
353 ok(hwinsta !=
NULL,
"Could not open desktop %s!\n", winsta);
368 ok(!
ret,
"EnumWindowStationsA returned successfully!\n");
377 win_skip(
"Not enough privileges for CreateWindowStation\n");
383 ok(
ret == 0x12345,
"EnumWindowStationsA returned %x\n",
ret);
388 ok(!
ret,
"EnumWindowStationsA returned %x\n",
ret);
394 trace(
"desktop_callbackA called with argument %s\n", desktop);
403 trace(
"open_desktop_callbackA called with argument %s\n", desktop);
409 ok(hdesk !=
NULL,
"Could not open desktop %s!\n", desktop);
423 ok(!
ret,
"EnumDesktopsA returned successfully!\n");
429 ok(
ret == 0x12345,
"EnumDesktopsA returned %x\n",
ret);
434 ok(
ret == 0x12345,
"EnumDesktopsA returned %x\n",
ret);
439 ok(!
ret,
"EnumDesktopsA returned %x\n",
ret);
444 ok(!
ret,
"EnumDesktopsA returned %x\n",
ret);
452 WCHAR foobarTestW[] = {
'\\',
'f',
'o',
'o',
'b',
'a',
'r',
'T',
'e',
's',
't',0};
453 WCHAR DesktopW[] = {
'D',
'e',
's',
'k',
't',
'o',
'p',0};
463 ok(desk != 0,
"open foobarTest desktop failed\n");
474 ok(!
ret,
"GetUserObjectInformationA returned %x\n",
ret);
483 ok(
ret,
"GetUserObjectInformationA returned %x\n",
ret);
494 ok(!
ret,
"GetUserObjectInformationW returned %x\n",
ret);
503 ok(
ret,
"GetUserObjectInformationW returned %x\n",
ret);
506 ok(
lstrcmpW(bufferW, foobarTestW + 1) == 0,
"Buffer is not set to 'foobarTest'\n");
523 ok(!
ret,
"GetUserObjectInformationA returned %x\n",
ret);
532 ok(
ret,
"GetUserObjectInformationA returned %x\n",
ret);
543 ok(!
ret,
"GetUserObjectInformationW returned %x\n",
ret);
552 ok(
ret,
"GetUserObjectInformationW returned %x\n",
ret);
555 ok(
lstrcmpW(bufferW, DesktopW) == 0,
"Buffer is not set to 'Desktop'\n");
563 HDESK input_desk, old_input_desk, thread_desk, old_thread_desk, new_desk;
569 U(inputs[0]).ki.wVk = 0;
570 U(inputs[0]).ki.wScan = 0x3c0;
571 U(inputs[0]).ki.dwFlags = KEYEVENTF_UNICODE;
575 ok(old_input_desk !=
NULL,
"OpenInputDesktop failed!\n");
578 ok(
ret,
"GetUserObjectInformation failed!\n");
582 ok(input_desk !=
NULL,
"OpenInputDesktop failed!\n");
585 ok(
ret,
"GetUserObjectInformation failed!\n");
588 ok(old_input_desk != input_desk,
"returned the same handle!\n");
590 ok(
ret,
"CloseDesktop failed!\n");
594 ok(old_thread_desk !=
NULL,
"GetThreadDesktop faile!\n");
602 ok(
ret == 1,
"unexpected return count %d\n",
ret);
606 ok(new_desk !=
NULL,
"CreateDesktop failed!\n");
608 ok(
ret,
"SetThreadDesktop failed!\n");
610 ok(thread_desk == new_desk,
"thread desktop doesn't match!\n");
632 ok(
ret,
"SetThreadDesktop failed!\n");
634 ok(thread_desk == old_thread_desk,
"thread desktop doesn't match!\n");
642 ok(
ret == 1,
"unexpected return count %d\n",
ret);
646 ok(
ret,
"SetThreadDesktop failed!\n");
648 ok(thread_desk == old_input_desk,
"thread desktop doesn't match!\n");
656 ok(
ret == 1,
"unexpected return count %d\n",
ret);
660 ok(
ret,
"SwitchDesktop failed!\n");
662 ok(input_desk !=
NULL,
"OpenInputDesktop failed!\n");
663 ok(input_desk != new_desk,
"returned the same handle!\n");
666 ok(
ret,
"GetUserObjectInformation failed!\n");
670 ok(
ret,
"CloseDesktop failed!\n");
680 ok(
ret,
"SetThreadDesktop failed!\n");
682 ok(thread_desk == new_desk,
"thread desktop doesn't match!\n");
690 ok(
ret == 1,
"unexpected return count %d\n",
ret);
696 ok(input_desk !=
NULL,
"OpenInputDesktop failed!\n");
697 ok(input_desk != old_input_desk,
"returned the same handle!\n");
700 ok(
ret,
"GetUserObjectInformation failed!\n");
704 ok(
ret,
"SetThreadDesktop failed!\n");
706 ok(thread_desk == old_thread_desk,
"thread desktop doesn't match!\n");
714 ok(
ret == 1,
"unexpected return count %d\n",
ret);
718 ok(
ret,
"CloseDesktop failed!\n");
720 ok(
ret,
"CloseDesktop failed!\n");
722 ok(
ret,
"CloseDesktop failed!\n");
728 HDESK thread_desk, new_desk, input_desk, hdesk;
732 ok(thread_desk !=
NULL,
"GetThreadDesktop failed!\n");
734 ok(
w1 !=
NULL,
"GetProcessWindowStation failed!\n");
741 win_skip(
"Not enough privileges for CreateWindowStation\n");
746 ok(!
ret,
"EnumDesktopsA failed!\n");
748 ok(input_desk !=
NULL,
"OpenInputDesktop failed!\n");
750 ok(
ret,
"CloseDesktop failed!\n");
753 ok(
ret,
"SetProcessWindowStation failed!\n");
755 ok(hdesk !=
NULL,
"GetThreadDesktop failed!\n");
756 ok(hdesk == thread_desk,
"thread desktop should not change after winstation changed!\n");
760 ok(new_desk !=
NULL,
"CreateDesktop failed!\n");
762 ok(!
ret,
"EnumDesktopsA failed!\n");
765 ok(input_desk ==
NULL,
"OpenInputDesktop should fail on non default winstation!\n");
769 ok(hdesk !=
NULL,
"OpenDesktop failed!\n");
773 ok(!
ret,
"Switch to desktop belong to non default winstation should fail!\n");
777 ok(
ret,
"SetThreadDesktop failed!\n");
782 ok(
ret,
"SetThreadDesktop should success even desktop is not belong to process winstation!\n");
784 ok(
ret,
"SetProcessWindowStation failed!\n");
786 ok(
ret,
"SetThreadDesktop failed!\n");
788 ok(
ret,
"CloseWindowStation failed!\n");
790 ok(
ret,
"CloseDesktop failed!\n");
792 ok(
ret,
"CloseDesktop failed!\n");
821 ok(
ret,
"SetThreadDesktop failed!\n");
822 param1->
hwnd =
CreateWindowA(
"test_class", param1->
wnd_name,
WS_POPUP, 0, 0, 100, 100,
NULL,
NULL,
NULL,
NULL);
823 ok(param1->
hwnd != 0,
"CreateWindowA failed!\n");
825 ok(
ret,
"SetEvent failed!\n");
846 trace(
"\"%s\" %p %08x hwnd %p %08x\n", win_text, hwnd_fore, fore_id,
hwnd, set_id);
848 trace(
"AttachThreadInput returned %08x\n",
ret);
850 trace(
"ShowWindow returned %08x\n",
ret);
852 trace(
"set topmost returned %08x\n",
ret);
854 trace(
"set notopmost returned %08x\n",
ret);
856 trace(
"SetForegroundWindow returned %08x\n",
ret);
864 HWND hwnd, hwnd_test, partners[2], hwnds[2];
866 int thread_desk_id, input_desk_id, hwnd_id;
874 memset( &wclass, 0,
sizeof(wclass) );
878 param.wnd_name =
"win_name";
881 ok(hdesks[0] !=
NULL,
"OpenDesktop failed!\n");
888 win_skip(
"Not enough privileges for CreateDesktop\n");
899 trace(
"old timeout %d\n", timeout_old);
902 ok(
ret,
"set foreground lock timeout failed!\n");
904 ok(
ret,
"get foreground lock timeout failed!\n");
907 for (thread_desk_id = 0; thread_desk_id <
DESKTOPS; thread_desk_id++)
909 param.hdesk = hdesks[thread_desk_id];
914 hwnds[thread_desk_id] =
param.hwnd;
917 for (thread_desk_id = 0; thread_desk_id <
DESKTOPS; thread_desk_id++)
919 param.hdesk = hdesks[thread_desk_id];
924 partners[thread_desk_id] =
param.hwnd;
927 trace(
"hwnd0 %p hwnd1 %p partner0 %p partner1 %p\n", hwnds[0], hwnds[1], partners[0], partners[1]);
929 for (hwnd_id = 0; hwnd_id <
DESKTOPS; hwnd_id++)
930 for (thread_desk_id = 0; thread_desk_id <
DESKTOPS; thread_desk_id++)
931 for (input_desk_id = 0; input_desk_id <
DESKTOPS; input_desk_id++)
933 trace(
"testing thread_desk %d input_desk %d hwnd %d\n",
934 thread_desk_id, input_desk_id, hwnd_id);
935 hwnd_test = hwnds[hwnd_id];
937 ok(
ret,
"set thread desktop failed!\n");
939 ok(
ret,
"switch desktop failed!\n");
943 ok(
hwnd != hwnd_test,
"unexpected foreground window %p\n",
hwnd);
947 trace(
"hwnd %p name %s\n",
hwnd, win_text);
948 if (input_desk_id == hwnd_id)
950 if (input_desk_id == thread_desk_id)
952 ok(
ret,
"SetForegroundWindow failed!\n");
954 ok(
hwnd == hwnd_test ,
"unexpected foreground window %p\n",
hwnd);
964 if (input_desk_id == thread_desk_id)
966 ok(!
ret,
"SetForegroundWindow should fail!\n");
968 ok(
hwnd == partners[input_desk_id] ,
"unexpected foreground window %p\n",
hwnd);
974 ok(
hwnd == 0,
"unexpected foreground window %p\n",
hwnd);
981 for (thread_desk_id =
DESKTOPS - 1; thread_desk_id >= 0; thread_desk_id--)
984 ok(
ret,
"set thread desktop failed!\n");
990 ok(
ret,
"switch desktop failed!\n");
994 ok(
ret,
"set foreground lock timeout failed!\n");
996 ok(
ret,
"get foreground lock timeout failed!\n");
1011 win_skip(
"WindowStation calls not supported on this platform\n");
int strcmp(const char *String1, const char *String2)
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
ACPI_SIZE strlen(const char *String)
char * strcpy(char *DstString, const char *SrcString)
#define ERROR_INSUFFICIENT_BUFFER
#define ERROR_INVALID_FUNCTION
#define ERROR_CALL_NOT_IMPLEMENTED
#define ERROR_INVALID_PARAMETER
#define GetProcAddress(x, y)
#define INVALID_HANDLE_VALUE
#define GetCurrentProcess()
#define ERROR_INVALID_HANDLE
#define ERROR_ACCESS_DENIED
ATOM WINAPI GlobalAddAtomA(LPCSTR lpString)
UINT WINAPI GlobalGetAtomNameA(ATOM nAtom, LPSTR lpBuffer, int nSize)
BOOL WINAPI GetHandleInformation(IN HANDLE hObject, OUT LPDWORD lpdwFlags)
BOOL WINAPI DuplicateHandle(IN HANDLE hSourceProcessHandle, IN HANDLE hSourceHandle, IN HANDLE hTargetProcessHandle, OUT LPHANDLE lpTargetHandle, IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwOptions)
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
int WINAPI lstrcmpiA(LPCSTR str1, LPCSTR str2)
GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint GLdouble GLdouble w2
GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint GLdouble w1
#define ERROR_FILE_NOT_FOUND
static HWND create_window(void)
#define todo_wine_if(is_todo)
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventA(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCSTR lpName OPTIONAL)
HANDLE WINAPI DECLSPEC_HOTPATCH CreateMutexA(IN LPSECURITY_ATTRIBUTES lpMutexAttributes OPTIONAL, IN BOOL bInitialOwner, IN LPCSTR lpName OPTIONAL)
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
TW_UINT32 TW_UINT16 TW_UINT16 MSG
HDESK WINAPI CreateDesktopA(LPCSTR lpszDesktop, LPCSTR lpszDevice, LPDEVMODEA pDevmode, DWORD dwFlags, ACCESS_MASK dwDesiredAccess, LPSECURITY_ATTRIBUTES lpsa)
int WINAPI GetWindowTextA(HWND hWnd, LPSTR lpString, int nMaxCount)
UINT WINAPI SendInput(UINT, LPINPUT, int)
DWORD WINAPI GetLastError(void)
DWORD WINAPI GetCurrentThreadId(void)
#define HANDLE_FLAG_PROTECT_FROM_CLOSE
DWORD WINAPI GetWindowThreadProcessId(HWND hWnd, PDWORD lpdwProcessId)
HWINSTA WINAPI GetProcessWindowStation(void)
#define ERROR_PATH_NOT_FOUND
#define ERROR_BAD_PATHNAME
static void register_class(void)
static BOOL CALLBACK desktop_callbackA(LPSTR desktop, LPARAM lp)
static void test_inputdesktop(void)
static void test_foregroundwindow(void)
static BOOL CALLBACK window_station_callbackA(LPSTR winsta, LPARAM lp)
static DWORD set_foreground(HWND hwnd)
static void test_enumdesktops(void)
static void test_getuserobjectinformation(void)
static BOOL CALLBACK open_window_station_callbackA(LPSTR winsta, LPARAM lp)
static void test_inputdesktop2(void)
static void test_enumstations(void)
struct tag_wnd_param wnd_param
#define DESKTOP_ALL_ACCESS
static OBJECT_INFORMATION_CLASS
static void print_object(HANDLE obj)
static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
static BOOL CALLBACK open_desktop_callbackA(LPSTR desktop, LPARAM lp)
static HDESK initial_desktop
static void test_handles(void)
HGDIOBJ WINAPI GetStockObject(_In_ int)
HDESK WINAPI GetThreadDesktop(_In_ DWORD)
LRESULT WINAPI DispatchMessageA(_In_ const MSG *)
BOOL WINAPI TranslateMessage(_In_ const MSG *)
HWND WINAPI CreateWindowExA(_In_ DWORD dwExStyle, _In_opt_ LPCSTR lpClassName, _In_opt_ LPCSTR lpWindowName, _In_ DWORD dwStyle, _In_ int X, _In_ int Y, _In_ int nWidth, _In_ int nHeight, _In_opt_ HWND hWndParent, _In_opt_ HMENU hMenu, _In_opt_ HINSTANCE hInstance, _In_opt_ LPVOID lpParam)
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
HWND WINAPI GetForegroundWindow(void)
BOOL WINAPI SwitchDesktop(_In_ HDESK)
HWINSTA WINAPI OpenWindowStationA(_In_ LPCSTR, _In_ BOOL, _In_ DWORD)
BOOL WINAPI AttachThreadInput(_In_ DWORD, _In_ DWORD, _In_ BOOL)
LRESULT WINAPI DefWindowProcA(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
BOOL WINAPI SetThreadDesktop(_In_ HDESK)
#define CreateWindowA(a, b, c, d, e, f, g, h, i, j, k)
BOOL WINAPI SetWindowPos(_In_ HWND, _In_opt_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
HDESK WINAPI OpenInputDesktop(_In_ DWORD, _In_ BOOL, _In_ DWORD)
HDESK WINAPI OpenDesktopA(_In_ LPCSTR, _In_ DWORD, _In_ BOOL, _In_ DWORD)
#define DESKTOP_ENUMERATE
BOOL WINAPI SetForegroundWindow(_In_ HWND)
LRESULT WINAPI SendMessageA(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
HWINSTA WINAPI CreateWindowStationA(_In_opt_ LPCSTR lpwinsta, _In_ DWORD dwFlags, _In_ ACCESS_MASK dwDesiredAccess, _In_opt_ LPSECURITY_ATTRIBUTES lpsa)
BOOL WINAPI CloseWindowStation(_In_ HWINSTA)
BOOL WINAPI EnumWindowStationsA(_In_ WINSTAENUMPROCA, _In_ LPARAM lParam)
BOOL WINAPI SetProcessWindowStation(_In_ HWINSTA)
HWND WINAPI GetDesktopWindow(void)
#define WINSTA_ALL_ACCESS
#define SPIF_UPDATEINIFILE
ATOM WINAPI RegisterClassA(_In_ CONST WNDCLASSA *)
BOOL WINAPI GetUserObjectInformationW(_In_ HANDLE hObj, _In_ int nIndex, _Out_writes_bytes_opt_(nLength) PVOID pvInfo, _In_ DWORD nLength, _Out_opt_ LPDWORD lpnLengthNeeded)
BOOL WINAPI GetUserObjectInformationA(_In_ HANDLE hObj, _In_ int nIndex, _Out_writes_bytes_opt_(nLength) PVOID pvInfo, _In_ DWORD nLength, _Out_opt_ LPDWORD lpnLengthNeeded)
BOOL WINAPI SystemParametersInfoA(_In_ UINT uiAction, _In_ UINT uiParam, _Inout_opt_ PVOID pvParam, _In_ UINT fWinIni)
BOOL WINAPI CloseDesktop(_In_ HDESK)
BOOL WINAPI GetMessageA(_Out_ LPMSG, _In_opt_ HWND, _In_ UINT, _In_ UINT)
BOOL WINAPI DestroyWindow(_In_ HWND)
HCURSOR WINAPI LoadCursorA(_In_opt_ HINSTANCE, _In_ LPCSTR)
BOOL WINAPI EnumDesktopsA(_In_opt_ HWINSTA, _In_ DESKTOPENUMPROCA, _In_ LPARAM)
#define DUPLICATE_SAME_ACCESS