4 * Copyright 1993 Robert J. Amstadt
9 #include "wine/winbase16.h"
17 #include "clipboard.h"
19 #include "cursoricon.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
)
43 int userPercent
, gdiPercent
;
47 case GFSR_USERRESOURCES
:
48 userPercent
= (int)LOCAL_CountFree( USER_HeapSel
) * 100 /
49 LOCAL_HeapSize( USER_HeapSel
);
53 case GFSR_GDIRESOURCES
:
54 gdiPercent
= (int)LOCAL_CountFree( GDI_HeapSel
) * 100 /
55 LOCAL_HeapSize( GDI_HeapSel
);
59 case GFSR_SYSTEMRESOURCES
:
60 userPercent
= (int)LOCAL_CountFree( USER_HeapSel
) * 100 /
61 LOCAL_HeapSize( USER_HeapSel
);
62 gdiPercent
= (int)LOCAL_CountFree( GDI_HeapSel
) * 100 /
63 LOCAL_HeapSize( GDI_HeapSel
);
69 return (WORD
)MIN( userPercent
, gdiPercent
);
73 /***********************************************************************
74 * SystemHeapInfo (TOOLHELP.71)
76 BOOL16 WINAPI
SystemHeapInfo16( SYSHEAPINFO
*pHeapInfo
)
78 pHeapInfo
->wUserFreePercent
= GetFreeSystemResources16( GFSR_USERRESOURCES
);
79 pHeapInfo
->wGDIFreePercent
= GetFreeSystemResources16( GFSR_GDIRESOURCES
);
80 pHeapInfo
->hUserSegment
= USER_HeapSel
;
81 pHeapInfo
->hGDISegment
= GDI_HeapSel
;
86 /***********************************************************************
87 * TimerCount (TOOLHELP.80)
89 BOOL16 WINAPI
TimerCount16( TIMERINFO
*pTimerInfo
)
92 * In standard mode, dwmsSinceStart = dwmsThisVM
94 * I tested this, under Windows in enhanced mode, and
95 * if you never switch VM (ie start/stop DOS) these
96 * values should be the same as well.
98 * Also, Wine should adjust for the hardware timer
99 * to reduce the amount of error to ~1ms.
100 * I can't be bothered, can you?
102 pTimerInfo
->dwmsSinceStart
= pTimerInfo
->dwmsThisVM
= GetTickCount();
106 /**********************************************************************
109 INT16 WINAPI
InitApp16( HINSTANCE16 hInstance
)
111 /* Hack: restore the divide-by-zero handler */
112 /* FIXME: should set a USER-specific handler that displays a msg box */
113 INT_SetPMHandler( 0, INT_GetPMHandler( 0xff ) );
115 /* Create task message queue */
116 if ( !GetFastQueue16() ) return 0;
121 /**********************************************************************
124 static void USER_ModuleUnload( HMODULE16 hModule
)
126 HOOK_FreeModuleHooks( hModule
);
127 CLASS_FreeModuleClasses( hModule
);
128 CURSORICON_FreeModuleIcons( hModule
);
131 /**********************************************************************
134 static void USER_QueueCleanup( HQUEUE16 hQueue
)
138 WND
* desktop
= WIN_GetDesktop();
140 /* Patch desktop window */
141 if ( desktop
->hmemTaskQ
== hQueue
)
143 HTASK16 nextTask
= TASK_GetNextTask( GetCurrentTask() );
144 desktop
->hmemTaskQ
= GetTaskQueue16( nextTask
);
147 /* Patch resident popup menu window */
148 MENU_PatchResidentPopup( hQueue
, NULL
);
150 TIMER_RemoveQueueTimers( hQueue
);
152 HOOK_FreeQueueHooks( hQueue
);
154 QUEUE_SetExitingQueue( hQueue
);
155 WIN_ResetQueueWindows( desktop
, hQueue
, (HQUEUE16
)0);
156 QUEUE_SetExitingQueue( 0 );
158 /* Free the message queue */
159 QUEUE_DeleteMsgQueue( hQueue
);
161 WIN_ReleaseDesktop();
165 /**********************************************************************
168 static void USER_AppExit( HINSTANCE16 hInstance
)
170 /* FIXME: maybe destroy menus (Windows only complains about them
174 /* ModuleUnload() in "Internals" */
176 hInstance
= GetExePtr( hInstance
);
177 if( GetModuleUsage16( hInstance
) <= 1 )
178 USER_ModuleUnload( hInstance
);
182 /***********************************************************************
183 * USER_SignalProc (USER.314)
185 void WINAPI
USER_SignalProc( HANDLE16 hTaskOrModule
, UINT16 uCode
,
186 UINT16 uExitFn
, HINSTANCE16 hInstance
,
189 FIXME_(win
)("Win 3.1 USER signal %04x\n", uCode
);
192 /***********************************************************************
193 * FinalUserInit (USER.400)
195 void WINAPI
FinalUserInit16( void )
197 /* FIXME: Should chain to FinalGdiInit now. */
200 /***********************************************************************
201 * UserSignalProc (USER.610) (USER32.559)
203 * For comments about the meaning of uCode and dwFlags
204 * see PROCESS_CallUserSignalProc.
207 WORD WINAPI
UserSignalProc( UINT uCode
, DWORD dwThreadOrProcessID
,
208 DWORD dwFlags
, HMODULE16 hModule
)
212 /* FIXME: Proper reaction to most signals still missing. */
216 case USIG_DLL_UNLOAD_WIN16
:
217 case USIG_DLL_UNLOAD_WIN32
:
218 USER_ModuleUnload( hModule
);
221 case USIG_DLL_UNLOAD_ORPHANS
:
224 case USIG_FAULT_DIALOG_PUSH
:
225 case USIG_FAULT_DIALOG_POP
:
228 case USIG_THREAD_INIT
:
231 case USIG_THREAD_EXIT
:
232 USER_QueueCleanup( GetThreadQueue16( dwThreadOrProcessID
) );
233 SetThreadQueue16( dwThreadOrProcessID
, 0 );
236 case USIG_PROCESS_CREATE
:
237 case USIG_PROCESS_INIT
:
238 case USIG_PROCESS_LOADED
:
239 case USIG_PROCESS_RUNNING
:
242 case USIG_PROCESS_EXIT
:
245 case USIG_PROCESS_DESTROY
:
246 hInst
= GetProcessDword( dwThreadOrProcessID
, GPD_HINSTANCE16
);
247 USER_AppExit( hInst
);
251 FIXME_(win
)("(%04x, %08lx, %04lx, %04x)\n",
252 uCode
, dwThreadOrProcessID
, dwFlags
, hModule
);
256 /* FIXME: Should chain to GdiSignalProc now. */
261 /***********************************************************************
262 * USER_DllEntryPoint (USER.374)
264 BOOL WINAPI
USER_DllEntryPoint( DWORD dwReason
, HINSTANCE hInstDLL
, WORD ds
,
265 WORD wHeapSize
, DWORD dwReserved1
, WORD wReserved2
)
269 case DLL_PROCESS_ATTACH
:
271 * We need to load the 32-bit library so as to be able
272 * to access the system resources stored there!
274 if ( !LoadLibraryA("USER32.DLL") )
276 ERR_(win
)( "Could not load USER32.DLL\n" );
285 /***********************************************************************
286 * ExitWindows16 (USER.7)
288 BOOL16 WINAPI
ExitWindows16( DWORD dwReturnCode
, UINT16 wReserved
)
290 return ExitWindowsEx( EWX_LOGOFF
, 0xffffffff );
294 /***********************************************************************
295 * ExitWindowsExec16 (USER.246)
297 BOOL16 WINAPI
ExitWindowsExec16( LPCSTR lpszExe
, LPCSTR lpszParams
)
299 TRACE_(system
)("Should run the following in DOS-mode: \"%s %s\"\n",
300 lpszExe
, lpszParams
);
301 return ExitWindowsEx( EWX_LOGOFF
, 0xffffffff );
305 /***********************************************************************
306 * ExitWindowsEx (USER32.196)
308 BOOL WINAPI
ExitWindowsEx( UINT flags
, DWORD reserved
)
314 /* We have to build a list of all windows first, as in EnumWindows */
316 if (!(list
= WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL
)))
318 WIN_ReleaseDesktop();
322 /* Send a WM_QUERYENDSESSION message to every window */
324 for (ppWnd
= list
, i
= 0; *ppWnd
; ppWnd
++, i
++)
326 /* Make sure that the window still exists */
327 if (!IsWindow( (*ppWnd
)->hwndSelf
)) continue;
328 if (!SendMessage16( (*ppWnd
)->hwndSelf
, WM_QUERYENDSESSION
, 0, 0 ))
333 /* Now notify all windows that got a WM_QUERYENDSESSION of the result */
335 for (ppWnd
= list
; i
> 0; i
--, ppWnd
++)
337 if (!IsWindow( (*ppWnd
)->hwndSelf
)) continue;
338 SendMessage16( (*ppWnd
)->hwndSelf
, WM_ENDSESSION
, result
, 0 );
340 WIN_ReleaseWinArray(list
);
342 if (result
) ExitKernel16();
343 WIN_ReleaseDesktop();
347 static void _dump_CDS_flags(DWORD flags
) {
348 #define X(x) if (flags & CDS_##x) MESSAGE(""#x ",");
349 X(UPDATEREGISTRY
);X(TEST
);X(FULLSCREEN
);X(GLOBAL
);
350 X(SET_PRIMARY
);X(RESET
);X(SETRECT
);X(NORESET
);
354 /***********************************************************************
355 * ChangeDisplaySettingA (USER32.589)
357 LONG WINAPI
ChangeDisplaySettingsA( LPDEVMODEA devmode
, DWORD flags
)
359 FIXME_(system
)("(%p,0x%08lx), stub\n",devmode
,flags
);
360 MESSAGE("\tflags=");_dump_CDS_flags(flags
);MESSAGE("\n");
362 FIXME_(system
)(" devmode=NULL (return to default mode)\n");
363 else if ( (devmode
->dmBitsPerPel
!= DESKTOP_GetScreenDepth())
364 || (devmode
->dmPelsHeight
!= DESKTOP_GetScreenHeight())
365 || (devmode
->dmPelsWidth
!= DESKTOP_GetScreenWidth()) )
369 if (devmode
->dmFields
& DM_BITSPERPEL
)
370 FIXME_(system
)(" bpp=%ld\n",devmode
->dmBitsPerPel
);
371 if (devmode
->dmFields
& DM_PELSWIDTH
)
372 FIXME_(system
)(" width=%ld\n",devmode
->dmPelsWidth
);
373 if (devmode
->dmFields
& DM_PELSHEIGHT
)
374 FIXME_(system
)(" height=%ld\n",devmode
->dmPelsHeight
);
375 FIXME_(system
)(" (Putting X in this mode beforehand might help)\n");
376 /* we don't, but the program ... does not need to know */
377 return DISP_CHANGE_SUCCESSFUL
;
379 return DISP_CHANGE_SUCCESSFUL
;
382 /***********************************************************************
383 * ChangeDisplaySettingExA (USER32.604)
385 LONG WINAPI
ChangeDisplaySettingsExA(
386 LPCSTR devname
, LPDEVMODEA devmode
, HWND hwnd
, DWORD flags
,
389 FIXME_(system
)("(%s,%p,0x%04x,0x%08lx,0x%08lx), stub\n",devname
,devmode
,hwnd
,flags
,lparam
);
390 MESSAGE("\tflags=");_dump_CDS_flags(flags
);MESSAGE("\n");
392 FIXME_(system
)(" devmode=NULL (return to default mode)\n");
393 else if ( (devmode
->dmBitsPerPel
!= DESKTOP_GetScreenDepth())
394 || (devmode
->dmPelsHeight
!= DESKTOP_GetScreenHeight())
395 || (devmode
->dmPelsWidth
!= DESKTOP_GetScreenWidth()) )
399 if (devmode
->dmFields
& DM_BITSPERPEL
)
400 FIXME_(system
)(" bpp=%ld\n",devmode
->dmBitsPerPel
);
401 if (devmode
->dmFields
& DM_PELSWIDTH
)
402 FIXME_(system
)(" width=%ld\n",devmode
->dmPelsWidth
);
403 if (devmode
->dmFields
& DM_PELSHEIGHT
)
404 FIXME_(system
)(" height=%ld\n",devmode
->dmPelsHeight
);
405 FIXME_(system
)(" (Putting X in this mode beforehand might help)\n");
406 /* we don't, but the program ... does not need to know */
407 return DISP_CHANGE_SUCCESSFUL
;
409 return DISP_CHANGE_SUCCESSFUL
;
412 /***********************************************************************
413 * EnumDisplaySettingsA (USER32.592)
414 * FIXME: Currently uses static list of modes.
417 * TRUE if nth setting exists found (described in the LPDEVMODE32A struct)
418 * FALSE if we do not have the nth setting
420 BOOL WINAPI
EnumDisplaySettingsA(
421 LPCSTR name
, /* [in] huh? */
422 DWORD n
, /* [in] nth entry in display settings list*/
423 LPDEVMODEA devmode
/* [out] devmode for that setting */
429 } modes
[NRMODES
]={{512,384},{640,400},{640,480},{800,600},{1024,768}};
430 int depths
[4] = {8,16,24,32};
432 TRACE_(system
)("(%s,%ld,%p)\n",name
,n
,devmode
);
434 devmode
->dmBitsPerPel
= DESKTOP_GetScreenDepth();
435 devmode
->dmPelsHeight
= DESKTOP_GetScreenHeight();
436 devmode
->dmPelsWidth
= DESKTOP_GetScreenWidth();
439 if ((n
-1)<NRMODES
*NRDEPTHS
) {
440 devmode
->dmBitsPerPel
= depths
[(n
-1)/NRMODES
];
441 devmode
->dmPelsHeight
= modes
[(n
-1)%NRMODES
].h
;
442 devmode
->dmPelsWidth
= modes
[(n
-1)%NRMODES
].w
;
448 /***********************************************************************
449 * EnumDisplaySettingsW (USER32.593)
451 BOOL WINAPI
EnumDisplaySettingsW(LPCWSTR name
,DWORD n
,LPDEVMODEW devmode
) {
452 LPSTR nameA
= HEAP_strdupWtoA(GetProcessHeap(),0,name
);
454 BOOL ret
= EnumDisplaySettingsA(nameA
,n
,&devmodeA
);
457 devmode
->dmBitsPerPel
= devmodeA
.dmBitsPerPel
;
458 devmode
->dmPelsHeight
= devmodeA
.dmPelsHeight
;
459 devmode
->dmPelsWidth
= devmodeA
.dmPelsWidth
;
460 /* FIXME: convert rest too, if they are ever returned */
462 HeapFree(GetProcessHeap(),0,nameA
);
466 /***********************************************************************
467 * EnumDisplayDevicesA (USER32.184)
469 BOOL WINAPI
EnumDisplayDevicesA(
470 LPVOID unused
,DWORD i
,LPDISPLAY_DEVICEA lpDisplayDevice
,DWORD dwFlags
474 FIXME_(system
)("(%p,%ld,%p,0x%08lx), stub!\n",unused
,i
,lpDisplayDevice
,dwFlags
);
475 strcpy(lpDisplayDevice
->DeviceName
,"X11");
476 strcpy(lpDisplayDevice
->DeviceString
,"X 11 Windowing System");
477 lpDisplayDevice
->StateFlags
=
478 DISPLAY_DEVICE_ATTACHED_TO_DESKTOP
|
479 DISPLAY_DEVICE_PRIMARY_DEVICE
|
480 DISPLAY_DEVICE_VGA_COMPATIBLE
;
484 /***********************************************************************
485 * EnumDisplayDevicesW (USER32.185)
487 BOOL WINAPI
EnumDisplayDevicesW(
488 LPVOID unused
,DWORD i
,LPDISPLAY_DEVICEW lpDisplayDevice
,DWORD dwFlags
492 FIXME_(system
)("(%p,%ld,%p,0x%08lx), stub!\n",unused
,i
,lpDisplayDevice
,dwFlags
);
493 lstrcpyAtoW(lpDisplayDevice
->DeviceName
,"X11");
494 lstrcpyAtoW(lpDisplayDevice
->DeviceString
,"X 11 Windowing System");
495 lpDisplayDevice
->StateFlags
=
496 DISPLAY_DEVICE_ATTACHED_TO_DESKTOP
|
497 DISPLAY_DEVICE_PRIMARY_DEVICE
|
498 DISPLAY_DEVICE_VGA_COMPATIBLE
;
502 /***********************************************************************
503 * SetEventHook (USER.321)
505 * Used by Turbo Debugger for Windows
507 FARPROC16 WINAPI
SetEventHook16(FARPROC16 lpfnEventHook
)
509 FIXME_(hook
)("(lpfnEventHook=%08x): stub\n", (UINT
)lpfnEventHook
);
513 /***********************************************************************
514 * UserSeeUserDo (USER.216)
516 DWORD WINAPI
UserSeeUserDo16(WORD wReqType
, WORD wParam1
, WORD wParam2
, WORD wParam3
)
520 case USUD_LOCALALLOC
:
521 return LOCAL_Alloc(USER_HeapSel
, wParam1
, wParam3
);
523 return LOCAL_Free(USER_HeapSel
, wParam1
);
524 case USUD_LOCALCOMPACT
:
525 return LOCAL_Compact(USER_HeapSel
, wParam3
, 0);
528 case USUD_FIRSTCLASS
:
529 FIXME_(local
)("return a pointer to the first window class.\n");
532 WARN_(local
)("wReqType %04x (unknown)", wReqType
);
537 /***********************************************************************
538 * GetSystemDebugState16 (USER.231)
540 WORD WINAPI
GetSystemDebugState16(void)
542 return 0; /* FIXME */
545 /***********************************************************************
546 * RegisterLogonProcess (USER32.434)
548 DWORD WINAPI
RegisterLogonProcess(HANDLE hprocess
,BOOL x
) {
549 FIXME_(win32
)("(%d,%d),stub!\n",hprocess
,x
);
553 /***********************************************************************
554 * CreateWindowStation32W (USER32.86)
556 HWINSTA WINAPI
CreateWindowStationW(
557 LPWSTR winstation
,DWORD res1
,DWORD desiredaccess
,
558 LPSECURITY_ATTRIBUTES lpsa
560 FIXME_(win32
)("(%s,0x%08lx,0x%08lx,%p),stub!\n",debugstr_w(winstation
),
561 res1
,desiredaccess
,lpsa
566 /***********************************************************************
567 * SetProcessWindowStation (USER32.496)
569 BOOL WINAPI
SetProcessWindowStation(HWINSTA hWinSta
) {
570 FIXME_(win32
)("(%d),stub!\n",hWinSta
);
574 /***********************************************************************
575 * SetUserObjectSecurity (USER32.514)
577 BOOL WINAPI
SetUserObjectSecurity(
579 /*LPSECURITY_INFORMATION*/LPVOID pSIRequested
,
580 PSECURITY_DESCRIPTOR pSID
582 FIXME_(win32
)("(0x%08x,%p,%p),stub!\n",hObj
,pSIRequested
,pSID
);
586 /***********************************************************************
587 * CreateDesktop32W (USER32.69)
589 HDESK WINAPI
CreateDesktopW(
590 LPWSTR lpszDesktop
,LPWSTR lpszDevice
,LPDEVMODEW pDevmode
,
591 DWORD dwFlags
,DWORD dwDesiredAccess
,LPSECURITY_ATTRIBUTES lpsa
593 FIXME_(win32
)("(%s,%s,%p,0x%08lx,0x%08lx,%p),stub!\n",
594 debugstr_w(lpszDesktop
),debugstr_w(lpszDevice
),pDevmode
,
595 dwFlags
,dwDesiredAccess
,lpsa
600 BOOL WINAPI
CloseWindowStation(HWINSTA hWinSta
)
602 FIXME_(win32
)("(0x%08x)\n", hWinSta
);
605 BOOL WINAPI
CloseDesktop(HDESK hDesk
)
607 FIXME_(win32
)("(0x%08x)\n", hDesk
);
611 /***********************************************************************
612 * SetWindowStationUser (USER32.521)
614 DWORD WINAPI
SetWindowStationUser(DWORD x1
,DWORD x2
) {
615 FIXME_(win32
)("(0x%08lx,0x%08lx),stub!\n",x1
,x2
);
619 /***********************************************************************
620 * SetLogonNotifyWindow (USER32.486)
622 DWORD WINAPI
SetLogonNotifyWindow(HWINSTA hwinsta
,HWND hwnd
) {
623 FIXME_(win32
)("(0x%x,%04x),stub!\n",hwinsta
,hwnd
);
627 /***********************************************************************
628 * LoadLocalFonts (USER32.486)
630 VOID WINAPI
LoadLocalFonts(VOID
) {
634 /***********************************************************************
635 * GetUserObjectInformation32A (USER32.299)
637 BOOL WINAPI
GetUserObjectInformationA( HANDLE hObj
, INT nIndex
, LPVOID pvInfo
, DWORD nLength
, LPDWORD lpnLen
)
638 { FIXME_(win32
)("(0x%x %i %p %ld %p),stub!\n", hObj
, nIndex
, pvInfo
, nLength
, lpnLen
);
641 /***********************************************************************
642 * GetUserObjectInformation32W (USER32.300)
644 BOOL WINAPI
GetUserObjectInformationW( HANDLE hObj
, INT nIndex
, LPVOID pvInfo
, DWORD nLength
, LPDWORD lpnLen
)
645 { FIXME_(win32
)("(0x%x %i %p %ld %p),stub!\n", hObj
, nIndex
, pvInfo
, nLength
, lpnLen
);
648 /***********************************************************************
649 * GetUserObjectSecurity32 (USER32.300)
651 BOOL WINAPI
GetUserObjectSecurity(HANDLE hObj
, SECURITY_INFORMATION
* pSIRequested
,
652 PSECURITY_DESCRIPTOR pSID
, DWORD nLength
, LPDWORD lpnLengthNeeded
)
653 { FIXME_(win32
)("(0x%x %p %p len=%ld %p),stub!\n", hObj
, pSIRequested
, pSID
, nLength
, lpnLengthNeeded
);
657 /***********************************************************************
658 * SetSystemCursor (USER32.507)
660 BOOL WINAPI
SetSystemCursor(HCURSOR hcur
, DWORD id
)
661 { FIXME_(win32
)("(%08x,%08lx),stub!\n", hcur
, id
);
665 /***********************************************************************
666 * RegisterSystemThread (USER32.435)
668 void WINAPI
RegisterSystemThread(DWORD flags
, DWORD reserved
)
670 FIXME_(win32
)("(%08lx, %08lx)\n", flags
, reserved
);