4 * Copyright 1993 Robert J. Amstadt
17 #include "clipboard.h"
30 /***********************************************************************
31 * GetFreeSystemResources (USER.284)
33 WORD WINAPI GetFreeSystemResources( WORD resType )
35 int userPercent, gdiPercent;
39 case GFSR_USERRESOURCES:
40 userPercent = (int)LOCAL_CountFree( USER_HeapSel ) * 100 /
41 LOCAL_HeapSize( USER_HeapSel );
45 case GFSR_GDIRESOURCES:
46 gdiPercent = (int)LOCAL_CountFree( GDI_HeapSel ) * 100 /
47 LOCAL_HeapSize( GDI_HeapSel );
51 case GFSR_SYSTEMRESOURCES:
52 userPercent = (int)LOCAL_CountFree( USER_HeapSel ) * 100 /
53 LOCAL_HeapSize( USER_HeapSel );
54 gdiPercent = (int)LOCAL_CountFree( GDI_HeapSel ) * 100 /
55 LOCAL_HeapSize( GDI_HeapSel );
61 return (WORD)MIN( userPercent, gdiPercent );
65 /***********************************************************************
66 * SystemHeapInfo (TOOLHELP.71)
68 BOOL16 WINAPI SystemHeapInfo( SYSHEAPINFO *pHeapInfo )
70 pHeapInfo->wUserFreePercent = GetFreeSystemResources( GFSR_USERRESOURCES );
71 pHeapInfo->wGDIFreePercent = GetFreeSystemResources( GFSR_GDIRESOURCES );
72 pHeapInfo->hUserSegment = USER_HeapSel;
73 pHeapInfo->hGDISegment = GDI_HeapSel;
78 /***********************************************************************
79 * TimerCount (TOOLHELP.80)
81 BOOL16 WINAPI TimerCount( TIMERINFO *pTimerInfo )
84 * In standard mode, dwmsSinceStart = dwmsThisVM
86 * I tested this, under Windows in enhanced mode, and
87 * if you never switch VM (ie start/stop DOS) these
88 * values should be the same as well.
90 * Also, Wine should adjust for the hardware timer
91 * to reduce the amount of error to ~1ms.
92 * I can't be bothered, can you?
94 pTimerInfo->dwmsSinceStart = pTimerInfo->dwmsThisVM = GetTickCount();
98 static FARPROC16 __r16loader = NULL;
100 /**********************************************************************
101 * USER_CallDefaultRsrcHandler
103 * Called by the LoadDIBIcon/CursorHandler().
105 HGLOBAL16 USER_CallDefaultRsrcHandler( HGLOBAL16 hMemObj, HMODULE16 hModule, HRSRC16 hRsrc )
107 return Callbacks->CallResourceHandlerProc( __r16loader, hMemObj, hModule, hRsrc );
110 /**********************************************************************
111 * USER_InstallRsrcHandler
113 static void USER_InstallRsrcHandler( HINSTANCE16 hInstance )
117 /* SetResourceHandler() returns previous function which is set
118 * when a module's resource table is loaded. */
120 proc = SetResourceHandler( hInstance, RT_ICON16,
121 MODULE_GetWndProcEntry16("LoadDIBIconHandler") );
122 if (!__r16loader) __r16loader = proc;
124 proc = SetResourceHandler( hInstance, RT_CURSOR16,
125 MODULE_GetWndProcEntry16("LoadDIBCursorHandler") );
126 if (!__r16loader) __r16loader = proc;
129 /**********************************************************************
132 INT16 WINAPI InitApp( HINSTANCE16 hInstance )
136 /* InitTask() calls LibMain()'s of implicitly loaded DLLs
137 * prior to InitApp() so there is no clean way to do
138 * SetTaskSignalHandler() in time. So, broken Windows bypasses
139 * a pTask->userhandler on startup and simply calls a global
140 * function pointer to the default USER signal handler.
143 USER_InstallRsrcHandler( hInstance );
145 /* Hack: restore the divide-by-zero handler */
146 /* FIXME: should set a USER-specific handler that displays a msg box */
147 INT_SetPMHandler( 0, INT_GetPMHandler( 0xff ) );
149 /* Create task message queue */
150 queueSize = GetProfileInt32A( "windows", "DefaultQueueSize", 8 );
151 if (!SetMessageQueue32( queueSize )) return 0;
156 /**********************************************************************
159 static void USER_ModuleUnload( HMODULE16 hModule )
161 HOOK_FreeModuleHooks( hModule );
162 CLASS_FreeModuleClasses( hModule );
165 /**********************************************************************
168 static void USER_AppExit( HTASK16 hTask, HINSTANCE16 hInstance, HQUEUE16 hQueue )
170 /* FIXME: empty clipboard if needed, maybe destroy menus (Windows
171 * only complains about them but does nothing);
174 WND* desktop = WIN_GetDesktop();
176 /* Patch desktop window */
177 if( desktop->hmemTaskQ == hQueue )
178 desktop->hmemTaskQ = GetTaskQueue(TASK_GetNextTask(hTask));
180 /* Patch resident popup menu window */
181 MENU_PatchResidentPopup( hQueue, NULL );
183 TIMER_RemoveQueueTimers( hQueue );
185 QUEUE_FlushMessages( hQueue );
186 HOOK_FreeQueueHooks( hQueue );
188 QUEUE_SetExitingQueue( hQueue );
189 WIN_ResetQueueWindows( desktop, hQueue, (HQUEUE16)0);
190 CLIPBOARD_ResetLock( hQueue, 0 );
191 QUEUE_SetExitingQueue( 0 );
193 /* Free the message queue */
195 QUEUE_DeleteMsgQueue( hQueue );
197 /* ModuleUnload() in "Internals" */
199 hInstance = GetExePtr( hInstance );
200 if( GetModuleUsage( hInstance ) <= 1 )
201 USER_ModuleUnload( hInstance );
205 /***********************************************************************
208 * Clean-up everything and exit the Wine process.
209 * This is the back-end of ExitWindows(), called when all windows
210 * have agreed to be terminated.
212 void USER_ExitWindows(void)
214 /* Do the clean-up stuff */
217 SHELL_SaveRegistry();
223 /***********************************************************************
224 * USER_SignalProc (USER.314)
226 void WINAPI USER_SignalProc( HANDLE16 hTaskOrModule, UINT16 uCode,
227 UINT16 uExitFn, HINSTANCE16 hInstance,
233 case USIG_TERMINATION:
234 USER_AppExit( hTaskOrModule, hInstance, hQueue ); /* task */
238 USER_InstallRsrcHandler( hTaskOrModule ); /* module */
241 case USIG_DLL_UNLOAD:
242 USER_ModuleUnload( hTaskOrModule ); /* module */
246 FIXME(msg,"Unimplemented USER signal: %i\n", (int)uCode );
251 /***********************************************************************
252 * ExitWindows16 (USER.7)
254 BOOL16 WINAPI ExitWindows16( DWORD dwReturnCode, UINT16 wReserved )
256 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
260 /***********************************************************************
261 * ExitWindowsExec16 (USER.246)
263 BOOL16 WINAPI ExitWindowsExec16( LPCSTR lpszExe, LPCSTR lpszParams )
265 TRACE(system, "Should run the following in DOS-mode: \"%s %s\"\n",
266 lpszExe, lpszParams);
267 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
271 /***********************************************************************
272 * ExitWindowsEx (USER32.196)
274 BOOL32 WINAPI ExitWindowsEx( UINT32 flags, DWORD reserved )
280 /* We have to build a list of all windows first, as in EnumWindows */
282 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL ))) return FALSE;
284 /* Send a WM_QUERYENDSESSION message to every window */
286 for (ppWnd = list, i = 0; *ppWnd; ppWnd++, i++)
288 /* Make sure that the window still exists */
289 if (!IsWindow32( (*ppWnd)->hwndSelf )) continue;
290 if (!SendMessage16( (*ppWnd)->hwndSelf, WM_QUERYENDSESSION, 0, 0 ))
295 /* Now notify all windows that got a WM_QUERYENDSESSION of the result */
297 for (ppWnd = list; i > 0; i--, ppWnd++)
299 if (!IsWindow32( (*ppWnd)->hwndSelf )) continue;
300 SendMessage16( (*ppWnd)->hwndSelf, WM_ENDSESSION, result, 0 );
302 HeapFree( SystemHeap, 0, list );
304 if (result) USER_ExitWindows();
309 /***********************************************************************
310 * ChangeDisplaySettingA (USER32.589)
312 LONG WINAPI ChangeDisplaySettings32A( LPDEVMODE32A devmode, DWORD flags )
314 FIXME(system, ": stub\n");
316 FIXME(system," devmode=NULL (return to default mode)\n");
317 else if ( (devmode->dmBitsPerPel != DefaultDepthOfScreen(screen))
318 || (devmode->dmPelsHeight != screenHeight)
319 || (devmode->dmPelsWidth != screenWidth) )
323 if (devmode->dmFields & DM_BITSPERPEL)
324 FIXME(system," bpp=%ld\n",devmode->dmBitsPerPel);
325 if (devmode->dmFields & DM_PELSWIDTH)
326 FIXME(system," width=%ld\n",devmode->dmPelsWidth);
327 if (devmode->dmFields & DM_PELSHEIGHT)
328 FIXME(system," height=%ld\n",devmode->dmPelsHeight);
329 FIXME(system," (Putting X in this mode beforehand might help)\n");
330 /* we don't, but the program ... does not need to know */
331 return DISP_CHANGE_SUCCESSFUL;
333 return DISP_CHANGE_SUCCESSFUL;
336 /***********************************************************************
337 * EnumDisplaySettingsA (USER32.592)
338 * FIXME: Currently uses static list of modes.
341 * TRUE if nth setting exists found (described in the LPDEVMODE32A struct)
342 * FALSE if we do not have the nth setting
344 BOOL32 WINAPI EnumDisplaySettings32A(
345 LPCSTR name, /* [in] huh? */
346 DWORD n, /* [in] nth entry in display settings list*/
347 LPDEVMODE32A devmode /* [out] devmode for that setting */
353 } modes[NRMODES]={{512,384},{640,400},{640,480},{800,600},{1024,768}};
354 int depths[4] = {8,16,24,32};
356 TRACE(system,"(%s,%ld,%p)\n",name,n,devmode);
358 devmode->dmBitsPerPel = DefaultDepthOfScreen(screen);
359 devmode->dmPelsHeight = screenHeight;
360 devmode->dmPelsWidth = screenWidth;
363 if ((n-1)<NRMODES*NRDEPTHS) {
364 devmode->dmBitsPerPel = depths[(n-1)/NRMODES];
365 devmode->dmPelsHeight = modes[(n-1)%NRMODES].h;
366 devmode->dmPelsWidth = modes[(n-1)%NRMODES].w;
372 /***********************************************************************
373 * EnumDisplaySettingsW (USER32.593)
375 BOOL32 WINAPI EnumDisplaySettings32W(LPCWSTR name,DWORD n,LPDEVMODE32W devmode) {
376 LPSTR nameA = HEAP_strdupWtoA(GetProcessHeap(),0,name);
378 BOOL32 ret = EnumDisplaySettings32A(nameA,n,&devmodeA);
381 devmode->dmBitsPerPel = devmodeA.dmBitsPerPel;
382 devmode->dmPelsHeight = devmodeA.dmPelsHeight;
383 devmode->dmPelsWidth = devmodeA.dmPelsWidth;
384 /* FIXME: convert rest too, if they are ever returned */
386 HeapFree(GetProcessHeap(),0,nameA);
390 /***********************************************************************
391 * SetEventHook (USER.321)
393 * Used by Turbo Debugger for Windows
395 FARPROC16 WINAPI SetEventHook(FARPROC16 lpfnEventHook)
397 FIXME(hook, "(lpfnEventHook=%08x): stub\n", (UINT32)lpfnEventHook);
401 /***********************************************************************
402 * UserSeeUserDo (USER.216)
404 DWORD WINAPI UserSeeUserDo(WORD wReqType, WORD wParam1, WORD wParam2, WORD wParam3)
408 case USUD_LOCALALLOC:
409 return LOCAL_Alloc(USER_HeapSel, wParam1, wParam3);
411 return LOCAL_Free(USER_HeapSel, wParam1);
412 case USUD_LOCALCOMPACT:
413 return LOCAL_Compact(USER_HeapSel, wParam3, 0);
416 case USUD_FIRSTCLASS:
417 FIXME(local, "return a pointer to the first window class.\n");
420 WARN(local, "wReqType %04x (unknown)", wReqType);
425 /***********************************************************************
426 * RegisterLogonProcess (USER32.434)
428 DWORD WINAPI RegisterLogonProcess(HANDLE32 hprocess,BOOL32 x) {
429 FIXME(win32,"(%d,%d),stub!\n",hprocess,x);
433 /***********************************************************************
434 * CreateWindowStation32W (USER32.86)
436 HWINSTA32 WINAPI CreateWindowStation32W(
437 LPWSTR winstation,DWORD res1,DWORD desiredaccess,
438 LPSECURITY_ATTRIBUTES lpsa
440 FIXME(win32,"(%s,0x%08lx,0x%08lx,%p),stub!\n",debugstr_w(winstation),
441 res1,desiredaccess,lpsa
446 /***********************************************************************
447 * SetProcessWindowStation (USER32.496)
449 BOOL32 WINAPI SetProcessWindowStation(HWINSTA32 hWinSta) {
450 FIXME(win32,"(%d),stub!\n",hWinSta);
454 /***********************************************************************
455 * SetUserObjectSecurity (USER32.514)
457 BOOL32 WINAPI SetUserObjectSecurity(
459 /*LPSECURITY_INFORMATION*/LPVOID pSIRequested,
460 /*LPSECURITY_DESCRIPTOR*/LPVOID pSID
462 FIXME(win32,"(%d,%p,%p),stub!\n",hObj,pSIRequested,pSID);
466 /***********************************************************************
467 * CreateDesktop32W (USER32.69)
469 HDESK32 WINAPI CreateDesktop32W(
470 LPWSTR lpszDesktop,LPWSTR lpszDevice,LPDEVMODE32W pDevmode,
471 DWORD dwFlags,DWORD dwDesiredAccess,LPSECURITY_ATTRIBUTES lpsa
473 FIXME(win32,"(%s,%s,%p,0x%08lx,0x%08lx,%p),stub!\n",
474 debugstr_w(lpszDesktop),debugstr_w(lpszDevice),pDevmode,
475 dwFlags,dwDesiredAccess,lpsa
480 /***********************************************************************
481 * SetWindowStationUser (USER32.521)
483 DWORD WINAPI SetWindowStationUser(DWORD x1,DWORD x2) {
484 FIXME(win32,"(%ld,%ld),stub!\n",x1,x2);
488 /***********************************************************************
489 * SetLogonNotifyWindow (USER32.486)
491 DWORD WINAPI SetLogonNotifyWindow(HWINSTA32 hwinsta,HWND32 hwnd) {
492 FIXME(win32,"(0x%x,%04x),stub!\n",hwinsta,hwnd);
496 /***********************************************************************
497 * LoadLocalFonts (USER32.486)
499 VOID WINAPI LoadLocalFonts(VOID) {
503 /***********************************************************************
504 * GetUserObjectInformation32A (USER32.299)
506 BOOL32 WINAPI GetUserObjectInformation32A( HANDLE32 hObj, int nIndex, LPVOID pvInfo, DWORD nLength, LPDWORD lpnLen )
507 { FIXME(win32,"(0x%x %i %p %ld %p),stub!\n", hObj, nIndex, pvInfo, nLength, lpnLen );
510 /***********************************************************************
511 * GetUserObjectInformation32W (USER32.300)
513 BOOL32 WINAPI GetUserObjectInformation32W( HANDLE32 hObj, int nIndex, LPVOID pvInfo, DWORD nLength, LPDWORD lpnLen )
514 { FIXME(win32,"(0x%x %i %p %ld %p),stub!\n", hObj, nIndex, pvInfo, nLength, lpnLen );