4 * Copyright 1993 Robert J. Amstadt
9 #include "wine/winbase16.h"
19 #include "clipboard.h"
21 #include "cursoricon.h"
26 #include "sysmetrics.h"
30 #include "debugtools.h"
32 DECLARE_DEBUG_CHANNEL(hook
);
33 DECLARE_DEBUG_CHANNEL(local
);
34 DECLARE_DEBUG_CHANNEL(system
);
35 DECLARE_DEBUG_CHANNEL(win
);
36 DECLARE_DEBUG_CHANNEL(win32
);
38 /***********************************************************************
39 * GetFreeSystemResources (USER.284)
41 WORD WINAPI
GetFreeSystemResources16( WORD resType
)
45 int userPercent
, gdiPercent
;
47 if ((gdi_inst
= LoadLibrary16( "GDI" )) < 32) return 0;
48 gdi_heap
= GlobalHandleToSel16( gdi_inst
);
52 case GFSR_USERRESOURCES
:
53 userPercent
= (int)LOCAL_CountFree( USER_HeapSel
) * 100 /
54 LOCAL_HeapSize( USER_HeapSel
);
58 case GFSR_GDIRESOURCES
:
59 gdiPercent
= (int)LOCAL_CountFree( gdi_inst
) * 100 /
60 LOCAL_HeapSize( gdi_inst
);
64 case GFSR_SYSTEMRESOURCES
:
65 userPercent
= (int)LOCAL_CountFree( USER_HeapSel
) * 100 /
66 LOCAL_HeapSize( USER_HeapSel
);
67 gdiPercent
= (int)LOCAL_CountFree( gdi_inst
) * 100 /
68 LOCAL_HeapSize( gdi_inst
);
72 userPercent
= gdiPercent
= 0;
75 FreeLibrary16( gdi_inst
);
76 return (WORD
)min( userPercent
, gdiPercent
);
80 /**********************************************************************
83 INT16 WINAPI
InitApp16( HINSTANCE16 hInstance
)
85 /* Hack: restore the divide-by-zero handler */
86 /* FIXME: should set a USER-specific handler that displays a msg box */
87 INT_SetPMHandler( 0, INT_GetPMHandler( 0xff ) );
89 /* Create task message queue */
90 if ( !GetFastQueue16() ) return 0;
95 /**********************************************************************
98 static void USER_ModuleUnload( HMODULE16 hModule
)
100 HOOK_FreeModuleHooks( hModule
);
101 CLASS_FreeModuleClasses( hModule
);
102 CURSORICON_FreeModuleIcons( hModule
);
105 /**********************************************************************
108 static void USER_QueueCleanup( HQUEUE16 hQueue
)
112 WND
* desktop
= WIN_GetDesktop();
114 /* Patch desktop window */
115 if ( desktop
->hmemTaskQ
== hQueue
)
117 HTASK16 nextTask
= TASK_GetNextTask( GetCurrentTask() );
118 desktop
->hmemTaskQ
= GetTaskQueue16( nextTask
);
121 /* Patch resident popup menu window */
122 MENU_PatchResidentPopup( hQueue
, NULL
);
124 TIMER_RemoveQueueTimers( hQueue
);
126 HOOK_FreeQueueHooks( hQueue
);
128 QUEUE_SetExitingQueue( hQueue
);
129 WIN_ResetQueueWindows( desktop
, hQueue
, (HQUEUE16
)0);
130 QUEUE_SetExitingQueue( 0 );
132 /* Free the message queue */
133 QUEUE_DeleteMsgQueue( hQueue
);
135 WIN_ReleaseDesktop();
139 /**********************************************************************
142 static void USER_AppExit( HINSTANCE16 hInstance
)
144 /* FIXME: maybe destroy menus (Windows only complains about them
148 /* ModuleUnload() in "Internals" */
150 hInstance
= GetExePtr( hInstance
);
151 if( GetModuleUsage16( hInstance
) <= 1 )
152 USER_ModuleUnload( hInstance
);
156 /***********************************************************************
157 * USER_SignalProc (USER.314)
159 void WINAPI
USER_SignalProc( HANDLE16 hTaskOrModule
, UINT16 uCode
,
160 UINT16 uExitFn
, HINSTANCE16 hInstance
,
163 FIXME_(win
)("Win 3.1 USER signal %04x\n", uCode
);
166 /***********************************************************************
167 * FinalUserInit (USER.400)
169 void WINAPI
FinalUserInit16( void )
171 /* FIXME: Should chain to FinalGdiInit now. */
174 /***********************************************************************
175 * UserSignalProc (USER.610) (USER32.559)
177 * For comments about the meaning of uCode and dwFlags
178 * see PROCESS_CallUserSignalProc.
181 WORD WINAPI
UserSignalProc( UINT uCode
, DWORD dwThreadOrProcessID
,
182 DWORD dwFlags
, HMODULE16 hModule
)
186 /* FIXME: Proper reaction to most signals still missing. */
190 case USIG_DLL_UNLOAD_WIN16
:
191 case USIG_DLL_UNLOAD_WIN32
:
192 USER_ModuleUnload( hModule
);
195 case USIG_DLL_UNLOAD_ORPHANS
:
198 case USIG_FAULT_DIALOG_PUSH
:
199 case USIG_FAULT_DIALOG_POP
:
202 case USIG_THREAD_INIT
:
205 case USIG_THREAD_EXIT
:
206 USER_QueueCleanup( GetThreadQueue16( dwThreadOrProcessID
) );
207 SetThreadQueue16( dwThreadOrProcessID
, 0 );
210 case USIG_PROCESS_CREATE
:
213 case USIG_PROCESS_INIT
:
214 case USIG_PROCESS_LOADED
:
216 case USIG_PROCESS_RUNNING
:
219 case USIG_PROCESS_EXIT
:
222 case USIG_PROCESS_DESTROY
:
223 hInst
= ((TDB
*)GlobalLock16( GetCurrentTask() ))->hInstance
;
224 USER_AppExit( hInst
);
228 FIXME_(win
)("(%04x, %08lx, %04lx, %04x)\n",
229 uCode
, dwThreadOrProcessID
, dwFlags
, hModule
);
233 /* FIXME: Should chain to GdiSignalProc now. */
238 /***********************************************************************
239 * USER_DllEntryPoint (USER.374)
241 BOOL WINAPI
USER_DllEntryPoint( DWORD dwReason
, HINSTANCE hInstDLL
, WORD ds
,
242 WORD wHeapSize
, DWORD dwReserved1
, WORD wReserved2
)
246 case DLL_PROCESS_ATTACH
:
248 * We need to load the 32-bit library so as to be able
249 * to access the system resources stored there!
251 if ( !LoadLibraryA("USER32.DLL") )
253 ERR_(win
)( "Could not load USER32.DLL\n" );
262 /***********************************************************************
263 * ExitWindows16 (USER.7)
265 BOOL16 WINAPI
ExitWindows16( DWORD dwReturnCode
, UINT16 wReserved
)
267 return ExitWindowsEx( EWX_LOGOFF
, 0xffffffff );
271 /***********************************************************************
272 * ExitWindowsExec16 (USER.246)
274 BOOL16 WINAPI
ExitWindowsExec16( LPCSTR lpszExe
, LPCSTR lpszParams
)
276 TRACE_(system
)("Should run the following in DOS-mode: \"%s %s\"\n",
277 lpszExe
, lpszParams
);
278 return ExitWindowsEx( EWX_LOGOFF
, 0xffffffff );
282 /***********************************************************************
283 * ExitWindowsEx (USER32.196)
285 BOOL WINAPI
ExitWindowsEx( UINT flags
, DWORD reserved
)
291 /* We have to build a list of all windows first, as in EnumWindows */
293 if (!(list
= WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL
)))
295 WIN_ReleaseDesktop();
299 /* Send a WM_QUERYENDSESSION message to every window */
301 for (ppWnd
= list
, i
= 0; *ppWnd
; ppWnd
++, i
++)
303 /* Make sure that the window still exists */
304 if (!IsWindow( (*ppWnd
)->hwndSelf
)) continue;
305 if (!SendMessage16( (*ppWnd
)->hwndSelf
, WM_QUERYENDSESSION
, 0, 0 ))
310 /* Now notify all windows that got a WM_QUERYENDSESSION of the result */
312 for (ppWnd
= list
; i
> 0; i
--, ppWnd
++)
314 if (!IsWindow( (*ppWnd
)->hwndSelf
)) continue;
315 SendMessage16( (*ppWnd
)->hwndSelf
, WM_ENDSESSION
, result
, 0 );
317 WIN_ReleaseWinArray(list
);
319 if (result
) ExitKernel16();
320 WIN_ReleaseDesktop();
324 static void _dump_CDS_flags(DWORD flags
) {
325 #define X(x) if (flags & CDS_##x) MESSAGE(""#x ",");
326 X(UPDATEREGISTRY
);X(TEST
);X(FULLSCREEN
);X(GLOBAL
);
327 X(SET_PRIMARY
);X(RESET
);X(SETRECT
);X(NORESET
);
331 /***********************************************************************
332 * ChangeDisplaySettingsA (USER32.589)
334 LONG WINAPI
ChangeDisplaySettingsA( LPDEVMODEA devmode
, DWORD flags
)
336 FIXME_(system
)("(%p,0x%08lx), stub\n",devmode
,flags
);
337 MESSAGE("\tflags=");_dump_CDS_flags(flags
);MESSAGE("\n");
339 FIXME_(system
)(" devmode=NULL (return to default mode)\n");
340 else if ( (devmode
->dmBitsPerPel
!= GetSystemMetrics(SM_WINE_BPP
))
341 || (devmode
->dmPelsHeight
!= GetSystemMetrics(SM_CYSCREEN
))
342 || (devmode
->dmPelsWidth
!= GetSystemMetrics(SM_CXSCREEN
)) )
346 if (devmode
->dmFields
& DM_BITSPERPEL
)
347 FIXME_(system
)(" bpp=%ld\n",devmode
->dmBitsPerPel
);
348 if (devmode
->dmFields
& DM_PELSWIDTH
)
349 FIXME_(system
)(" width=%ld\n",devmode
->dmPelsWidth
);
350 if (devmode
->dmFields
& DM_PELSHEIGHT
)
351 FIXME_(system
)(" height=%ld\n",devmode
->dmPelsHeight
);
352 FIXME_(system
)(" (Putting X in this mode beforehand might help)\n");
353 /* we don't, but the program ... does not need to know */
354 return DISP_CHANGE_SUCCESSFUL
;
356 return DISP_CHANGE_SUCCESSFUL
;
359 /***********************************************************************
360 * ChangeDisplaySettingsExA (USER32.604)
362 LONG WINAPI
ChangeDisplaySettingsExA(
363 LPCSTR devname
, LPDEVMODEA devmode
, HWND hwnd
, DWORD flags
,
366 FIXME_(system
)("(%s,%p,0x%04x,0x%08lx,0x%08lx), stub\n",devname
,devmode
,hwnd
,flags
,lparam
);
367 MESSAGE("\tflags=");_dump_CDS_flags(flags
);MESSAGE("\n");
369 FIXME_(system
)(" devmode=NULL (return to default mode)\n");
370 else if ( (devmode
->dmBitsPerPel
!= GetSystemMetrics(SM_WINE_BPP
))
371 || (devmode
->dmPelsHeight
!= GetSystemMetrics(SM_CYSCREEN
))
372 || (devmode
->dmPelsWidth
!= GetSystemMetrics(SM_CXSCREEN
)) )
376 if (devmode
->dmFields
& DM_BITSPERPEL
)
377 FIXME_(system
)(" bpp=%ld\n",devmode
->dmBitsPerPel
);
378 if (devmode
->dmFields
& DM_PELSWIDTH
)
379 FIXME_(system
)(" width=%ld\n",devmode
->dmPelsWidth
);
380 if (devmode
->dmFields
& DM_PELSHEIGHT
)
381 FIXME_(system
)(" height=%ld\n",devmode
->dmPelsHeight
);
382 FIXME_(system
)(" (Putting X in this mode beforehand might help)\n");
383 /* we don't, but the program ... does not need to know */
384 return DISP_CHANGE_SUCCESSFUL
;
386 return DISP_CHANGE_SUCCESSFUL
;
389 /***********************************************************************
390 * EnumDisplaySettingsA (USER32.592)
391 * FIXME: Currently uses static list of modes.
394 * TRUE if nth setting exists found (described in the LPDEVMODEA struct)
395 * FALSE if we do not have the nth setting
397 BOOL WINAPI
EnumDisplaySettingsA(
398 LPCSTR name
, /* [in] huh? */
399 DWORD n
, /* [in] nth entry in display settings list*/
400 LPDEVMODEA devmode
/* [out] devmode for that setting */
406 } modes
[NRMODES
]={{512,384},{640,400},{640,480},{800,600},{1024,768}};
407 int depths
[4] = {8,16,24,32};
409 TRACE_(system
)("(%s,%ld,%p)\n",name
,n
,devmode
);
411 devmode
->dmBitsPerPel
= GetSystemMetrics(SM_WINE_BPP
);
412 devmode
->dmPelsHeight
= GetSystemMetrics(SM_CYSCREEN
);
413 devmode
->dmPelsWidth
= GetSystemMetrics(SM_CXSCREEN
);
416 if ((n
-1)<NRMODES
*NRDEPTHS
) {
417 devmode
->dmBitsPerPel
= depths
[(n
-1)/NRMODES
];
418 devmode
->dmPelsHeight
= modes
[(n
-1)%NRMODES
].h
;
419 devmode
->dmPelsWidth
= modes
[(n
-1)%NRMODES
].w
;
425 /***********************************************************************
426 * EnumDisplaySettingsW (USER32.593)
428 BOOL WINAPI
EnumDisplaySettingsW(LPCWSTR name
,DWORD n
,LPDEVMODEW devmode
) {
429 LPSTR nameA
= HEAP_strdupWtoA(GetProcessHeap(),0,name
);
431 BOOL ret
= EnumDisplaySettingsA(nameA
,n
,&devmodeA
);
434 devmode
->dmBitsPerPel
= devmodeA
.dmBitsPerPel
;
435 devmode
->dmPelsHeight
= devmodeA
.dmPelsHeight
;
436 devmode
->dmPelsWidth
= devmodeA
.dmPelsWidth
;
437 /* FIXME: convert rest too, if they are ever returned */
439 HeapFree(GetProcessHeap(),0,nameA
);
443 /***********************************************************************
444 * EnumDisplayDevicesA (USER32.184)
446 BOOL WINAPI
EnumDisplayDevicesA(
447 LPVOID unused
,DWORD i
,LPDISPLAY_DEVICEA lpDisplayDevice
,DWORD dwFlags
451 FIXME_(system
)("(%p,%ld,%p,0x%08lx), stub!\n",unused
,i
,lpDisplayDevice
,dwFlags
);
452 strcpy(lpDisplayDevice
->DeviceName
,"X11");
453 strcpy(lpDisplayDevice
->DeviceString
,"X 11 Windowing System");
454 lpDisplayDevice
->StateFlags
=
455 DISPLAY_DEVICE_ATTACHED_TO_DESKTOP
|
456 DISPLAY_DEVICE_PRIMARY_DEVICE
|
457 DISPLAY_DEVICE_VGA_COMPATIBLE
;
461 /***********************************************************************
462 * EnumDisplayDevicesW (USER32.185)
464 BOOL WINAPI
EnumDisplayDevicesW(
465 LPVOID unused
,DWORD i
,LPDISPLAY_DEVICEW lpDisplayDevice
,DWORD dwFlags
469 FIXME_(system
)("(%p,%ld,%p,0x%08lx), stub!\n",unused
,i
,lpDisplayDevice
,dwFlags
);
470 MultiByteToWideChar( CP_ACP
, 0, "X11", -1, lpDisplayDevice
->DeviceName
,
471 sizeof(lpDisplayDevice
->DeviceName
)/sizeof(WCHAR
) );
472 MultiByteToWideChar( CP_ACP
, 0, "X11 Windowing System", -1, lpDisplayDevice
->DeviceString
,
473 sizeof(lpDisplayDevice
->DeviceString
)/sizeof(WCHAR
) );
474 lpDisplayDevice
->StateFlags
=
475 DISPLAY_DEVICE_ATTACHED_TO_DESKTOP
|
476 DISPLAY_DEVICE_PRIMARY_DEVICE
|
477 DISPLAY_DEVICE_VGA_COMPATIBLE
;
481 /***********************************************************************
482 * SetEventHook (USER.321)
484 * Used by Turbo Debugger for Windows
486 FARPROC16 WINAPI
SetEventHook16(FARPROC16 lpfnEventHook
)
488 FIXME_(hook
)("(lpfnEventHook=%08x): stub\n", (UINT
)lpfnEventHook
);
492 /***********************************************************************
493 * UserSeeUserDo (USER.216)
495 DWORD WINAPI
UserSeeUserDo16(WORD wReqType
, WORD wParam1
, WORD wParam2
, WORD wParam3
)
499 case USUD_LOCALALLOC
:
500 return LOCAL_Alloc(USER_HeapSel
, wParam1
, wParam3
);
502 return LOCAL_Free(USER_HeapSel
, wParam1
);
503 case USUD_LOCALCOMPACT
:
504 return LOCAL_Compact(USER_HeapSel
, wParam3
, 0);
507 case USUD_FIRSTCLASS
:
508 FIXME_(local
)("return a pointer to the first window class.\n");
511 WARN_(local
)("wReqType %04x (unknown)", wReqType
);
516 /***********************************************************************
517 * GetSystemDebugState16 (USER.231)
519 WORD WINAPI
GetSystemDebugState16(void)
521 return 0; /* FIXME */
524 /***********************************************************************
525 * RegisterLogonProcess (USER32.434)
527 DWORD WINAPI
RegisterLogonProcess(HANDLE hprocess
,BOOL x
) {
528 FIXME_(win32
)("(%d,%d),stub!\n",hprocess
,x
);
532 /***********************************************************************
533 * CreateWindowStationW (USER32.86)
535 HWINSTA WINAPI
CreateWindowStationW(
536 LPWSTR winstation
,DWORD res1
,DWORD desiredaccess
,
537 LPSECURITY_ATTRIBUTES lpsa
539 FIXME_(win32
)("(%s,0x%08lx,0x%08lx,%p),stub!\n",debugstr_w(winstation
),
540 res1
,desiredaccess
,lpsa
545 /***********************************************************************
546 * SetProcessWindowStation (USER32.496)
548 BOOL WINAPI
SetProcessWindowStation(HWINSTA hWinSta
) {
549 FIXME_(win32
)("(%d),stub!\n",hWinSta
);
553 /***********************************************************************
554 * SetUserObjectSecurity (USER32.514)
556 BOOL WINAPI
SetUserObjectSecurity(
558 PSECURITY_INFORMATION pSIRequested
,
559 PSECURITY_DESCRIPTOR pSID
561 FIXME_(win32
)("(0x%08x,%p,%p),stub!\n",hObj
,pSIRequested
,pSID
);
565 /***********************************************************************
566 * CreateDesktopA (USER32.68)
568 HDESK WINAPI
CreateDesktopA(
569 LPSTR lpszDesktop
,LPSTR lpszDevice
,LPDEVMODEA pDevmode
,
570 DWORD dwFlags
,DWORD dwDesiredAccess
,LPSECURITY_ATTRIBUTES lpsa
572 FIXME_(win32
)("(%s,%s,%p,0x%08lx,0x%08lx,%p),stub!\n",
573 lpszDesktop
,lpszDevice
,pDevmode
,
574 dwFlags
,dwDesiredAccess
,lpsa
579 /***********************************************************************
580 * CreateDesktopW (USER32.69)
582 HDESK WINAPI
CreateDesktopW(
583 LPWSTR lpszDesktop
,LPWSTR lpszDevice
,LPDEVMODEW pDevmode
,
584 DWORD dwFlags
,DWORD dwDesiredAccess
,LPSECURITY_ATTRIBUTES lpsa
586 FIXME_(win32
)("(%s,%s,%p,0x%08lx,0x%08lx,%p),stub!\n",
587 debugstr_w(lpszDesktop
),debugstr_w(lpszDevice
),pDevmode
,
588 dwFlags
,dwDesiredAccess
,lpsa
593 /***********************************************************************
594 * EnumDesktopWindows (USER32.591)
596 BOOL WINAPI
EnumDesktopWindows( HDESK hDesktop
, WNDENUMPROC lpfn
, LPARAM lParam
) {
597 FIXME_(win32
)("(0x%08x, %p, 0x%08lx), stub!\n", hDesktop
, lpfn
, lParam
);
602 /***********************************************************************
605 BOOL WINAPI
CloseWindowStation(HWINSTA hWinSta
)
607 FIXME_(win32
)("(0x%08x)\n", hWinSta
);
611 /***********************************************************************
614 BOOL WINAPI
CloseDesktop(HDESK hDesk
)
616 FIXME_(win32
)("(0x%08x)\n", hDesk
);
620 /***********************************************************************
621 * SetWindowStationUser (USER32.521)
623 DWORD WINAPI
SetWindowStationUser(DWORD x1
,DWORD x2
) {
624 FIXME_(win32
)("(0x%08lx,0x%08lx),stub!\n",x1
,x2
);
628 /***********************************************************************
629 * SetLogonNotifyWindow (USER32.486)
631 DWORD WINAPI
SetLogonNotifyWindow(HWINSTA hwinsta
,HWND hwnd
) {
632 FIXME_(win32
)("(0x%x,%04x),stub!\n",hwinsta
,hwnd
);
636 /***********************************************************************
637 * LoadLocalFonts (USER32.486)
639 VOID WINAPI
LoadLocalFonts(VOID
) {
643 /***********************************************************************
644 * GetUserObjectInformationA (USER32.299)
646 BOOL WINAPI
GetUserObjectInformationA( HANDLE hObj
, INT nIndex
, LPVOID pvInfo
, DWORD nLength
, LPDWORD lpnLen
)
647 { FIXME_(win32
)("(0x%x %i %p %ld %p),stub!\n", hObj
, nIndex
, pvInfo
, nLength
, lpnLen
);
650 /***********************************************************************
651 * GetUserObjectInformationW (USER32.300)
653 BOOL WINAPI
GetUserObjectInformationW( HANDLE hObj
, INT nIndex
, LPVOID pvInfo
, DWORD nLength
, LPDWORD lpnLen
)
654 { FIXME_(win32
)("(0x%x %i %p %ld %p),stub!\n", hObj
, nIndex
, pvInfo
, nLength
, lpnLen
);
657 /***********************************************************************
658 * GetUserObjectSecurity (USER32.300)
660 BOOL WINAPI
GetUserObjectSecurity(HANDLE hObj
, PSECURITY_INFORMATION pSIRequested
,
661 PSECURITY_DESCRIPTOR pSID
, DWORD nLength
, LPDWORD lpnLengthNeeded
)
662 { FIXME_(win32
)("(0x%x %p %p len=%ld %p),stub!\n", hObj
, pSIRequested
, pSID
, nLength
, lpnLengthNeeded
);
666 /***********************************************************************
667 * SetSystemCursor (USER32.507)
669 BOOL WINAPI
SetSystemCursor(HCURSOR hcur
, DWORD id
)
670 { FIXME_(win32
)("(%08x,%08lx),stub!\n", hcur
, id
);
674 /***********************************************************************
675 * RegisterSystemThread (USER32.435)
677 void WINAPI
RegisterSystemThread(DWORD flags
, DWORD reserved
)
679 FIXME_(win32
)("(%08lx, %08lx)\n", flags
, reserved
);
682 /***********************************************************************
683 * RegisterDeviceNotificationA (USER32.477)
685 HDEVNOTIFY WINAPI
RegisterDeviceNotificationA(
686 HANDLE hnd
, LPVOID notifyfilter
, DWORD flags
688 FIXME_(win32
)("(hwnd=%08x, filter=%p,flags=0x%08lx), STUB!\n",
689 hnd
,notifyfilter
,flags