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"
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 /***********************************************************************
48 * Initialize the DPI awareness style.
50 static void dpiaware_init(void)
55 if (!LdrQueryImageFileExecutionOptions( &NtCurrentTeb()->Peb
->ProcessParameters
->ImagePathName
,
56 L
"dpiAwareness", REG_DWORD
, &option
, sizeof(option
), NULL
))
58 TRACE( "got option %lx\n", option
);
61 SetProcessDpiAwarenessContext( (DPI_AWARENESS_CONTEXT
)~(ULONG_PTR
)option
);
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
;
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
);
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
);
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
);
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 ¶ms
->tracking_info
, params
->arrows
, params
->interior
,
112 &rect
, params
->enable_flags
, params
->arrow_size
, params
->thumb_pos
,
113 params
->thumb_size
, params
->vertical
);
117 static NTSTATUS WINAPI
User32DrawText( const struct draw_text_params
*params
, ULONG size
)
119 RECT rect
= params
->rect
;
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
;
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
,
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
= { .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
))
190 if (params
->result
) *params
->result
= result
;
191 else NtCallbackReturn( &result
, sizeof(result
), TRUE
);
195 static const void *kernel_callback_table
[NtUserCallCount
] =
197 User32CallEnumDisplayMonitor
,
198 User32CallSendAsyncCallback
,
199 User32CallWinEventHook
,
200 User32CallWindowProc
,
201 User32CallWindowsHook
,
205 User32FreeCachedClipboardData
,
207 User32ImmTranslateMessage
,
208 User32InitBuiltinClasses
,
212 User32PostDDEMessage
,
213 User32RenderSsynthesizedFormat
,
214 User32UnpackDDEMessage
,
218 /***********************************************************************
219 * USER initialisation routine
221 static BOOL
process_attach(void)
223 NtCurrentTeb()->Peb
->KernelCallbackTable
= kernel_callback_table
;
233 /**********************************************************************
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
;
261 case DLL_PROCESS_ATTACH
:
262 user32_module
= inst
;
263 ret
= process_attach();
265 imm32_module
= LoadLibraryW(L
"imm32.dll");
267 case DLL_THREAD_DETACH
:
270 case DLL_PROCESS_DETACH
:
271 FreeLibrary(imm32_module
);
278 /***********************************************************************
279 * ExitWindowsEx (USER32.@)
281 BOOL WINAPI
ExitWindowsEx( UINT flags
, DWORD reason
)
284 WCHAR cmdline
[MAX_PATH
+ 64];
285 PROCESS_INFORMATION pi
;
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" );
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
);
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
) );
310 Wow64RevertWow64FsRedirection( redir
);
311 CloseHandle( pi
.hProcess
);
312 CloseHandle( pi
.hThread
);
316 /***********************************************************************
317 * LockWorkStation (USER32.@)
319 BOOL WINAPI
LockWorkStation(void)
322 SetLastError( ERROR_CALL_NOT_IMPLEMENTED
);
326 /***********************************************************************
327 * RegisterServicesProcess (USER32.@)
329 int WINAPI
RegisterServicesProcess(DWORD ServicesProcessId
)
331 FIXME("(0x%lx): stub\n", ServicesProcessId
);
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
);
345 /***********************************************************************
346 * ShutdownBlockReasonDestroy (USER32.@)
348 BOOL WINAPI
ShutdownBlockReasonDestroy(HWND hwnd
)
350 FIXME("(%p): stub\n", hwnd
);
351 SetLastError( ERROR_CALL_NOT_IMPLEMENTED
);
355 const char *SPY_GetMsgName( UINT msg
, HWND hwnd
)
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
);