4 * Copyright 1993 Robert J. Amstadt
16 #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 )
134 /* InitTask() calls LibMain()'s of implicitly loaded DLLs
135 * prior to InitApp() so there is no clean way to do
136 * SetTaskSignalHandler() in time. So, broken Windows bypasses
137 * a pTask->userhandler on startup and simply calls a global
138 * function pointer to the default USER signal handler.
141 USER_InstallRsrcHandler( hInstance );
143 /* Hack: restore the divide-by-zero handler */
144 /* FIXME: should set a USER-specific handler that displays a msg box */
145 INT_SetPMHandler( 0, INT_GetPMHandler( 0xff ) );
147 /* Create task message queue */
148 if ( !GetFastQueue() ) return 0;
153 /**********************************************************************
156 static void USER_ModuleUnload( HMODULE16 hModule )
158 HOOK_FreeModuleHooks( hModule );
159 CLASS_FreeModuleClasses( hModule );
162 /**********************************************************************
165 void USER_QueueCleanup( HQUEUE16 hQueue )
169 WND* desktop = WIN_GetDesktop();
171 /* Patch resident popup menu window */
172 MENU_PatchResidentPopup( hQueue, NULL );
174 TIMER_RemoveQueueTimers( hQueue );
176 HOOK_FreeQueueHooks( hQueue );
178 QUEUE_SetExitingQueue( hQueue );
179 WIN_ResetQueueWindows( desktop, hQueue, (HQUEUE16)0);
180 CLIPBOARD_ResetLock( hQueue, 0 );
181 QUEUE_SetExitingQueue( 0 );
183 /* Free the message queue */
184 QUEUE_DeleteMsgQueue( hQueue );
188 /**********************************************************************
191 static void USER_AppExit( HTASK16 hTask, HINSTANCE16 hInstance, HQUEUE16 hQueue )
193 /* FIXME: empty clipboard if needed, maybe destroy menus (Windows
194 * only complains about them but does nothing);
197 WND* desktop = WIN_GetDesktop();
199 /* Patch desktop window */
200 if( desktop->hmemTaskQ == hQueue )
201 desktop->hmemTaskQ = GetTaskQueue(TASK_GetNextTask(hTask));
203 USER_QueueCleanup(hQueue);
205 /* ModuleUnload() in "Internals" */
207 hInstance = GetExePtr( hInstance );
208 if( GetModuleUsage( hInstance ) <= 1 )
209 USER_ModuleUnload( hInstance );
213 /***********************************************************************
216 * Clean-up everything and exit the Wine process.
217 * This is the back-end of ExitWindows(), called when all windows
218 * have agreed to be terminated.
220 void USER_ExitWindows(void)
222 /* Do the clean-up stuff */
225 SHELL_SaveRegistry();
231 /***********************************************************************
232 * USER_SignalProc (USER.314)
234 void WINAPI USER_SignalProc( HANDLE16 hTaskOrModule, UINT16 uCode,
235 UINT16 uExitFn, HINSTANCE16 hInstance,
241 case USIG_TERMINATION:
242 USER_AppExit( hTaskOrModule, hInstance, hQueue ); /* task */
246 USER_InstallRsrcHandler( hTaskOrModule ); /* module */
249 case USIG_DLL_UNLOAD:
250 USER_ModuleUnload( hTaskOrModule ); /* module */
254 FIXME(msg,"Unimplemented USER signal: %i\n", (int)uCode );
259 /***********************************************************************
260 * ExitWindows16 (USER.7)
262 BOOL16 WINAPI ExitWindows16( DWORD dwReturnCode, UINT16 wReserved )
264 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
268 /***********************************************************************
269 * ExitWindowsExec16 (USER.246)
271 BOOL16 WINAPI ExitWindowsExec16( LPCSTR lpszExe, LPCSTR lpszParams )
273 TRACE(system, "Should run the following in DOS-mode: \"%s %s\"\n",
274 lpszExe, lpszParams);
275 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
279 /***********************************************************************
280 * ExitWindowsEx (USER32.196)
282 BOOL32 WINAPI ExitWindowsEx( UINT32 flags, DWORD reserved )
288 /* We have to build a list of all windows first, as in EnumWindows */
290 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL ))) return FALSE;
292 /* Send a WM_QUERYENDSESSION message to every window */
294 for (ppWnd = list, i = 0; *ppWnd; ppWnd++, i++)
296 /* Make sure that the window still exists */
297 if (!IsWindow32( (*ppWnd)->hwndSelf )) continue;
298 if (!SendMessage16( (*ppWnd)->hwndSelf, WM_QUERYENDSESSION, 0, 0 ))
303 /* Now notify all windows that got a WM_QUERYENDSESSION of the result */
305 for (ppWnd = list; i > 0; i--, ppWnd++)
307 if (!IsWindow32( (*ppWnd)->hwndSelf )) continue;
308 SendMessage16( (*ppWnd)->hwndSelf, WM_ENDSESSION, result, 0 );
310 HeapFree( SystemHeap, 0, list );
312 if (result) USER_ExitWindows();
317 /***********************************************************************
318 * ChangeDisplaySettingA (USER32.589)
320 LONG WINAPI ChangeDisplaySettings32A( LPDEVMODE32A devmode, DWORD flags )
322 FIXME(system, ": stub\n");
324 FIXME(system," devmode=NULL (return to default mode)\n");
325 else if ( (devmode->dmBitsPerPel != DESKTOP_GetScreenDepth())
326 || (devmode->dmPelsHeight != DESKTOP_GetScreenHeight())
327 || (devmode->dmPelsWidth != DESKTOP_GetScreenWidth()) )
331 if (devmode->dmFields & DM_BITSPERPEL)
332 FIXME(system," bpp=%ld\n",devmode->dmBitsPerPel);
333 if (devmode->dmFields & DM_PELSWIDTH)
334 FIXME(system," width=%ld\n",devmode->dmPelsWidth);
335 if (devmode->dmFields & DM_PELSHEIGHT)
336 FIXME(system," height=%ld\n",devmode->dmPelsHeight);
337 FIXME(system," (Putting X in this mode beforehand might help)\n");
338 /* we don't, but the program ... does not need to know */
339 return DISP_CHANGE_SUCCESSFUL;
341 return DISP_CHANGE_SUCCESSFUL;
344 /***********************************************************************
345 * EnumDisplaySettingsA (USER32.592)
346 * FIXME: Currently uses static list of modes.
349 * TRUE if nth setting exists found (described in the LPDEVMODE32A struct)
350 * FALSE if we do not have the nth setting
352 BOOL32 WINAPI EnumDisplaySettings32A(
353 LPCSTR name, /* [in] huh? */
354 DWORD n, /* [in] nth entry in display settings list*/
355 LPDEVMODE32A devmode /* [out] devmode for that setting */
361 } modes[NRMODES]={{512,384},{640,400},{640,480},{800,600},{1024,768}};
362 int depths[4] = {8,16,24,32};
364 TRACE(system,"(%s,%ld,%p)\n",name,n,devmode);
366 devmode->dmBitsPerPel = DESKTOP_GetScreenDepth();
367 devmode->dmPelsHeight = DESKTOP_GetScreenHeight();
368 devmode->dmPelsWidth = DESKTOP_GetScreenWidth();
371 if ((n-1)<NRMODES*NRDEPTHS) {
372 devmode->dmBitsPerPel = depths[(n-1)/NRMODES];
373 devmode->dmPelsHeight = modes[(n-1)%NRMODES].h;
374 devmode->dmPelsWidth = modes[(n-1)%NRMODES].w;
380 /***********************************************************************
381 * EnumDisplaySettingsW (USER32.593)
383 BOOL32 WINAPI EnumDisplaySettings32W(LPCWSTR name,DWORD n,LPDEVMODE32W devmode) {
384 LPSTR nameA = HEAP_strdupWtoA(GetProcessHeap(),0,name);
386 BOOL32 ret = EnumDisplaySettings32A(nameA,n,&devmodeA);
389 devmode->dmBitsPerPel = devmodeA.dmBitsPerPel;
390 devmode->dmPelsHeight = devmodeA.dmPelsHeight;
391 devmode->dmPelsWidth = devmodeA.dmPelsWidth;
392 /* FIXME: convert rest too, if they are ever returned */
394 HeapFree(GetProcessHeap(),0,nameA);
398 /***********************************************************************
399 * SetEventHook (USER.321)
401 * Used by Turbo Debugger for Windows
403 FARPROC16 WINAPI SetEventHook(FARPROC16 lpfnEventHook)
405 FIXME(hook, "(lpfnEventHook=%08x): stub\n", (UINT32)lpfnEventHook);
409 /***********************************************************************
410 * UserSeeUserDo (USER.216)
412 DWORD WINAPI UserSeeUserDo(WORD wReqType, WORD wParam1, WORD wParam2, WORD wParam3)
416 case USUD_LOCALALLOC:
417 return LOCAL_Alloc(USER_HeapSel, wParam1, wParam3);
419 return LOCAL_Free(USER_HeapSel, wParam1);
420 case USUD_LOCALCOMPACT:
421 return LOCAL_Compact(USER_HeapSel, wParam3, 0);
424 case USUD_FIRSTCLASS:
425 FIXME(local, "return a pointer to the first window class.\n");
428 WARN(local, "wReqType %04x (unknown)", wReqType);
433 /***********************************************************************
434 * RegisterLogonProcess (USER32.434)
436 DWORD WINAPI RegisterLogonProcess(HANDLE32 hprocess,BOOL32 x) {
437 FIXME(win32,"(%d,%d),stub!\n",hprocess,x);
441 /***********************************************************************
442 * CreateWindowStation32W (USER32.86)
444 HWINSTA32 WINAPI CreateWindowStation32W(
445 LPWSTR winstation,DWORD res1,DWORD desiredaccess,
446 LPSECURITY_ATTRIBUTES lpsa
448 FIXME(win32,"(%s,0x%08lx,0x%08lx,%p),stub!\n",debugstr_w(winstation),
449 res1,desiredaccess,lpsa
454 /***********************************************************************
455 * SetProcessWindowStation (USER32.496)
457 BOOL32 WINAPI SetProcessWindowStation(HWINSTA32 hWinSta) {
458 FIXME(win32,"(%d),stub!\n",hWinSta);
462 /***********************************************************************
463 * SetUserObjectSecurity (USER32.514)
465 BOOL32 WINAPI SetUserObjectSecurity(
467 /*LPSECURITY_INFORMATION*/LPVOID pSIRequested,
468 PSECURITY_DESCRIPTOR pSID
470 FIXME(win32,"(0x%08x,%p,%p),stub!\n",hObj,pSIRequested,pSID);
474 /***********************************************************************
475 * CreateDesktop32W (USER32.69)
477 HDESK32 WINAPI CreateDesktop32W(
478 LPWSTR lpszDesktop,LPWSTR lpszDevice,LPDEVMODE32W pDevmode,
479 DWORD dwFlags,DWORD dwDesiredAccess,LPSECURITY_ATTRIBUTES lpsa
481 FIXME(win32,"(%s,%s,%p,0x%08lx,0x%08lx,%p),stub!\n",
482 debugstr_w(lpszDesktop),debugstr_w(lpszDevice),pDevmode,
483 dwFlags,dwDesiredAccess,lpsa
488 /***********************************************************************
489 * SetWindowStationUser (USER32.521)
491 DWORD WINAPI SetWindowStationUser(DWORD x1,DWORD x2) {
492 FIXME(win32,"(0x%08lx,0x%08lx),stub!\n",x1,x2);
496 /***********************************************************************
497 * SetLogonNotifyWindow (USER32.486)
499 DWORD WINAPI SetLogonNotifyWindow(HWINSTA32 hwinsta,HWND32 hwnd) {
500 FIXME(win32,"(0x%x,%04x),stub!\n",hwinsta,hwnd);
504 /***********************************************************************
505 * LoadLocalFonts (USER32.486)
507 VOID WINAPI LoadLocalFonts(VOID) {
511 /***********************************************************************
512 * GetUserObjectInformation32A (USER32.299)
514 BOOL32 WINAPI GetUserObjectInformation32A( HANDLE32 hObj, int nIndex, LPVOID pvInfo, DWORD nLength, LPDWORD lpnLen )
515 { FIXME(win32,"(0x%x %i %p %ld %p),stub!\n", hObj, nIndex, pvInfo, nLength, lpnLen );
518 /***********************************************************************
519 * GetUserObjectInformation32W (USER32.300)
521 BOOL32 WINAPI GetUserObjectInformation32W( HANDLE32 hObj, int nIndex, LPVOID pvInfo, DWORD nLength, LPDWORD lpnLen )
522 { FIXME(win32,"(0x%x %i %p %ld %p),stub!\n", hObj, nIndex, pvInfo, nLength, lpnLen );
525 /***********************************************************************
526 * GetUserObjectSecurity32 (USER32.300)
528 BOOL32 WINAPI GetUserObjectSecurity32(HANDLE32 hObj, SECURITY_INFORMATION * pSIRequested,
529 PSECURITY_DESCRIPTOR pSID, DWORD nLength, LPDWORD lpnLengthNeeded)
530 { FIXME(win32,"(0x%x %p %p len=%ld %p),stub!\n", hObj, pSIRequested, pSID, nLength, lpnLengthNeeded);