4 * Copyright 1993 Robert J. Amstadt
22 WORD USER_HeapSel
= 0;
24 extern BOOL32
MENU_SwitchTPWndTo(HTASK16
);
25 extern void QUEUE_FlushMessages(HQUEUE16
);
27 /***********************************************************************
28 * GetFreeSystemResources (USER.284)
30 WORD
GetFreeSystemResources( WORD resType
)
32 int userPercent
, gdiPercent
;
36 case GFSR_USERRESOURCES
:
37 userPercent
= (int)LOCAL_CountFree( USER_HeapSel
) * 100 /
38 LOCAL_HeapSize( USER_HeapSel
);
42 case GFSR_GDIRESOURCES
:
43 gdiPercent
= (int)LOCAL_CountFree( GDI_HeapSel
) * 100 /
44 LOCAL_HeapSize( GDI_HeapSel
);
48 case GFSR_SYSTEMRESOURCES
:
49 userPercent
= (int)LOCAL_CountFree( USER_HeapSel
) * 100 /
50 LOCAL_HeapSize( USER_HeapSel
);
51 gdiPercent
= (int)LOCAL_CountFree( GDI_HeapSel
) * 100 /
52 LOCAL_HeapSize( GDI_HeapSel
);
58 return (WORD
)MIN( userPercent
, gdiPercent
);
62 /***********************************************************************
63 * SystemHeapInfo (TOOLHELP.71)
65 BOOL16
SystemHeapInfo( SYSHEAPINFO
*pHeapInfo
)
67 pHeapInfo
->wUserFreePercent
= GetFreeSystemResources( GFSR_USERRESOURCES
);
68 pHeapInfo
->wGDIFreePercent
= GetFreeSystemResources( GFSR_GDIRESOURCES
);
69 pHeapInfo
->hUserSegment
= USER_HeapSel
;
70 pHeapInfo
->hGDISegment
= GDI_HeapSel
;
75 /***********************************************************************
76 * TimerCount (TOOLHELP.80)
78 BOOL16
TimerCount( TIMERINFO
*pTimerInfo
)
81 * In standard mode, dwmsSinceStart = dwmsThisVM
83 * I tested this, under Windows in enhanced mode, and
84 * if you never switch VM (ie start/stop DOS) these
85 * values should be the same as well.
87 * Also, Wine should adjust for the hardware timer
88 * to reduce the amount of error to ~1ms.
89 * I can't be bothered, can you?
91 pTimerInfo
->dwmsSinceStart
= pTimerInfo
->dwmsThisVM
= GetTickCount();
96 /**********************************************************************
99 INT16
InitApp( HINSTANCE16 hInstance
)
103 /* Create task message queue */
104 queueSize
= GetProfileInt32A( "windows", "DefaultQueueSize", 8 );
105 if (!SetMessageQueue32( queueSize
)) return 0;
110 /**********************************************************************
113 void USER_AppExit( HTASK16 hTask
, HINSTANCE16 hInstance
, HQUEUE16 hQueue
)
115 /* FIXME: empty clipboard if needed, maybe destroy menus (Windows
116 * only complains about them but does nothing);
119 WND
* desktop
= WIN_GetDesktop();
121 /* Patch desktop window */
122 if( desktop
->hmemTaskQ
== hQueue
)
123 desktop
->hmemTaskQ
= GetTaskQueue(TASK_GetNextTask(hTask
));
125 /* Patch resident popup menu window */
126 MENU_SwitchTPWndTo(0);
128 TIMER_RemoveQueueTimers( hQueue
);
130 QUEUE_FlushMessages( hQueue
);
131 HOOK_FreeQueueHooks( hQueue
);
133 QUEUE_SetDoomedQueue( hQueue
);
134 WIN_ResetQueueWindows( desktop
->child
, hQueue
, (HQUEUE16
)0);
135 QUEUE_SetDoomedQueue( 0 );
137 /* Free the message queue */
139 QUEUE_DeleteMsgQueue( hQueue
);
143 /***********************************************************************
146 * Clean-up everything and exit the Wine process.
147 * This is the back-end of ExitWindows(), called when all windows
148 * have agreed to be terminated.
150 void USER_ExitWindows(void)
152 /* Do the clean-up stuff */
155 SHELL_SaveRegistry();
161 /***********************************************************************
162 * ExitWindows16 (USER.7)
164 BOOL16
ExitWindows16( DWORD dwReturnCode
, UINT16 wReserved
)
166 return ExitWindowsEx( EWX_LOGOFF
, 0xffffffff );
170 /***********************************************************************
171 * ExitWindowsEx (USER32.195)
173 BOOL32
ExitWindowsEx( UINT32 flags
, DWORD reserved
)
179 /* We have to build a list of all windows first, as in EnumWindows */
181 if (!(list
= WIN_BuildWinArray( WIN_GetDesktop() ))) return FALSE
;
183 /* Send a WM_QUERYENDSESSION message to every window */
185 for (ppWnd
= list
, i
= 0; *ppWnd
; ppWnd
++, i
++)
187 /* Make sure that the window still exists */
188 if (!IsWindow32( (*ppWnd
)->hwndSelf
)) continue;
189 if (!SendMessage16( (*ppWnd
)->hwndSelf
, WM_QUERYENDSESSION
, 0, 0 ))
194 /* Now notify all windows that got a WM_QUERYENDSESSION of the result */
196 for (ppWnd
= list
; i
> 0; i
--, ppWnd
++)
198 if (!IsWindow32( (*ppWnd
)->hwndSelf
)) continue;
199 SendMessage16( (*ppWnd
)->hwndSelf
, WM_ENDSESSION
, result
, 0 );
201 HeapFree( SystemHeap
, 0, list
);
203 if (result
) USER_ExitWindows();