4 * Copyright 1993 Robert J. Amstadt
9 #include "wine/winbase16.h"
20 #include "clipboard.h"
22 #include "cursoricon.h"
33 #include "debugtools.h"
35 DECLARE_DEBUG_CHANNEL(hook
)
36 DECLARE_DEBUG_CHANNEL(local
)
37 DECLARE_DEBUG_CHANNEL(system
)
38 DECLARE_DEBUG_CHANNEL(win
)
39 DECLARE_DEBUG_CHANNEL(win32
)
41 /***********************************************************************
42 * GetFreeSystemResources (USER.284)
44 WORD WINAPI
GetFreeSystemResources16( WORD resType
)
46 int userPercent
, gdiPercent
;
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_HeapSel
) * 100 /
58 LOCAL_HeapSize( GDI_HeapSel
);
62 case GFSR_SYSTEMRESOURCES
:
63 userPercent
= (int)LOCAL_CountFree( USER_HeapSel
) * 100 /
64 LOCAL_HeapSize( USER_HeapSel
);
65 gdiPercent
= (int)LOCAL_CountFree( GDI_HeapSel
) * 100 /
66 LOCAL_HeapSize( GDI_HeapSel
);
72 return (WORD
)min( userPercent
, gdiPercent
);
76 /***********************************************************************
77 * SystemHeapInfo (TOOLHELP.71)
79 BOOL16 WINAPI
SystemHeapInfo16( SYSHEAPINFO
*pHeapInfo
)
81 pHeapInfo
->wUserFreePercent
= GetFreeSystemResources16( GFSR_USERRESOURCES
);
82 pHeapInfo
->wGDIFreePercent
= GetFreeSystemResources16( GFSR_GDIRESOURCES
);
83 pHeapInfo
->hUserSegment
= USER_HeapSel
;
84 pHeapInfo
->hGDISegment
= GDI_HeapSel
;
89 /***********************************************************************
90 * TimerCount (TOOLHELP.80)
92 BOOL16 WINAPI
TimerCount16( TIMERINFO
*pTimerInfo
)
95 * In standard mode, dwmsSinceStart = dwmsThisVM
97 * I tested this, under Windows in enhanced mode, and
98 * if you never switch VM (ie start/stop DOS) these
99 * values should be the same as well.
101 * Also, Wine should adjust for the hardware timer
102 * to reduce the amount of error to ~1ms.
103 * I can't be bothered, can you?
105 pTimerInfo
->dwmsSinceStart
= pTimerInfo
->dwmsThisVM
= GetTickCount();
109 /**********************************************************************
112 INT16 WINAPI
InitApp16( HINSTANCE16 hInstance
)
114 /* Hack: restore the divide-by-zero handler */
115 /* FIXME: should set a USER-specific handler that displays a msg box */
116 INT_SetPMHandler( 0, INT_GetPMHandler( 0xff ) );
118 /* Create task message queue */
119 if ( !GetFastQueue16() ) return 0;
124 /**********************************************************************
127 static void USER_ModuleUnload( HMODULE16 hModule
)
129 HOOK_FreeModuleHooks( hModule
);
130 CLASS_FreeModuleClasses( hModule
);
131 CURSORICON_FreeModuleIcons( hModule
);
134 /**********************************************************************
137 static void USER_QueueCleanup( HQUEUE16 hQueue
)
141 WND
* desktop
= WIN_GetDesktop();
143 /* Patch desktop window */
144 if ( desktop
->hmemTaskQ
== hQueue
)
146 HTASK16 nextTask
= TASK_GetNextTask( GetCurrentTask() );
147 desktop
->hmemTaskQ
= GetTaskQueue16( nextTask
);
150 /* Patch resident popup menu window */
151 MENU_PatchResidentPopup( hQueue
, NULL
);
153 TIMER_RemoveQueueTimers( hQueue
);
155 HOOK_FreeQueueHooks( hQueue
);
157 QUEUE_SetExitingQueue( hQueue
);
158 WIN_ResetQueueWindows( desktop
, hQueue
, (HQUEUE16
)0);
159 QUEUE_SetExitingQueue( 0 );
161 /* Free the message queue */
162 QUEUE_DeleteMsgQueue( hQueue
);
164 WIN_ReleaseDesktop();
168 /**********************************************************************
171 static void USER_AppExit( HINSTANCE16 hInstance
)
173 /* FIXME: maybe destroy menus (Windows only complains about them
177 /* ModuleUnload() in "Internals" */
179 hInstance
= GetExePtr( hInstance
);
180 if( GetModuleUsage16( hInstance
) <= 1 )
181 USER_ModuleUnload( hInstance
);
185 /***********************************************************************
186 * USER_SignalProc (USER.314)
188 void WINAPI
USER_SignalProc( HANDLE16 hTaskOrModule
, UINT16 uCode
,
189 UINT16 uExitFn
, HINSTANCE16 hInstance
,
192 FIXME_(win
)("Win 3.1 USER signal %04x\n", uCode
);
195 /***********************************************************************
196 * FinalUserInit (USER.400)
198 void WINAPI
FinalUserInit16( void )
200 /* FIXME: Should chain to FinalGdiInit now. */
203 /***********************************************************************
204 * UserSignalProc (USER.610) (USER32.559)
206 * For comments about the meaning of uCode and dwFlags
207 * see PROCESS_CallUserSignalProc.
210 WORD WINAPI
UserSignalProc( UINT uCode
, DWORD dwThreadOrProcessID
,
211 DWORD dwFlags
, HMODULE16 hModule
)
215 /* FIXME: Proper reaction to most signals still missing. */
219 case USIG_DLL_UNLOAD_WIN16
:
220 case USIG_DLL_UNLOAD_WIN32
:
221 USER_ModuleUnload( hModule
);
224 case USIG_DLL_UNLOAD_ORPHANS
:
227 case USIG_FAULT_DIALOG_PUSH
:
228 case USIG_FAULT_DIALOG_POP
:
231 case USIG_THREAD_INIT
:
234 case USIG_THREAD_EXIT
:
235 USER_QueueCleanup( GetThreadQueue16( dwThreadOrProcessID
) );
236 SetThreadQueue16( dwThreadOrProcessID
, 0 );
239 case USIG_PROCESS_CREATE
:
242 case USIG_PROCESS_INIT
:
243 case USIG_PROCESS_LOADED
:
245 case USIG_PROCESS_RUNNING
:
248 case USIG_PROCESS_EXIT
:
251 case USIG_PROCESS_DESTROY
:
252 hInst
= ((TDB
*)GlobalLock16( GetCurrentTask() ))->hInstance
;
253 USER_AppExit( hInst
);
257 FIXME_(win
)("(%04x, %08lx, %04lx, %04x)\n",
258 uCode
, dwThreadOrProcessID
, dwFlags
, hModule
);
262 /* FIXME: Should chain to GdiSignalProc now. */
267 /***********************************************************************
268 * USER_DllEntryPoint (USER.374)
270 BOOL WINAPI
USER_DllEntryPoint( DWORD dwReason
, HINSTANCE hInstDLL
, WORD ds
,
271 WORD wHeapSize
, DWORD dwReserved1
, WORD wReserved2
)
275 case DLL_PROCESS_ATTACH
:
277 * We need to load the 32-bit library so as to be able
278 * to access the system resources stored there!
280 if ( !LoadLibraryA("USER32.DLL") )
282 ERR_(win
)( "Could not load USER32.DLL\n" );
291 /***********************************************************************
292 * ExitWindows16 (USER.7)
294 BOOL16 WINAPI
ExitWindows16( DWORD dwReturnCode
, UINT16 wReserved
)
296 return ExitWindowsEx( EWX_LOGOFF
, 0xffffffff );
300 /***********************************************************************
301 * ExitWindowsExec16 (USER.246)
303 BOOL16 WINAPI
ExitWindowsExec16( LPCSTR lpszExe
, LPCSTR lpszParams
)
305 TRACE_(system
)("Should run the following in DOS-mode: \"%s %s\"\n",
306 lpszExe
, lpszParams
);
307 return ExitWindowsEx( EWX_LOGOFF
, 0xffffffff );
311 /***********************************************************************
312 * ExitWindowsEx (USER32.196)
314 BOOL WINAPI
ExitWindowsEx( UINT flags
, DWORD reserved
)
320 /* We have to build a list of all windows first, as in EnumWindows */
322 if (!(list
= WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL
)))
324 WIN_ReleaseDesktop();
328 /* Send a WM_QUERYENDSESSION message to every window */
330 for (ppWnd
= list
, i
= 0; *ppWnd
; ppWnd
++, i
++)
332 /* Make sure that the window still exists */
333 if (!IsWindow( (*ppWnd
)->hwndSelf
)) continue;
334 if (!SendMessage16( (*ppWnd
)->hwndSelf
, WM_QUERYENDSESSION
, 0, 0 ))
339 /* Now notify all windows that got a WM_QUERYENDSESSION of the result */
341 for (ppWnd
= list
; i
> 0; i
--, ppWnd
++)
343 if (!IsWindow( (*ppWnd
)->hwndSelf
)) continue;
344 SendMessage16( (*ppWnd
)->hwndSelf
, WM_ENDSESSION
, result
, 0 );
346 WIN_ReleaseWinArray(list
);
348 if (result
) ExitKernel16();
349 WIN_ReleaseDesktop();
353 static void _dump_CDS_flags(DWORD flags
) {
354 #define X(x) if (flags & CDS_##x) MESSAGE(""#x ",");
355 X(UPDATEREGISTRY
);X(TEST
);X(FULLSCREEN
);X(GLOBAL
);
356 X(SET_PRIMARY
);X(RESET
);X(SETRECT
);X(NORESET
);
360 /***********************************************************************
361 * ChangeDisplaySettingsA (USER32.589)
363 LONG WINAPI
ChangeDisplaySettingsA( LPDEVMODEA devmode
, DWORD flags
)
365 FIXME_(system
)("(%p,0x%08lx), stub\n",devmode
,flags
);
366 MESSAGE("\tflags=");_dump_CDS_flags(flags
);MESSAGE("\n");
368 FIXME_(system
)(" devmode=NULL (return to default mode)\n");
369 else if ( (devmode
->dmBitsPerPel
!= MONITOR_GetDepth(&MONITOR_PrimaryMonitor
))
370 || (devmode
->dmPelsHeight
!= MONITOR_GetHeight(&MONITOR_PrimaryMonitor
))
371 || (devmode
->dmPelsWidth
!= MONITOR_GetWidth(&MONITOR_PrimaryMonitor
)) )
375 if (devmode
->dmFields
& DM_BITSPERPEL
)
376 FIXME_(system
)(" bpp=%ld\n",devmode
->dmBitsPerPel
);
377 if (devmode
->dmFields
& DM_PELSWIDTH
)
378 FIXME_(system
)(" width=%ld\n",devmode
->dmPelsWidth
);
379 if (devmode
->dmFields
& DM_PELSHEIGHT
)
380 FIXME_(system
)(" height=%ld\n",devmode
->dmPelsHeight
);
381 FIXME_(system
)(" (Putting X in this mode beforehand might help)\n");
382 /* we don't, but the program ... does not need to know */
383 return DISP_CHANGE_SUCCESSFUL
;
385 return DISP_CHANGE_SUCCESSFUL
;
388 /***********************************************************************
389 * ChangeDisplaySettingsExA (USER32.604)
391 LONG WINAPI
ChangeDisplaySettingsExA(
392 LPCSTR devname
, LPDEVMODEA devmode
, HWND hwnd
, DWORD flags
,
395 FIXME_(system
)("(%s,%p,0x%04x,0x%08lx,0x%08lx), stub\n",devname
,devmode
,hwnd
,flags
,lparam
);
396 MESSAGE("\tflags=");_dump_CDS_flags(flags
);MESSAGE("\n");
398 FIXME_(system
)(" devmode=NULL (return to default mode)\n");
399 else if ( (devmode
->dmBitsPerPel
!= MONITOR_GetDepth(&MONITOR_PrimaryMonitor
))
400 || (devmode
->dmPelsHeight
!= MONITOR_GetHeight(&MONITOR_PrimaryMonitor
))
401 || (devmode
->dmPelsWidth
!= MONITOR_GetWidth(&MONITOR_PrimaryMonitor
)) )
405 if (devmode
->dmFields
& DM_BITSPERPEL
)
406 FIXME_(system
)(" bpp=%ld\n",devmode
->dmBitsPerPel
);
407 if (devmode
->dmFields
& DM_PELSWIDTH
)
408 FIXME_(system
)(" width=%ld\n",devmode
->dmPelsWidth
);
409 if (devmode
->dmFields
& DM_PELSHEIGHT
)
410 FIXME_(system
)(" height=%ld\n",devmode
->dmPelsHeight
);
411 FIXME_(system
)(" (Putting X in this mode beforehand might help)\n");
412 /* we don't, but the program ... does not need to know */
413 return DISP_CHANGE_SUCCESSFUL
;
415 return DISP_CHANGE_SUCCESSFUL
;
418 /***********************************************************************
419 * EnumDisplaySettingsA (USER32.592)
420 * FIXME: Currently uses static list of modes.
423 * TRUE if nth setting exists found (described in the LPDEVMODEA struct)
424 * FALSE if we do not have the nth setting
426 BOOL WINAPI
EnumDisplaySettingsA(
427 LPCSTR name
, /* [in] huh? */
428 DWORD n
, /* [in] nth entry in display settings list*/
429 LPDEVMODEA devmode
/* [out] devmode for that setting */
435 } modes
[NRMODES
]={{512,384},{640,400},{640,480},{800,600},{1024,768}};
436 int depths
[4] = {8,16,24,32};
438 TRACE_(system
)("(%s,%ld,%p)\n",name
,n
,devmode
);
440 devmode
->dmBitsPerPel
= MONITOR_GetDepth(&MONITOR_PrimaryMonitor
);
441 devmode
->dmPelsHeight
= MONITOR_GetHeight(&MONITOR_PrimaryMonitor
);
442 devmode
->dmPelsWidth
= MONITOR_GetWidth(&MONITOR_PrimaryMonitor
);
445 if ((n
-1)<NRMODES
*NRDEPTHS
) {
446 devmode
->dmBitsPerPel
= depths
[(n
-1)/NRMODES
];
447 devmode
->dmPelsHeight
= modes
[(n
-1)%NRMODES
].h
;
448 devmode
->dmPelsWidth
= modes
[(n
-1)%NRMODES
].w
;
454 /***********************************************************************
455 * EnumDisplaySettingsW (USER32.593)
457 BOOL WINAPI
EnumDisplaySettingsW(LPCWSTR name
,DWORD n
,LPDEVMODEW devmode
) {
458 LPSTR nameA
= HEAP_strdupWtoA(GetProcessHeap(),0,name
);
460 BOOL ret
= EnumDisplaySettingsA(nameA
,n
,&devmodeA
);
463 devmode
->dmBitsPerPel
= devmodeA
.dmBitsPerPel
;
464 devmode
->dmPelsHeight
= devmodeA
.dmPelsHeight
;
465 devmode
->dmPelsWidth
= devmodeA
.dmPelsWidth
;
466 /* FIXME: convert rest too, if they are ever returned */
468 HeapFree(GetProcessHeap(),0,nameA
);
472 /***********************************************************************
473 * EnumDisplayDevicesA (USER32.184)
475 BOOL WINAPI
EnumDisplayDevicesA(
476 LPVOID unused
,DWORD i
,LPDISPLAY_DEVICEA lpDisplayDevice
,DWORD dwFlags
480 FIXME_(system
)("(%p,%ld,%p,0x%08lx), stub!\n",unused
,i
,lpDisplayDevice
,dwFlags
);
481 strcpy(lpDisplayDevice
->DeviceName
,"X11");
482 strcpy(lpDisplayDevice
->DeviceString
,"X 11 Windowing System");
483 lpDisplayDevice
->StateFlags
=
484 DISPLAY_DEVICE_ATTACHED_TO_DESKTOP
|
485 DISPLAY_DEVICE_PRIMARY_DEVICE
|
486 DISPLAY_DEVICE_VGA_COMPATIBLE
;
490 /***********************************************************************
491 * EnumDisplayDevicesW (USER32.185)
493 BOOL WINAPI
EnumDisplayDevicesW(
494 LPVOID unused
,DWORD i
,LPDISPLAY_DEVICEW lpDisplayDevice
,DWORD dwFlags
498 FIXME_(system
)("(%p,%ld,%p,0x%08lx), stub!\n",unused
,i
,lpDisplayDevice
,dwFlags
);
499 lstrcpyAtoW(lpDisplayDevice
->DeviceName
,"X11");
500 lstrcpyAtoW(lpDisplayDevice
->DeviceString
,"X 11 Windowing System");
501 lpDisplayDevice
->StateFlags
=
502 DISPLAY_DEVICE_ATTACHED_TO_DESKTOP
|
503 DISPLAY_DEVICE_PRIMARY_DEVICE
|
504 DISPLAY_DEVICE_VGA_COMPATIBLE
;
508 /***********************************************************************
509 * SetEventHook (USER.321)
511 * Used by Turbo Debugger for Windows
513 FARPROC16 WINAPI
SetEventHook16(FARPROC16 lpfnEventHook
)
515 FIXME_(hook
)("(lpfnEventHook=%08x): stub\n", (UINT
)lpfnEventHook
);
519 /***********************************************************************
520 * UserSeeUserDo (USER.216)
522 DWORD WINAPI
UserSeeUserDo16(WORD wReqType
, WORD wParam1
, WORD wParam2
, WORD wParam3
)
526 case USUD_LOCALALLOC
:
527 return LOCAL_Alloc(USER_HeapSel
, wParam1
, wParam3
);
529 return LOCAL_Free(USER_HeapSel
, wParam1
);
530 case USUD_LOCALCOMPACT
:
531 return LOCAL_Compact(USER_HeapSel
, wParam3
, 0);
534 case USUD_FIRSTCLASS
:
535 FIXME_(local
)("return a pointer to the first window class.\n");
538 WARN_(local
)("wReqType %04x (unknown)", wReqType
);
543 /***********************************************************************
544 * GetSystemDebugState16 (USER.231)
546 WORD WINAPI
GetSystemDebugState16(void)
548 return 0; /* FIXME */
551 /***********************************************************************
552 * RegisterLogonProcess (USER32.434)
554 DWORD WINAPI
RegisterLogonProcess(HANDLE hprocess
,BOOL x
) {
555 FIXME_(win32
)("(%d,%d),stub!\n",hprocess
,x
);
559 /***********************************************************************
560 * CreateWindowStationW (USER32.86)
562 HWINSTA WINAPI
CreateWindowStationW(
563 LPWSTR winstation
,DWORD res1
,DWORD desiredaccess
,
564 LPSECURITY_ATTRIBUTES lpsa
566 FIXME_(win32
)("(%s,0x%08lx,0x%08lx,%p),stub!\n",debugstr_w(winstation
),
567 res1
,desiredaccess
,lpsa
572 /***********************************************************************
573 * SetProcessWindowStation (USER32.496)
575 BOOL WINAPI
SetProcessWindowStation(HWINSTA hWinSta
) {
576 FIXME_(win32
)("(%d),stub!\n",hWinSta
);
580 /***********************************************************************
581 * SetUserObjectSecurity (USER32.514)
583 BOOL WINAPI
SetUserObjectSecurity(
585 /*LPSECURITY_INFORMATION*/LPVOID pSIRequested
,
586 PSECURITY_DESCRIPTOR pSID
588 FIXME_(win32
)("(0x%08x,%p,%p),stub!\n",hObj
,pSIRequested
,pSID
);
592 /***********************************************************************
593 * CreateDesktopW (USER32.69)
595 HDESK WINAPI
CreateDesktopW(
596 LPWSTR lpszDesktop
,LPWSTR lpszDevice
,LPDEVMODEW pDevmode
,
597 DWORD dwFlags
,DWORD dwDesiredAccess
,LPSECURITY_ATTRIBUTES lpsa
599 FIXME_(win32
)("(%s,%s,%p,0x%08lx,0x%08lx,%p),stub!\n",
600 debugstr_w(lpszDesktop
),debugstr_w(lpszDevice
),pDevmode
,
601 dwFlags
,dwDesiredAccess
,lpsa
606 /***********************************************************************
609 BOOL WINAPI
CloseWindowStation(HWINSTA hWinSta
)
611 FIXME_(win32
)("(0x%08x)\n", hWinSta
);
615 /***********************************************************************
618 BOOL WINAPI
CloseDesktop(HDESK hDesk
)
620 FIXME_(win32
)("(0x%08x)\n", hDesk
);
624 /***********************************************************************
625 * SetWindowStationUser (USER32.521)
627 DWORD WINAPI
SetWindowStationUser(DWORD x1
,DWORD x2
) {
628 FIXME_(win32
)("(0x%08lx,0x%08lx),stub!\n",x1
,x2
);
632 /***********************************************************************
633 * SetLogonNotifyWindow (USER32.486)
635 DWORD WINAPI
SetLogonNotifyWindow(HWINSTA hwinsta
,HWND hwnd
) {
636 FIXME_(win32
)("(0x%x,%04x),stub!\n",hwinsta
,hwnd
);
640 /***********************************************************************
641 * LoadLocalFonts (USER32.486)
643 VOID WINAPI
LoadLocalFonts(VOID
) {
647 /***********************************************************************
648 * GetUserObjectInformationA (USER32.299)
650 BOOL WINAPI
GetUserObjectInformationA( HANDLE hObj
, INT nIndex
, LPVOID pvInfo
, DWORD nLength
, LPDWORD lpnLen
)
651 { FIXME_(win32
)("(0x%x %i %p %ld %p),stub!\n", hObj
, nIndex
, pvInfo
, nLength
, lpnLen
);
654 /***********************************************************************
655 * GetUserObjectInformationW (USER32.300)
657 BOOL WINAPI
GetUserObjectInformationW( HANDLE hObj
, INT nIndex
, LPVOID pvInfo
, DWORD nLength
, LPDWORD lpnLen
)
658 { FIXME_(win32
)("(0x%x %i %p %ld %p),stub!\n", hObj
, nIndex
, pvInfo
, nLength
, lpnLen
);
661 /***********************************************************************
662 * GetUserObjectSecurity (USER32.300)
664 BOOL WINAPI
GetUserObjectSecurity(HANDLE hObj
, SECURITY_INFORMATION
* pSIRequested
,
665 PSECURITY_DESCRIPTOR pSID
, DWORD nLength
, LPDWORD lpnLengthNeeded
)
666 { FIXME_(win32
)("(0x%x %p %p len=%ld %p),stub!\n", hObj
, pSIRequested
, pSID
, nLength
, lpnLengthNeeded
);
670 /***********************************************************************
671 * SetSystemCursor (USER32.507)
673 BOOL WINAPI
SetSystemCursor(HCURSOR hcur
, DWORD id
)
674 { FIXME_(win32
)("(%08x,%08lx),stub!\n", hcur
, id
);
678 /***********************************************************************
679 * RegisterSystemThread (USER32.435)
681 void WINAPI
RegisterSystemThread(DWORD flags
, DWORD reserved
)
683 FIXME_(win32
)("(%08lx, %08lx)\n", flags
, reserved
);