Release 970329
[wine/multimedia.git] / misc / user.c
blob0d0ecb8d544327ed3a7dee9a8201a8eab6c75350
1 /*
2 * Misc. USER functions
4 * Copyright 1993 Robert J. Amstadt
5 * 1996 Alex Korobka
6 */
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include "windows.h"
11 #include "gdi.h"
12 #include "user.h"
13 #include "task.h"
14 #include "queue.h"
15 #include "win.h"
16 #include "hook.h"
17 #include "debug.h"
18 #include "toolhelp.h"
19 #include "message.h"
21 WORD USER_HeapSel = 0;
23 extern BOOL32 MENU_SwitchTPWndTo(HTASK16);
25 /***********************************************************************
26 * GetFreeSystemResources (USER.284)
28 WORD GetFreeSystemResources( WORD resType )
30 int userPercent, gdiPercent;
32 switch(resType)
34 case GFSR_USERRESOURCES:
35 userPercent = (int)LOCAL_CountFree( USER_HeapSel ) * 100 /
36 LOCAL_HeapSize( USER_HeapSel );
37 gdiPercent = 100;
38 break;
40 case GFSR_GDIRESOURCES:
41 gdiPercent = (int)LOCAL_CountFree( GDI_HeapSel ) * 100 /
42 LOCAL_HeapSize( GDI_HeapSel );
43 userPercent = 100;
44 break;
46 case GFSR_SYSTEMRESOURCES:
47 userPercent = (int)LOCAL_CountFree( USER_HeapSel ) * 100 /
48 LOCAL_HeapSize( USER_HeapSel );
49 gdiPercent = (int)LOCAL_CountFree( GDI_HeapSel ) * 100 /
50 LOCAL_HeapSize( GDI_HeapSel );
51 break;
53 default:
54 return 0;
56 return (WORD)MIN( userPercent, gdiPercent );
60 /***********************************************************************
61 * SystemHeapInfo (TOOLHELP.71)
63 BOOL16 SystemHeapInfo( SYSHEAPINFO *pHeapInfo )
65 pHeapInfo->wUserFreePercent = GetFreeSystemResources( GFSR_USERRESOURCES );
66 pHeapInfo->wGDIFreePercent = GetFreeSystemResources( GFSR_GDIRESOURCES );
67 pHeapInfo->hUserSegment = USER_HeapSel;
68 pHeapInfo->hGDISegment = GDI_HeapSel;
69 return TRUE;
73 /***********************************************************************
74 * TimerCount (TOOLHELP.80)
76 BOOL16 TimerCount( TIMERINFO *pTimerInfo )
78 /* FIXME
79 * In standard mode, dwmsSinceStart = dwmsThisVM
81 * I tested this, under Windows in enhanced mode, and
82 * if you never switch VM (ie start/stop DOS) these
83 * values should be the same as well.
85 * Also, Wine should adjust for the hardware timer
86 * to reduce the amount of error to ~1ms.
87 * I can't be bothered, can you?
89 pTimerInfo->dwmsSinceStart = pTimerInfo->dwmsThisVM = GetTickCount();
90 return TRUE;
94 /**********************************************************************
95 * InitApp (USER.5)
97 INT16 InitApp( HINSTANCE16 hInstance )
99 int queueSize;
101 /* Create task message queue */
102 queueSize = GetProfileInt32A( "windows", "DefaultQueueSize", 8 );
103 if (!SetMessageQueue32( queueSize )) return 0;
105 return 1;
108 /**********************************************************************
109 * USER_AppExit
111 void USER_AppExit( HTASK16 hTask, HINSTANCE16 hInstance, HQUEUE16 hQueue )
113 /* FIXME: empty clipboard if needed, maybe destroy menus (Windows
114 * only complains about them but does nothing);
117 WND* desktop = WIN_GetDesktop();
119 /* Patch desktop window */
120 if( desktop->hmemTaskQ == hQueue )
121 desktop->hmemTaskQ = GetTaskQueue(TASK_GetNextTask(hTask));
123 /* Patch resident popup menu window */
124 MENU_SwitchTPWndTo(0);
126 TIMER_RemoveQueueTimers( hQueue );
128 QUEUE_FlushMessages( hQueue );
129 HOOK_FreeQueueHooks( hQueue );
131 QUEUE_SetDoomedQueue( hQueue );
132 WIN_ResetQueueWindows( desktop->child, hQueue, (HQUEUE16)0);
133 QUEUE_SetDoomedQueue( 0 );
135 /* Free the message queue */
137 QUEUE_DeleteMsgQueue( hQueue );