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 )
133 /* InitTask() calls LibMain()'s of implicitly loaded DLLs
134 * prior to InitApp() so there is no clean way to do
135 * SetTaskSignalHandler() in time. So, broken Windows bypasses
136 * a pTask->userhandler on startup and simply calls a global
137 * function pointer to the default USER signal handler.
140 USER_InstallRsrcHandler( hInstance );
142 /* Hack: restore the divide-by-zero handler */
143 /* FIXME: should set a USER-specific handler that displays a msg box */
144 INT_SetPMHandler( 0, INT_GetPMHandler( 0xff ) );
146 /* Create task message queue */
147 if ( !GetFastQueue() ) return 0;
152 /**********************************************************************
155 static void USER_ModuleUnload( HMODULE16 hModule )
157 HOOK_FreeModuleHooks( hModule );
158 CLASS_FreeModuleClasses( hModule );
161 /**********************************************************************
164 static void USER_AppExit( HTASK16 hTask, HINSTANCE16 hInstance, HQUEUE16 hQueue )
168 /* FIXME: empty clipboard if needed, maybe destroy menus (Windows
169 * only complains about them but does nothing);
172 WND* desktop = WIN_GetDesktop();
174 /* Patch desktop window */
175 if( desktop->hmemTaskQ == hQueue )
176 desktop->hmemTaskQ = GetTaskQueue(TASK_GetNextTask(hTask));
178 /* Patch resident popup menu window */
179 MENU_PatchResidentPopup( hQueue, NULL );
181 TIMER_RemoveQueueTimers( hQueue );
183 QUEUE_FlushMessages( hQueue );
184 HOOK_FreeQueueHooks( hQueue );
186 QUEUE_SetExitingQueue( hQueue );
187 WIN_ResetQueueWindows( desktop, hQueue, (HQUEUE16)0);
188 CLIPBOARD_ResetLock( hQueue, 0 );
189 QUEUE_SetExitingQueue( 0 );
191 /* Free the message queue */
192 QUEUE_DeleteMsgQueue( hQueue );
195 /* ModuleUnload() in "Internals" */
197 hInstance = GetExePtr( hInstance );
198 if( GetModuleUsage( hInstance ) <= 1 )
199 USER_ModuleUnload( hInstance );
203 /***********************************************************************
206 * Clean-up everything and exit the Wine process.
207 * This is the back-end of ExitWindows(), called when all windows
208 * have agreed to be terminated.
210 void USER_ExitWindows(void)
212 /* Do the clean-up stuff */
215 SHELL_SaveRegistry();
221 /***********************************************************************
222 * USER_SignalProc (USER.314)
224 void WINAPI USER_SignalProc( HANDLE16 hTaskOrModule, UINT16 uCode,
225 UINT16 uExitFn, HINSTANCE16 hInstance,
231 case USIG_TERMINATION:
232 USER_AppExit( hTaskOrModule, hInstance, hQueue ); /* task */
236 USER_InstallRsrcHandler( hTaskOrModule ); /* module */
239 case USIG_DLL_UNLOAD:
240 USER_ModuleUnload( hTaskOrModule ); /* module */
244 FIXME(msg,"Unimplemented USER signal: %i\n", (int)uCode );
249 /***********************************************************************
250 * ExitWindows16 (USER.7)
252 BOOL16 WINAPI ExitWindows16( DWORD dwReturnCode, UINT16 wReserved )
254 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
258 /***********************************************************************
259 * ExitWindowsExec16 (USER.246)
261 BOOL16 WINAPI ExitWindowsExec16( LPCSTR lpszExe, LPCSTR lpszParams )
263 TRACE(system, "Should run the following in DOS-mode: \"%s %s\"\n",
264 lpszExe, lpszParams);
265 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
269 /***********************************************************************
270 * ExitWindowsEx (USER32.196)
272 BOOL32 WINAPI ExitWindowsEx( UINT32 flags, DWORD reserved )
278 /* We have to build a list of all windows first, as in EnumWindows */
280 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL ))) return FALSE;
282 /* Send a WM_QUERYENDSESSION message to every window */
284 for (ppWnd = list, i = 0; *ppWnd; ppWnd++, i++)
286 /* Make sure that the window still exists */
287 if (!IsWindow32( (*ppWnd)->hwndSelf )) continue;
288 if (!SendMessage16( (*ppWnd)->hwndSelf, WM_QUERYENDSESSION, 0, 0 ))
293 /* Now notify all windows that got a WM_QUERYENDSESSION of the result */
295 for (ppWnd = list; i > 0; i--, ppWnd++)
297 if (!IsWindow32( (*ppWnd)->hwndSelf )) continue;
298 SendMessage16( (*ppWnd)->hwndSelf, WM_ENDSESSION, result, 0 );
300 HeapFree( SystemHeap, 0, list );
302 if (result) USER_ExitWindows();
307 /***********************************************************************
308 * ChangeDisplaySettingA (USER32.589)
310 LONG WINAPI ChangeDisplaySettings32A( LPDEVMODE32A devmode, DWORD flags )
312 FIXME(system, ": stub\n");
314 FIXME(system," devmode=NULL (return to default mode)\n");
315 else if ( (devmode->dmBitsPerPel != DefaultDepthOfScreen(screen))
316 || (devmode->dmPelsHeight != screenHeight)
317 || (devmode->dmPelsWidth != screenWidth) )
321 if (devmode->dmFields & DM_BITSPERPEL)
322 FIXME(system," bpp=%ld\n",devmode->dmBitsPerPel);
323 if (devmode->dmFields & DM_PELSWIDTH)
324 FIXME(system," width=%ld\n",devmode->dmPelsWidth);
325 if (devmode->dmFields & DM_PELSHEIGHT)
326 FIXME(system," height=%ld\n",devmode->dmPelsHeight);
327 FIXME(system," (Putting X in this mode beforehand might help)\n");
328 /* we don't, but the program ... does not need to know */
329 return DISP_CHANGE_SUCCESSFUL;
331 return DISP_CHANGE_SUCCESSFUL;
334 /***********************************************************************
335 * EnumDisplaySettingsA (USER32.592)
336 * FIXME: Currently uses static list of modes.
339 * TRUE if nth setting exists found (described in the LPDEVMODE32A struct)
340 * FALSE if we do not have the nth setting
342 BOOL32 WINAPI EnumDisplaySettings32A(
343 LPCSTR name, /* [in] huh? */
344 DWORD n, /* [in] nth entry in display settings list*/
345 LPDEVMODE32A devmode /* [out] devmode for that setting */
351 } modes[NRMODES]={{512,384},{640,400},{640,480},{800,600},{1024,768}};
352 int depths[4] = {8,16,24,32};
354 TRACE(system,"(%s,%ld,%p)\n",name,n,devmode);
356 devmode->dmBitsPerPel = DefaultDepthOfScreen(screen);
357 devmode->dmPelsHeight = screenHeight;
358 devmode->dmPelsWidth = screenWidth;
361 if ((n-1)<NRMODES*NRDEPTHS) {
362 devmode->dmBitsPerPel = depths[(n-1)/NRMODES];
363 devmode->dmPelsHeight = modes[(n-1)%NRMODES].h;
364 devmode->dmPelsWidth = modes[(n-1)%NRMODES].w;
370 /***********************************************************************
371 * EnumDisplaySettingsW (USER32.593)
373 BOOL32 WINAPI EnumDisplaySettings32W(LPCWSTR name,DWORD n,LPDEVMODE32W devmode) {
374 LPSTR nameA = HEAP_strdupWtoA(GetProcessHeap(),0,name);
376 BOOL32 ret = EnumDisplaySettings32A(nameA,n,&devmodeA);
379 devmode->dmBitsPerPel = devmodeA.dmBitsPerPel;
380 devmode->dmPelsHeight = devmodeA.dmPelsHeight;
381 devmode->dmPelsWidth = devmodeA.dmPelsWidth;
382 /* FIXME: convert rest too, if they are ever returned */
384 HeapFree(GetProcessHeap(),0,nameA);
388 /***********************************************************************
389 * SetEventHook (USER.321)
391 * Used by Turbo Debugger for Windows
393 FARPROC16 WINAPI SetEventHook(FARPROC16 lpfnEventHook)
395 FIXME(hook, "(lpfnEventHook=%08x): stub\n", (UINT32)lpfnEventHook);
399 /***********************************************************************
400 * UserSeeUserDo (USER.216)
402 DWORD WINAPI UserSeeUserDo(WORD wReqType, WORD wParam1, WORD wParam2, WORD wParam3)
406 case USUD_LOCALALLOC:
407 return LOCAL_Alloc(USER_HeapSel, wParam1, wParam3);
409 return LOCAL_Free(USER_HeapSel, wParam1);
410 case USUD_LOCALCOMPACT:
411 return LOCAL_Compact(USER_HeapSel, wParam3, 0);
414 case USUD_FIRSTCLASS:
415 FIXME(local, "return a pointer to the first window class.\n");
418 WARN(local, "wReqType %04x (unknown)", wReqType);
423 /***********************************************************************
424 * RegisterLogonProcess (USER32.434)
426 DWORD WINAPI RegisterLogonProcess(HANDLE32 hprocess,BOOL32 x) {
427 FIXME(win32,"(%d,%d),stub!\n",hprocess,x);
431 /***********************************************************************
432 * CreateWindowStation32W (USER32.86)
434 HWINSTA32 WINAPI CreateWindowStation32W(
435 LPWSTR winstation,DWORD res1,DWORD desiredaccess,
436 LPSECURITY_ATTRIBUTES lpsa
438 FIXME(win32,"(%s,0x%08lx,0x%08lx,%p),stub!\n",debugstr_w(winstation),
439 res1,desiredaccess,lpsa
444 /***********************************************************************
445 * SetProcessWindowStation (USER32.496)
447 BOOL32 WINAPI SetProcessWindowStation(HWINSTA32 hWinSta) {
448 FIXME(win32,"(%d),stub!\n",hWinSta);
452 /***********************************************************************
453 * SetUserObjectSecurity (USER32.514)
455 BOOL32 WINAPI SetUserObjectSecurity(
457 /*LPSECURITY_INFORMATION*/LPVOID pSIRequested,
458 /*LPSECURITY_DESCRIPTOR*/LPVOID pSID
460 FIXME(win32,"(%d,%p,%p),stub!\n",hObj,pSIRequested,pSID);
464 /***********************************************************************
465 * CreateDesktop32W (USER32.69)
467 HDESK32 WINAPI CreateDesktop32W(
468 LPWSTR lpszDesktop,LPWSTR lpszDevice,LPDEVMODE32W pDevmode,
469 DWORD dwFlags,DWORD dwDesiredAccess,LPSECURITY_ATTRIBUTES lpsa
471 FIXME(win32,"(%s,%s,%p,0x%08lx,0x%08lx,%p),stub!\n",
472 debugstr_w(lpszDesktop),debugstr_w(lpszDevice),pDevmode,
473 dwFlags,dwDesiredAccess,lpsa
478 /***********************************************************************
479 * SetWindowStationUser (USER32.521)
481 DWORD WINAPI SetWindowStationUser(DWORD x1,DWORD x2) {
482 FIXME(win32,"(%ld,%ld),stub!\n",x1,x2);
486 /***********************************************************************
487 * SetLogonNotifyWindow (USER32.486)
489 DWORD WINAPI SetLogonNotifyWindow(HWINSTA32 hwinsta,HWND32 hwnd) {
490 FIXME(win32,"(0x%x,%04x),stub!\n",hwinsta,hwnd);
494 /***********************************************************************
495 * LoadLocalFonts (USER32.486)
497 VOID WINAPI LoadLocalFonts(VOID) {
501 /***********************************************************************
502 * GetUserObjectInformation32A (USER32.299)
504 BOOL32 WINAPI GetUserObjectInformation32A( HANDLE32 hObj, int nIndex, LPVOID pvInfo, DWORD nLength, LPDWORD lpnLen )
505 { FIXME(win32,"(0x%x %i %p %ld %p),stub!\n", hObj, nIndex, pvInfo, nLength, lpnLen );
508 /***********************************************************************
509 * GetUserObjectInformation32W (USER32.300)
511 BOOL32 WINAPI GetUserObjectInformation32W( HANDLE32 hObj, int nIndex, LPVOID pvInfo, DWORD nLength, LPDWORD lpnLen )
512 { FIXME(win32,"(0x%x %i %p %ld %p),stub!\n", hObj, nIndex, pvInfo, nLength, lpnLen );