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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "wine/winbase16.h"
28 #include "wine/winuser16.h"
31 #include "cursoricon.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(graphics
);
41 USER_DRIVER USER_Driver
;
43 WINE_LOOK TWEAK_WineLook
= WIN31_LOOK
;
45 WORD USER_HeapSel
= 0; /* USER heap selector */
47 extern HPALETTE (WINAPI
*pfnGDISelectPalette
)(HDC hdc
, HPALETTE hpal
, WORD bkgnd
);
48 extern UINT (WINAPI
*pfnGDIRealizePalette
)(HDC hdc
);
50 static HMODULE graphics_driver
;
51 static DWORD exiting_thread_id
;
53 extern void COMM_Init(void);
54 extern void WDML_NotifyThreadDetach(void);
56 #define GET_USER_FUNC(name) USER_Driver.p##name = (void*)GetProcAddress( graphics_driver, #name )
58 /* load the graphics driver */
59 static BOOL
load_driver(void)
61 char buffer
[MAX_PATH
];
65 strcpy( buffer
, "x11drv" ); /* default value */
66 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Wine\\Config\\Wine", &hkey
))
68 count
= sizeof(buffer
);
69 RegQueryValueExA( hkey
, "GraphicsDriver", 0, &type
, buffer
, &count
);
73 if (!(graphics_driver
= LoadLibraryA( buffer
)))
75 MESSAGE( "Could not load graphics driver '%s'\n", buffer
);
79 GET_USER_FUNC(InitKeyboard
);
80 GET_USER_FUNC(VkKeyScan
);
81 GET_USER_FUNC(MapVirtualKey
);
82 GET_USER_FUNC(GetKeyNameText
);
83 GET_USER_FUNC(ToUnicode
);
85 GET_USER_FUNC(InitMouse
);
86 GET_USER_FUNC(SetCursor
);
87 GET_USER_FUNC(GetCursorPos
);
88 GET_USER_FUNC(SetCursorPos
);
89 GET_USER_FUNC(GetScreenSaveActive
);
90 GET_USER_FUNC(SetScreenSaveActive
);
91 GET_USER_FUNC(AcquireClipboard
);
92 GET_USER_FUNC(EmptyClipboard
);
93 GET_USER_FUNC(SetClipboardData
);
94 GET_USER_FUNC(GetClipboardData
);
95 GET_USER_FUNC(CountClipboardFormats
);
96 GET_USER_FUNC(EnumClipboardFormats
);
97 GET_USER_FUNC(IsClipboardFormatAvailable
);
98 GET_USER_FUNC(RegisterClipboardFormat
);
99 GET_USER_FUNC(GetClipboardFormatName
);
100 GET_USER_FUNC(EndClipboardUpdate
);
101 GET_USER_FUNC(ResetSelectionOwner
);
102 GET_USER_FUNC(ChangeDisplaySettingsExW
);
103 GET_USER_FUNC(EnumDisplaySettingsExW
);
104 GET_USER_FUNC(CreateWindow
);
105 GET_USER_FUNC(DestroyWindow
);
106 GET_USER_FUNC(GetDC
);
107 GET_USER_FUNC(ForceWindowRaise
);
108 GET_USER_FUNC(MsgWaitForMultipleObjectsEx
);
109 GET_USER_FUNC(ReleaseDC
);
110 GET_USER_FUNC(ScrollDC
);
111 GET_USER_FUNC(ScrollWindowEx
);
112 GET_USER_FUNC(SetFocus
);
113 GET_USER_FUNC(SetParent
);
114 GET_USER_FUNC(SetWindowPos
);
115 GET_USER_FUNC(SetWindowRgn
);
116 GET_USER_FUNC(SetWindowIcon
);
117 GET_USER_FUNC(SetWindowStyle
);
118 GET_USER_FUNC(SetWindowText
);
119 GET_USER_FUNC(ShowWindow
);
120 GET_USER_FUNC(SysCommandSizeMove
);
126 /***********************************************************************
129 * Register the classes for the builtin controls
131 static void controls_init(void)
133 extern const struct builtin_class_descr BUTTON_builtin_class
;
134 extern const struct builtin_class_descr COMBO_builtin_class
;
135 extern const struct builtin_class_descr COMBOLBOX_builtin_class
;
136 extern const struct builtin_class_descr DIALOG_builtin_class
;
137 extern const struct builtin_class_descr DESKTOP_builtin_class
;
138 extern const struct builtin_class_descr EDIT_builtin_class
;
139 extern const struct builtin_class_descr ICONTITLE_builtin_class
;
140 extern const struct builtin_class_descr LISTBOX_builtin_class
;
141 extern const struct builtin_class_descr MDICLIENT_builtin_class
;
142 extern const struct builtin_class_descr MENU_builtin_class
;
143 extern const struct builtin_class_descr SCROLL_builtin_class
;
144 extern const struct builtin_class_descr STATIC_builtin_class
;
146 CLASS_RegisterBuiltinClass( &BUTTON_builtin_class
);
147 CLASS_RegisterBuiltinClass( &COMBO_builtin_class
);
148 CLASS_RegisterBuiltinClass( &COMBOLBOX_builtin_class
);
149 CLASS_RegisterBuiltinClass( &DIALOG_builtin_class
);
150 CLASS_RegisterBuiltinClass( &DESKTOP_builtin_class
);
151 CLASS_RegisterBuiltinClass( &EDIT_builtin_class
);
152 CLASS_RegisterBuiltinClass( &ICONTITLE_builtin_class
);
153 CLASS_RegisterBuiltinClass( &LISTBOX_builtin_class
);
154 CLASS_RegisterBuiltinClass( &MDICLIENT_builtin_class
);
155 CLASS_RegisterBuiltinClass( &MENU_builtin_class
);
156 CLASS_RegisterBuiltinClass( &SCROLL_builtin_class
);
157 CLASS_RegisterBuiltinClass( &STATIC_builtin_class
);
161 /***********************************************************************
164 * Patch the function pointers in GDI for SelectPalette and RealizePalette
166 static void palette_init(void)
169 HMODULE module
= GetModuleHandleA( "gdi32" );
172 ERR( "cannot get GDI32 handle\n" );
175 if ((ptr
= (void**)GetProcAddress( module
, "pfnSelectPalette" )))
176 pfnGDISelectPalette
= InterlockedExchangePointer( ptr
, SelectPalette
);
177 else ERR( "cannot find pfnSelectPalette in GDI32\n" );
178 if ((ptr
= (void**)GetProcAddress( module
, "pfnRealizePalette" )))
179 pfnGDIRealizePalette
= InterlockedExchangePointer( ptr
, UserRealizePalette
);
180 else ERR( "cannot find pfnRealizePalette in GDI32\n" );
184 /***********************************************************************
187 static void tweak_init(void)
189 static const char *OS
= "Win3.1";
192 DWORD type
, count
= sizeof(buffer
);
194 if (RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Wine\\Config\\Tweak.Layout", &hkey
))
196 if (RegQueryValueExA( hkey
, "WineLook", 0, &type
, buffer
, &count
))
197 strcpy( buffer
, "Win31" ); /* default value */
200 /* WIN31_LOOK is default */
201 if (!strncasecmp( buffer
, "Win95", 5 ))
203 TWEAK_WineLook
= WIN95_LOOK
;
206 else if (!strncasecmp( buffer
, "Win98", 5 ))
208 TWEAK_WineLook
= WIN98_LOOK
;
211 TRACE("Using %s look and feel.\n", OS
);
215 /***********************************************************************
216 * USER initialisation routine
218 static BOOL
process_attach(void)
220 HINSTANCE16 instance
;
222 /* Create USER heap */
223 if ((instance
= LoadLibrary16( "USER.EXE" )) >= 32) USER_HeapSel
= instance
| 7;
226 USER_HeapSel
= GlobalAlloc16( GMEM_FIXED
, 65536 );
227 LocalInit16( USER_HeapSel
, 32, 65534 );
230 /* Load the graphics driver */
232 if (!load_driver()) return FALSE
;
234 /* Initialize system colors and metrics */
238 /* Setup palette function pointers */
241 /* Initialize window procedures */
242 if (!WINPROC_Init()) return FALSE
;
244 /* Initialize built-in window classes */
247 /* Initialize dialog manager */
248 if (!DIALOG_Init()) return FALSE
;
250 /* Initialize menus */
251 if (!MENU_Init()) return FALSE
;
253 /* Initialize message spying */
254 if (!SPY_Init()) return FALSE
;
256 /* Create message queue of initial thread */
257 InitThreadInput16( 0, 0 );
259 /* Create desktop window */
260 if (!WIN_CreateDesktopWindow()) return FALSE
;
262 /* Initialize keyboard driver */
263 if (USER_Driver
.pInitKeyboard
) USER_Driver
.pInitKeyboard( InputKeyStateTable
);
265 /* Initialize mouse driver */
266 if (USER_Driver
.pInitMouse
) USER_Driver
.pInitMouse( InputKeyStateTable
);
268 /* Initialize 16-bit serial communications */
275 /**********************************************************************
276 * USER_IsExitingThread
278 BOOL
USER_IsExitingThread( DWORD tid
)
280 return (tid
== exiting_thread_id
);
284 /**********************************************************************
287 static void thread_detach(void)
289 exiting_thread_id
= GetCurrentThreadId();
291 WDML_NotifyThreadDetach();
293 TIMER_RemoveThreadTimers();
294 WIN_DestroyThreadWindows( GetDesktopWindow() );
295 QUEUE_DeleteMsgQueue();
297 exiting_thread_id
= 0;
301 /***********************************************************************
302 * UserClientDllInitialize (USER32.@)
304 * USER dll initialisation routine
306 BOOL WINAPI
UserClientDllInitialize( HINSTANCE inst
, DWORD reason
, LPVOID reserved
)
311 case DLL_PROCESS_ATTACH
:
312 ret
= process_attach();
314 case DLL_THREAD_DETACH
: