gdi32/tests: Mark tests failing randomly on Windows as flaky.
[wine.git] / dlls / user32 / user_main.c
blob963f07b70efa785c3cdedac70a4a4437bb4590b5
1 /*
2 * USER initialization code
4 * Copyright 2000 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "user_private.h"
22 #include "controls.h"
23 #include "imm.h"
24 #include "ddk/imm.h"
25 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(graphics);
29 WINE_DECLARE_DEBUG_CHANNEL(message);
31 HMODULE user32_module = 0;
33 extern void WDML_NotifyThreadDetach(void);
36 /***********************************************************************
37 * UserRealizePalette (USER32.@)
39 UINT WINAPI UserRealizePalette( HDC hdc )
41 return NtUserRealizePalette( hdc );
45 /***********************************************************************
46 * dpiaware_init
48 * Initialize the DPI awareness style.
50 static void dpiaware_init(void)
52 WCHAR buffer[256];
53 DWORD option;
55 if (!LdrQueryImageFileExecutionOptions( &NtCurrentTeb()->Peb->ProcessParameters->ImagePathName,
56 L"dpiAwareness", REG_DWORD, &option, sizeof(option), NULL ))
58 TRACE( "got option %lx\n", option );
59 if (option <= 2)
61 SetProcessDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)~(ULONG_PTR)option );
62 return;
66 if (QueryActCtxSettingsW( 0, NULL, L"http://schemas.microsoft.com/SMI/2016/WindowsSettings",
67 L"dpiAwareness", buffer, ARRAY_SIZE(buffer), NULL ))
69 static const WCHAR * const types[] = { L"unaware", L"system", L"permonitor", L"permonitorv2" };
70 WCHAR *p, *start, *end;
71 ULONG_PTR i;
73 TRACE( "got dpiAwareness=%s\n", debugstr_w(buffer) );
74 for (start = buffer; *start; start = end)
76 start += wcsspn( start, L" \t\r\n" );
77 if (!(end = wcschr( start, ',' ))) end = start + lstrlenW(start);
78 else *end++ = 0;
79 if ((p = wcspbrk( start, L" \t\r\n" ))) *p = 0;
80 for (i = 0; i < ARRAY_SIZE(types); i++)
82 if (wcsicmp( start, types[i] )) continue;
83 SetProcessDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)~i );
84 return;
88 else if (QueryActCtxSettingsW( 0, NULL, L"http://schemas.microsoft.com/SMI/2005/WindowsSettings",
89 L"dpiAware", buffer, ARRAY_SIZE(buffer), NULL ))
91 TRACE( "got dpiAware=%s\n", debugstr_w(buffer) );
92 if (!wcsicmp( buffer, L"true" ))
93 SetProcessDpiAwarenessContext( DPI_AWARENESS_CONTEXT_SYSTEM_AWARE );
94 else if (!wcsicmp( buffer, L"true/pm" ) || !wcsicmp( buffer, L"per monitor" ))
95 SetProcessDpiAwarenessContext( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE );
96 else
97 SetProcessDpiAwarenessContext( DPI_AWARENESS_CONTEXT_UNAWARE );
101 static NTSTATUS WINAPI User32CopyImage( const struct copy_image_params *params, ULONG size )
103 HANDLE ret = CopyImage( params->hwnd, params->type, params->dx, params->dy, params->flags );
104 return HandleToUlong( ret );
107 static NTSTATUS WINAPI User32DrawScrollBar( const struct draw_scroll_bar_params *params, ULONG size )
109 RECT rect = params->rect;
110 user_api->pScrollBarDraw( params->hwnd, params->hdc, params->bar, params->hit_test,
111 &params->tracking_info, params->arrows, params->interior,
112 &rect, params->enable_flags, params->arrow_size, params->thumb_pos,
113 params->thumb_size, params->vertical );
114 return 0;
117 static NTSTATUS WINAPI User32DrawText( const struct draw_text_params *params, ULONG size )
119 RECT rect = params->rect;
120 int ret;
122 size -= FIELD_OFFSET( struct draw_text_params, str );
123 ret = DrawTextW( params->hdc, params->str, size / sizeof(WCHAR), &rect, params->flags );
124 if (params->ret_rect)
126 *params->ret_rect = rect;
127 return ret;
129 return NtCallbackReturn( &rect, sizeof(rect), ret );
132 static NTSTATUS WINAPI User32ImmProcessKey( const struct imm_process_key_params *params, ULONG size )
134 return ImmProcessKey( params->hwnd, params->hkl, params->vkey, params->key_data, 0 );
137 static NTSTATUS WINAPI User32ImmTranslateMessage( const struct imm_translate_message_params *params,
138 ULONG size )
140 return ImmTranslateMessage( params->hwnd, params->msg, params->wparam, params->key_data );
143 static NTSTATUS WINAPI User32LoadImage( const struct load_image_params *params, ULONG size )
145 HANDLE ret = LoadImageW( params->hinst, params->name, params->type,
146 params->dx, params->dy, params->flags );
147 return HandleToUlong( ret );
150 static NTSTATUS WINAPI User32LoadSysMenu( const struct load_sys_menu_params *params, ULONG size )
152 HMENU ret = LoadMenuW( user32_module, params->mdi ? L"SYSMENUMDI" : L"SYSMENU" );
153 return HandleToUlong( ret );
156 static NTSTATUS WINAPI User32FreeCachedClipboardData( const struct free_cached_data_params *params,
157 ULONG size )
159 free_cached_data( params->format, params->handle );
160 return 0;
163 static NTSTATUS WINAPI User32PostDDEMessage( const struct post_dde_message_params *params, ULONG size )
165 return post_dde_message( params->hwnd, params->msg, params->wparam, params->lparam,
166 params->dest_tid, params->type );
169 static NTSTATUS WINAPI User32RenderSsynthesizedFormat( const struct render_synthesized_format_params *params,
170 ULONG size )
172 render_synthesized_format( params->format, params->from );
173 return 0;
176 static BOOL WINAPI User32LoadDriver( const WCHAR *path, ULONG size )
178 return LoadLibraryW( path ) != NULL;
181 static NTSTATUS WINAPI User32UnpackDDEMessage( const struct unpack_dde_message_params *params, ULONG size )
183 struct unpack_dde_message_result result = { .wparam = params->wparam, .lparam = params->lparam };
185 size -= FIELD_OFFSET( struct unpack_dde_message_params, data );
186 if (!unpack_dde_message( params->hwnd, params->message, &result.wparam, &result.lparam,
187 params->data, size ))
188 return FALSE;
190 if (params->result) *params->result = result;
191 else NtCallbackReturn( &result, sizeof(result), TRUE );
192 return TRUE;
195 static const void *kernel_callback_table[NtUserCallCount] =
197 User32CallEnumDisplayMonitor,
198 User32CallSendAsyncCallback,
199 User32CallWinEventHook,
200 User32CallWindowProc,
201 User32CallWindowsHook,
202 User32CopyImage,
203 User32DrawScrollBar,
204 User32DrawText,
205 User32FreeCachedClipboardData,
206 User32ImmProcessKey,
207 User32ImmTranslateMessage,
208 User32InitBuiltinClasses,
209 User32LoadDriver,
210 User32LoadImage,
211 User32LoadSysMenu,
212 User32PostDDEMessage,
213 User32RenderSsynthesizedFormat,
214 User32UnpackDDEMessage,
218 /***********************************************************************
219 * USER initialisation routine
221 static BOOL process_attach(void)
223 NtCurrentTeb()->Peb->KernelCallbackTable = kernel_callback_table;
225 winproc_init();
226 dpiaware_init();
227 SYSPARAMS_Init();
229 return TRUE;
233 /**********************************************************************
234 * thread_detach
236 static void thread_detach(void)
238 struct ntuser_thread_info *thread_info = NtUserGetThreadInfo();
240 NtUserCallNoParam( NtUserExitingThread );
242 WDML_NotifyThreadDetach();
244 NtUserCallNoParam( NtUserThreadDetach );
245 HeapFree( GetProcessHeap(), 0, (void *)(UINT_PTR)thread_info->wmchar_data );
249 /***********************************************************************
250 * UserClientDllInitialize (USER32.@)
252 * USER dll initialisation routine (exported as UserClientDllInitialize for compatibility).
254 BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved )
256 static HMODULE imm32_module;
257 BOOL ret = TRUE;
259 switch(reason)
261 case DLL_PROCESS_ATTACH:
262 user32_module = inst;
263 ret = process_attach();
264 if(ret)
265 imm32_module = LoadLibraryW(L"imm32.dll");
266 break;
267 case DLL_THREAD_DETACH:
268 thread_detach();
269 break;
270 case DLL_PROCESS_DETACH:
271 FreeLibrary(imm32_module);
272 break;
274 return ret;
278 /***********************************************************************
279 * ExitWindowsEx (USER32.@)
281 BOOL WINAPI ExitWindowsEx( UINT flags, DWORD reason )
283 WCHAR app[MAX_PATH];
284 WCHAR cmdline[MAX_PATH + 64];
285 PROCESS_INFORMATION pi;
286 STARTUPINFOW si;
287 void *redir;
289 GetSystemDirectoryW( app, MAX_PATH - ARRAY_SIZE( L"\\wineboot.exe" ));
290 lstrcatW( app, L"\\wineboot.exe" );
291 lstrcpyW( cmdline, app );
293 if (flags & EWX_FORCE) lstrcatW( cmdline, L" --kill" );
294 else
296 lstrcatW( cmdline, L" --end-session" );
297 if (flags & EWX_FORCEIFHUNG) lstrcatW( cmdline, L" --force" );
299 if (!(flags & EWX_REBOOT)) lstrcatW( cmdline, L" --shutdown" );
301 memset( &si, 0, sizeof si );
302 si.cb = sizeof si;
303 Wow64DisableWow64FsRedirection( &redir );
304 if (!CreateProcessW( app, cmdline, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, NULL, &si, &pi ))
306 Wow64RevertWow64FsRedirection( redir );
307 ERR( "Failed to run %s\n", debugstr_w(cmdline) );
308 return FALSE;
310 Wow64RevertWow64FsRedirection( redir );
311 CloseHandle( pi.hProcess );
312 CloseHandle( pi.hThread );
313 return TRUE;
316 /***********************************************************************
317 * LockWorkStation (USER32.@)
319 BOOL WINAPI LockWorkStation(void)
321 TRACE(": stub\n");
322 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
323 return FALSE;
326 /***********************************************************************
327 * RegisterServicesProcess (USER32.@)
329 int WINAPI RegisterServicesProcess(DWORD ServicesProcessId)
331 FIXME("(0x%lx): stub\n", ServicesProcessId);
332 return 0;
335 /***********************************************************************
336 * ShutdownBlockReasonCreate (USER32.@)
338 BOOL WINAPI ShutdownBlockReasonCreate(HWND hwnd, LPCWSTR reason)
340 FIXME("(%p, %s): stub\n", hwnd, debugstr_w(reason));
341 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
342 return FALSE;
345 /***********************************************************************
346 * ShutdownBlockReasonDestroy (USER32.@)
348 BOOL WINAPI ShutdownBlockReasonDestroy(HWND hwnd)
350 FIXME("(%p): stub\n", hwnd);
351 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
352 return FALSE;
355 const char *SPY_GetMsgName( UINT msg, HWND hwnd )
357 char buf[128];
358 NtUserMessageCall( hwnd, msg, ARRAYSIZE(buf), 0, buf, NtUserSpyGetMsgName, FALSE );
359 return wine_dbg_sprintf( "%s", buf );
362 void SPY_EnterMessage( INT flag, HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
364 if (TRACE_ON(message)) NtUserMessageCall( hwnd, msg, wparam, lparam, 0, NtUserSpyEnter, flag );
367 void SPY_ExitMessage( INT flag, HWND hwnd, UINT msg, LRESULT lreturn, WPARAM wparam, LPARAM lparam )
369 if (TRACE_ON(message)) NtUserMessageCall( hwnd, msg, wparam, lparam, (void *)lreturn,
370 NtUserSpyExit, flag );