4 * Copyright 1993 Robert J. Amstadt
17 #include "clipboard.h"
29 /***********************************************************************
30 * GetFreeSystemResources (USER.284)
32 WORD WINAPI
GetFreeSystemResources( WORD resType
)
34 int userPercent
, gdiPercent
;
38 case GFSR_USERRESOURCES
:
39 userPercent
= (int)LOCAL_CountFree( USER_HeapSel
) * 100 /
40 LOCAL_HeapSize( USER_HeapSel
);
44 case GFSR_GDIRESOURCES
:
45 gdiPercent
= (int)LOCAL_CountFree( GDI_HeapSel
) * 100 /
46 LOCAL_HeapSize( GDI_HeapSel
);
50 case GFSR_SYSTEMRESOURCES
:
51 userPercent
= (int)LOCAL_CountFree( USER_HeapSel
) * 100 /
52 LOCAL_HeapSize( USER_HeapSel
);
53 gdiPercent
= (int)LOCAL_CountFree( GDI_HeapSel
) * 100 /
54 LOCAL_HeapSize( GDI_HeapSel
);
60 return (WORD
)MIN( userPercent
, gdiPercent
);
64 /***********************************************************************
65 * SystemHeapInfo (TOOLHELP.71)
67 BOOL16 WINAPI
SystemHeapInfo( SYSHEAPINFO
*pHeapInfo
)
69 pHeapInfo
->wUserFreePercent
= GetFreeSystemResources( GFSR_USERRESOURCES
);
70 pHeapInfo
->wGDIFreePercent
= GetFreeSystemResources( GFSR_GDIRESOURCES
);
71 pHeapInfo
->hUserSegment
= USER_HeapSel
;
72 pHeapInfo
->hGDISegment
= GDI_HeapSel
;
77 /***********************************************************************
78 * TimerCount (TOOLHELP.80)
80 BOOL16 WINAPI
TimerCount( TIMERINFO
*pTimerInfo
)
83 * In standard mode, dwmsSinceStart = dwmsThisVM
85 * I tested this, under Windows in enhanced mode, and
86 * if you never switch VM (ie start/stop DOS) these
87 * values should be the same as well.
89 * Also, Wine should adjust for the hardware timer
90 * to reduce the amount of error to ~1ms.
91 * I can't be bothered, can you?
93 pTimerInfo
->dwmsSinceStart
= pTimerInfo
->dwmsThisVM
= GetTickCount();
97 static FARPROC16 __r16loader
= NULL
;
99 /**********************************************************************
100 * USER_CallDefaultRsrcHandler
102 * Called by the LoadDIBIcon/CursorHandler().
104 HGLOBAL16
USER_CallDefaultRsrcHandler( HGLOBAL16 hMemObj
, HMODULE16 hModule
, HRSRC16 hRsrc
)
106 return Callbacks
->CallResourceHandlerProc( __r16loader
, hMemObj
, hModule
, hRsrc
);
109 /**********************************************************************
110 * USER_InstallRsrcHandler
112 static void USER_InstallRsrcHandler( HINSTANCE16 hInstance
)
116 /* SetResourceHandler() returns previous function which is set
117 * when a module's resource table is loaded. */
119 proc
= SetResourceHandler( hInstance
, RT_ICON16
,
120 MODULE_GetWndProcEntry16("LoadDIBIconHandler") );
121 if (!__r16loader
) __r16loader
= proc
;
123 proc
= SetResourceHandler( hInstance
, RT_CURSOR16
,
124 MODULE_GetWndProcEntry16("LoadDIBCursorHandler") );
125 if (!__r16loader
) __r16loader
= proc
;
128 /**********************************************************************
131 INT16 WINAPI
InitApp( HINSTANCE16 hInstance
)
135 /* InitTask() calls LibMain()'s of implicitly loaded DLLs
136 * prior to InitApp() so there is no clean way to do
137 * SetTaskSignalHandler() in time. So, broken Windows bypasses
138 * a pTask->userhandler on startup and simply calls a global
139 * function pointer to the default USER signal handler.
142 USER_InstallRsrcHandler( hInstance
);
144 /* Hack: restore the divide-by-zero handler */
145 /* FIXME: should set a USER-specific handler that displays a msg box */
146 INT_SetPMHandler( 0, INT_GetPMHandler( 0xff ) );
148 /* Create task message queue */
149 queueSize
= GetProfileInt32A( "windows", "DefaultQueueSize", 8 );
150 if (!SetMessageQueue32( queueSize
)) return 0;
155 /**********************************************************************
158 static void USER_ModuleUnload( HMODULE16 hModule
)
160 HOOK_FreeModuleHooks( hModule
);
161 CLASS_FreeModuleClasses( hModule
);
164 /**********************************************************************
167 static void USER_AppExit( HTASK16 hTask
, HINSTANCE16 hInstance
, HQUEUE16 hQueue
)
169 /* FIXME: empty clipboard if needed, maybe destroy menus (Windows
170 * only complains about them but does nothing);
173 WND
* desktop
= WIN_GetDesktop();
175 /* Patch desktop window */
176 if( desktop
->hmemTaskQ
== hQueue
)
177 desktop
->hmemTaskQ
= GetTaskQueue(TASK_GetNextTask(hTask
));
179 /* Patch resident popup menu window */
180 MENU_PatchResidentPopup( hQueue
, NULL
);
182 TIMER_RemoveQueueTimers( hQueue
);
184 QUEUE_FlushMessages( hQueue
);
185 HOOK_FreeQueueHooks( hQueue
);
187 QUEUE_SetExitingQueue( hQueue
);
188 WIN_ResetQueueWindows( desktop
, hQueue
, (HQUEUE16
)0);
189 CLIPBOARD_ResetLock( hQueue
, 0 );
190 QUEUE_SetExitingQueue( 0 );
192 /* Free the message queue */
194 QUEUE_DeleteMsgQueue( hQueue
);
196 /* ModuleUnload() in "Internals" */
198 hInstance
= GetExePtr( hInstance
);
199 if( GetModuleUsage( hInstance
) <= 1 )
200 USER_ModuleUnload( hInstance
);
204 /***********************************************************************
207 * Clean-up everything and exit the Wine process.
208 * This is the back-end of ExitWindows(), called when all windows
209 * have agreed to be terminated.
211 void USER_ExitWindows(void)
213 /* Do the clean-up stuff */
216 SHELL_SaveRegistry();
222 /***********************************************************************
223 * USER_SignalProc (USER.314)
225 void WINAPI
USER_SignalProc( HANDLE16 hTaskOrModule
, UINT16 uCode
,
226 UINT16 uExitFn
, HINSTANCE16 hInstance
,
232 case USIG_TERMINATION
:
233 USER_AppExit( hTaskOrModule
, hInstance
, hQueue
); /* task */
237 USER_InstallRsrcHandler( hTaskOrModule
); /* module */
240 case USIG_DLL_UNLOAD
:
241 USER_ModuleUnload( hTaskOrModule
); /* module */
245 FIXME(msg
,"Unimplemented USER signal: %i\n", (int)uCode
);
250 /***********************************************************************
251 * ExitWindows16 (USER.7)
253 BOOL16 WINAPI
ExitWindows16( DWORD dwReturnCode
, UINT16 wReserved
)
255 return ExitWindowsEx( EWX_LOGOFF
, 0xffffffff );
259 /***********************************************************************
260 * ExitWindowsExec16 (USER.246)
262 BOOL16 WINAPI
ExitWindowsExec16( LPCSTR lpszExe
, LPCSTR lpszParams
)
264 TRACE(system
, "Should run the following in DOS-mode: \"%s %s\"\n",
265 lpszExe
, lpszParams
);
266 return ExitWindowsEx( EWX_LOGOFF
, 0xffffffff );
270 /***********************************************************************
271 * ExitWindowsEx (USER32.196)
273 BOOL32 WINAPI
ExitWindowsEx( UINT32 flags
, DWORD reserved
)
279 /* We have to build a list of all windows first, as in EnumWindows */
281 if (!(list
= WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL
))) return FALSE
;
283 /* Send a WM_QUERYENDSESSION message to every window */
285 for (ppWnd
= list
, i
= 0; *ppWnd
; ppWnd
++, i
++)
287 /* Make sure that the window still exists */
288 if (!IsWindow32( (*ppWnd
)->hwndSelf
)) continue;
289 if (!SendMessage16( (*ppWnd
)->hwndSelf
, WM_QUERYENDSESSION
, 0, 0 ))
294 /* Now notify all windows that got a WM_QUERYENDSESSION of the result */
296 for (ppWnd
= list
; i
> 0; i
--, ppWnd
++)
298 if (!IsWindow32( (*ppWnd
)->hwndSelf
)) continue;
299 SendMessage16( (*ppWnd
)->hwndSelf
, WM_ENDSESSION
, result
, 0 );
301 HeapFree( SystemHeap
, 0, list
);
303 if (result
) USER_ExitWindows();
308 /***********************************************************************
309 * ChangeDisplaySettingA (USER32.589)
311 LONG WINAPI
ChangeDisplaySettings32A( LPDEVMODE32A devmode
, DWORD flags
)
313 FIXME(system
, ": stub\n");
315 FIXME(system
," devmode=NULL (return to default mode)\n");
316 else if ( (devmode
->dmBitsPerPel
!= DefaultDepthOfScreen(screen
))
317 || (devmode
->dmPelsHeight
!= screenHeight
)
318 || (devmode
->dmPelsWidth
!= screenWidth
) )
322 if (devmode
->dmFields
& DM_BITSPERPEL
)
323 FIXME(system
," bpp=%ld\n",devmode
->dmBitsPerPel
);
324 if (devmode
->dmFields
& DM_PELSWIDTH
)
325 FIXME(system
," width=%ld\n",devmode
->dmPelsWidth
);
326 if (devmode
->dmFields
& DM_PELSHEIGHT
)
327 FIXME(system
," height=%ld\n",devmode
->dmPelsHeight
);
328 FIXME(system
," (Putting X in this mode beforehand might help)\n");
330 return DISP_CHANGE_SUCCESSFUL
;
334 /***********************************************************************
335 * EnumDisplaySettingsA (USER32.592)
337 BOOL32 WINAPI
EnumDisplaySettings32A(LPCSTR name
,DWORD n
,LPDEVMODE32A devmode
) {
338 TRACE(system
,"(%s,%ld,%p)\n",name
,n
,devmode
);
340 devmode
->dmBitsPerPel
= DefaultDepthOfScreen(screen
);
341 devmode
->dmPelsHeight
= screenHeight
;
342 devmode
->dmPelsWidth
= screenWidth
;
349 /***********************************************************************
350 * SetEventHook (USER.321)
352 * Used by Turbo Debugger for Windows
354 FARPROC16 WINAPI
SetEventHook(FARPROC16 lpfnEventHook
)
356 FIXME(hook
, "(lpfnEventHook=%08x): stub\n", (UINT32
)lpfnEventHook
);
360 /***********************************************************************
361 * UserSeeUserDo (USER.216)
363 DWORD WINAPI
UserSeeUserDo(WORD wReqType
, WORD wParam1
, WORD wParam2
, WORD wParam3
)
367 case USUD_LOCALALLOC
:
368 return LOCAL_Alloc(USER_HeapSel
, wParam1
, wParam3
);
370 return LOCAL_Free(USER_HeapSel
, wParam1
);
371 case USUD_LOCALCOMPACT
:
372 return LOCAL_Compact(USER_HeapSel
, wParam3
, 0);
375 case USUD_FIRSTCLASS
:
376 FIXME(local
, "return a pointer to the first window class.\n");
379 WARN(local
, "wReqType %04x (unknown)", wReqType
);