4 * Copyright 1993 Robert J. Amstadt
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "wine/winbase16.h"
28 #include "wine/winuser16.h"
32 #include "cursoricon.h"
37 #include "wine/debug.h"
39 WINE_DECLARE_DEBUG_CHANNEL(hook);
40 WINE_DECLARE_DEBUG_CHANNEL(local);
41 WINE_DECLARE_DEBUG_CHANNEL(system);
42 WINE_DECLARE_DEBUG_CHANNEL(win);
43 WINE_DECLARE_DEBUG_CHANNEL(win32);
45 SYSLEVEL USER_SysLevel = { CRITICAL_SECTION_INIT("USER_SysLevel"), 2 };
48 /* USER signal proc flags and codes */
49 /* See UserSignalProc for comments */
50 #define USIG_FLAGS_WIN32 0x0001
51 #define USIG_FLAGS_GUI 0x0002
52 #define USIG_FLAGS_FEEDBACK 0x0004
53 #define USIG_FLAGS_FAULT 0x0008
55 #define USIG_DLL_UNLOAD_WIN16 0x0001
56 #define USIG_DLL_UNLOAD_WIN32 0x0002
57 #define USIG_FAULT_DIALOG_PUSH 0x0003
58 #define USIG_FAULT_DIALOG_POP 0x0004
59 #define USIG_DLL_UNLOAD_ORPHANS 0x0005
60 #define USIG_THREAD_INIT 0x0010
61 #define USIG_THREAD_EXIT 0x0020
62 #define USIG_PROCESS_CREATE 0x0100
63 #define USIG_PROCESS_INIT 0x0200
64 #define USIG_PROCESS_EXIT 0x0300
65 #define USIG_PROCESS_DESTROY 0x0400
66 #define USIG_PROCESS_RUNNING 0x0500
67 #define USIG_PROCESS_LOADED 0x0600
70 /***********************************************************************
71 * GetFreeSystemResources (USER.284)
73 WORD WINAPI GetFreeSystemResources16( WORD resType )
77 int userPercent, gdiPercent;
79 if ((gdi_inst = LoadLibrary16( "GDI" )) < 32) return 0;
80 gdi_heap = gdi_inst | 7;
84 case GFSR_USERRESOURCES:
85 userPercent = (int)LOCAL_CountFree( USER_HeapSel ) * 100 /
86 LOCAL_HeapSize( USER_HeapSel );
90 case GFSR_GDIRESOURCES:
91 gdiPercent = (int)LOCAL_CountFree( gdi_inst ) * 100 /
92 LOCAL_HeapSize( gdi_inst );
96 case GFSR_SYSTEMRESOURCES:
97 userPercent = (int)LOCAL_CountFree( USER_HeapSel ) * 100 /
98 LOCAL_HeapSize( USER_HeapSel );
99 gdiPercent = (int)LOCAL_CountFree( gdi_inst ) * 100 /
100 LOCAL_HeapSize( gdi_inst );
104 userPercent = gdiPercent = 0;
107 FreeLibrary16( gdi_inst );
108 TRACE_(local)("<- userPercent %d, gdiPercent %d\n", userPercent, gdiPercent);
109 return (WORD)min( userPercent, gdiPercent );
113 /**********************************************************************
116 INT16 WINAPI InitApp16( HINSTANCE16 hInstance )
118 /* Create task message queue */
119 if ( !InitThreadInput16( 0, 0 ) ) return 0;
125 /***********************************************************************
130 _EnterSysLevel( &USER_SysLevel );
134 /***********************************************************************
137 void USER_Unlock(void)
139 _LeaveSysLevel( &USER_SysLevel );
143 /***********************************************************************
146 * Make sure that we don't hold the user lock.
148 void USER_CheckNotLock(void)
150 _CheckNotSysLevel( &USER_SysLevel );
154 /***********************************************************************
155 * FinalUserInit (USER.400)
157 void WINAPI FinalUserInit16( void )
159 /* FIXME: Should chain to FinalGdiInit now. */
162 /***********************************************************************
163 * SignalProc32 (USER.391)
164 * UserSignalProc (USER32.@)
166 * The exact meaning of the USER signals is undocumented, but this
167 * should cover the basic idea:
169 * USIG_DLL_UNLOAD_WIN16
170 * This is sent when a 16-bit module is unloaded.
172 * USIG_DLL_UNLOAD_WIN32
173 * This is sent when a 32-bit module is unloaded.
175 * USIG_DLL_UNLOAD_ORPHANS
176 * This is sent after the last Win3.1 module is unloaded,
177 * to allow removal of orphaned menus.
179 * USIG_FAULT_DIALOG_PUSH
180 * USIG_FAULT_DIALOG_POP
181 * These are called to allow USER to prepare for displaying a
182 * fault dialog, even though the fault might have happened while
183 * inside a USER critical section.
186 * This is called from the context of a new thread, as soon as it
187 * has started to run.
190 * This is called, still in its context, just before a thread is
191 * about to terminate.
193 * USIG_PROCESS_CREATE
194 * This is called, in the parent process context, after a new process
198 * This is called in the new process context, just after the main thread
199 * has started execution (after the main thread's USIG_THREAD_INIT has
202 * USIG_PROCESS_LOADED
203 * This is called after the executable file has been loaded into the
204 * new process context.
206 * USIG_PROCESS_RUNNING
207 * This is called immediately before the main entry point is called.
210 * This is called in the context of a process that is about to
211 * terminate (but before the last thread's USIG_THREAD_EXIT has
214 * USIG_PROCESS_DESTROY
215 * This is called after a process has terminated.
218 * The meaning of the dwFlags bits is as follows:
221 * Current process is 32-bit.
224 * Current process is a (Win32) GUI process.
226 * USIG_FLAGS_FEEDBACK
227 * Current process needs 'feedback' (determined from the STARTUPINFO
228 * flags STARTF_FORCEONFEEDBACK / STARTF_FORCEOFFFEEDBACK).
231 * The signal is being sent due to a fault.
233 WORD WINAPI UserSignalProc( UINT uCode, DWORD dwThreadOrProcessID,
234 DWORD dwFlags, HMODULE16 hModule )
236 FIXME_(win)("(%04x, %08lx, %04lx, %04x)\n",
237 uCode, dwThreadOrProcessID, dwFlags, hModule );
238 /* FIXME: Should chain to GdiSignalProc now. */
242 /***********************************************************************
243 * ExitWindows (USER.7)
245 BOOL16 WINAPI ExitWindows16( DWORD dwReturnCode, UINT16 wReserved )
247 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
251 /***********************************************************************
252 * ExitWindowsExec (USER.246)
254 BOOL16 WINAPI ExitWindowsExec16( LPCSTR lpszExe, LPCSTR lpszParams )
256 TRACE_(system)("Should run the following in DOS-mode: \"%s %s\"\n",
257 lpszExe, lpszParams);
258 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
262 /***********************************************************************
263 * ExitWindowsEx (USER32.@)
265 BOOL WINAPI ExitWindowsEx( UINT flags, DWORD reserved )
271 /* We have to build a list of all windows first, as in EnumWindows */
273 if (!(list = WIN_ListChildren( GetDesktopWindow() ))) return FALSE;
275 /* Send a WM_QUERYENDSESSION message to every window */
277 for (i = 0; list[i]; i++)
279 /* Make sure that the window still exists */
280 if (!IsWindow( list[i] )) continue;
281 if (!SendMessageW( list[i], WM_QUERYENDSESSION, 0, 0 )) break;
285 /* Now notify all windows that got a WM_QUERYENDSESSION of the result */
287 for (phwnd = list; i > 0; i--, phwnd++)
289 if (!IsWindow( *phwnd )) continue;
290 SendMessageW( *phwnd, WM_ENDSESSION, result, 0 );
292 HeapFree( GetProcessHeap(), 0, list );
294 if (result) ExitKernel16();
298 /***********************************************************************
299 * ChangeDisplaySettingsA (USER32.@)
301 LONG WINAPI ChangeDisplaySettingsA( LPDEVMODEA devmode, DWORD flags )
303 return ChangeDisplaySettingsExA(NULL,devmode,NULL,flags,NULL);
306 /***********************************************************************
307 * ChangeDisplaySettingsW (USER32.@)
309 LONG WINAPI ChangeDisplaySettingsW( LPDEVMODEW devmode, DWORD flags )
311 return ChangeDisplaySettingsExW(NULL,devmode,NULL,flags,NULL);
314 /***********************************************************************
315 * ChangeDisplaySettings (USER.620)
317 LONG WINAPI ChangeDisplaySettings16( LPDEVMODEA devmode, DWORD flags )
319 return ChangeDisplaySettingsA(devmode, flags);
322 /***********************************************************************
323 * ChangeDisplaySettingsExA (USER32.@)
325 LONG WINAPI ChangeDisplaySettingsExA(
326 LPCSTR devname, LPDEVMODEA devmode, HWND hwnd, DWORD flags,
331 UNICODE_STRING nameW;
333 if (devname) RtlCreateUnicodeStringFromAsciiz(&nameW, devname);
334 else nameW.Buffer = NULL;
338 devmodeW.dmBitsPerPel = devmode->dmBitsPerPel;
339 devmodeW.dmPelsHeight = devmode->dmPelsHeight;
340 devmodeW.dmPelsWidth = devmode->dmPelsWidth;
341 devmodeW.dmDisplayFlags = devmode->dmDisplayFlags;
342 devmodeW.dmDisplayFrequency = devmode->dmDisplayFrequency;
343 devmodeW.dmFields = devmode->dmFields;
344 ret = ChangeDisplaySettingsExW(nameW.Buffer, &devmodeW, hwnd, flags, lparam);
348 ret = ChangeDisplaySettingsExW(nameW.Buffer, NULL, hwnd, flags, lparam);
351 if (devname) RtlFreeUnicodeString(&nameW);
355 /***********************************************************************
356 * ChangeDisplaySettingsExW (USER32.@)
358 LONG WINAPI ChangeDisplaySettingsExW( LPCWSTR devname, LPDEVMODEW devmode, HWND hwnd,
359 DWORD flags, LPVOID lparam )
361 /* Pass the request on to the driver */
362 if (!USER_Driver.pChangeDisplaySettingsExW) return DISP_CHANGE_FAILED;
363 return USER_Driver.pChangeDisplaySettingsExW( devname, devmode, hwnd, flags, lparam );
366 /***********************************************************************
367 * EnumDisplaySettingsW (USER32.@)
370 * TRUE if nth setting exists found (described in the LPDEVMODEW struct)
371 * FALSE if we do not have the nth setting
373 BOOL WINAPI EnumDisplaySettingsW(
374 LPCWSTR name, /* [in] huh? */
375 DWORD n, /* [in] nth entry in display settings list*/
376 LPDEVMODEW devmode /* [out] devmode for that setting */
378 return EnumDisplaySettingsExW(name, n, devmode, 0);
381 /***********************************************************************
382 * EnumDisplaySettingsA (USER32.@)
384 BOOL WINAPI EnumDisplaySettingsA(LPCSTR name,DWORD n,LPDEVMODEA devmode)
386 return EnumDisplaySettingsExA(name, n, devmode, 0);
389 /***********************************************************************
390 * EnumDisplaySettings (USER.621)
392 BOOL16 WINAPI EnumDisplaySettings16(
393 LPCSTR name, /* [in] huh? */
394 DWORD n, /* [in] nth entry in display settings list*/
395 LPDEVMODEA devmode /* [out] devmode for that setting */
397 return (BOOL16)EnumDisplaySettingsA(name, n, devmode);
400 /***********************************************************************
401 * EnumDisplaySettingsExA (USER32.@)
403 BOOL WINAPI EnumDisplaySettingsExA(LPCSTR lpszDeviceName, DWORD iModeNum,
404 LPDEVMODEA lpDevMode, DWORD dwFlags)
408 UNICODE_STRING nameW;
410 if (lpszDeviceName) RtlCreateUnicodeStringFromAsciiz(&nameW, lpszDeviceName);
411 else nameW.Buffer = NULL;
413 ret = EnumDisplaySettingsExW(nameW.Buffer,iModeNum,&devmodeW,dwFlags);
416 lpDevMode->dmBitsPerPel = devmodeW.dmBitsPerPel;
417 lpDevMode->dmPelsHeight = devmodeW.dmPelsHeight;
418 lpDevMode->dmPelsWidth = devmodeW.dmPelsWidth;
419 lpDevMode->dmDisplayFlags = devmodeW.dmDisplayFlags;
420 lpDevMode->dmDisplayFrequency = devmodeW.dmDisplayFrequency;
421 lpDevMode->dmFields = devmodeW.dmFields;
423 if (lpszDeviceName) RtlFreeUnicodeString(&nameW);
427 /***********************************************************************
428 * EnumDisplaySettingsExW (USER32.@)
430 BOOL WINAPI EnumDisplaySettingsExW(LPCWSTR lpszDeviceName, DWORD iModeNum,
431 LPDEVMODEW lpDevMode, DWORD dwFlags)
433 /* Pass the request on to the driver */
434 if (!USER_Driver.pEnumDisplaySettingsExW) return FALSE;
435 return USER_Driver.pEnumDisplaySettingsExW(lpszDeviceName, iModeNum, lpDevMode, dwFlags);
438 /***********************************************************************
439 * EnumDisplayDevicesA (USER32.@)
441 BOOL WINAPI EnumDisplayDevicesA(
442 LPVOID unused,DWORD i,LPDISPLAY_DEVICEA lpDisplayDevice,DWORD dwFlags
446 FIXME_(system)("(%p,%ld,%p,0x%08lx), stub!\n",unused,i,lpDisplayDevice,dwFlags);
447 strcpy(lpDisplayDevice->DeviceName,"X11");
448 strcpy(lpDisplayDevice->DeviceString,"X 11 Windowing System");
449 lpDisplayDevice->StateFlags =
450 DISPLAY_DEVICE_ATTACHED_TO_DESKTOP |
451 DISPLAY_DEVICE_PRIMARY_DEVICE |
452 DISPLAY_DEVICE_VGA_COMPATIBLE;
456 /***********************************************************************
457 * EnumDisplayDevicesW (USER32.@)
459 BOOL WINAPI EnumDisplayDevicesW(
460 LPVOID unused,DWORD i,LPDISPLAY_DEVICEW lpDisplayDevice,DWORD dwFlags
464 FIXME_(system)("(%p,%ld,%p,0x%08lx), stub!\n",unused,i,lpDisplayDevice,dwFlags);
465 MultiByteToWideChar( CP_ACP, 0, "X11", -1, lpDisplayDevice->DeviceName,
466 sizeof(lpDisplayDevice->DeviceName)/sizeof(WCHAR) );
467 MultiByteToWideChar( CP_ACP, 0, "X11 Windowing System", -1, lpDisplayDevice->DeviceString,
468 sizeof(lpDisplayDevice->DeviceString)/sizeof(WCHAR) );
469 lpDisplayDevice->StateFlags =
470 DISPLAY_DEVICE_ATTACHED_TO_DESKTOP |
471 DISPLAY_DEVICE_PRIMARY_DEVICE |
472 DISPLAY_DEVICE_VGA_COMPATIBLE;
476 /***********************************************************************
477 * SetEventHook (USER.321)
479 * Used by Turbo Debugger for Windows
481 FARPROC16 WINAPI SetEventHook16(FARPROC16 lpfnEventHook)
483 FIXME_(hook)("(lpfnEventHook=%08x): stub\n", (UINT)lpfnEventHook);
487 /***********************************************************************
488 * UserSeeUserDo (USER.216)
490 DWORD WINAPI UserSeeUserDo16(WORD wReqType, WORD wParam1, WORD wParam2, WORD wParam3)
494 case USUD_LOCALALLOC:
495 return LOCAL_Alloc(USER_HeapSel, wParam1, wParam3);
497 return LOCAL_Free(USER_HeapSel, wParam1);
498 case USUD_LOCALCOMPACT:
499 return LOCAL_Compact(USER_HeapSel, wParam3, 0);
502 case USUD_FIRSTCLASS:
503 FIXME_(local)("return a pointer to the first window class.\n");
506 WARN_(local)("wReqType %04x (unknown)", wReqType);
511 /***********************************************************************
512 * GetSystemDebugState (USER.231)
514 WORD WINAPI GetSystemDebugState16(void)
516 return 0; /* FIXME */
519 /***********************************************************************
520 * RegisterLogonProcess (USER32.@)
522 DWORD WINAPI RegisterLogonProcess(HANDLE hprocess,BOOL x) {
523 FIXME_(win32)("(%p,%d),stub!\n",hprocess,x);
527 /***********************************************************************
528 * CreateWindowStationW (USER32.@)
530 HWINSTA WINAPI CreateWindowStationW(
531 LPWSTR winstation,DWORD res1,DWORD desiredaccess,
532 LPSECURITY_ATTRIBUTES lpsa
534 FIXME_(win32)("(%s,0x%08lx,0x%08lx,%p),stub!\n",debugstr_w(winstation),
535 res1,desiredaccess,lpsa
537 return (HWINSTA)0xdeadcafe;
540 /***********************************************************************
541 * SetProcessWindowStation (USER32.@)
543 BOOL WINAPI SetProcessWindowStation(HWINSTA hWinSta) {
544 FIXME_(win32)("(%p),stub!\n",hWinSta);
548 /***********************************************************************
549 * SetUserObjectSecurity (USER32.@)
551 BOOL WINAPI SetUserObjectSecurity(
553 PSECURITY_INFORMATION pSIRequested,
554 PSECURITY_DESCRIPTOR pSID
556 FIXME_(win32)("(%p,%p,%p),stub!\n",hObj,pSIRequested,pSID);
560 /***********************************************************************
561 * CreateDesktopA (USER32.@)
563 HDESK WINAPI CreateDesktopA(
564 LPSTR lpszDesktop,LPSTR lpszDevice,LPDEVMODEA pDevmode,
565 DWORD dwFlags,DWORD dwDesiredAccess,LPSECURITY_ATTRIBUTES lpsa
567 FIXME_(win32)("(%s,%s,%p,0x%08lx,0x%08lx,%p),stub!\n",
568 lpszDesktop,lpszDevice,pDevmode,
569 dwFlags,dwDesiredAccess,lpsa
571 return (HDESK)0xcafedead;
574 /***********************************************************************
575 * CreateDesktopW (USER32.@)
577 HDESK WINAPI CreateDesktopW(
578 LPWSTR lpszDesktop,LPWSTR lpszDevice,LPDEVMODEW pDevmode,
579 DWORD dwFlags,DWORD dwDesiredAccess,LPSECURITY_ATTRIBUTES lpsa
581 FIXME_(win32)("(%s,%s,%p,0x%08lx,0x%08lx,%p),stub!\n",
582 debugstr_w(lpszDesktop),debugstr_w(lpszDevice),pDevmode,
583 dwFlags,dwDesiredAccess,lpsa
585 return (HDESK)0xcafedead;
588 /***********************************************************************
589 * EnumDesktopWindows (USER32.@)
591 BOOL WINAPI EnumDesktopWindows( HDESK hDesktop, WNDENUMPROC lpfn, LPARAM lParam ) {
592 FIXME_(win32)("(%p, %p, 0x%08lx), stub!\n", hDesktop, lpfn, lParam );
597 /***********************************************************************
598 * CloseWindowStation (USER32.@)
600 BOOL WINAPI CloseWindowStation(HWINSTA hWinSta)
602 FIXME_(win32)("(%p)\n", hWinSta);
606 /***********************************************************************
607 * CloseDesktop (USER32.@)
609 BOOL WINAPI CloseDesktop(HDESK hDesk)
611 FIXME_(win32)("(%p)\n", hDesk);
615 /***********************************************************************
616 * SetWindowStationUser (USER32.@)
618 DWORD WINAPI SetWindowStationUser(DWORD x1,DWORD x2) {
619 FIXME_(win32)("(0x%08lx,0x%08lx),stub!\n",x1,x2);
623 /***********************************************************************
624 * SetLogonNotifyWindow (USER32.@)
626 DWORD WINAPI SetLogonNotifyWindow(HWINSTA hwinsta,HWND hwnd) {
627 FIXME_(win32)("(%p,%p),stub!\n",hwinsta,hwnd);
631 /***********************************************************************
632 * LoadLocalFonts (USER32.@)
634 VOID WINAPI LoadLocalFonts(VOID) {
638 /***********************************************************************
639 * GetUserObjectInformationA (USER32.@)
641 BOOL WINAPI GetUserObjectInformationA( HANDLE hObj, INT nIndex, LPVOID pvInfo, DWORD nLength, LPDWORD lpnLen )
642 { FIXME_(win32)("(%p %i %p %ld %p),stub!\n", hObj, nIndex, pvInfo, nLength, lpnLen );
645 /***********************************************************************
646 * GetUserObjectInformationW (USER32.@)
648 BOOL WINAPI GetUserObjectInformationW( HANDLE hObj, INT nIndex, LPVOID pvInfo, DWORD nLength, LPDWORD lpnLen )
649 { FIXME_(win32)("(%p %i %p %ld %p),stub!\n", hObj, nIndex, pvInfo, nLength, lpnLen );
652 /***********************************************************************
653 * GetUserObjectSecurity (USER32.@)
655 BOOL WINAPI GetUserObjectSecurity(HANDLE hObj, PSECURITY_INFORMATION pSIRequested,
656 PSECURITY_DESCRIPTOR pSID, DWORD nLength, LPDWORD lpnLengthNeeded)
657 { FIXME_(win32)("(%p %p %p len=%ld %p),stub!\n", hObj, pSIRequested, pSID, nLength, lpnLengthNeeded);
661 /***********************************************************************
662 * SetSystemCursor (USER32.@)
664 BOOL WINAPI SetSystemCursor(HCURSOR hcur, DWORD id)
665 { FIXME_(win32)("(%p,%08lx),stub!\n", hcur, id);
669 /***********************************************************************
670 * RegisterSystemThread (USER32.@)
672 void WINAPI RegisterSystemThread(DWORD flags, DWORD reserved)
674 FIXME_(win32)("(%08lx, %08lx)\n", flags, reserved);
677 /***********************************************************************
678 * RegisterDeviceNotificationA (USER32.@)
680 HDEVNOTIFY WINAPI RegisterDeviceNotificationA(
681 HANDLE hnd, LPVOID notifyfilter, DWORD flags
683 FIXME_(win32)("(hwnd=%p, filter=%p,flags=0x%08lx), STUB!\n", hnd,notifyfilter,flags );