Preload keyboard.drv when Windows version is Win9x.
[wine/multimedia.git] / dlls / user / user_main.c
blob1aa1d99b7af748f47e80c38ad0ef027d1b6296b0
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <stdarg.h>
22 #include <string.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wingdi.h"
26 #include "winuser.h"
27 #include "winreg.h"
28 #include "wine/winbase16.h"
29 #include "wine/winuser16.h"
31 #include "controls.h"
32 #include "cursoricon.h"
33 #include "message.h"
34 #include "user.h"
35 #include "win.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(graphics);
40 USER_DRIVER USER_Driver;
42 WORD USER_HeapSel = 0; /* USER heap selector */
43 HMODULE user32_module = 0;
45 extern HPALETTE (WINAPI *pfnGDISelectPalette)(HDC hdc, HPALETTE hpal, WORD bkgnd );
46 extern UINT (WINAPI *pfnGDIRealizePalette)(HDC hdc);
48 static HMODULE graphics_driver;
49 static DWORD exiting_thread_id;
51 extern void WDML_NotifyThreadDetach(void);
53 #define GET_USER_FUNC(name) USER_Driver.p##name = (void*)GetProcAddress( graphics_driver, #name )
55 /* load the graphics driver */
56 static BOOL load_driver(void)
58 char buffer[MAX_PATH];
59 HKEY hkey;
60 DWORD type, count;
62 strcpy( buffer, "x11drv" ); /* default value */
63 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Wine", &hkey ))
65 count = sizeof(buffer);
66 RegQueryValueExA( hkey, "GraphicsDriver", 0, &type, buffer, &count );
67 RegCloseKey( hkey );
70 if (!(graphics_driver = LoadLibraryA( buffer )))
72 MESSAGE( "Could not load graphics driver '%s'\n", buffer );
73 return FALSE;
76 GET_USER_FUNC(InitKeyboard);
77 GET_USER_FUNC(VkKeyScanEx);
78 GET_USER_FUNC(MapVirtualKeyEx);
79 GET_USER_FUNC(GetKeyNameText);
80 GET_USER_FUNC(ToUnicodeEx);
81 GET_USER_FUNC(GetKeyboardLayoutList);
82 GET_USER_FUNC(GetKeyboardLayout);
83 GET_USER_FUNC(GetKeyboardLayoutName);
84 GET_USER_FUNC(LoadKeyboardLayout);
85 GET_USER_FUNC(ActivateKeyboardLayout);
86 GET_USER_FUNC(UnloadKeyboardLayout);
87 GET_USER_FUNC(Beep);
88 GET_USER_FUNC(InitMouse);
89 GET_USER_FUNC(SetCursor);
90 GET_USER_FUNC(GetCursorPos);
91 GET_USER_FUNC(SetCursorPos);
92 GET_USER_FUNC(GetScreenSaveActive);
93 GET_USER_FUNC(SetScreenSaveActive);
94 GET_USER_FUNC(AcquireClipboard);
95 GET_USER_FUNC(EmptyClipboard);
96 GET_USER_FUNC(SetClipboardData);
97 GET_USER_FUNC(GetClipboardData);
98 GET_USER_FUNC(CountClipboardFormats);
99 GET_USER_FUNC(EnumClipboardFormats);
100 GET_USER_FUNC(IsClipboardFormatAvailable);
101 GET_USER_FUNC(RegisterClipboardFormat);
102 GET_USER_FUNC(GetClipboardFormatName);
103 GET_USER_FUNC(EndClipboardUpdate);
104 GET_USER_FUNC(ResetSelectionOwner);
105 GET_USER_FUNC(ChangeDisplaySettingsExW);
106 GET_USER_FUNC(EnumDisplaySettingsExW);
107 GET_USER_FUNC(CreateWindow);
108 GET_USER_FUNC(DestroyWindow);
109 GET_USER_FUNC(GetDC);
110 GET_USER_FUNC(ForceWindowRaise);
111 GET_USER_FUNC(MsgWaitForMultipleObjectsEx);
112 GET_USER_FUNC(ReleaseDC);
113 GET_USER_FUNC(ScrollWindowEx);
114 GET_USER_FUNC(SetFocus);
115 GET_USER_FUNC(SetParent);
116 GET_USER_FUNC(SetWindowPos);
117 GET_USER_FUNC(SetWindowRgn);
118 GET_USER_FUNC(SetWindowIcon);
119 GET_USER_FUNC(SetWindowStyle);
120 GET_USER_FUNC(SetWindowText);
121 GET_USER_FUNC(ShowWindow);
122 GET_USER_FUNC(SysCommandSizeMove);
124 return TRUE;
128 /***********************************************************************
129 * palette_init
131 * Patch the function pointers in GDI for SelectPalette and RealizePalette
133 static void palette_init(void)
135 void **ptr;
136 HMODULE module = GetModuleHandleA( "gdi32" );
137 if (!module)
139 ERR( "cannot get GDI32 handle\n" );
140 return;
142 if ((ptr = (void**)GetProcAddress( module, "pfnSelectPalette" )))
143 pfnGDISelectPalette = InterlockedExchangePointer( ptr, SelectPalette );
144 else ERR( "cannot find pfnSelectPalette in GDI32\n" );
145 if ((ptr = (void**)GetProcAddress( module, "pfnRealizePalette" )))
146 pfnGDIRealizePalette = InterlockedExchangePointer( ptr, UserRealizePalette );
147 else ERR( "cannot find pfnRealizePalette in GDI32\n" );
151 /***********************************************************************
152 * USER initialisation routine
154 static BOOL process_attach(void)
156 HINSTANCE16 instance;
158 /* Create USER heap */
159 if ((instance = LoadLibrary16( "USER.EXE" )) >= 32) USER_HeapSel = instance | 7;
160 else
162 USER_HeapSel = GlobalAlloc16( GMEM_FIXED, 65536 );
163 LocalInit16( USER_HeapSel, 32, 65534 );
166 /* some Win9x dlls expect keyboard to be loaded */
167 if (GetVersion() & 0x80000000) LoadLibrary16( "keyboard.drv" );
169 /* Load the graphics driver */
170 if (!load_driver()) return FALSE;
172 /* Initialize system colors and metrics */
173 SYSMETRICS_Init();
174 SYSCOLOR_Init();
176 /* Setup palette function pointers */
177 palette_init();
179 /* Initialize built-in window classes */
180 CLASS_RegisterBuiltinClasses();
182 /* Initialize menus */
183 if (!MENU_Init()) return FALSE;
185 /* Initialize message spying */
186 if (!SPY_Init()) return FALSE;
188 /* Create message queue of initial thread */
189 InitThreadInput16( 0, 0 );
191 /* Create desktop window */
192 if (!WIN_CreateDesktopWindow()) return FALSE;
194 /* Initialize keyboard driver */
195 if (USER_Driver.pInitKeyboard) USER_Driver.pInitKeyboard( InputKeyStateTable );
197 /* Initialize mouse driver */
198 if (USER_Driver.pInitMouse) USER_Driver.pInitMouse( InputKeyStateTable );
200 return TRUE;
204 /**********************************************************************
205 * USER_IsExitingThread
207 BOOL USER_IsExitingThread( DWORD tid )
209 return (tid == exiting_thread_id);
213 /**********************************************************************
214 * thread_detach
216 static void thread_detach(void)
218 exiting_thread_id = GetCurrentThreadId();
220 WDML_NotifyThreadDetach();
222 TIMER_RemoveThreadTimers();
223 WIN_DestroyThreadWindows( GetDesktopWindow() );
224 QUEUE_DeleteMsgQueue();
226 exiting_thread_id = 0;
230 /***********************************************************************
231 * UserClientDllInitialize (USER32.@)
233 * USER dll initialisation routine (exported as UserClientDllInitialize for compatibility).
235 BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved )
237 BOOL ret = TRUE;
238 switch(reason)
240 case DLL_PROCESS_ATTACH:
241 user32_module = inst;
242 ret = process_attach();
243 break;
244 case DLL_THREAD_DETACH:
245 thread_detach();
246 break;
248 return ret;