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 /***********************************************************************
35 * GetFreeSystemResources (USER.284)
37 WORD WINAPI
GetFreeSystemResources16( WORD resType
)
41 int userPercent
, gdiPercent
;
43 if ((gdi_inst
= LoadLibrary16( "GDI" )) < 32) return 0;
44 gdi_heap
= gdi_inst
| 7;
48 case GFSR_USERRESOURCES
:
49 userPercent
= (int)LOCAL_CountFree( USER_HeapSel
) * 100 /
50 LOCAL_HeapSize( USER_HeapSel
);
54 case GFSR_GDIRESOURCES
:
55 gdiPercent
= (int)LOCAL_CountFree( gdi_inst
) * 100 /
56 LOCAL_HeapSize( gdi_inst
);
60 case GFSR_SYSTEMRESOURCES
:
61 userPercent
= (int)LOCAL_CountFree( USER_HeapSel
) * 100 /
62 LOCAL_HeapSize( USER_HeapSel
);
63 gdiPercent
= (int)LOCAL_CountFree( gdi_inst
) * 100 /
64 LOCAL_HeapSize( gdi_inst
);
68 userPercent
= gdiPercent
= 0;
71 FreeLibrary16( gdi_inst
);
72 return (WORD
)min( userPercent
, gdiPercent
);
76 /**********************************************************************
79 INT16 WINAPI
InitApp16( HINSTANCE16 hInstance
)
81 /* Hack: restore the divide-by-zero handler */
82 /* FIXME: should set a USER-specific handler that displays a msg box */
83 INT_SetPMHandler( 0, INT_GetPMHandler( 0xff ) );
85 /* Create task message queue */
86 if ( !InitThreadInput16( 0, 0 ) ) return 0;
91 /**********************************************************************
94 static void USER_ModuleUnload( HMODULE16 hModule
)
96 HOOK_FreeModuleHooks( hModule
);
97 CLASS_FreeModuleClasses( hModule
);
98 CURSORICON_FreeModuleIcons( hModule
);
101 /***********************************************************************
102 * SignalProc (USER.314)
104 void WINAPI
USER_SignalProc( HANDLE16 hTaskOrModule
, UINT16 uCode
,
105 UINT16 uExitFn
, HINSTANCE16 hInstance
,
108 FIXME_(win
)("Win 3.1 USER signal %04x\n", uCode
);
111 /***********************************************************************
112 * FinalUserInit (USER.400)
114 void WINAPI
FinalUserInit16( void )
116 /* FIXME: Should chain to FinalGdiInit now. */
119 /***********************************************************************
120 * SignalProc32 (USER.391)
121 * UserSignalProc (USER32.@)
123 * For comments about the meaning of uCode and dwFlags
124 * see PROCESS_CallUserSignalProc.
127 WORD WINAPI
UserSignalProc( UINT uCode
, DWORD dwThreadOrProcessID
,
128 DWORD dwFlags
, HMODULE16 hModule
)
130 /* FIXME: Proper reaction to most signals still missing. */
134 case USIG_DLL_UNLOAD_WIN16
:
135 case USIG_DLL_UNLOAD_WIN32
:
136 USER_ModuleUnload( hModule
);
139 case USIG_DLL_UNLOAD_ORPHANS
:
140 case USIG_FAULT_DIALOG_PUSH
:
141 case USIG_FAULT_DIALOG_POP
:
142 case USIG_THREAD_INIT
:
143 case USIG_THREAD_EXIT
:
144 case USIG_PROCESS_CREATE
:
145 case USIG_PROCESS_INIT
:
146 case USIG_PROCESS_LOADED
:
147 case USIG_PROCESS_RUNNING
:
148 case USIG_PROCESS_EXIT
:
149 case USIG_PROCESS_DESTROY
:
153 FIXME_(win
)("(%04x, %08lx, %04lx, %04x)\n",
154 uCode
, dwThreadOrProcessID
, dwFlags
, hModule
);
158 /* FIXME: Should chain to GdiSignalProc now. */
163 /***********************************************************************
164 * ExitWindows (USER.7)
166 BOOL16 WINAPI
ExitWindows16( DWORD dwReturnCode
, UINT16 wReserved
)
168 return ExitWindowsEx( EWX_LOGOFF
, 0xffffffff );
172 /***********************************************************************
173 * ExitWindowsExec (USER.246)
175 BOOL16 WINAPI
ExitWindowsExec16( LPCSTR lpszExe
, LPCSTR lpszParams
)
177 TRACE_(system
)("Should run the following in DOS-mode: \"%s %s\"\n",
178 lpszExe
, lpszParams
);
179 return ExitWindowsEx( EWX_LOGOFF
, 0xffffffff );
183 /***********************************************************************
184 * ExitWindowsEx (USER32.@)
186 BOOL WINAPI
ExitWindowsEx( UINT flags
, DWORD reserved
)
192 /* We have to build a list of all windows first, as in EnumWindows */
194 if (!(list
= WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL
)))
196 WIN_ReleaseDesktop();
200 /* Send a WM_QUERYENDSESSION message to every window */
202 for (ppWnd
= list
, i
= 0; *ppWnd
; ppWnd
++, i
++)
204 /* Make sure that the window still exists */
205 if (!IsWindow( (*ppWnd
)->hwndSelf
)) continue;
206 if (!SendMessage16( (*ppWnd
)->hwndSelf
, WM_QUERYENDSESSION
, 0, 0 ))
211 /* Now notify all windows that got a WM_QUERYENDSESSION of the result */
213 for (ppWnd
= list
; i
> 0; i
--, ppWnd
++)
215 if (!IsWindow( (*ppWnd
)->hwndSelf
)) continue;
216 SendMessage16( (*ppWnd
)->hwndSelf
, WM_ENDSESSION
, result
, 0 );
218 WIN_ReleaseWinArray(list
);
220 if (result
) ExitKernel16();
221 WIN_ReleaseDesktop();
225 static void _dump_CDS_flags(DWORD flags
) {
226 #define X(x) if (flags & CDS_##x) MESSAGE(""#x ",");
227 X(UPDATEREGISTRY
);X(TEST
);X(FULLSCREEN
);X(GLOBAL
);
228 X(SET_PRIMARY
);X(RESET
);X(SETRECT
);X(NORESET
);
232 /***********************************************************************
233 * ChangeDisplaySettingsA (USER32.@)
235 LONG WINAPI
ChangeDisplaySettingsA( LPDEVMODEA devmode
, DWORD flags
)
237 FIXME_(system
)("(%p,0x%08lx), stub\n",devmode
,flags
);
238 MESSAGE("\tflags=");_dump_CDS_flags(flags
);MESSAGE("\n");
240 FIXME_(system
)(" devmode=NULL (return to default mode)\n");
241 else if ( (devmode
->dmBitsPerPel
!= GetSystemMetrics(SM_WINE_BPP
))
242 || (devmode
->dmPelsHeight
!= GetSystemMetrics(SM_CYSCREEN
))
243 || (devmode
->dmPelsWidth
!= GetSystemMetrics(SM_CXSCREEN
)) )
247 if (devmode
->dmFields
& DM_BITSPERPEL
)
248 FIXME_(system
)(" bpp=%ld\n",devmode
->dmBitsPerPel
);
249 if (devmode
->dmFields
& DM_PELSWIDTH
)
250 FIXME_(system
)(" width=%ld\n",devmode
->dmPelsWidth
);
251 if (devmode
->dmFields
& DM_PELSHEIGHT
)
252 FIXME_(system
)(" height=%ld\n",devmode
->dmPelsHeight
);
253 FIXME_(system
)(" (Putting X in this mode beforehand might help)\n");
254 /* we don't, but the program ... does not need to know */
255 return DISP_CHANGE_SUCCESSFUL
;
257 return DISP_CHANGE_SUCCESSFUL
;
260 /***********************************************************************
261 * ChangeDisplaySettings (USER.620)
263 LONG WINAPI
ChangeDisplaySettings16( LPDEVMODEA devmode
, DWORD flags
)
265 TRACE_(system
)("(%p,0x%08lx), stub\n",devmode
,flags
);
266 return ChangeDisplaySettingsA(devmode
, flags
);
269 /***********************************************************************
270 * ChangeDisplaySettingsExA (USER32.@)
272 LONG WINAPI
ChangeDisplaySettingsExA(
273 LPCSTR devname
, LPDEVMODEA devmode
, HWND hwnd
, DWORD flags
,
276 FIXME_(system
)("(%s,%p,0x%04x,0x%08lx,0x%08lx), stub\n",devname
,devmode
,hwnd
,flags
,lparam
);
277 MESSAGE("\tflags=");_dump_CDS_flags(flags
);MESSAGE("\n");
279 FIXME_(system
)(" devmode=NULL (return to default mode)\n");
280 else if ( (devmode
->dmBitsPerPel
!= GetSystemMetrics(SM_WINE_BPP
))
281 || (devmode
->dmPelsHeight
!= GetSystemMetrics(SM_CYSCREEN
))
282 || (devmode
->dmPelsWidth
!= GetSystemMetrics(SM_CXSCREEN
)) )
286 if (devmode
->dmFields
& DM_BITSPERPEL
)
287 FIXME_(system
)(" bpp=%ld\n",devmode
->dmBitsPerPel
);
288 if (devmode
->dmFields
& DM_PELSWIDTH
)
289 FIXME_(system
)(" width=%ld\n",devmode
->dmPelsWidth
);
290 if (devmode
->dmFields
& DM_PELSHEIGHT
)
291 FIXME_(system
)(" height=%ld\n",devmode
->dmPelsHeight
);
292 FIXME_(system
)(" (Putting X in this mode beforehand might help)\n");
293 /* we don't, but the program ... does not need to know */
294 return DISP_CHANGE_SUCCESSFUL
;
296 return DISP_CHANGE_SUCCESSFUL
;
299 /***********************************************************************
300 * EnumDisplaySettingsA (USER32.@)
301 * FIXME: Currently uses static list of modes.
304 * TRUE if nth setting exists found (described in the LPDEVMODEA struct)
305 * FALSE if we do not have the nth setting
307 BOOL WINAPI
EnumDisplaySettingsA(
308 LPCSTR name
, /* [in] huh? */
309 DWORD n
, /* [in] nth entry in display settings list*/
310 LPDEVMODEA devmode
/* [out] devmode for that setting */
316 } modes
[NRMODES
]={{512,384},{640,400},{640,480},{800,600},{1024,768}};
317 int depths
[4] = {8,16,24,32};
319 TRACE_(system
)("(%s,%ld,%p)\n",name
,n
,devmode
);
320 devmode
->dmDisplayFlags
= 0;
321 devmode
->dmDisplayFrequency
= 85;
322 if (n
==0 || n
== (DWORD
)-1 || n
== (DWORD
)-2) {
323 devmode
->dmBitsPerPel
= GetSystemMetrics(SM_WINE_BPP
);
324 devmode
->dmPelsHeight
= GetSystemMetrics(SM_CYSCREEN
);
325 devmode
->dmPelsWidth
= GetSystemMetrics(SM_CXSCREEN
);
328 if ((n
-1)<NRMODES
*NRDEPTHS
) {
329 devmode
->dmBitsPerPel
= depths
[(n
-1)/NRMODES
];
330 devmode
->dmPelsHeight
= modes
[(n
-1)%NRMODES
].h
;
331 devmode
->dmPelsWidth
= modes
[(n
-1)%NRMODES
].w
;
337 /***********************************************************************
338 * EnumDisplaySettingsW (USER32.@)
340 BOOL WINAPI
EnumDisplaySettingsW(LPCWSTR name
,DWORD n
,LPDEVMODEW devmode
) {
341 LPSTR nameA
= HEAP_strdupWtoA(GetProcessHeap(),0,name
);
343 BOOL ret
= EnumDisplaySettingsA(nameA
,n
,&devmodeA
);
346 devmode
->dmBitsPerPel
= devmodeA
.dmBitsPerPel
;
347 devmode
->dmPelsHeight
= devmodeA
.dmPelsHeight
;
348 devmode
->dmPelsWidth
= devmodeA
.dmPelsWidth
;
349 devmode
->dmDisplayFlags
= devmodeA
.dmDisplayFlags
;
350 devmode
->dmDisplayFrequency
= devmodeA
.dmDisplayFrequency
;
351 /* FIXME: convert rest too, if they are ever returned */
353 HeapFree(GetProcessHeap(),0,nameA
);
357 /***********************************************************************
358 * EnumDisplaySettings (USER.621)
360 BOOL16 WINAPI
EnumDisplaySettings16(
361 LPCSTR name
, /* [in] huh? */
362 DWORD n
, /* [in] nth entry in display settings list*/
363 LPDEVMODEA devmode
/* [out] devmode for that setting */
365 TRACE_(system
)("(%s, %ld, %p)\n", name
, n
, devmode
);
366 return (BOOL16
)EnumDisplaySettingsA(name
, n
, devmode
);
369 /***********************************************************************
370 * EnumDisplaySettingsExA (USER32.@)
372 BOOL WINAPI
EnumDisplaySettingsExA(LPCSTR lpszDeviceName
, DWORD iModeNum
,
373 LPDEVMODEA lpDevMode
, DWORD dwFlags
)
375 TRACE_(system
)("(%s,%lu,%p,%08lx): stub\n",
376 debugstr_a(lpszDeviceName
), iModeNum
, lpDevMode
, dwFlags
);
378 return EnumDisplaySettingsA(lpszDeviceName
, iModeNum
, lpDevMode
);
381 /***********************************************************************
382 * EnumDisplaySettingsExW (USER32.@)
384 BOOL WINAPI
EnumDisplaySettingsExW(LPCWSTR lpszDeviceName
, DWORD iModeNum
,
385 LPDEVMODEW lpDevMode
, DWORD dwFlags
)
387 TRACE_(system
)("(%s,%lu,%p,%08lx): stub\n",
388 debugstr_w(lpszDeviceName
), iModeNum
, lpDevMode
, dwFlags
);
390 return EnumDisplaySettingsW(lpszDeviceName
, iModeNum
, lpDevMode
);
393 /***********************************************************************
394 * EnumDisplayDevicesA (USER32.@)
396 BOOL WINAPI
EnumDisplayDevicesA(
397 LPVOID unused
,DWORD i
,LPDISPLAY_DEVICEA lpDisplayDevice
,DWORD dwFlags
401 FIXME_(system
)("(%p,%ld,%p,0x%08lx), stub!\n",unused
,i
,lpDisplayDevice
,dwFlags
);
402 strcpy(lpDisplayDevice
->DeviceName
,"X11");
403 strcpy(lpDisplayDevice
->DeviceString
,"X 11 Windowing System");
404 lpDisplayDevice
->StateFlags
=
405 DISPLAY_DEVICE_ATTACHED_TO_DESKTOP
|
406 DISPLAY_DEVICE_PRIMARY_DEVICE
|
407 DISPLAY_DEVICE_VGA_COMPATIBLE
;
411 /***********************************************************************
412 * EnumDisplayDevicesW (USER32.@)
414 BOOL WINAPI
EnumDisplayDevicesW(
415 LPVOID unused
,DWORD i
,LPDISPLAY_DEVICEW lpDisplayDevice
,DWORD dwFlags
419 FIXME_(system
)("(%p,%ld,%p,0x%08lx), stub!\n",unused
,i
,lpDisplayDevice
,dwFlags
);
420 MultiByteToWideChar( CP_ACP
, 0, "X11", -1, lpDisplayDevice
->DeviceName
,
421 sizeof(lpDisplayDevice
->DeviceName
)/sizeof(WCHAR
) );
422 MultiByteToWideChar( CP_ACP
, 0, "X11 Windowing System", -1, lpDisplayDevice
->DeviceString
,
423 sizeof(lpDisplayDevice
->DeviceString
)/sizeof(WCHAR
) );
424 lpDisplayDevice
->StateFlags
=
425 DISPLAY_DEVICE_ATTACHED_TO_DESKTOP
|
426 DISPLAY_DEVICE_PRIMARY_DEVICE
|
427 DISPLAY_DEVICE_VGA_COMPATIBLE
;
431 /***********************************************************************
432 * SetEventHook (USER.321)
434 * Used by Turbo Debugger for Windows
436 FARPROC16 WINAPI
SetEventHook16(FARPROC16 lpfnEventHook
)
438 FIXME_(hook
)("(lpfnEventHook=%08x): stub\n", (UINT
)lpfnEventHook
);
442 /***********************************************************************
443 * UserSeeUserDo (USER.216)
445 DWORD WINAPI
UserSeeUserDo16(WORD wReqType
, WORD wParam1
, WORD wParam2
, WORD wParam3
)
449 case USUD_LOCALALLOC
:
450 return LOCAL_Alloc(USER_HeapSel
, wParam1
, wParam3
);
452 return LOCAL_Free(USER_HeapSel
, wParam1
);
453 case USUD_LOCALCOMPACT
:
454 return LOCAL_Compact(USER_HeapSel
, wParam3
, 0);
457 case USUD_FIRSTCLASS
:
458 FIXME_(local
)("return a pointer to the first window class.\n");
461 WARN_(local
)("wReqType %04x (unknown)", wReqType
);
466 /***********************************************************************
467 * GetSystemDebugState (USER.231)
469 WORD WINAPI
GetSystemDebugState16(void)
471 return 0; /* FIXME */
474 /***********************************************************************
475 * RegisterLogonProcess (USER32.@)
477 DWORD WINAPI
RegisterLogonProcess(HANDLE hprocess
,BOOL x
) {
478 FIXME_(win32
)("(%d,%d),stub!\n",hprocess
,x
);
482 /***********************************************************************
483 * CreateWindowStationW (USER32.@)
485 HWINSTA WINAPI
CreateWindowStationW(
486 LPWSTR winstation
,DWORD res1
,DWORD desiredaccess
,
487 LPSECURITY_ATTRIBUTES lpsa
489 FIXME_(win32
)("(%s,0x%08lx,0x%08lx,%p),stub!\n",debugstr_w(winstation
),
490 res1
,desiredaccess
,lpsa
492 return (HWINSTA
)0xdeadcafe;
495 /***********************************************************************
496 * SetProcessWindowStation (USER32.@)
498 BOOL WINAPI
SetProcessWindowStation(HWINSTA hWinSta
) {
499 FIXME_(win32
)("(%d),stub!\n",hWinSta
);
503 /***********************************************************************
504 * SetUserObjectSecurity (USER32.@)
506 BOOL WINAPI
SetUserObjectSecurity(
508 PSECURITY_INFORMATION pSIRequested
,
509 PSECURITY_DESCRIPTOR pSID
511 FIXME_(win32
)("(0x%08x,%p,%p),stub!\n",hObj
,pSIRequested
,pSID
);
515 /***********************************************************************
516 * CreateDesktopA (USER32.@)
518 HDESK WINAPI
CreateDesktopA(
519 LPSTR lpszDesktop
,LPSTR lpszDevice
,LPDEVMODEA pDevmode
,
520 DWORD dwFlags
,DWORD dwDesiredAccess
,LPSECURITY_ATTRIBUTES lpsa
522 FIXME_(win32
)("(%s,%s,%p,0x%08lx,0x%08lx,%p),stub!\n",
523 lpszDesktop
,lpszDevice
,pDevmode
,
524 dwFlags
,dwDesiredAccess
,lpsa
526 return (HDESK
)0xcafedead;
529 /***********************************************************************
530 * CreateDesktopW (USER32.@)
532 HDESK WINAPI
CreateDesktopW(
533 LPWSTR lpszDesktop
,LPWSTR lpszDevice
,LPDEVMODEW pDevmode
,
534 DWORD dwFlags
,DWORD dwDesiredAccess
,LPSECURITY_ATTRIBUTES lpsa
536 FIXME_(win32
)("(%s,%s,%p,0x%08lx,0x%08lx,%p),stub!\n",
537 debugstr_w(lpszDesktop
),debugstr_w(lpszDevice
),pDevmode
,
538 dwFlags
,dwDesiredAccess
,lpsa
540 return (HDESK
)0xcafedead;
543 /***********************************************************************
544 * EnumDesktopWindows (USER32.@)
546 BOOL WINAPI
EnumDesktopWindows( HDESK hDesktop
, WNDENUMPROC lpfn
, LPARAM lParam
) {
547 FIXME_(win32
)("(0x%08x, %p, 0x%08lx), stub!\n", hDesktop
, lpfn
, lParam
);
552 /***********************************************************************
553 * CloseWindowStation (USER32.@)
555 BOOL WINAPI
CloseWindowStation(HWINSTA hWinSta
)
557 FIXME_(win32
)("(0x%08x)\n", hWinSta
);
561 /***********************************************************************
562 * CloseDesktop (USER32.@)
564 BOOL WINAPI
CloseDesktop(HDESK hDesk
)
566 FIXME_(win32
)("(0x%08x)\n", hDesk
);
570 /***********************************************************************
571 * SetWindowStationUser (USER32.@)
573 DWORD WINAPI
SetWindowStationUser(DWORD x1
,DWORD x2
) {
574 FIXME_(win32
)("(0x%08lx,0x%08lx),stub!\n",x1
,x2
);
578 /***********************************************************************
579 * SetLogonNotifyWindow (USER32.@)
581 DWORD WINAPI
SetLogonNotifyWindow(HWINSTA hwinsta
,HWND hwnd
) {
582 FIXME_(win32
)("(0x%x,%04x),stub!\n",hwinsta
,hwnd
);
586 /***********************************************************************
587 * LoadLocalFonts (USER32.@)
589 VOID WINAPI
LoadLocalFonts(VOID
) {
593 /***********************************************************************
594 * GetUserObjectInformationA (USER32.@)
596 BOOL WINAPI
GetUserObjectInformationA( HANDLE hObj
, INT nIndex
, LPVOID pvInfo
, DWORD nLength
, LPDWORD lpnLen
)
597 { FIXME_(win32
)("(0x%x %i %p %ld %p),stub!\n", hObj
, nIndex
, pvInfo
, nLength
, lpnLen
);
600 /***********************************************************************
601 * GetUserObjectInformationW (USER32.@)
603 BOOL WINAPI
GetUserObjectInformationW( HANDLE hObj
, INT nIndex
, LPVOID pvInfo
, DWORD nLength
, LPDWORD lpnLen
)
604 { FIXME_(win32
)("(0x%x %i %p %ld %p),stub!\n", hObj
, nIndex
, pvInfo
, nLength
, lpnLen
);
607 /***********************************************************************
608 * GetUserObjectSecurity (USER32.@)
610 BOOL WINAPI
GetUserObjectSecurity(HANDLE hObj
, PSECURITY_INFORMATION pSIRequested
,
611 PSECURITY_DESCRIPTOR pSID
, DWORD nLength
, LPDWORD lpnLengthNeeded
)
612 { FIXME_(win32
)("(0x%x %p %p len=%ld %p),stub!\n", hObj
, pSIRequested
, pSID
, nLength
, lpnLengthNeeded
);
616 /***********************************************************************
617 * SetSystemCursor (USER32.@)
619 BOOL WINAPI
SetSystemCursor(HCURSOR hcur
, DWORD id
)
620 { FIXME_(win32
)("(%08x,%08lx),stub!\n", hcur
, id
);
624 /***********************************************************************
625 * RegisterSystemThread (USER32.@)
627 void WINAPI
RegisterSystemThread(DWORD flags
, DWORD reserved
)
629 FIXME_(win32
)("(%08lx, %08lx)\n", flags
, reserved
);
632 /***********************************************************************
633 * RegisterDeviceNotificationA (USER32.@)
635 HDEVNOTIFY WINAPI
RegisterDeviceNotificationA(
636 HANDLE hnd
, LPVOID notifyfilter
, DWORD flags
638 FIXME_(win32
)("(hwnd=%08x, filter=%p,flags=0x%08lx), STUB!\n",
639 hnd
,notifyfilter
,flags