4 * Copyright 1993 Robert J. Amstadt
9 #include "wine/winbase16.h"
13 #include "wine/winestring.h"
20 #include "clipboard.h"
22 #include "cursoricon.h"
28 #include "sysmetrics.h"
32 #include "debugtools.h"
34 DECLARE_DEBUG_CHANNEL(hook
);
35 DECLARE_DEBUG_CHANNEL(local
);
36 DECLARE_DEBUG_CHANNEL(system
);
37 DECLARE_DEBUG_CHANNEL(win
);
38 DECLARE_DEBUG_CHANNEL(win32
);
40 /***********************************************************************
41 * GetFreeSystemResources (USER.284)
43 WORD WINAPI
GetFreeSystemResources16( WORD resType
)
47 int userPercent
, gdiPercent
;
49 if ((gdi_inst
= LoadLibrary16( "GDI" )) < 32) return 0;
50 gdi_heap
= GlobalHandleToSel16( gdi_inst
);
54 case GFSR_USERRESOURCES
:
55 userPercent
= (int)LOCAL_CountFree( USER_HeapSel
) * 100 /
56 LOCAL_HeapSize( USER_HeapSel
);
60 case GFSR_GDIRESOURCES
:
61 gdiPercent
= (int)LOCAL_CountFree( gdi_inst
) * 100 /
62 LOCAL_HeapSize( gdi_inst
);
66 case GFSR_SYSTEMRESOURCES
:
67 userPercent
= (int)LOCAL_CountFree( USER_HeapSel
) * 100 /
68 LOCAL_HeapSize( USER_HeapSel
);
69 gdiPercent
= (int)LOCAL_CountFree( gdi_inst
) * 100 /
70 LOCAL_HeapSize( gdi_inst
);
74 userPercent
= gdiPercent
= 0;
77 FreeLibrary16( gdi_inst
);
78 return (WORD
)min( userPercent
, gdiPercent
);
82 /**********************************************************************
85 INT16 WINAPI
InitApp16( HINSTANCE16 hInstance
)
87 /* Hack: restore the divide-by-zero handler */
88 /* FIXME: should set a USER-specific handler that displays a msg box */
89 INT_SetPMHandler( 0, INT_GetPMHandler( 0xff ) );
91 /* Create task message queue */
92 if ( !GetFastQueue16() ) return 0;
97 /**********************************************************************
100 static void USER_ModuleUnload( HMODULE16 hModule
)
102 HOOK_FreeModuleHooks( hModule
);
103 CLASS_FreeModuleClasses( hModule
);
104 CURSORICON_FreeModuleIcons( hModule
);
107 /**********************************************************************
110 static void USER_QueueCleanup( HQUEUE16 hQueue
)
114 WND
* desktop
= WIN_GetDesktop();
116 /* Patch desktop window */
117 if ( desktop
->hmemTaskQ
== hQueue
)
119 HTASK16 nextTask
= TASK_GetNextTask( GetCurrentTask() );
120 desktop
->hmemTaskQ
= GetTaskQueue16( nextTask
);
123 /* Patch resident popup menu window */
124 MENU_PatchResidentPopup( hQueue
, NULL
);
126 TIMER_RemoveQueueTimers( hQueue
);
128 HOOK_FreeQueueHooks( hQueue
);
130 QUEUE_SetExitingQueue( hQueue
);
131 WIN_ResetQueueWindows( desktop
, hQueue
, (HQUEUE16
)0);
132 QUEUE_SetExitingQueue( 0 );
134 /* Free the message queue */
135 QUEUE_DeleteMsgQueue( hQueue
);
137 WIN_ReleaseDesktop();
141 /**********************************************************************
144 static void USER_AppExit( HINSTANCE16 hInstance
)
146 /* FIXME: maybe destroy menus (Windows only complains about them
150 /* ModuleUnload() in "Internals" */
152 hInstance
= GetExePtr( hInstance
);
153 if( GetModuleUsage16( hInstance
) <= 1 )
154 USER_ModuleUnload( hInstance
);
158 /***********************************************************************
159 * USER_SignalProc (USER.314)
161 void WINAPI
USER_SignalProc( HANDLE16 hTaskOrModule
, UINT16 uCode
,
162 UINT16 uExitFn
, HINSTANCE16 hInstance
,
165 FIXME_(win
)("Win 3.1 USER signal %04x\n", uCode
);
168 /***********************************************************************
169 * FinalUserInit (USER.400)
171 void WINAPI
FinalUserInit16( void )
173 /* FIXME: Should chain to FinalGdiInit now. */
176 /***********************************************************************
177 * UserSignalProc (USER.610) (USER32.559)
179 * For comments about the meaning of uCode and dwFlags
180 * see PROCESS_CallUserSignalProc.
183 WORD WINAPI
UserSignalProc( UINT uCode
, DWORD dwThreadOrProcessID
,
184 DWORD dwFlags
, HMODULE16 hModule
)
188 /* FIXME: Proper reaction to most signals still missing. */
192 case USIG_DLL_UNLOAD_WIN16
:
193 case USIG_DLL_UNLOAD_WIN32
:
194 USER_ModuleUnload( hModule
);
197 case USIG_DLL_UNLOAD_ORPHANS
:
200 case USIG_FAULT_DIALOG_PUSH
:
201 case USIG_FAULT_DIALOG_POP
:
204 case USIG_THREAD_INIT
:
207 case USIG_THREAD_EXIT
:
208 USER_QueueCleanup( GetThreadQueue16( dwThreadOrProcessID
) );
209 SetThreadQueue16( dwThreadOrProcessID
, 0 );
212 case USIG_PROCESS_CREATE
:
215 case USIG_PROCESS_INIT
:
216 case USIG_PROCESS_LOADED
:
218 case USIG_PROCESS_RUNNING
:
221 case USIG_PROCESS_EXIT
:
224 case USIG_PROCESS_DESTROY
:
225 hInst
= ((TDB
*)GlobalLock16( GetCurrentTask() ))->hInstance
;
226 USER_AppExit( hInst
);
230 FIXME_(win
)("(%04x, %08lx, %04lx, %04x)\n",
231 uCode
, dwThreadOrProcessID
, dwFlags
, hModule
);
235 /* FIXME: Should chain to GdiSignalProc now. */
240 /***********************************************************************
241 * USER_DllEntryPoint (USER.374)
243 BOOL WINAPI
USER_DllEntryPoint( DWORD dwReason
, HINSTANCE hInstDLL
, WORD ds
,
244 WORD wHeapSize
, DWORD dwReserved1
, WORD wReserved2
)
248 case DLL_PROCESS_ATTACH
:
250 * We need to load the 32-bit library so as to be able
251 * to access the system resources stored there!
253 if ( !LoadLibraryA("USER32.DLL") )
255 ERR_(win
)( "Could not load USER32.DLL\n" );
264 /***********************************************************************
265 * ExitWindows16 (USER.7)
267 BOOL16 WINAPI
ExitWindows16( DWORD dwReturnCode
, UINT16 wReserved
)
269 return ExitWindowsEx( EWX_LOGOFF
, 0xffffffff );
273 /***********************************************************************
274 * ExitWindowsExec16 (USER.246)
276 BOOL16 WINAPI
ExitWindowsExec16( LPCSTR lpszExe
, LPCSTR lpszParams
)
278 TRACE_(system
)("Should run the following in DOS-mode: \"%s %s\"\n",
279 lpszExe
, lpszParams
);
280 return ExitWindowsEx( EWX_LOGOFF
, 0xffffffff );
284 /***********************************************************************
285 * ExitWindowsEx (USER32.196)
287 BOOL WINAPI
ExitWindowsEx( UINT flags
, DWORD reserved
)
293 /* We have to build a list of all windows first, as in EnumWindows */
295 if (!(list
= WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL
)))
297 WIN_ReleaseDesktop();
301 /* Send a WM_QUERYENDSESSION message to every window */
303 for (ppWnd
= list
, i
= 0; *ppWnd
; ppWnd
++, i
++)
305 /* Make sure that the window still exists */
306 if (!IsWindow( (*ppWnd
)->hwndSelf
)) continue;
307 if (!SendMessage16( (*ppWnd
)->hwndSelf
, WM_QUERYENDSESSION
, 0, 0 ))
312 /* Now notify all windows that got a WM_QUERYENDSESSION of the result */
314 for (ppWnd
= list
; i
> 0; i
--, ppWnd
++)
316 if (!IsWindow( (*ppWnd
)->hwndSelf
)) continue;
317 SendMessage16( (*ppWnd
)->hwndSelf
, WM_ENDSESSION
, result
, 0 );
319 WIN_ReleaseWinArray(list
);
321 if (result
) ExitKernel16();
322 WIN_ReleaseDesktop();
326 static void _dump_CDS_flags(DWORD flags
) {
327 #define X(x) if (flags & CDS_##x) MESSAGE(""#x ",");
328 X(UPDATEREGISTRY
);X(TEST
);X(FULLSCREEN
);X(GLOBAL
);
329 X(SET_PRIMARY
);X(RESET
);X(SETRECT
);X(NORESET
);
333 /***********************************************************************
334 * ChangeDisplaySettingsA (USER32.589)
336 LONG WINAPI
ChangeDisplaySettingsA( LPDEVMODEA devmode
, DWORD flags
)
338 FIXME_(system
)("(%p,0x%08lx), stub\n",devmode
,flags
);
339 MESSAGE("\tflags=");_dump_CDS_flags(flags
);MESSAGE("\n");
341 FIXME_(system
)(" devmode=NULL (return to default mode)\n");
342 else if ( (devmode
->dmBitsPerPel
!= GetSystemMetrics(SM_WINE_BPP
))
343 || (devmode
->dmPelsHeight
!= GetSystemMetrics(SM_CYSCREEN
))
344 || (devmode
->dmPelsWidth
!= GetSystemMetrics(SM_CXSCREEN
)) )
348 if (devmode
->dmFields
& DM_BITSPERPEL
)
349 FIXME_(system
)(" bpp=%ld\n",devmode
->dmBitsPerPel
);
350 if (devmode
->dmFields
& DM_PELSWIDTH
)
351 FIXME_(system
)(" width=%ld\n",devmode
->dmPelsWidth
);
352 if (devmode
->dmFields
& DM_PELSHEIGHT
)
353 FIXME_(system
)(" height=%ld\n",devmode
->dmPelsHeight
);
354 FIXME_(system
)(" (Putting X in this mode beforehand might help)\n");
355 /* we don't, but the program ... does not need to know */
356 return DISP_CHANGE_SUCCESSFUL
;
358 return DISP_CHANGE_SUCCESSFUL
;
361 /***********************************************************************
362 * ChangeDisplaySettingsExA (USER32.604)
364 LONG WINAPI
ChangeDisplaySettingsExA(
365 LPCSTR devname
, LPDEVMODEA devmode
, HWND hwnd
, DWORD flags
,
368 FIXME_(system
)("(%s,%p,0x%04x,0x%08lx,0x%08lx), stub\n",devname
,devmode
,hwnd
,flags
,lparam
);
369 MESSAGE("\tflags=");_dump_CDS_flags(flags
);MESSAGE("\n");
371 FIXME_(system
)(" devmode=NULL (return to default mode)\n");
372 else if ( (devmode
->dmBitsPerPel
!= GetSystemMetrics(SM_WINE_BPP
))
373 || (devmode
->dmPelsHeight
!= GetSystemMetrics(SM_CYSCREEN
))
374 || (devmode
->dmPelsWidth
!= GetSystemMetrics(SM_CXSCREEN
)) )
378 if (devmode
->dmFields
& DM_BITSPERPEL
)
379 FIXME_(system
)(" bpp=%ld\n",devmode
->dmBitsPerPel
);
380 if (devmode
->dmFields
& DM_PELSWIDTH
)
381 FIXME_(system
)(" width=%ld\n",devmode
->dmPelsWidth
);
382 if (devmode
->dmFields
& DM_PELSHEIGHT
)
383 FIXME_(system
)(" height=%ld\n",devmode
->dmPelsHeight
);
384 FIXME_(system
)(" (Putting X in this mode beforehand might help)\n");
385 /* we don't, but the program ... does not need to know */
386 return DISP_CHANGE_SUCCESSFUL
;
388 return DISP_CHANGE_SUCCESSFUL
;
391 /***********************************************************************
392 * EnumDisplaySettingsA (USER32.592)
393 * FIXME: Currently uses static list of modes.
396 * TRUE if nth setting exists found (described in the LPDEVMODEA struct)
397 * FALSE if we do not have the nth setting
399 BOOL WINAPI
EnumDisplaySettingsA(
400 LPCSTR name
, /* [in] huh? */
401 DWORD n
, /* [in] nth entry in display settings list*/
402 LPDEVMODEA devmode
/* [out] devmode for that setting */
408 } modes
[NRMODES
]={{512,384},{640,400},{640,480},{800,600},{1024,768}};
409 int depths
[4] = {8,16,24,32};
411 TRACE_(system
)("(%s,%ld,%p)\n",name
,n
,devmode
);
413 devmode
->dmBitsPerPel
= GetSystemMetrics(SM_WINE_BPP
);
414 devmode
->dmPelsHeight
= GetSystemMetrics(SM_CYSCREEN
);
415 devmode
->dmPelsWidth
= GetSystemMetrics(SM_CXSCREEN
);
418 if ((n
-1)<NRMODES
*NRDEPTHS
) {
419 devmode
->dmBitsPerPel
= depths
[(n
-1)/NRMODES
];
420 devmode
->dmPelsHeight
= modes
[(n
-1)%NRMODES
].h
;
421 devmode
->dmPelsWidth
= modes
[(n
-1)%NRMODES
].w
;
427 /***********************************************************************
428 * EnumDisplaySettingsW (USER32.593)
430 BOOL WINAPI
EnumDisplaySettingsW(LPCWSTR name
,DWORD n
,LPDEVMODEW devmode
) {
431 LPSTR nameA
= HEAP_strdupWtoA(GetProcessHeap(),0,name
);
433 BOOL ret
= EnumDisplaySettingsA(nameA
,n
,&devmodeA
);
436 devmode
->dmBitsPerPel
= devmodeA
.dmBitsPerPel
;
437 devmode
->dmPelsHeight
= devmodeA
.dmPelsHeight
;
438 devmode
->dmPelsWidth
= devmodeA
.dmPelsWidth
;
439 /* FIXME: convert rest too, if they are ever returned */
441 HeapFree(GetProcessHeap(),0,nameA
);
445 /***********************************************************************
446 * EnumDisplayDevicesA (USER32.184)
448 BOOL WINAPI
EnumDisplayDevicesA(
449 LPVOID unused
,DWORD i
,LPDISPLAY_DEVICEA lpDisplayDevice
,DWORD dwFlags
453 FIXME_(system
)("(%p,%ld,%p,0x%08lx), stub!\n",unused
,i
,lpDisplayDevice
,dwFlags
);
454 strcpy(lpDisplayDevice
->DeviceName
,"X11");
455 strcpy(lpDisplayDevice
->DeviceString
,"X 11 Windowing System");
456 lpDisplayDevice
->StateFlags
=
457 DISPLAY_DEVICE_ATTACHED_TO_DESKTOP
|
458 DISPLAY_DEVICE_PRIMARY_DEVICE
|
459 DISPLAY_DEVICE_VGA_COMPATIBLE
;
463 /***********************************************************************
464 * EnumDisplayDevicesW (USER32.185)
466 BOOL WINAPI
EnumDisplayDevicesW(
467 LPVOID unused
,DWORD i
,LPDISPLAY_DEVICEW lpDisplayDevice
,DWORD dwFlags
471 FIXME_(system
)("(%p,%ld,%p,0x%08lx), stub!\n",unused
,i
,lpDisplayDevice
,dwFlags
);
472 lstrcpyAtoW(lpDisplayDevice
->DeviceName
,"X11");
473 lstrcpyAtoW(lpDisplayDevice
->DeviceString
,"X 11 Windowing System");
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 * RegisterDeviceNotification (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