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
32 #include "user_private.h"
34 #include "wine/debug.h"
35 #include "wine/exception.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(graphics
);
38 WINE_DECLARE_DEBUG_CHANNEL(message
);
40 HMODULE user32_module
= 0;
42 extern void WDML_NotifyThreadDetach(void);
45 /***********************************************************************
46 * UserRealizePalette (USER32.@)
48 UINT WINAPI
UserRealizePalette( HDC hdc
)
50 return NtUserRealizePalette( hdc
);
54 /***********************************************************************
57 * Initialize the DPI awareness style.
59 static void dpiaware_init(void)
64 if (!LdrQueryImageFileExecutionOptions( &NtCurrentTeb()->Peb
->ProcessParameters
->ImagePathName
,
65 L
"dpiAwareness", REG_DWORD
, &option
, sizeof(option
), NULL
))
67 TRACE( "got option %lx\n", option
);
70 SetProcessDpiAwarenessContext( (DPI_AWARENESS_CONTEXT
)~(ULONG_PTR
)option
);
75 if (QueryActCtxSettingsW( 0, NULL
, L
"http://schemas.microsoft.com/SMI/2016/WindowsSettings",
76 L
"dpiAwareness", buffer
, ARRAY_SIZE(buffer
), NULL
))
78 static const WCHAR
* const types
[] = { L
"unaware", L
"system", L
"permonitor", L
"permonitorv2" };
79 WCHAR
*p
, *start
, *end
;
82 TRACE( "got dpiAwareness=%s\n", debugstr_w(buffer
) );
83 for (start
= buffer
; *start
; start
= end
)
85 start
+= wcsspn( start
, L
" \t\r\n" );
86 if (!(end
= wcschr( start
, ',' ))) end
= start
+ lstrlenW(start
);
88 if ((p
= wcspbrk( start
, L
" \t\r\n" ))) *p
= 0;
89 for (i
= 0; i
< ARRAY_SIZE(types
); i
++)
91 if (wcsicmp( start
, types
[i
] )) continue;
92 SetProcessDpiAwarenessContext( (DPI_AWARENESS_CONTEXT
)~i
);
97 else if (QueryActCtxSettingsW( 0, NULL
, L
"http://schemas.microsoft.com/SMI/2005/WindowsSettings",
98 L
"dpiAware", buffer
, ARRAY_SIZE(buffer
), NULL
))
100 TRACE( "got dpiAware=%s\n", debugstr_w(buffer
) );
101 if (!wcsicmp( buffer
, L
"true" ))
102 SetProcessDpiAwarenessContext( DPI_AWARENESS_CONTEXT_SYSTEM_AWARE
);
103 else if (!wcsicmp( buffer
, L
"true/pm" ) || !wcsicmp( buffer
, L
"per monitor" ))
104 SetProcessDpiAwarenessContext( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE
);
106 SetProcessDpiAwarenessContext( DPI_AWARENESS_CONTEXT_UNAWARE
);
110 static NTSTATUS WINAPI
User32CopyImage( const struct copy_image_params
*params
, ULONG size
)
112 HANDLE ret
= CopyImage( params
->hwnd
, params
->type
, params
->dx
, params
->dy
, params
->flags
);
113 return HandleToUlong( ret
);
116 static NTSTATUS WINAPI
User32DrawScrollBar( const struct draw_scroll_bar_params
*params
, ULONG size
)
118 RECT rect
= params
->rect
;
119 user_api
->pScrollBarDraw( params
->hwnd
, params
->hdc
, params
->bar
, params
->hit_test
,
120 ¶ms
->tracking_info
, params
->arrows
, params
->interior
,
121 &rect
, params
->enable_flags
, params
->arrow_size
, params
->thumb_pos
,
122 params
->thumb_size
, params
->vertical
);
126 static NTSTATUS WINAPI
User32DrawText( const struct draw_text_params
*params
, ULONG size
)
128 size
-= FIELD_OFFSET( struct draw_text_params
, str
);
129 return DrawTextW( params
->hdc
, params
->str
, size
/ sizeof(WCHAR
), params
->rect
, params
->flags
);
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
,
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
,
159 free_cached_data( params
->format
, params
->handle
);
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
,
172 render_synthesized_format( params
->format
, params
->from
);
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
= params
->result
;
184 result
->wparam
= params
->wparam
;
185 result
->lparam
= params
->lparam
;
186 size
-= FIELD_OFFSET( struct unpack_dde_message_params
, data
);
187 return unpack_dde_message( params
->hwnd
, params
->message
, &result
->wparam
, &result
->lparam
,
188 params
->data
, size
);
191 static const void *kernel_callback_table
[NtUserCallCount
] =
193 User32CallEnumDisplayMonitor
,
194 User32CallSendAsyncCallback
,
195 User32CallWinEventHook
,
196 User32CallWindowProc
,
197 User32CallWindowsHook
,
201 User32FreeCachedClipboardData
,
203 User32ImmTranslateMessage
,
204 User32InitBuiltinClasses
,
208 User32PostDDEMessage
,
209 User32RenderSsynthesizedFormat
,
210 User32UnpackDDEMessage
,
214 /***********************************************************************
215 * USER initialisation routine
217 static BOOL
process_attach(void)
219 NtCurrentTeb()->Peb
->KernelCallbackTable
= kernel_callback_table
;
224 /* Initialize system colors and metrics */
231 /**********************************************************************
234 static void thread_detach(void)
236 struct ntuser_thread_info
*thread_info
= NtUserGetThreadInfo();
238 NtUserCallNoParam( NtUserExitingThread
);
240 WDML_NotifyThreadDetach();
242 NtUserCallNoParam( NtUserThreadDetach
);
243 HeapFree( GetProcessHeap(), 0, (void *)(UINT_PTR
)thread_info
->wmchar_data
);
247 /***********************************************************************
248 * UserClientDllInitialize (USER32.@)
250 * USER dll initialisation routine (exported as UserClientDllInitialize for compatibility).
252 BOOL WINAPI
DllMain( HINSTANCE inst
, DWORD reason
, LPVOID reserved
)
254 static HMODULE imm32_module
;
259 case DLL_PROCESS_ATTACH
:
260 user32_module
= inst
;
261 ret
= process_attach();
263 imm32_module
= LoadLibraryW(L
"imm32.dll");
265 case DLL_THREAD_DETACH
:
268 case DLL_PROCESS_DETACH
:
269 FreeLibrary(imm32_module
);
276 /***********************************************************************
277 * ExitWindowsEx (USER32.@)
279 BOOL WINAPI
ExitWindowsEx( UINT flags
, DWORD reason
)
282 WCHAR cmdline
[MAX_PATH
+ 64];
283 PROCESS_INFORMATION pi
;
287 GetSystemDirectoryW( app
, MAX_PATH
- ARRAY_SIZE( L
"\\wineboot.exe" ));
288 lstrcatW( app
, L
"\\wineboot.exe" );
289 lstrcpyW( cmdline
, app
);
291 if (flags
& EWX_FORCE
) lstrcatW( cmdline
, L
" --kill" );
294 lstrcatW( cmdline
, L
" --end-session" );
295 if (flags
& EWX_FORCEIFHUNG
) lstrcatW( cmdline
, L
" --force" );
297 if (!(flags
& EWX_REBOOT
)) lstrcatW( cmdline
, L
" --shutdown" );
299 memset( &si
, 0, sizeof si
);
301 Wow64DisableWow64FsRedirection( &redir
);
302 if (!CreateProcessW( app
, cmdline
, NULL
, NULL
, FALSE
, DETACHED_PROCESS
, NULL
, NULL
, &si
, &pi
))
304 Wow64RevertWow64FsRedirection( redir
);
305 ERR( "Failed to run %s\n", debugstr_w(cmdline
) );
308 Wow64RevertWow64FsRedirection( redir
);
309 CloseHandle( pi
.hProcess
);
310 CloseHandle( pi
.hThread
);
314 /***********************************************************************
315 * LockWorkStation (USER32.@)
317 BOOL WINAPI
LockWorkStation(void)
320 SetLastError( ERROR_CALL_NOT_IMPLEMENTED
);
324 /***********************************************************************
325 * RegisterServicesProcess (USER32.@)
327 int WINAPI
RegisterServicesProcess(DWORD ServicesProcessId
)
329 FIXME("(0x%lx): stub\n", ServicesProcessId
);
333 /***********************************************************************
334 * ShutdownBlockReasonCreate (USER32.@)
336 BOOL WINAPI
ShutdownBlockReasonCreate(HWND hwnd
, LPCWSTR reason
)
338 FIXME("(%p, %s): stub\n", hwnd
, debugstr_w(reason
));
339 SetLastError( ERROR_CALL_NOT_IMPLEMENTED
);
343 /***********************************************************************
344 * ShutdownBlockReasonDestroy (USER32.@)
346 BOOL WINAPI
ShutdownBlockReasonDestroy(HWND hwnd
)
348 FIXME("(%p): stub\n", hwnd
);
349 SetLastError( ERROR_CALL_NOT_IMPLEMENTED
);
353 const char *SPY_GetMsgName( UINT msg
, HWND hwnd
)
355 return (const char *)NtUserCallHwndParam( hwnd
, msg
, NtUserSpyGetMsgName
);
358 void SPY_EnterMessage( INT flag
, HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
360 if (TRACE_ON(message
)) NtUserMessageCall( hwnd
, msg
, wparam
, lparam
, 0, NtUserSpyEnter
, flag
);
363 void SPY_ExitMessage( INT flag
, HWND hwnd
, UINT msg
, LRESULT lreturn
, WPARAM wparam
, LPARAM lparam
)
365 if (TRACE_ON(message
)) NtUserMessageCall( hwnd
, msg
, wparam
, lparam
, (void *)lreturn
,
366 NtUserSpyExit
, flag
);