4 * Copyright 1993 Robert J. Amstadt
10 #include "wine/winbase16.h"
18 #include "cursoricon.h"
22 #include "sysmetrics.h"
26 #include "debugtools.h"
28 DECLARE_DEBUG_CHANNEL(hook
);
29 DECLARE_DEBUG_CHANNEL(local
);
30 DECLARE_DEBUG_CHANNEL(system
);
31 DECLARE_DEBUG_CHANNEL(win
);
32 DECLARE_DEBUG_CHANNEL(win32
);
34 SYSLEVEL USER_SysLevel
= { CRITICAL_SECTION_INIT("USER_SysLevel"), 2 };
37 /***********************************************************************
38 * GetFreeSystemResources (USER.284)
40 WORD WINAPI
GetFreeSystemResources16( WORD resType
)
44 int userPercent
, gdiPercent
;
46 if ((gdi_inst
= LoadLibrary16( "GDI" )) < 32) return 0;
47 gdi_heap
= gdi_inst
| 7;
51 case GFSR_USERRESOURCES
:
52 userPercent
= (int)LOCAL_CountFree( USER_HeapSel
) * 100 /
53 LOCAL_HeapSize( USER_HeapSel
);
57 case GFSR_GDIRESOURCES
:
58 gdiPercent
= (int)LOCAL_CountFree( gdi_inst
) * 100 /
59 LOCAL_HeapSize( gdi_inst
);
63 case GFSR_SYSTEMRESOURCES
:
64 userPercent
= (int)LOCAL_CountFree( USER_HeapSel
) * 100 /
65 LOCAL_HeapSize( USER_HeapSel
);
66 gdiPercent
= (int)LOCAL_CountFree( gdi_inst
) * 100 /
67 LOCAL_HeapSize( gdi_inst
);
71 userPercent
= gdiPercent
= 0;
74 FreeLibrary16( gdi_inst
);
75 return (WORD
)min( userPercent
, gdiPercent
);
79 /**********************************************************************
82 INT16 WINAPI
InitApp16( HINSTANCE16 hInstance
)
84 /* Hack: restore the divide-by-zero handler */
85 /* FIXME: should set a USER-specific handler that displays a msg box */
86 INT_SetPMHandler( 0, INT_GetPMHandler( 0xff ) );
88 /* Create task message queue */
89 if ( !InitThreadInput16( 0, 0 ) ) return 0;
95 /***********************************************************************
100 _EnterSysLevel( &USER_SysLevel
);
104 /***********************************************************************
107 void USER_Unlock(void)
109 _LeaveSysLevel( &USER_SysLevel
);
113 /***********************************************************************
116 * Make sure that we don't hold the user lock.
118 void USER_CheckNotLock(void)
120 _CheckNotSysLevel( &USER_SysLevel
);
124 /**********************************************************************
127 static void USER_ModuleUnload( HMODULE16 hModule
)
129 HOOK_FreeModuleHooks( hModule
);
130 CLASS_FreeModuleClasses( hModule
);
131 CURSORICON_FreeModuleIcons( hModule
);
134 /***********************************************************************
135 * SignalProc (USER.314)
137 void WINAPI
USER_SignalProc( HANDLE16 hTaskOrModule
, UINT16 uCode
,
138 UINT16 uExitFn
, HINSTANCE16 hInstance
,
141 FIXME_(win
)("Win 3.1 USER signal %04x\n", uCode
);
144 /***********************************************************************
145 * FinalUserInit (USER.400)
147 void WINAPI
FinalUserInit16( void )
149 /* FIXME: Should chain to FinalGdiInit now. */
152 /***********************************************************************
153 * SignalProc32 (USER.391)
154 * UserSignalProc (USER32.@)
156 * For comments about the meaning of uCode and dwFlags
157 * see PROCESS_CallUserSignalProc.
160 WORD WINAPI
UserSignalProc( UINT uCode
, DWORD dwThreadOrProcessID
,
161 DWORD dwFlags
, HMODULE16 hModule
)
163 /* FIXME: Proper reaction to most signals still missing. */
167 case USIG_DLL_UNLOAD_WIN16
:
168 case USIG_DLL_UNLOAD_WIN32
:
169 USER_ModuleUnload( hModule
);
172 case USIG_DLL_UNLOAD_ORPHANS
:
173 case USIG_FAULT_DIALOG_PUSH
:
174 case USIG_FAULT_DIALOG_POP
:
175 case USIG_THREAD_INIT
:
176 case USIG_THREAD_EXIT
:
177 case USIG_PROCESS_CREATE
:
178 case USIG_PROCESS_INIT
:
179 case USIG_PROCESS_LOADED
:
180 case USIG_PROCESS_RUNNING
:
181 case USIG_PROCESS_EXIT
:
182 case USIG_PROCESS_DESTROY
:
186 FIXME_(win
)("(%04x, %08lx, %04lx, %04x)\n",
187 uCode
, dwThreadOrProcessID
, dwFlags
, hModule
);
191 /* FIXME: Should chain to GdiSignalProc now. */
196 /***********************************************************************
197 * ExitWindows (USER.7)
199 BOOL16 WINAPI
ExitWindows16( DWORD dwReturnCode
, UINT16 wReserved
)
201 return ExitWindowsEx( EWX_LOGOFF
, 0xffffffff );
205 /***********************************************************************
206 * ExitWindowsExec (USER.246)
208 BOOL16 WINAPI
ExitWindowsExec16( LPCSTR lpszExe
, LPCSTR lpszParams
)
210 TRACE_(system
)("Should run the following in DOS-mode: \"%s %s\"\n",
211 lpszExe
, lpszParams
);
212 return ExitWindowsEx( EWX_LOGOFF
, 0xffffffff );
216 /***********************************************************************
217 * ExitWindowsEx (USER32.@)
219 BOOL WINAPI
ExitWindowsEx( UINT flags
, DWORD reserved
)
225 /* We have to build a list of all windows first, as in EnumWindows */
227 if (!(list
= WIN_ListChildren( GetDesktopWindow() ))) return FALSE
;
229 /* Send a WM_QUERYENDSESSION message to every window */
231 for (i
= 0; list
[i
]; i
++)
233 /* Make sure that the window still exists */
234 if (!IsWindow( list
[i
] )) continue;
235 if (!SendMessageW( list
[i
], WM_QUERYENDSESSION
, 0, 0 )) break;
239 /* Now notify all windows that got a WM_QUERYENDSESSION of the result */
241 for (phwnd
= list
; i
> 0; i
--, phwnd
++)
243 if (!IsWindow( *phwnd
)) continue;
244 SendMessageW( *phwnd
, WM_ENDSESSION
, result
, 0 );
246 HeapFree( GetProcessHeap(), 0, list
);
248 if (result
) ExitKernel16();
252 static void _dump_CDS_flags(DWORD flags
) {
253 #define X(x) if (flags & CDS_##x) MESSAGE(""#x ",");
254 X(UPDATEREGISTRY
);X(TEST
);X(FULLSCREEN
);X(GLOBAL
);
255 X(SET_PRIMARY
);X(RESET
);X(SETRECT
);X(NORESET
);
259 /***********************************************************************
260 * ChangeDisplaySettingsA (USER32.@)
262 LONG WINAPI
ChangeDisplaySettingsA( LPDEVMODEA devmode
, DWORD flags
)
264 FIXME_(system
)("(%p,0x%08lx), stub\n",devmode
,flags
);
265 MESSAGE("\tflags=");_dump_CDS_flags(flags
);MESSAGE("\n");
267 FIXME_(system
)(" devmode=NULL (return to default mode)\n");
268 else if ( (devmode
->dmBitsPerPel
!= GetSystemMetrics(SM_WINE_BPP
))
269 || (devmode
->dmPelsHeight
!= GetSystemMetrics(SM_CYSCREEN
))
270 || (devmode
->dmPelsWidth
!= GetSystemMetrics(SM_CXSCREEN
)) )
274 if (devmode
->dmFields
& DM_BITSPERPEL
)
275 FIXME_(system
)(" bpp=%ld\n",devmode
->dmBitsPerPel
);
276 if (devmode
->dmFields
& DM_PELSWIDTH
)
277 FIXME_(system
)(" width=%ld\n",devmode
->dmPelsWidth
);
278 if (devmode
->dmFields
& DM_PELSHEIGHT
)
279 FIXME_(system
)(" height=%ld\n",devmode
->dmPelsHeight
);
280 FIXME_(system
)(" (Putting X in this mode beforehand might help)\n");
281 /* we don't, but the program ... does not need to know */
282 return DISP_CHANGE_SUCCESSFUL
;
284 return DISP_CHANGE_SUCCESSFUL
;
287 /***********************************************************************
288 * ChangeDisplaySettings (USER.620)
290 LONG WINAPI
ChangeDisplaySettings16( LPDEVMODEA devmode
, DWORD flags
)
292 TRACE_(system
)("(%p,0x%08lx), stub\n",devmode
,flags
);
293 return ChangeDisplaySettingsA(devmode
, flags
);
296 /***********************************************************************
297 * ChangeDisplaySettingsExA (USER32.@)
299 LONG WINAPI
ChangeDisplaySettingsExA(
300 LPCSTR devname
, LPDEVMODEA devmode
, HWND hwnd
, DWORD flags
,
303 FIXME_(system
)("(%s,%p,0x%04x,0x%08lx,0x%08lx), stub\n",devname
,devmode
,hwnd
,flags
,lparam
);
304 MESSAGE("\tflags=");_dump_CDS_flags(flags
);MESSAGE("\n");
306 FIXME_(system
)(" devmode=NULL (return to default mode)\n");
307 else if ( (devmode
->dmBitsPerPel
!= GetSystemMetrics(SM_WINE_BPP
))
308 || (devmode
->dmPelsHeight
!= GetSystemMetrics(SM_CYSCREEN
))
309 || (devmode
->dmPelsWidth
!= GetSystemMetrics(SM_CXSCREEN
)) )
313 if (devmode
->dmFields
& DM_BITSPERPEL
)
314 FIXME_(system
)(" bpp=%ld\n",devmode
->dmBitsPerPel
);
315 if (devmode
->dmFields
& DM_PELSWIDTH
)
316 FIXME_(system
)(" width=%ld\n",devmode
->dmPelsWidth
);
317 if (devmode
->dmFields
& DM_PELSHEIGHT
)
318 FIXME_(system
)(" height=%ld\n",devmode
->dmPelsHeight
);
319 FIXME_(system
)(" (Putting X in this mode beforehand might help)\n");
320 /* we don't, but the program ... does not need to know */
321 return DISP_CHANGE_SUCCESSFUL
;
323 return DISP_CHANGE_SUCCESSFUL
;
326 /***********************************************************************
327 * EnumDisplaySettingsA (USER32.@)
328 * FIXME: Currently uses static list of modes.
331 * TRUE if nth setting exists found (described in the LPDEVMODEA struct)
332 * FALSE if we do not have the nth setting
334 BOOL WINAPI
EnumDisplaySettingsA(
335 LPCSTR name
, /* [in] huh? */
336 DWORD n
, /* [in] nth entry in display settings list*/
337 LPDEVMODEA devmode
/* [out] devmode for that setting */
343 } modes
[NRMODES
]={{512,384},{640,400},{640,480},{800,600},{1024,768}};
344 int depths
[4] = {8,16,24,32};
346 TRACE_(system
)("(%s,%ld,%p)\n",name
,n
,devmode
);
347 devmode
->dmDisplayFlags
= 0;
348 devmode
->dmDisplayFrequency
= 85;
349 if (n
==0 || n
== (DWORD
)-1 || n
== (DWORD
)-2) {
350 devmode
->dmBitsPerPel
= GetSystemMetrics(SM_WINE_BPP
);
351 devmode
->dmPelsHeight
= GetSystemMetrics(SM_CYSCREEN
);
352 devmode
->dmPelsWidth
= GetSystemMetrics(SM_CXSCREEN
);
355 if ((n
-1)<NRMODES
*NRDEPTHS
) {
356 devmode
->dmBitsPerPel
= depths
[(n
-1)/NRMODES
];
357 devmode
->dmPelsHeight
= modes
[(n
-1)%NRMODES
].h
;
358 devmode
->dmPelsWidth
= modes
[(n
-1)%NRMODES
].w
;
364 /***********************************************************************
365 * EnumDisplaySettingsW (USER32.@)
367 BOOL WINAPI
EnumDisplaySettingsW(LPCWSTR name
,DWORD n
,LPDEVMODEW devmode
) {
368 LPSTR nameA
= HEAP_strdupWtoA(GetProcessHeap(),0,name
);
370 BOOL ret
= EnumDisplaySettingsA(nameA
,n
,&devmodeA
);
373 devmode
->dmBitsPerPel
= devmodeA
.dmBitsPerPel
;
374 devmode
->dmPelsHeight
= devmodeA
.dmPelsHeight
;
375 devmode
->dmPelsWidth
= devmodeA
.dmPelsWidth
;
376 devmode
->dmDisplayFlags
= devmodeA
.dmDisplayFlags
;
377 devmode
->dmDisplayFrequency
= devmodeA
.dmDisplayFrequency
;
378 /* FIXME: convert rest too, if they are ever returned */
380 HeapFree(GetProcessHeap(),0,nameA
);
384 /***********************************************************************
385 * EnumDisplaySettings (USER.621)
387 BOOL16 WINAPI
EnumDisplaySettings16(
388 LPCSTR name
, /* [in] huh? */
389 DWORD n
, /* [in] nth entry in display settings list*/
390 LPDEVMODEA devmode
/* [out] devmode for that setting */
392 TRACE_(system
)("(%s, %ld, %p)\n", name
, n
, devmode
);
393 return (BOOL16
)EnumDisplaySettingsA(name
, n
, devmode
);
396 /***********************************************************************
397 * EnumDisplaySettingsExA (USER32.@)
399 BOOL WINAPI
EnumDisplaySettingsExA(LPCSTR lpszDeviceName
, DWORD iModeNum
,
400 LPDEVMODEA lpDevMode
, DWORD dwFlags
)
402 TRACE_(system
)("(%s,%lu,%p,%08lx): stub\n",
403 debugstr_a(lpszDeviceName
), iModeNum
, lpDevMode
, dwFlags
);
405 return EnumDisplaySettingsA(lpszDeviceName
, iModeNum
, lpDevMode
);
408 /***********************************************************************
409 * EnumDisplaySettingsExW (USER32.@)
411 BOOL WINAPI
EnumDisplaySettingsExW(LPCWSTR lpszDeviceName
, DWORD iModeNum
,
412 LPDEVMODEW lpDevMode
, DWORD dwFlags
)
414 TRACE_(system
)("(%s,%lu,%p,%08lx): stub\n",
415 debugstr_w(lpszDeviceName
), iModeNum
, lpDevMode
, dwFlags
);
417 return EnumDisplaySettingsW(lpszDeviceName
, iModeNum
, lpDevMode
);
420 /***********************************************************************
421 * EnumDisplayDevicesA (USER32.@)
423 BOOL WINAPI
EnumDisplayDevicesA(
424 LPVOID unused
,DWORD i
,LPDISPLAY_DEVICEA lpDisplayDevice
,DWORD dwFlags
428 FIXME_(system
)("(%p,%ld,%p,0x%08lx), stub!\n",unused
,i
,lpDisplayDevice
,dwFlags
);
429 strcpy(lpDisplayDevice
->DeviceName
,"X11");
430 strcpy(lpDisplayDevice
->DeviceString
,"X 11 Windowing System");
431 lpDisplayDevice
->StateFlags
=
432 DISPLAY_DEVICE_ATTACHED_TO_DESKTOP
|
433 DISPLAY_DEVICE_PRIMARY_DEVICE
|
434 DISPLAY_DEVICE_VGA_COMPATIBLE
;
438 /***********************************************************************
439 * EnumDisplayDevicesW (USER32.@)
441 BOOL WINAPI
EnumDisplayDevicesW(
442 LPVOID unused
,DWORD i
,LPDISPLAY_DEVICEW lpDisplayDevice
,DWORD dwFlags
446 FIXME_(system
)("(%p,%ld,%p,0x%08lx), stub!\n",unused
,i
,lpDisplayDevice
,dwFlags
);
447 MultiByteToWideChar( CP_ACP
, 0, "X11", -1, lpDisplayDevice
->DeviceName
,
448 sizeof(lpDisplayDevice
->DeviceName
)/sizeof(WCHAR
) );
449 MultiByteToWideChar( CP_ACP
, 0, "X11 Windowing System", -1, lpDisplayDevice
->DeviceString
,
450 sizeof(lpDisplayDevice
->DeviceString
)/sizeof(WCHAR
) );
451 lpDisplayDevice
->StateFlags
=
452 DISPLAY_DEVICE_ATTACHED_TO_DESKTOP
|
453 DISPLAY_DEVICE_PRIMARY_DEVICE
|
454 DISPLAY_DEVICE_VGA_COMPATIBLE
;
458 /***********************************************************************
459 * SetEventHook (USER.321)
461 * Used by Turbo Debugger for Windows
463 FARPROC16 WINAPI
SetEventHook16(FARPROC16 lpfnEventHook
)
465 FIXME_(hook
)("(lpfnEventHook=%08x): stub\n", (UINT
)lpfnEventHook
);
469 /***********************************************************************
470 * UserSeeUserDo (USER.216)
472 DWORD WINAPI
UserSeeUserDo16(WORD wReqType
, WORD wParam1
, WORD wParam2
, WORD wParam3
)
476 case USUD_LOCALALLOC
:
477 return LOCAL_Alloc(USER_HeapSel
, wParam1
, wParam3
);
479 return LOCAL_Free(USER_HeapSel
, wParam1
);
480 case USUD_LOCALCOMPACT
:
481 return LOCAL_Compact(USER_HeapSel
, wParam3
, 0);
484 case USUD_FIRSTCLASS
:
485 FIXME_(local
)("return a pointer to the first window class.\n");
488 WARN_(local
)("wReqType %04x (unknown)", wReqType
);
493 /***********************************************************************
494 * GetSystemDebugState (USER.231)
496 WORD WINAPI
GetSystemDebugState16(void)
498 return 0; /* FIXME */
501 /***********************************************************************
502 * RegisterLogonProcess (USER32.@)
504 DWORD WINAPI
RegisterLogonProcess(HANDLE hprocess
,BOOL x
) {
505 FIXME_(win32
)("(%d,%d),stub!\n",hprocess
,x
);
509 /***********************************************************************
510 * CreateWindowStationW (USER32.@)
512 HWINSTA WINAPI
CreateWindowStationW(
513 LPWSTR winstation
,DWORD res1
,DWORD desiredaccess
,
514 LPSECURITY_ATTRIBUTES lpsa
516 FIXME_(win32
)("(%s,0x%08lx,0x%08lx,%p),stub!\n",debugstr_w(winstation
),
517 res1
,desiredaccess
,lpsa
519 return (HWINSTA
)0xdeadcafe;
522 /***********************************************************************
523 * SetProcessWindowStation (USER32.@)
525 BOOL WINAPI
SetProcessWindowStation(HWINSTA hWinSta
) {
526 FIXME_(win32
)("(%d),stub!\n",hWinSta
);
530 /***********************************************************************
531 * SetUserObjectSecurity (USER32.@)
533 BOOL WINAPI
SetUserObjectSecurity(
535 PSECURITY_INFORMATION pSIRequested
,
536 PSECURITY_DESCRIPTOR pSID
538 FIXME_(win32
)("(0x%08x,%p,%p),stub!\n",hObj
,pSIRequested
,pSID
);
542 /***********************************************************************
543 * CreateDesktopA (USER32.@)
545 HDESK WINAPI
CreateDesktopA(
546 LPSTR lpszDesktop
,LPSTR lpszDevice
,LPDEVMODEA pDevmode
,
547 DWORD dwFlags
,DWORD dwDesiredAccess
,LPSECURITY_ATTRIBUTES lpsa
549 FIXME_(win32
)("(%s,%s,%p,0x%08lx,0x%08lx,%p),stub!\n",
550 lpszDesktop
,lpszDevice
,pDevmode
,
551 dwFlags
,dwDesiredAccess
,lpsa
553 return (HDESK
)0xcafedead;
556 /***********************************************************************
557 * CreateDesktopW (USER32.@)
559 HDESK WINAPI
CreateDesktopW(
560 LPWSTR lpszDesktop
,LPWSTR lpszDevice
,LPDEVMODEW pDevmode
,
561 DWORD dwFlags
,DWORD dwDesiredAccess
,LPSECURITY_ATTRIBUTES lpsa
563 FIXME_(win32
)("(%s,%s,%p,0x%08lx,0x%08lx,%p),stub!\n",
564 debugstr_w(lpszDesktop
),debugstr_w(lpszDevice
),pDevmode
,
565 dwFlags
,dwDesiredAccess
,lpsa
567 return (HDESK
)0xcafedead;
570 /***********************************************************************
571 * EnumDesktopWindows (USER32.@)
573 BOOL WINAPI
EnumDesktopWindows( HDESK hDesktop
, WNDENUMPROC lpfn
, LPARAM lParam
) {
574 FIXME_(win32
)("(0x%08x, %p, 0x%08lx), stub!\n", hDesktop
, lpfn
, lParam
);
579 /***********************************************************************
580 * CloseWindowStation (USER32.@)
582 BOOL WINAPI
CloseWindowStation(HWINSTA hWinSta
)
584 FIXME_(win32
)("(0x%08x)\n", hWinSta
);
588 /***********************************************************************
589 * CloseDesktop (USER32.@)
591 BOOL WINAPI
CloseDesktop(HDESK hDesk
)
593 FIXME_(win32
)("(0x%08x)\n", hDesk
);
597 /***********************************************************************
598 * SetWindowStationUser (USER32.@)
600 DWORD WINAPI
SetWindowStationUser(DWORD x1
,DWORD x2
) {
601 FIXME_(win32
)("(0x%08lx,0x%08lx),stub!\n",x1
,x2
);
605 /***********************************************************************
606 * SetLogonNotifyWindow (USER32.@)
608 DWORD WINAPI
SetLogonNotifyWindow(HWINSTA hwinsta
,HWND hwnd
) {
609 FIXME_(win32
)("(0x%x,%04x),stub!\n",hwinsta
,hwnd
);
613 /***********************************************************************
614 * LoadLocalFonts (USER32.@)
616 VOID WINAPI
LoadLocalFonts(VOID
) {
620 /***********************************************************************
621 * GetUserObjectInformationA (USER32.@)
623 BOOL WINAPI
GetUserObjectInformationA( HANDLE hObj
, INT nIndex
, LPVOID pvInfo
, DWORD nLength
, LPDWORD lpnLen
)
624 { FIXME_(win32
)("(0x%x %i %p %ld %p),stub!\n", hObj
, nIndex
, pvInfo
, nLength
, lpnLen
);
627 /***********************************************************************
628 * GetUserObjectInformationW (USER32.@)
630 BOOL WINAPI
GetUserObjectInformationW( HANDLE hObj
, INT nIndex
, LPVOID pvInfo
, DWORD nLength
, LPDWORD lpnLen
)
631 { FIXME_(win32
)("(0x%x %i %p %ld %p),stub!\n", hObj
, nIndex
, pvInfo
, nLength
, lpnLen
);
634 /***********************************************************************
635 * GetUserObjectSecurity (USER32.@)
637 BOOL WINAPI
GetUserObjectSecurity(HANDLE hObj
, PSECURITY_INFORMATION pSIRequested
,
638 PSECURITY_DESCRIPTOR pSID
, DWORD nLength
, LPDWORD lpnLengthNeeded
)
639 { FIXME_(win32
)("(0x%x %p %p len=%ld %p),stub!\n", hObj
, pSIRequested
, pSID
, nLength
, lpnLengthNeeded
);
643 /***********************************************************************
644 * SetSystemCursor (USER32.@)
646 BOOL WINAPI
SetSystemCursor(HCURSOR hcur
, DWORD id
)
647 { FIXME_(win32
)("(%08x,%08lx),stub!\n", hcur
, id
);
651 /***********************************************************************
652 * RegisterSystemThread (USER32.@)
654 void WINAPI
RegisterSystemThread(DWORD flags
, DWORD reserved
)
656 FIXME_(win32
)("(%08lx, %08lx)\n", flags
, reserved
);
659 /***********************************************************************
660 * RegisterDeviceNotificationA (USER32.@)
662 HDEVNOTIFY WINAPI
RegisterDeviceNotificationA(
663 HANDLE hnd
, LPVOID notifyfilter
, DWORD flags
665 FIXME_(win32
)("(hwnd=%08x, filter=%p,flags=0x%08lx), STUB!\n",
666 hnd
,notifyfilter
,flags