4 * Copyright 1993 Robert J. Amstadt
10 #include "wine/winbase16.h"
14 #include "wine/winuser16.h"
18 #include "cursoricon.h"
22 #include "sysmetrics.h"
25 #include "debugtools.h"
27 DECLARE_DEBUG_CHANNEL(hook);
28 DECLARE_DEBUG_CHANNEL(local);
29 DECLARE_DEBUG_CHANNEL(system);
30 DECLARE_DEBUG_CHANNEL(win);
31 DECLARE_DEBUG_CHANNEL(win32);
33 SYSLEVEL USER_SysLevel = { CRITICAL_SECTION_INIT("USER_SysLevel"), 2 };
36 /***********************************************************************
37 * GetFreeSystemResources (USER.284)
39 WORD WINAPI GetFreeSystemResources16( WORD resType )
43 int userPercent, gdiPercent;
45 if ((gdi_inst = LoadLibrary16( "GDI" )) < 32) return 0;
46 gdi_heap = gdi_inst | 7;
50 case GFSR_USERRESOURCES:
51 userPercent = (int)LOCAL_CountFree( USER_HeapSel ) * 100 /
52 LOCAL_HeapSize( USER_HeapSel );
56 case GFSR_GDIRESOURCES:
57 gdiPercent = (int)LOCAL_CountFree( gdi_inst ) * 100 /
58 LOCAL_HeapSize( gdi_inst );
62 case GFSR_SYSTEMRESOURCES:
63 userPercent = (int)LOCAL_CountFree( USER_HeapSel ) * 100 /
64 LOCAL_HeapSize( USER_HeapSel );
65 gdiPercent = (int)LOCAL_CountFree( gdi_inst ) * 100 /
66 LOCAL_HeapSize( gdi_inst );
70 userPercent = gdiPercent = 0;
73 FreeLibrary16( gdi_inst );
74 return (WORD)min( userPercent, gdiPercent );
78 /**********************************************************************
81 INT16 WINAPI InitApp16( HINSTANCE16 hInstance )
83 /* Hack: restore the divide-by-zero handler */
84 /* FIXME: should set a USER-specific handler that displays a msg box */
85 INT_SetPMHandler( 0, INT_GetPMHandler( 0xff ) );
87 /* Create task message queue */
88 if ( !InitThreadInput16( 0, 0 ) ) return 0;
94 /***********************************************************************
99 _EnterSysLevel( &USER_SysLevel );
103 /***********************************************************************
106 void USER_Unlock(void)
108 _LeaveSysLevel( &USER_SysLevel );
112 /***********************************************************************
115 * Make sure that we don't hold the user lock.
117 void USER_CheckNotLock(void)
119 _CheckNotSysLevel( &USER_SysLevel );
123 /**********************************************************************
126 static void USER_ModuleUnload( HMODULE16 hModule )
128 HOOK_FreeModuleHooks( hModule );
129 CLASS_FreeModuleClasses( hModule );
130 CURSORICON_FreeModuleIcons( hModule );
133 /***********************************************************************
134 * SignalProc (USER.314)
136 void WINAPI USER_SignalProc( HANDLE16 hTaskOrModule, UINT16 uCode,
137 UINT16 uExitFn, HINSTANCE16 hInstance,
140 FIXME_(win)("Win 3.1 USER signal %04x\n", uCode );
143 /***********************************************************************
144 * FinalUserInit (USER.400)
146 void WINAPI FinalUserInit16( void )
148 /* FIXME: Should chain to FinalGdiInit now. */
151 /***********************************************************************
152 * SignalProc32 (USER.391)
153 * UserSignalProc (USER32.@)
155 * For comments about the meaning of uCode and dwFlags
156 * see PROCESS_CallUserSignalProc.
159 WORD WINAPI UserSignalProc( UINT uCode, DWORD dwThreadOrProcessID,
160 DWORD dwFlags, HMODULE16 hModule )
162 /* FIXME: Proper reaction to most signals still missing. */
166 case USIG_DLL_UNLOAD_WIN16:
167 case USIG_DLL_UNLOAD_WIN32:
168 USER_ModuleUnload( hModule );
171 case USIG_DLL_UNLOAD_ORPHANS:
172 case USIG_FAULT_DIALOG_PUSH:
173 case USIG_FAULT_DIALOG_POP:
174 case USIG_THREAD_INIT:
175 case USIG_THREAD_EXIT:
176 case USIG_PROCESS_CREATE:
177 case USIG_PROCESS_INIT:
178 case USIG_PROCESS_LOADED:
179 case USIG_PROCESS_RUNNING:
180 case USIG_PROCESS_EXIT:
181 case USIG_PROCESS_DESTROY:
185 FIXME_(win)("(%04x, %08lx, %04lx, %04x)\n",
186 uCode, dwThreadOrProcessID, dwFlags, hModule );
190 /* FIXME: Should chain to GdiSignalProc now. */
195 /***********************************************************************
196 * ExitWindows (USER.7)
198 BOOL16 WINAPI ExitWindows16( DWORD dwReturnCode, UINT16 wReserved )
200 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
204 /***********************************************************************
205 * ExitWindowsExec (USER.246)
207 BOOL16 WINAPI ExitWindowsExec16( LPCSTR lpszExe, LPCSTR lpszParams )
209 TRACE_(system)("Should run the following in DOS-mode: \"%s %s\"\n",
210 lpszExe, lpszParams);
211 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
215 /***********************************************************************
216 * ExitWindowsEx (USER32.@)
218 BOOL WINAPI ExitWindowsEx( UINT flags, DWORD reserved )
224 /* We have to build a list of all windows first, as in EnumWindows */
226 if (!(list = WIN_ListChildren( GetDesktopWindow() ))) return FALSE;
228 /* Send a WM_QUERYENDSESSION message to every window */
230 for (i = 0; list[i]; i++)
232 /* Make sure that the window still exists */
233 if (!IsWindow( list[i] )) continue;
234 if (!SendMessageW( list[i], WM_QUERYENDSESSION, 0, 0 )) break;
238 /* Now notify all windows that got a WM_QUERYENDSESSION of the result */
240 for (phwnd = list; i > 0; i--, phwnd++)
242 if (!IsWindow( *phwnd )) continue;
243 SendMessageW( *phwnd, WM_ENDSESSION, result, 0 );
245 HeapFree( GetProcessHeap(), 0, list );
247 if (result) ExitKernel16();
251 static void _dump_CDS_flags(DWORD flags) {
252 #define X(x) if (flags & CDS_##x) MESSAGE(""#x ",");
253 X(UPDATEREGISTRY);X(TEST);X(FULLSCREEN);X(GLOBAL);
254 X(SET_PRIMARY);X(RESET);X(SETRECT);X(NORESET);
258 /***********************************************************************
259 * ChangeDisplaySettingsA (USER32.@)
261 LONG WINAPI ChangeDisplaySettingsA( LPDEVMODEA devmode, DWORD flags )
263 FIXME_(system)("(%p,0x%08lx), stub\n",devmode,flags);
264 MESSAGE("\tflags=");_dump_CDS_flags(flags);MESSAGE("\n");
266 FIXME_(system)(" devmode=NULL (return to default mode)\n");
267 else if ( (devmode->dmBitsPerPel != GetSystemMetrics(SM_WINE_BPP))
268 || (devmode->dmPelsHeight != GetSystemMetrics(SM_CYSCREEN))
269 || (devmode->dmPelsWidth != GetSystemMetrics(SM_CXSCREEN)) )
273 if (devmode->dmFields & DM_BITSPERPEL)
274 FIXME_(system)(" bpp=%ld\n",devmode->dmBitsPerPel);
275 if (devmode->dmFields & DM_PELSWIDTH)
276 FIXME_(system)(" width=%ld\n",devmode->dmPelsWidth);
277 if (devmode->dmFields & DM_PELSHEIGHT)
278 FIXME_(system)(" height=%ld\n",devmode->dmPelsHeight);
279 FIXME_(system)(" (Putting X in this mode beforehand might help)\n");
280 /* we don't, but the program ... does not need to know */
281 return DISP_CHANGE_SUCCESSFUL;
283 return DISP_CHANGE_SUCCESSFUL;
286 /***********************************************************************
287 * ChangeDisplaySettings (USER.620)
289 LONG WINAPI ChangeDisplaySettings16( LPDEVMODEA devmode, DWORD flags )
291 TRACE_(system)("(%p,0x%08lx), stub\n",devmode,flags);
292 return ChangeDisplaySettingsA(devmode, flags);
295 /***********************************************************************
296 * ChangeDisplaySettingsExA (USER32.@)
298 LONG WINAPI ChangeDisplaySettingsExA(
299 LPCSTR devname, LPDEVMODEA devmode, HWND hwnd, DWORD flags,
302 FIXME_(system)("(%s,%p,0x%04x,0x%08lx,0x%08lx), stub\n",devname,devmode,hwnd,flags,lparam);
303 MESSAGE("\tflags=");_dump_CDS_flags(flags);MESSAGE("\n");
305 FIXME_(system)(" devmode=NULL (return to default mode)\n");
306 else if ( (devmode->dmBitsPerPel != GetSystemMetrics(SM_WINE_BPP))
307 || (devmode->dmPelsHeight != GetSystemMetrics(SM_CYSCREEN))
308 || (devmode->dmPelsWidth != GetSystemMetrics(SM_CXSCREEN)) )
312 if (devmode->dmFields & DM_BITSPERPEL)
313 FIXME_(system)(" bpp=%ld\n",devmode->dmBitsPerPel);
314 if (devmode->dmFields & DM_PELSWIDTH)
315 FIXME_(system)(" width=%ld\n",devmode->dmPelsWidth);
316 if (devmode->dmFields & DM_PELSHEIGHT)
317 FIXME_(system)(" height=%ld\n",devmode->dmPelsHeight);
318 FIXME_(system)(" (Putting X in this mode beforehand might help)\n");
319 /* we don't, but the program ... does not need to know */
320 return DISP_CHANGE_SUCCESSFUL;
322 return DISP_CHANGE_SUCCESSFUL;
325 /***********************************************************************
326 * EnumDisplaySettingsA (USER32.@)
327 * FIXME: Currently uses static list of modes.
330 * TRUE if nth setting exists found (described in the LPDEVMODEA struct)
331 * FALSE if we do not have the nth setting
333 BOOL WINAPI EnumDisplaySettingsA(
334 LPCSTR name, /* [in] huh? */
335 DWORD n, /* [in] nth entry in display settings list*/
336 LPDEVMODEA devmode /* [out] devmode for that setting */
342 } modes[NRMODES]={{512,384},{640,400},{640,480},{800,600},{1024,768}};
343 int depths[4] = {8,16,24,32};
345 TRACE_(system)("(%s,%ld,%p)\n",name,n,devmode);
346 devmode->dmDisplayFlags = 0;
347 devmode->dmDisplayFrequency = 85;
348 if (n==0 || n == (DWORD)-1 || n == (DWORD)-2) {
349 devmode->dmBitsPerPel = GetSystemMetrics(SM_WINE_BPP);
350 devmode->dmPelsHeight = GetSystemMetrics(SM_CYSCREEN);
351 devmode->dmPelsWidth = GetSystemMetrics(SM_CXSCREEN);
354 if ((n-1)<NRMODES*NRDEPTHS) {
355 devmode->dmBitsPerPel = depths[(n-1)/NRMODES];
356 devmode->dmPelsHeight = modes[(n-1)%NRMODES].h;
357 devmode->dmPelsWidth = modes[(n-1)%NRMODES].w;
363 /***********************************************************************
364 * EnumDisplaySettingsW (USER32.@)
366 BOOL WINAPI EnumDisplaySettingsW(LPCWSTR name,DWORD n,LPDEVMODEW devmode)
370 DWORD len = WideCharToMultiByte( CP_ACP, 0, name, -1, NULL, 0, NULL, NULL );
371 LPSTR nameA = HeapAlloc( GetProcessHeap(), 0, len );
373 WideCharToMultiByte( CP_ACP, 0, name, -1, nameA, len, NULL, NULL );
374 ret = EnumDisplaySettingsA(nameA,n,&devmodeA);
377 devmode->dmBitsPerPel = devmodeA.dmBitsPerPel;
378 devmode->dmPelsHeight = devmodeA.dmPelsHeight;
379 devmode->dmPelsWidth = devmodeA.dmPelsWidth;
380 devmode->dmDisplayFlags = devmodeA.dmDisplayFlags;
381 devmode->dmDisplayFrequency = devmodeA.dmDisplayFrequency;
382 /* FIXME: convert rest too, if they are ever returned */
384 HeapFree(GetProcessHeap(),0,nameA);
388 /***********************************************************************
389 * EnumDisplaySettings (USER.621)
391 BOOL16 WINAPI EnumDisplaySettings16(
392 LPCSTR name, /* [in] huh? */
393 DWORD n, /* [in] nth entry in display settings list*/
394 LPDEVMODEA devmode /* [out] devmode for that setting */
396 TRACE_(system)("(%s, %ld, %p)\n", name, n, devmode);
397 return (BOOL16)EnumDisplaySettingsA(name, n, devmode);
400 /***********************************************************************
401 * EnumDisplaySettingsExA (USER32.@)
403 BOOL WINAPI EnumDisplaySettingsExA(LPCSTR lpszDeviceName, DWORD iModeNum,
404 LPDEVMODEA lpDevMode, DWORD dwFlags)
406 TRACE_(system)("(%s,%lu,%p,%08lx): stub\n",
407 debugstr_a(lpszDeviceName), iModeNum, lpDevMode, dwFlags);
409 return EnumDisplaySettingsA(lpszDeviceName, iModeNum, lpDevMode);
412 /***********************************************************************
413 * EnumDisplaySettingsExW (USER32.@)
415 BOOL WINAPI EnumDisplaySettingsExW(LPCWSTR lpszDeviceName, DWORD iModeNum,
416 LPDEVMODEW lpDevMode, DWORD dwFlags)
418 TRACE_(system)("(%s,%lu,%p,%08lx): stub\n",
419 debugstr_w(lpszDeviceName), iModeNum, lpDevMode, dwFlags);
421 return EnumDisplaySettingsW(lpszDeviceName, iModeNum, lpDevMode);
424 /***********************************************************************
425 * EnumDisplayDevicesA (USER32.@)
427 BOOL WINAPI EnumDisplayDevicesA(
428 LPVOID unused,DWORD i,LPDISPLAY_DEVICEA lpDisplayDevice,DWORD dwFlags
432 FIXME_(system)("(%p,%ld,%p,0x%08lx), stub!\n",unused,i,lpDisplayDevice,dwFlags);
433 strcpy(lpDisplayDevice->DeviceName,"X11");
434 strcpy(lpDisplayDevice->DeviceString,"X 11 Windowing System");
435 lpDisplayDevice->StateFlags =
436 DISPLAY_DEVICE_ATTACHED_TO_DESKTOP |
437 DISPLAY_DEVICE_PRIMARY_DEVICE |
438 DISPLAY_DEVICE_VGA_COMPATIBLE;
442 /***********************************************************************
443 * EnumDisplayDevicesW (USER32.@)
445 BOOL WINAPI EnumDisplayDevicesW(
446 LPVOID unused,DWORD i,LPDISPLAY_DEVICEW lpDisplayDevice,DWORD dwFlags
450 FIXME_(system)("(%p,%ld,%p,0x%08lx), stub!\n",unused,i,lpDisplayDevice,dwFlags);
451 MultiByteToWideChar( CP_ACP, 0, "X11", -1, lpDisplayDevice->DeviceName,
452 sizeof(lpDisplayDevice->DeviceName)/sizeof(WCHAR) );
453 MultiByteToWideChar( CP_ACP, 0, "X11 Windowing System", -1, lpDisplayDevice->DeviceString,
454 sizeof(lpDisplayDevice->DeviceString)/sizeof(WCHAR) );
455 lpDisplayDevice->StateFlags =
456 DISPLAY_DEVICE_ATTACHED_TO_DESKTOP |
457 DISPLAY_DEVICE_PRIMARY_DEVICE |
458 DISPLAY_DEVICE_VGA_COMPATIBLE;
462 /***********************************************************************
463 * SetEventHook (USER.321)
465 * Used by Turbo Debugger for Windows
467 FARPROC16 WINAPI SetEventHook16(FARPROC16 lpfnEventHook)
469 FIXME_(hook)("(lpfnEventHook=%08x): stub\n", (UINT)lpfnEventHook);
473 /***********************************************************************
474 * UserSeeUserDo (USER.216)
476 DWORD WINAPI UserSeeUserDo16(WORD wReqType, WORD wParam1, WORD wParam2, WORD wParam3)
480 case USUD_LOCALALLOC:
481 return LOCAL_Alloc(USER_HeapSel, wParam1, wParam3);
483 return LOCAL_Free(USER_HeapSel, wParam1);
484 case USUD_LOCALCOMPACT:
485 return LOCAL_Compact(USER_HeapSel, wParam3, 0);
488 case USUD_FIRSTCLASS:
489 FIXME_(local)("return a pointer to the first window class.\n");
492 WARN_(local)("wReqType %04x (unknown)", wReqType);
497 /***********************************************************************
498 * GetSystemDebugState (USER.231)
500 WORD WINAPI GetSystemDebugState16(void)
502 return 0; /* FIXME */
505 /***********************************************************************
506 * RegisterLogonProcess (USER32.@)
508 DWORD WINAPI RegisterLogonProcess(HANDLE hprocess,BOOL x) {
509 FIXME_(win32)("(%d,%d),stub!\n",hprocess,x);
513 /***********************************************************************
514 * CreateWindowStationW (USER32.@)
516 HWINSTA WINAPI CreateWindowStationW(
517 LPWSTR winstation,DWORD res1,DWORD desiredaccess,
518 LPSECURITY_ATTRIBUTES lpsa
520 FIXME_(win32)("(%s,0x%08lx,0x%08lx,%p),stub!\n",debugstr_w(winstation),
521 res1,desiredaccess,lpsa
523 return (HWINSTA)0xdeadcafe;
526 /***********************************************************************
527 * SetProcessWindowStation (USER32.@)
529 BOOL WINAPI SetProcessWindowStation(HWINSTA hWinSta) {
530 FIXME_(win32)("(%d),stub!\n",hWinSta);
534 /***********************************************************************
535 * SetUserObjectSecurity (USER32.@)
537 BOOL WINAPI SetUserObjectSecurity(
539 PSECURITY_INFORMATION pSIRequested,
540 PSECURITY_DESCRIPTOR pSID
542 FIXME_(win32)("(0x%08x,%p,%p),stub!\n",hObj,pSIRequested,pSID);
546 /***********************************************************************
547 * CreateDesktopA (USER32.@)
549 HDESK WINAPI CreateDesktopA(
550 LPSTR lpszDesktop,LPSTR lpszDevice,LPDEVMODEA pDevmode,
551 DWORD dwFlags,DWORD dwDesiredAccess,LPSECURITY_ATTRIBUTES lpsa
553 FIXME_(win32)("(%s,%s,%p,0x%08lx,0x%08lx,%p),stub!\n",
554 lpszDesktop,lpszDevice,pDevmode,
555 dwFlags,dwDesiredAccess,lpsa
557 return (HDESK)0xcafedead;
560 /***********************************************************************
561 * CreateDesktopW (USER32.@)
563 HDESK WINAPI CreateDesktopW(
564 LPWSTR lpszDesktop,LPWSTR lpszDevice,LPDEVMODEW pDevmode,
565 DWORD dwFlags,DWORD dwDesiredAccess,LPSECURITY_ATTRIBUTES lpsa
567 FIXME_(win32)("(%s,%s,%p,0x%08lx,0x%08lx,%p),stub!\n",
568 debugstr_w(lpszDesktop),debugstr_w(lpszDevice),pDevmode,
569 dwFlags,dwDesiredAccess,lpsa
571 return (HDESK)0xcafedead;
574 /***********************************************************************
575 * EnumDesktopWindows (USER32.@)
577 BOOL WINAPI EnumDesktopWindows( HDESK hDesktop, WNDENUMPROC lpfn, LPARAM lParam ) {
578 FIXME_(win32)("(0x%08x, %p, 0x%08lx), stub!\n", hDesktop, lpfn, lParam );
583 /***********************************************************************
584 * CloseWindowStation (USER32.@)
586 BOOL WINAPI CloseWindowStation(HWINSTA hWinSta)
588 FIXME_(win32)("(0x%08x)\n", hWinSta);
592 /***********************************************************************
593 * CloseDesktop (USER32.@)
595 BOOL WINAPI CloseDesktop(HDESK hDesk)
597 FIXME_(win32)("(0x%08x)\n", hDesk);
601 /***********************************************************************
602 * SetWindowStationUser (USER32.@)
604 DWORD WINAPI SetWindowStationUser(DWORD x1,DWORD x2) {
605 FIXME_(win32)("(0x%08lx,0x%08lx),stub!\n",x1,x2);
609 /***********************************************************************
610 * SetLogonNotifyWindow (USER32.@)
612 DWORD WINAPI SetLogonNotifyWindow(HWINSTA hwinsta,HWND hwnd) {
613 FIXME_(win32)("(0x%x,%04x),stub!\n",hwinsta,hwnd);
617 /***********************************************************************
618 * LoadLocalFonts (USER32.@)
620 VOID WINAPI LoadLocalFonts(VOID) {
624 /***********************************************************************
625 * GetUserObjectInformationA (USER32.@)
627 BOOL WINAPI GetUserObjectInformationA( HANDLE hObj, INT nIndex, LPVOID pvInfo, DWORD nLength, LPDWORD lpnLen )
628 { FIXME_(win32)("(0x%x %i %p %ld %p),stub!\n", hObj, nIndex, pvInfo, nLength, lpnLen );
631 /***********************************************************************
632 * GetUserObjectInformationW (USER32.@)
634 BOOL WINAPI GetUserObjectInformationW( HANDLE hObj, INT nIndex, LPVOID pvInfo, DWORD nLength, LPDWORD lpnLen )
635 { FIXME_(win32)("(0x%x %i %p %ld %p),stub!\n", hObj, nIndex, pvInfo, nLength, lpnLen );
638 /***********************************************************************
639 * GetUserObjectSecurity (USER32.@)
641 BOOL WINAPI GetUserObjectSecurity(HANDLE hObj, PSECURITY_INFORMATION pSIRequested,
642 PSECURITY_DESCRIPTOR pSID, DWORD nLength, LPDWORD lpnLengthNeeded)
643 { FIXME_(win32)("(0x%x %p %p len=%ld %p),stub!\n", hObj, pSIRequested, pSID, nLength, lpnLengthNeeded);
647 /***********************************************************************
648 * SetSystemCursor (USER32.@)
650 BOOL WINAPI SetSystemCursor(HCURSOR hcur, DWORD id)
651 { FIXME_(win32)("(%08x,%08lx),stub!\n", hcur, id);
655 /***********************************************************************
656 * RegisterSystemThread (USER32.@)
658 void WINAPI RegisterSystemThread(DWORD flags, DWORD reserved)
660 FIXME_(win32)("(%08lx, %08lx)\n", flags, reserved);
663 /***********************************************************************
664 * RegisterDeviceNotificationA (USER32.@)
666 HDEVNOTIFY WINAPI RegisterDeviceNotificationA(
667 HANDLE hnd, LPVOID notifyfilter, DWORD flags
669 FIXME_(win32)("(hwnd=%08x, filter=%p,flags=0x%08lx), STUB!\n",
670 hnd,notifyfilter,flags