Release 1.5.29.
[wine] / dlls / user32 / driver.c
1 /*
2  * USER driver support
3  *
4  * Copyright 2000, 2005 Alexandre Julliard
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <stdarg.h>
22 #include <stdio.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wingdi.h"
26 #include "winuser.h"
27 #include "wine/debug.h"
28 #include "wine/gdi_driver.h"
29
30 #include "user_private.h"
31
32 static USER_DRIVER null_driver, lazy_load_driver;
33
34 const USER_DRIVER *USER_Driver = &lazy_load_driver;
35 static DWORD driver_load_error;
36
37 /* load the graphics driver */
38 static const USER_DRIVER *load_driver(void)
39 {
40     static const WCHAR displayW[] = {'D','I','S','P','L','A','Y',0};
41     HDC hdc;
42     void *ptr;
43     HMODULE graphics_driver;
44     USER_DRIVER *driver, *prev;
45
46     driver = HeapAlloc( GetProcessHeap(), 0, sizeof(*driver) );
47     *driver = null_driver;
48
49     hdc = CreateDCW( displayW, NULL, NULL, NULL );
50
51     graphics_driver = __wine_get_driver_module( hdc );
52     if (graphics_driver)
53     {
54 #define GET_USER_FUNC(name) \
55     do { if ((ptr = GetProcAddress( graphics_driver, #name ))) driver->p##name = ptr; } while(0)
56
57         GET_USER_FUNC(ActivateKeyboardLayout);
58         GET_USER_FUNC(Beep);
59         GET_USER_FUNC(GetAsyncKeyState);
60         GET_USER_FUNC(GetKeyNameText);
61         GET_USER_FUNC(GetKeyboardLayout);
62         GET_USER_FUNC(GetKeyboardLayoutName);
63         GET_USER_FUNC(LoadKeyboardLayout);
64         GET_USER_FUNC(MapVirtualKeyEx);
65         GET_USER_FUNC(RegisterHotKey);
66         GET_USER_FUNC(ToUnicodeEx);
67         GET_USER_FUNC(UnloadKeyboardLayout);
68         GET_USER_FUNC(UnregisterHotKey);
69         GET_USER_FUNC(VkKeyScanEx);
70         GET_USER_FUNC(CreateCursorIcon);
71         GET_USER_FUNC(DestroyCursorIcon);
72         GET_USER_FUNC(SetCursor);
73         GET_USER_FUNC(GetCursorPos);
74         GET_USER_FUNC(SetCursorPos);
75         GET_USER_FUNC(ClipCursor);
76         GET_USER_FUNC(AcquireClipboard);
77         GET_USER_FUNC(EmptyClipboard);
78         GET_USER_FUNC(SetClipboardData);
79         GET_USER_FUNC(GetClipboardData);
80         GET_USER_FUNC(CountClipboardFormats);
81         GET_USER_FUNC(EnumClipboardFormats);
82         GET_USER_FUNC(IsClipboardFormatAvailable);
83         GET_USER_FUNC(EndClipboardUpdate);
84         GET_USER_FUNC(ChangeDisplaySettingsEx);
85         GET_USER_FUNC(EnumDisplayMonitors);
86         GET_USER_FUNC(EnumDisplaySettingsEx);
87         GET_USER_FUNC(GetMonitorInfo);
88         GET_USER_FUNC(CreateDesktopWindow);
89         GET_USER_FUNC(CreateWindow);
90         GET_USER_FUNC(DestroyWindow);
91         GET_USER_FUNC(GetDC);
92         GET_USER_FUNC(MsgWaitForMultipleObjectsEx);
93         GET_USER_FUNC(ReleaseDC);
94         GET_USER_FUNC(ScrollDC);
95         GET_USER_FUNC(SetCapture);
96         GET_USER_FUNC(SetFocus);
97         GET_USER_FUNC(SetLayeredWindowAttributes);
98         GET_USER_FUNC(SetParent);
99         GET_USER_FUNC(SetWindowRgn);
100         GET_USER_FUNC(SetWindowIcon);
101         GET_USER_FUNC(SetWindowStyle);
102         GET_USER_FUNC(SetWindowText);
103         GET_USER_FUNC(ShowWindow);
104         GET_USER_FUNC(SysCommand);
105         GET_USER_FUNC(UpdateLayeredWindow);
106         GET_USER_FUNC(WindowMessage);
107         GET_USER_FUNC(WindowPosChanging);
108         GET_USER_FUNC(WindowPosChanged);
109         GET_USER_FUNC(SystemParametersInfo);
110 #undef GET_USER_FUNC
111     }
112     else driver_load_error = GetLastError();
113
114     prev = InterlockedCompareExchangePointer( (void **)&USER_Driver, driver, &lazy_load_driver );
115     if (prev != &lazy_load_driver)
116     {
117         /* another thread beat us to it */
118         HeapFree( GetProcessHeap(), 0, driver );
119         driver = prev;
120     }
121     else LdrAddRefDll( 0, graphics_driver );
122
123     DeleteDC( hdc );
124     return driver;
125 }
126
127 /* unload the graphics driver on process exit */
128 void USER_unload_driver(void)
129 {
130     USER_DRIVER *prev;
131     /* make sure we don't try to call the driver after it has been detached */
132     prev = InterlockedExchangePointer( (void **)&USER_Driver, &null_driver );
133     if (prev != &lazy_load_driver && prev != &null_driver)
134         HeapFree( GetProcessHeap(), 0, prev );
135 }
136
137
138 /**********************************************************************
139  * Null user driver
140  *
141  * These are fallbacks for entry points that are not implemented in the real driver.
142  */
143
144 static HKL CDECL nulldrv_ActivateKeyboardLayout( HKL layout, UINT flags )
145 {
146     return 0;
147 }
148
149 static void CDECL nulldrv_Beep(void)
150 {
151 }
152
153 static SHORT CDECL nulldrv_GetAsyncKeyState( INT key )
154 {
155     return -1;
156 }
157
158 static INT CDECL nulldrv_GetKeyNameText( LONG lparam, LPWSTR buffer, INT size )
159 {
160     return 0;
161 }
162
163 static HKL CDECL nulldrv_GetKeyboardLayout( DWORD thread_id )
164 {
165     return 0;
166 }
167
168 static BOOL CDECL nulldrv_GetKeyboardLayoutName( LPWSTR name )
169 {
170     return FALSE;
171 }
172
173 static HKL CDECL nulldrv_LoadKeyboardLayout( LPCWSTR name, UINT flags )
174 {
175     return 0;
176 }
177
178 static UINT CDECL nulldrv_MapVirtualKeyEx( UINT code, UINT type, HKL layout )
179 {
180     return 0;
181 }
182
183 static BOOL CDECL nulldrv_RegisterHotKey( HWND hwnd, UINT modifiers, UINT vk )
184 {
185     return TRUE;
186 }
187
188 static INT CDECL nulldrv_ToUnicodeEx( UINT virt, UINT scan, const BYTE *state, LPWSTR str,
189                                       int size, UINT flags, HKL layout )
190 {
191     return 0;
192 }
193
194 static BOOL CDECL nulldrv_UnloadKeyboardLayout( HKL layout )
195 {
196     return 0;
197 }
198
199 static void CDECL nulldrv_UnregisterHotKey( HWND hwnd, UINT modifiers, UINT vk )
200 {
201 }
202
203 static SHORT CDECL nulldrv_VkKeyScanEx( WCHAR ch, HKL layout )
204 {
205     return -1;
206 }
207
208 static void CDECL nulldrv_CreateCursorIcon( HCURSOR cursor )
209 {
210 }
211
212 static void CDECL nulldrv_DestroyCursorIcon( HCURSOR cursor )
213 {
214 }
215
216 static void CDECL nulldrv_SetCursor( HCURSOR cursor )
217 {
218 }
219
220 static BOOL CDECL nulldrv_GetCursorPos( LPPOINT pt )
221 {
222     return FALSE;
223 }
224
225 static BOOL CDECL nulldrv_SetCursorPos( INT x, INT y )
226 {
227     return FALSE;
228 }
229
230 static BOOL CDECL nulldrv_ClipCursor( LPCRECT clip )
231 {
232     return FALSE;
233 }
234
235 static INT CDECL nulldrv_AcquireClipboard( HWND hwnd )
236 {
237     return 0;
238 }
239
240 static BOOL CDECL nulldrv_CountClipboardFormats(void)
241 {
242     return 0;
243 }
244
245 static void CDECL nulldrv_EmptyClipboard( BOOL keepunowned )
246 {
247 }
248
249 static void CDECL nulldrv_EndClipboardUpdate(void)
250 {
251 }
252
253 static UINT CDECL nulldrv_EnumClipboardFormats( UINT format )
254 {
255     return 0;
256 }
257
258 static HANDLE CDECL nulldrv_GetClipboardData( UINT format )
259 {
260     return 0;
261 }
262
263 static BOOL CDECL nulldrv_IsClipboardFormatAvailable( UINT format )
264 {
265     return FALSE;
266 }
267
268 static BOOL CDECL nulldrv_SetClipboardData( UINT format, HANDLE handle, BOOL owner )
269 {
270     return FALSE;
271 }
272
273 static LONG CDECL nulldrv_ChangeDisplaySettingsEx( LPCWSTR name, LPDEVMODEW mode, HWND hwnd,
274                                              DWORD flags, LPVOID lparam )
275 {
276     return DISP_CHANGE_FAILED;
277 }
278
279 static BOOL CDECL nulldrv_EnumDisplayMonitors( HDC hdc, LPRECT rect, MONITORENUMPROC proc, LPARAM lp )
280 {
281     return FALSE;
282 }
283
284 static BOOL CDECL nulldrv_EnumDisplaySettingsEx( LPCWSTR name, DWORD num, LPDEVMODEW mode, DWORD flags )
285 {
286     return FALSE;
287 }
288
289 static BOOL CDECL nulldrv_GetMonitorInfo( HMONITOR handle, LPMONITORINFO info )
290 {
291     return FALSE;
292 }
293
294 static BOOL CDECL nulldrv_CreateDesktopWindow( HWND hwnd )
295 {
296     return TRUE;
297 }
298
299 static BOOL CDECL nulldrv_CreateWindow( HWND hwnd )
300 {
301     static int warned;
302     HWND parent = GetAncestor( hwnd, GA_PARENT );
303
304     /* HWND_MESSAGE windows don't need a graphics driver */
305     if (!parent || parent == get_user_thread_info()->msg_window) return TRUE;
306     if (warned++) return FALSE;
307
308     MESSAGE( "Application tried to create a window, but no driver could be loaded.\n");
309     switch (driver_load_error)
310     {
311     case ERROR_MOD_NOT_FOUND:
312         MESSAGE( "The graphics driver is missing. Check your build!\n" );
313         break;
314     case ERROR_DLL_INIT_FAILED:
315         MESSAGE( "Make sure that your X server is running and that $DISPLAY is set correctly.\n" );
316         break;
317     default:
318         MESSAGE( "Unknown error (%d).\n", driver_load_error );
319     }
320
321     return FALSE;
322 }
323
324 static void CDECL nulldrv_DestroyWindow( HWND hwnd )
325 {
326 }
327
328 static void CDECL nulldrv_GetDC( HDC hdc, HWND hwnd, HWND top_win, const RECT *win_rect,
329                                  const RECT *top_rect, DWORD flags )
330 {
331 }
332
333 static DWORD CDECL nulldrv_MsgWaitForMultipleObjectsEx( DWORD count, const HANDLE *handles, DWORD timeout,
334                                                         DWORD mask, DWORD flags )
335 {
336     return WaitForMultipleObjectsEx( count, handles, flags & MWMO_WAITALL,
337                                      timeout, flags & MWMO_ALERTABLE );
338 }
339
340 static void CDECL nulldrv_ReleaseDC( HWND hwnd, HDC hdc )
341 {
342 }
343
344 static BOOL CDECL nulldrv_ScrollDC( HDC hdc, INT dx, INT dy, HRGN update )
345 {
346     RECT rect;
347
348     GetClipBox( hdc, &rect );
349     return BitBlt( hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
350                    hdc, rect.left - dx, rect.top - dy, SRCCOPY );
351 }
352
353 static void CDECL nulldrv_SetCapture( HWND hwnd, UINT flags )
354 {
355 }
356
357 static void CDECL nulldrv_SetFocus( HWND hwnd )
358 {
359 }
360
361 static void CDECL nulldrv_SetLayeredWindowAttributes( HWND hwnd, COLORREF key, BYTE alpha, DWORD flags )
362 {
363 }
364
365 static void CDECL nulldrv_SetParent( HWND hwnd, HWND parent, HWND old_parent )
366 {
367 }
368
369 static int CDECL nulldrv_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw )
370 {
371     return 1;
372 }
373
374 static void CDECL nulldrv_SetWindowIcon( HWND hwnd, UINT type, HICON icon )
375 {
376 }
377
378 static void CDECL nulldrv_SetWindowStyle( HWND hwnd, INT offset, STYLESTRUCT *style )
379 {
380 }
381
382 static void CDECL nulldrv_SetWindowText( HWND hwnd, LPCWSTR text )
383 {
384 }
385
386 static UINT CDECL nulldrv_ShowWindow( HWND hwnd, INT cmd, RECT *rect, UINT swp )
387 {
388     return swp;
389 }
390
391 static LRESULT CDECL nulldrv_SysCommand( HWND hwnd, WPARAM wparam, LPARAM lparam )
392 {
393     return -1;
394 }
395
396 static BOOL CDECL nulldrv_UpdateLayeredWindow( HWND hwnd, const UPDATELAYEREDWINDOWINFO *info,
397                                                const RECT *window_rect )
398 {
399     return TRUE;
400 }
401
402 static LRESULT CDECL nulldrv_WindowMessage( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
403 {
404     return 0;
405 }
406
407 static void CDECL nulldrv_WindowPosChanging( HWND hwnd, HWND insert_after, UINT swp_flags,
408                                              const RECT *window_rect, const RECT *client_rect,
409                                              RECT *visible_rect, struct window_surface **surface )
410 {
411 }
412
413 static void CDECL nulldrv_WindowPosChanged( HWND hwnd, HWND insert_after, UINT swp_flags,
414                                             const RECT *window_rect, const RECT *client_rect,
415                                             const RECT *visible_rect, const RECT *valid_rects,
416                                             struct window_surface *surface )
417 {
418 }
419
420 static BOOL CDECL nulldrv_SystemParametersInfo( UINT action, UINT int_param, void *ptr_param, UINT flags )
421 {
422     return FALSE;
423 }
424
425 static USER_DRIVER null_driver =
426 {
427     /* keyboard functions */
428     nulldrv_ActivateKeyboardLayout,
429     nulldrv_Beep,
430     nulldrv_GetAsyncKeyState,
431     nulldrv_GetKeyNameText,
432     nulldrv_GetKeyboardLayout,
433     nulldrv_GetKeyboardLayoutName,
434     nulldrv_LoadKeyboardLayout,
435     nulldrv_MapVirtualKeyEx,
436     nulldrv_RegisterHotKey,
437     nulldrv_ToUnicodeEx,
438     nulldrv_UnloadKeyboardLayout,
439     nulldrv_UnregisterHotKey,
440     nulldrv_VkKeyScanEx,
441     /* cursor/icon functions */
442     nulldrv_CreateCursorIcon,
443     nulldrv_DestroyCursorIcon,
444     nulldrv_SetCursor,
445     nulldrv_GetCursorPos,
446     nulldrv_SetCursorPos,
447     nulldrv_ClipCursor,
448     /* clipboard functions */
449     nulldrv_AcquireClipboard,
450     nulldrv_CountClipboardFormats,
451     nulldrv_EmptyClipboard,
452     nulldrv_EndClipboardUpdate,
453     nulldrv_EnumClipboardFormats,
454     nulldrv_GetClipboardData,
455     nulldrv_IsClipboardFormatAvailable,
456     nulldrv_SetClipboardData,
457     /* display modes */
458     nulldrv_ChangeDisplaySettingsEx,
459     nulldrv_EnumDisplayMonitors,
460     nulldrv_EnumDisplaySettingsEx,
461     nulldrv_GetMonitorInfo,
462     /* windowing functions */
463     nulldrv_CreateDesktopWindow,
464     nulldrv_CreateWindow,
465     nulldrv_DestroyWindow,
466     nulldrv_GetDC,
467     nulldrv_MsgWaitForMultipleObjectsEx,
468     nulldrv_ReleaseDC,
469     nulldrv_ScrollDC,
470     nulldrv_SetCapture,
471     nulldrv_SetFocus,
472     nulldrv_SetLayeredWindowAttributes,
473     nulldrv_SetParent,
474     nulldrv_SetWindowRgn,
475     nulldrv_SetWindowIcon,
476     nulldrv_SetWindowStyle,
477     nulldrv_SetWindowText,
478     nulldrv_ShowWindow,
479     nulldrv_SysCommand,
480     nulldrv_UpdateLayeredWindow,
481     nulldrv_WindowMessage,
482     nulldrv_WindowPosChanging,
483     nulldrv_WindowPosChanged,
484     /* system parameters */
485     nulldrv_SystemParametersInfo
486 };
487
488
489 /**********************************************************************
490  * Lazy loading user driver
491  *
492  * Initial driver used before another driver is loaded.
493  * Each entry point simply loads the real driver and chains to it.
494  */
495
496 static HKL CDECL loaderdrv_ActivateKeyboardLayout( HKL layout, UINT flags )
497 {
498     return load_driver()->pActivateKeyboardLayout( layout, flags );
499 }
500
501 static void CDECL loaderdrv_Beep(void)
502 {
503     load_driver()->pBeep();
504 }
505
506 static SHORT CDECL loaderdrv_GetAsyncKeyState( INT key )
507 {
508     return load_driver()->pGetAsyncKeyState( key );
509 }
510
511 static INT CDECL loaderdrv_GetKeyNameText( LONG lparam, LPWSTR buffer, INT size )
512 {
513     return load_driver()->pGetKeyNameText( lparam, buffer, size );
514 }
515
516 static HKL CDECL loaderdrv_GetKeyboardLayout( DWORD thread_id )
517 {
518     return load_driver()->pGetKeyboardLayout( thread_id );
519 }
520
521 static BOOL CDECL loaderdrv_GetKeyboardLayoutName( LPWSTR name )
522 {
523     return load_driver()->pGetKeyboardLayoutName( name );
524 }
525
526 static HKL CDECL loaderdrv_LoadKeyboardLayout( LPCWSTR name, UINT flags )
527 {
528     return load_driver()->pLoadKeyboardLayout( name, flags );
529 }
530
531 static UINT CDECL loaderdrv_MapVirtualKeyEx( UINT code, UINT type, HKL layout )
532 {
533     return load_driver()->pMapVirtualKeyEx( code, type, layout );
534 }
535
536 static BOOL CDECL loaderdrv_RegisterHotKey( HWND hwnd, UINT modifiers, UINT vk )
537 {
538     return load_driver()->pRegisterHotKey( hwnd, modifiers, vk );
539 }
540
541 static INT CDECL loaderdrv_ToUnicodeEx( UINT virt, UINT scan, const BYTE *state, LPWSTR str,
542                                   int size, UINT flags, HKL layout )
543 {
544     return load_driver()->pToUnicodeEx( virt, scan, state, str, size, flags, layout );
545 }
546
547 static BOOL CDECL loaderdrv_UnloadKeyboardLayout( HKL layout )
548 {
549     return load_driver()->pUnloadKeyboardLayout( layout );
550 }
551
552 static void CDECL loaderdrv_UnregisterHotKey( HWND hwnd, UINT modifiers, UINT vk )
553 {
554     load_driver()->pUnregisterHotKey( hwnd, modifiers, vk );
555 }
556
557 static SHORT CDECL loaderdrv_VkKeyScanEx( WCHAR ch, HKL layout )
558 {
559     return load_driver()->pVkKeyScanEx( ch, layout );
560 }
561
562 static void CDECL loaderdrv_CreateCursorIcon( HCURSOR cursor )
563 {
564     load_driver()->pCreateCursorIcon( cursor );
565 }
566
567 static void CDECL loaderdrv_DestroyCursorIcon( HCURSOR cursor )
568 {
569     load_driver()->pDestroyCursorIcon( cursor );
570 }
571
572 static void CDECL loaderdrv_SetCursor( HCURSOR cursor )
573 {
574     load_driver()->pSetCursor( cursor );
575 }
576
577 static BOOL CDECL loaderdrv_GetCursorPos( LPPOINT pt )
578 {
579     return load_driver()->pGetCursorPos( pt );
580 }
581
582 static BOOL CDECL loaderdrv_SetCursorPos( INT x, INT y )
583 {
584     return load_driver()->pSetCursorPos( x, y );
585 }
586
587 static BOOL CDECL loaderdrv_ClipCursor( LPCRECT clip )
588 {
589     return load_driver()->pClipCursor( clip );
590 }
591
592 static INT CDECL loaderdrv_AcquireClipboard( HWND hwnd )
593 {
594     return load_driver()->pAcquireClipboard( hwnd );
595 }
596
597 static BOOL CDECL loaderdrv_CountClipboardFormats(void)
598 {
599     return load_driver()->pCountClipboardFormats();
600 }
601
602 static void CDECL loaderdrv_EmptyClipboard( BOOL keepunowned )
603 {
604     load_driver()->pEmptyClipboard( keepunowned );
605 }
606
607 static void CDECL loaderdrv_EndClipboardUpdate(void)
608 {
609     load_driver()->pEndClipboardUpdate();
610 }
611
612 static UINT CDECL loaderdrv_EnumClipboardFormats( UINT format )
613 {
614     return load_driver()->pEnumClipboardFormats( format );
615 }
616
617 static HANDLE CDECL loaderdrv_GetClipboardData( UINT format )
618 {
619     return load_driver()->pGetClipboardData( format );
620 }
621
622 static BOOL CDECL loaderdrv_IsClipboardFormatAvailable( UINT format )
623 {
624     return load_driver()->pIsClipboardFormatAvailable( format );
625 }
626
627 static BOOL CDECL loaderdrv_SetClipboardData( UINT format, HANDLE handle, BOOL owner )
628 {
629     return load_driver()->pSetClipboardData( format, handle, owner );
630 }
631
632 static LONG CDECL loaderdrv_ChangeDisplaySettingsEx( LPCWSTR name, LPDEVMODEW mode, HWND hwnd,
633                                                      DWORD flags, LPVOID lparam )
634 {
635     return load_driver()->pChangeDisplaySettingsEx( name, mode, hwnd, flags, lparam );
636 }
637
638 static BOOL CDECL loaderdrv_EnumDisplayMonitors( HDC hdc, LPRECT rect, MONITORENUMPROC proc, LPARAM lp )
639 {
640     return load_driver()->pEnumDisplayMonitors( hdc, rect, proc, lp );
641 }
642
643 static BOOL CDECL loaderdrv_EnumDisplaySettingsEx( LPCWSTR name, DWORD num, LPDEVMODEW mode, DWORD flags )
644 {
645     return load_driver()->pEnumDisplaySettingsEx( name, num, mode, flags );
646 }
647
648 static BOOL CDECL loaderdrv_GetMonitorInfo( HMONITOR handle, LPMONITORINFO info )
649 {
650     return load_driver()->pGetMonitorInfo( handle, info );
651 }
652
653 static BOOL CDECL loaderdrv_CreateDesktopWindow( HWND hwnd )
654 {
655     return load_driver()->pCreateDesktopWindow( hwnd );
656 }
657
658 static BOOL CDECL loaderdrv_CreateWindow( HWND hwnd )
659 {
660     return load_driver()->pCreateWindow( hwnd );
661 }
662
663 static void CDECL loaderdrv_DestroyWindow( HWND hwnd )
664 {
665     load_driver()->pDestroyWindow( hwnd );
666 }
667
668 static void CDECL loaderdrv_GetDC( HDC hdc, HWND hwnd, HWND top_win, const RECT *win_rect,
669                                    const RECT *top_rect, DWORD flags )
670 {
671     load_driver()->pGetDC( hdc, hwnd, top_win, win_rect, top_rect, flags );
672 }
673
674 static DWORD CDECL loaderdrv_MsgWaitForMultipleObjectsEx( DWORD count, const HANDLE *handles, DWORD timeout,
675                                                           DWORD mask, DWORD flags )
676 {
677     return load_driver()->pMsgWaitForMultipleObjectsEx( count, handles, timeout, mask, flags );
678 }
679
680 static void CDECL loaderdrv_ReleaseDC( HWND hwnd, HDC hdc )
681 {
682     load_driver()->pReleaseDC( hwnd, hdc );
683 }
684
685 static BOOL CDECL loaderdrv_ScrollDC( HDC hdc, INT dx, INT dy, HRGN update )
686 {
687     return load_driver()->pScrollDC( hdc, dx, dy, update );
688 }
689
690 static void CDECL loaderdrv_SetCapture( HWND hwnd, UINT flags )
691 {
692     load_driver()->pSetCapture( hwnd, flags );
693 }
694
695 static void CDECL loaderdrv_SetFocus( HWND hwnd )
696 {
697     load_driver()->pSetFocus( hwnd );
698 }
699
700 static void CDECL loaderdrv_SetLayeredWindowAttributes( HWND hwnd, COLORREF key, BYTE alpha, DWORD flags )
701 {
702     load_driver()->pSetLayeredWindowAttributes( hwnd, key, alpha, flags );
703 }
704
705 static void CDECL loaderdrv_SetParent( HWND hwnd, HWND parent, HWND old_parent )
706 {
707     load_driver()->pSetParent( hwnd, parent, old_parent );
708 }
709
710 static int CDECL loaderdrv_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw )
711 {
712     return load_driver()->pSetWindowRgn( hwnd, hrgn, redraw );
713 }
714
715 static void CDECL loaderdrv_SetWindowIcon( HWND hwnd, UINT type, HICON icon )
716 {
717     load_driver()->pSetWindowIcon( hwnd, type, icon );
718 }
719
720 static void CDECL loaderdrv_SetWindowStyle( HWND hwnd, INT offset, STYLESTRUCT *style )
721 {
722     load_driver()->pSetWindowStyle( hwnd, offset, style );
723 }
724
725 static void CDECL loaderdrv_SetWindowText( HWND hwnd, LPCWSTR text )
726 {
727     load_driver()->pSetWindowText( hwnd, text );
728 }
729
730 static UINT CDECL loaderdrv_ShowWindow( HWND hwnd, INT cmd, RECT *rect, UINT swp )
731 {
732     return load_driver()->pShowWindow( hwnd, cmd, rect, swp );
733 }
734
735 static LRESULT CDECL loaderdrv_SysCommand( HWND hwnd, WPARAM wparam, LPARAM lparam )
736 {
737     return load_driver()->pSysCommand( hwnd, wparam, lparam );
738 }
739
740 static BOOL CDECL loaderdrv_UpdateLayeredWindow( HWND hwnd, const UPDATELAYEREDWINDOWINFO *info,
741                                                  const RECT *window_rect )
742 {
743     return load_driver()->pUpdateLayeredWindow( hwnd, info, window_rect );
744 }
745
746 static LRESULT CDECL loaderdrv_WindowMessage( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
747 {
748     return load_driver()->pWindowMessage( hwnd, msg, wparam, lparam );
749 }
750
751 static void CDECL loaderdrv_WindowPosChanging( HWND hwnd, HWND insert_after, UINT swp_flags,
752                                                const RECT *window_rect, const RECT *client_rect,
753                                                RECT *visible_rect, struct window_surface **surface )
754 {
755     load_driver()->pWindowPosChanging( hwnd, insert_after, swp_flags,
756                                        window_rect, client_rect, visible_rect, surface );
757 }
758
759 static void CDECL loaderdrv_WindowPosChanged( HWND hwnd, HWND insert_after, UINT swp_flags,
760                                               const RECT *window_rect, const RECT *client_rect,
761                                               const RECT *visible_rect, const RECT *valid_rects,
762                                               struct window_surface *surface )
763 {
764     load_driver()->pWindowPosChanged( hwnd, insert_after, swp_flags, window_rect,
765                                       client_rect, visible_rect, valid_rects, surface );
766 }
767
768 static BOOL CDECL loaderdrv_SystemParametersInfo( UINT action, UINT int_param, void *ptr_param, UINT flags )
769 {
770     return FALSE;  /* don't trigger a driver load */
771 }
772
773 static USER_DRIVER lazy_load_driver =
774 {
775     /* keyboard functions */
776     loaderdrv_ActivateKeyboardLayout,
777     loaderdrv_Beep,
778     loaderdrv_GetAsyncKeyState,
779     loaderdrv_GetKeyNameText,
780     loaderdrv_GetKeyboardLayout,
781     loaderdrv_GetKeyboardLayoutName,
782     loaderdrv_LoadKeyboardLayout,
783     loaderdrv_MapVirtualKeyEx,
784     loaderdrv_RegisterHotKey,
785     loaderdrv_ToUnicodeEx,
786     loaderdrv_UnloadKeyboardLayout,
787     loaderdrv_UnregisterHotKey,
788     loaderdrv_VkKeyScanEx,
789     /* cursor/icon functions */
790     loaderdrv_CreateCursorIcon,
791     loaderdrv_DestroyCursorIcon,
792     loaderdrv_SetCursor,
793     loaderdrv_GetCursorPos,
794     loaderdrv_SetCursorPos,
795     loaderdrv_ClipCursor,
796     /* clipboard functions */
797     loaderdrv_AcquireClipboard,
798     loaderdrv_CountClipboardFormats,
799     loaderdrv_EmptyClipboard,
800     loaderdrv_EndClipboardUpdate,
801     loaderdrv_EnumClipboardFormats,
802     loaderdrv_GetClipboardData,
803     loaderdrv_IsClipboardFormatAvailable,
804     loaderdrv_SetClipboardData,
805     /* display modes */
806     loaderdrv_ChangeDisplaySettingsEx,
807     loaderdrv_EnumDisplayMonitors,
808     loaderdrv_EnumDisplaySettingsEx,
809     loaderdrv_GetMonitorInfo,
810     /* windowing functions */
811     loaderdrv_CreateDesktopWindow,
812     loaderdrv_CreateWindow,
813     loaderdrv_DestroyWindow,
814     loaderdrv_GetDC,
815     loaderdrv_MsgWaitForMultipleObjectsEx,
816     loaderdrv_ReleaseDC,
817     loaderdrv_ScrollDC,
818     loaderdrv_SetCapture,
819     loaderdrv_SetFocus,
820     loaderdrv_SetLayeredWindowAttributes,
821     loaderdrv_SetParent,
822     loaderdrv_SetWindowRgn,
823     loaderdrv_SetWindowIcon,
824     loaderdrv_SetWindowStyle,
825     loaderdrv_SetWindowText,
826     loaderdrv_ShowWindow,
827     loaderdrv_SysCommand,
828     loaderdrv_UpdateLayeredWindow,
829     loaderdrv_WindowMessage,
830     loaderdrv_WindowPosChanging,
831     loaderdrv_WindowPosChanged,
832     /* system parameters */
833     loaderdrv_SystemParametersInfo
834 };