secur32/tests: Use importlib for functions available since Windows XP.
[wine.git] / dlls / wintab32 / wintab32.c
blob30379639ae28be562d7d51c4f651ff054e10310f
1 /*
2 * WinTab32 library
4 * Copyright 2003 CodeWeavers, Aric Stewart
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 <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winreg.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28 #include "winerror.h"
29 #define NOFIX32
30 #include "wintab.h"
31 #include "wintab_internal.h"
32 #include "wine/unicode.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(wintab32);
37 HWND hwndDefault = NULL;
38 static const WCHAR
39 WC_TABLETCLASSNAME[] = {'W','i','n','e','T','a','b','l','e','t','C','l','a','s','s',0};
40 static CRITICAL_SECTION_DEBUG csTablet_debug =
42 0, 0, &csTablet,
43 { &csTablet_debug.ProcessLocksList, &csTablet_debug.ProcessLocksList },
44 0, 0, { (DWORD_PTR)(__FILE__ ": csTablet") }
46 CRITICAL_SECTION csTablet = { &csTablet_debug, -1, 0, 0, 0, 0 };
48 int (CDECL *pLoadTabletInfo)(HWND hwnddefault) = NULL;
49 int (CDECL *pGetCurrentPacket)(LPWTPACKET packet) = NULL;
50 int (CDECL *pAttachEventQueueToTablet)(HWND hOwner) = NULL;
51 UINT (CDECL *pWTInfoW)(UINT wCategory, UINT nIndex, LPVOID lpOutput) = NULL;
53 static LRESULT WINAPI TABLET_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
54 LPARAM lParam);
56 static VOID TABLET_Register(void)
58 WNDCLASSW wndClass;
59 ZeroMemory(&wndClass, sizeof(WNDCLASSW));
60 wndClass.style = CS_GLOBALCLASS;
61 wndClass.lpfnWndProc = TABLET_WindowProc;
62 wndClass.cbClsExtra = 0;
63 wndClass.cbWndExtra = 0;
64 wndClass.hCursor = NULL;
65 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW +1);
66 wndClass.lpszClassName = WC_TABLETCLASSNAME;
67 RegisterClassW(&wndClass);
70 static VOID TABLET_Unregister(void)
72 UnregisterClassW(WC_TABLETCLASSNAME, NULL);
75 static HMODULE load_graphics_driver(void)
77 static const WCHAR display_device_guid_propW[] = {
78 '_','_','w','i','n','e','_','d','i','s','p','l','a','y','_',
79 'd','e','v','i','c','e','_','g','u','i','d',0 };
80 static const WCHAR key_pathW[] = {
81 'S','y','s','t','e','m','\\',
82 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
83 'C','o','n','t','r','o','l','\\',
84 'V','i','d','e','o','\\','{',0};
85 static const WCHAR displayW[] = {'}','\\','0','0','0','0',0};
86 static const WCHAR driverW[] = {'G','r','a','p','h','i','c','s','D','r','i','v','e','r',0};
88 HMODULE ret = 0;
89 HKEY hkey;
90 DWORD size;
91 WCHAR path[MAX_PATH];
92 WCHAR key[(sizeof(key_pathW) + sizeof(displayW)) / sizeof(WCHAR) + 40];
93 UINT guid_atom = HandleToULong( GetPropW( GetDesktopWindow(), display_device_guid_propW ));
95 if (!guid_atom) return 0;
96 memcpy( key, key_pathW, sizeof(key_pathW) );
97 if (!GlobalGetAtomNameW( guid_atom, key + strlenW(key), 40 )) return 0;
98 strcatW( key, displayW );
99 if (RegOpenKeyW( HKEY_LOCAL_MACHINE, key, &hkey )) return 0;
100 size = sizeof(path);
101 if (!RegQueryValueExW( hkey, driverW, NULL, NULL, (BYTE *)path, &size )) ret = LoadLibraryW( path );
102 RegCloseKey( hkey );
103 TRACE( "%s %p\n", debugstr_w(path), ret );
104 return ret;
107 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpReserved)
109 static const WCHAR name[] = {'T','a','b','l','e','t',0};
111 TRACE("%p, %x, %p\n",hInstDLL,fdwReason,lpReserved);
112 switch (fdwReason)
114 case DLL_PROCESS_ATTACH:
115 TRACE("Initialization\n");
116 DisableThreadLibraryCalls(hInstDLL);
117 TABLET_Register();
118 hwndDefault = CreateWindowW(WC_TABLETCLASSNAME, name,
119 WS_POPUPWINDOW,0,0,0,0,0,0,hInstDLL,0);
120 if (hwndDefault)
122 HMODULE module = load_graphics_driver();
123 pLoadTabletInfo = (void *)GetProcAddress(module, "LoadTabletInfo");
124 pAttachEventQueueToTablet = (void *)GetProcAddress(module, "AttachEventQueueToTablet");
125 pGetCurrentPacket = (void *)GetProcAddress(module, "GetCurrentPacket");
126 pWTInfoW = (void *)GetProcAddress(module, "WTInfoW");
128 else
129 return FALSE;
130 break;
131 case DLL_PROCESS_DETACH:
132 if (lpReserved) break;
133 TRACE("Detaching\n");
134 if (hwndDefault) DestroyWindow(hwndDefault);
135 TABLET_Unregister();
136 DeleteCriticalSection(&csTablet);
137 break;
139 return TRUE;
144 * The window proc for the default TABLET window
146 static LRESULT WINAPI TABLET_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
147 LPARAM lParam)
149 TRACE("Incoming Message 0x%x (0x%08x, 0x%08x)\n", uMsg, (UINT)wParam,
150 (UINT)lParam);
152 switch(uMsg)
154 case WM_NCCREATE:
155 return TRUE;
157 case WT_PACKET:
159 WTPACKET packet;
160 LPOPENCONTEXT handler;
161 if (pGetCurrentPacket)
163 pGetCurrentPacket(&packet);
164 handler = AddPacketToContextQueue(&packet,(HWND)lParam);
165 if (handler && handler->context.lcOptions & CXO_MESSAGES)
166 TABLET_PostTabletMessage(handler, _WT_PACKET(handler->context.lcMsgBase),
167 (WPARAM)packet.pkSerialNumber,
168 (LPARAM)handler->handle, FALSE);
170 break;
172 case WT_PROXIMITY:
174 WTPACKET packet;
175 LPOPENCONTEXT handler;
176 if (pGetCurrentPacket)
178 pGetCurrentPacket(&packet);
179 handler = AddPacketToContextQueue(&packet,(HWND)wParam);
180 if (handler)
181 TABLET_PostTabletMessage(handler, WT_PROXIMITY,
182 (WPARAM)handler->handle, lParam, TRUE);
184 break;
187 return 0;