Release 960712
[wine/multimedia.git] / misc / user.c
blobeadf06b25f7259b4d7589bf2c11ffd09385cc589
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"
20 WORD USER_HeapSel = 0;
23 extern HTASK TASK_GetNextTask(HTASK);
24 extern void QUEUE_SetDoomedQueue(HQUEUE);
26 /***********************************************************************
27 * GetFreeSystemResources (USER.284)
29 WORD GetFreeSystemResources( WORD resType )
31 int userPercent, gdiPercent;
33 switch(resType)
35 case GFSR_USERRESOURCES:
36 userPercent = (int)LOCAL_CountFree( USER_HeapSel ) * 100 /
37 LOCAL_HeapSize( USER_HeapSel );
38 gdiPercent = 100;
39 break;
41 case GFSR_GDIRESOURCES:
42 gdiPercent = (int)LOCAL_CountFree( GDI_HeapSel ) * 100 /
43 LOCAL_HeapSize( GDI_HeapSel );
44 userPercent = 100;
45 break;
47 case GFSR_SYSTEMRESOURCES:
48 userPercent = (int)LOCAL_CountFree( USER_HeapSel ) * 100 /
49 LOCAL_HeapSize( USER_HeapSel );
50 gdiPercent = (int)LOCAL_CountFree( GDI_HeapSel ) * 100 /
51 LOCAL_HeapSize( GDI_HeapSel );
52 break;
54 default:
55 return 0;
57 return (WORD)MIN( userPercent, gdiPercent );
61 /***********************************************************************
62 * SystemHeapInfo (TOOLHELP.71)
64 BOOL16 SystemHeapInfo( SYSHEAPINFO *pHeapInfo )
66 pHeapInfo->wUserFreePercent = GetFreeSystemResources( GFSR_USERRESOURCES );
67 pHeapInfo->wGDIFreePercent = GetFreeSystemResources( GFSR_GDIRESOURCES );
68 pHeapInfo->hUserSegment = USER_HeapSel;
69 pHeapInfo->hGDISegment = GDI_HeapSel;
70 return TRUE;
74 /***********************************************************************
75 * TimerCount (TOOLHELP.80)
77 BOOL16 TimerCount( TIMERINFO *pTimerInfo )
79 /* FIXME
80 * In standard mode, dwmsSinceStart = dwmsThisVM
82 * I tested this, under Windows in enhanced mode, and
83 * if you never switch VM (ie start/stop DOS) these
84 * values should be the same as well.
86 * Also, Wine should adjust for the hardware timer
87 * to reduce the amount of error to ~1ms.
88 * I can't be bothered, can you?
90 pTimerInfo->dwmsSinceStart = pTimerInfo->dwmsThisVM = GetTickCount();
91 return TRUE;
95 /**********************************************************************
96 * USER_InitApp
98 int USER_InitApp(HINSTANCE hInstance)
100 int queueSize;
102 /* Create task message queue */
103 queueSize = GetProfileInt( "windows", "DefaultQueueSize", 8 );
104 if (!SetMessageQueue( queueSize )) return 0;
106 return 1;
109 /**********************************************************************
110 * USER_AppExit
112 void USER_AppExit(HTASK hTask, HINSTANCE hInstance, HQUEUE hQueue)
114 /* FIXME: flush send messages (which are not implemented yet),
115 * 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 queue */
122 if( desktop->hmemTaskQ == hQueue )
123 desktop->hmemTaskQ = GetTaskQueue(TASK_GetNextTask(hTask));
125 /* Nuke timers */
127 TIMER_RemoveQueueTimers( hQueue );
129 HOOK_FreeQueueHooks( hQueue );
131 QUEUE_SetDoomedQueue( hQueue );
133 /* Nuke orphaned windows */
135 WIN_DestroyQueueWindows( desktop->child, hQueue );
137 QUEUE_SetDoomedQueue( 0 );
139 /* Free the message queue */
141 QUEUE_DeleteMsgQueue( hQueue );