4 * Copyright 1993 Robert J. Amstadt
9 #include "wine/winbase16.h"
17 #include "clipboard.h"
19 #include "cursoricon.h"
33 /***********************************************************************
34 * GetFreeSystemResources (USER.284)
36 WORD WINAPI GetFreeSystemResources16( WORD resType )
38 int userPercent, gdiPercent;
42 case GFSR_USERRESOURCES:
43 userPercent = (int)LOCAL_CountFree( USER_HeapSel ) * 100 /
44 LOCAL_HeapSize( USER_HeapSel );
48 case GFSR_GDIRESOURCES:
49 gdiPercent = (int)LOCAL_CountFree( GDI_HeapSel ) * 100 /
50 LOCAL_HeapSize( GDI_HeapSel );
54 case GFSR_SYSTEMRESOURCES:
55 userPercent = (int)LOCAL_CountFree( USER_HeapSel ) * 100 /
56 LOCAL_HeapSize( USER_HeapSel );
57 gdiPercent = (int)LOCAL_CountFree( GDI_HeapSel ) * 100 /
58 LOCAL_HeapSize( GDI_HeapSel );
64 return (WORD)MIN( userPercent, gdiPercent );
68 /***********************************************************************
69 * SystemHeapInfo (TOOLHELP.71)
71 BOOL16 WINAPI SystemHeapInfo16( SYSHEAPINFO *pHeapInfo )
73 pHeapInfo->wUserFreePercent = GetFreeSystemResources16( GFSR_USERRESOURCES );
74 pHeapInfo->wGDIFreePercent = GetFreeSystemResources16( GFSR_GDIRESOURCES );
75 pHeapInfo->hUserSegment = USER_HeapSel;
76 pHeapInfo->hGDISegment = GDI_HeapSel;
81 /***********************************************************************
82 * TimerCount (TOOLHELP.80)
84 BOOL16 WINAPI TimerCount16( TIMERINFO *pTimerInfo )
87 * In standard mode, dwmsSinceStart = dwmsThisVM
89 * I tested this, under Windows in enhanced mode, and
90 * if you never switch VM (ie start/stop DOS) these
91 * values should be the same as well.
93 * Also, Wine should adjust for the hardware timer
94 * to reduce the amount of error to ~1ms.
95 * I can't be bothered, can you?
97 pTimerInfo->dwmsSinceStart = pTimerInfo->dwmsThisVM = GetTickCount();
101 /**********************************************************************
104 INT16 WINAPI InitApp16( HINSTANCE16 hInstance )
106 /* Hack: restore the divide-by-zero handler */
107 /* FIXME: should set a USER-specific handler that displays a msg box */
108 INT_SetPMHandler( 0, INT_GetPMHandler( 0xff ) );
110 /* Create task message queue */
111 if ( !GetFastQueue16() ) return 0;
116 /**********************************************************************
119 static void USER_ModuleUnload( HMODULE16 hModule )
121 HOOK_FreeModuleHooks( hModule );
122 CLASS_FreeModuleClasses( hModule );
123 CURSORICON_FreeModuleIcons( hModule );
126 /**********************************************************************
129 static void USER_QueueCleanup( HQUEUE16 hQueue )
133 WND* desktop = WIN_GetDesktop();
135 /* Patch desktop window */
136 if ( desktop->hmemTaskQ == hQueue )
138 HTASK16 nextTask = TASK_GetNextTask( GetCurrentTask() );
139 desktop->hmemTaskQ = GetTaskQueue16( nextTask );
142 /* Patch resident popup menu window */
143 MENU_PatchResidentPopup( hQueue, NULL );
145 TIMER_RemoveQueueTimers( hQueue );
147 HOOK_FreeQueueHooks( hQueue );
149 QUEUE_SetExitingQueue( hQueue );
150 WIN_ResetQueueWindows( desktop, hQueue, (HQUEUE16)0);
151 CLIPBOARD_ResetLock( hQueue, 0 );
152 QUEUE_SetExitingQueue( 0 );
154 /* Free the message queue */
155 QUEUE_DeleteMsgQueue( hQueue );
157 WIN_ReleaseDesktop();
161 /**********************************************************************
164 static void USER_AppExit( HINSTANCE16 hInstance )
166 /* FIXME: empty clipboard if needed, maybe destroy menus (Windows
167 * only complains about them but does nothing);
170 /* ModuleUnload() in "Internals" */
172 hInstance = GetExePtr( hInstance );
173 if( GetModuleUsage16( hInstance ) <= 1 )
174 USER_ModuleUnload( hInstance );
178 /***********************************************************************
181 * Clean-up everything and exit the Wine process.
182 * This is the back-end of ExitWindows(), called when all windows
183 * have agreed to be terminated.
185 void USER_ExitWindows(void)
187 /* Do the clean-up stuff */
189 WriteOutProfiles16();
190 SHELL_SaveRegistry();
196 /***********************************************************************
197 * USER_SignalProc (USER.314)
199 void WINAPI USER_SignalProc( HANDLE16 hTaskOrModule, UINT16 uCode,
200 UINT16 uExitFn, HINSTANCE16 hInstance,
203 FIXME( win, "Win 3.1 USER signal %04x\n", uCode );
206 /***********************************************************************
207 * UserSignalProc (USER.610) (USER32.559)
209 * For comments about the meaning of uCode and dwFlags
210 * see PROCESS_CallUserSignalProc.
213 WORD WINAPI UserSignalProc( UINT uCode, DWORD dwThreadOrProcessID,
214 DWORD dwFlags, HMODULE16 hModule )
218 /* FIXME: Proper reaction to most signals still missing. */
222 case USIG_DLL_UNLOAD_WIN16:
223 case USIG_DLL_UNLOAD_WIN32:
224 USER_ModuleUnload( hModule );
227 case USIG_DLL_UNLOAD_ORPHANS:
230 case USIG_FAULT_DIALOG_PUSH:
231 case USIG_FAULT_DIALOG_POP:
234 case USIG_THREAD_INIT:
237 case USIG_THREAD_EXIT:
238 USER_QueueCleanup( GetThreadQueue16( dwThreadOrProcessID ) );
239 SetThreadQueue16( dwThreadOrProcessID, 0 );
242 case USIG_PROCESS_CREATE:
243 case USIG_PROCESS_INIT:
244 case USIG_PROCESS_LOADED:
245 case USIG_PROCESS_RUNNING:
248 case USIG_PROCESS_EXIT:
251 case USIG_PROCESS_DESTROY:
252 hInst = GetProcessDword( dwThreadOrProcessID, GPD_HINSTANCE16 );
253 USER_AppExit( hInst );
257 FIXME( win, "(%04x, %08lx, %04lx, %04x)\n",
258 uCode, dwThreadOrProcessID, dwFlags, hModule );
262 /* FIXME: Should chain to GdiSignalProc now. */
269 /***********************************************************************
270 * ExitWindows16 (USER.7)
272 BOOL16 WINAPI ExitWindows16( DWORD dwReturnCode, UINT16 wReserved )
274 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
278 /***********************************************************************
279 * ExitWindowsExec16 (USER.246)
281 BOOL16 WINAPI ExitWindowsExec16( LPCSTR lpszExe, LPCSTR lpszParams )
283 TRACE(system, "Should run the following in DOS-mode: \"%s %s\"\n",
284 lpszExe, lpszParams);
285 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
289 /***********************************************************************
290 * ExitWindowsEx (USER32.196)
292 BOOL WINAPI ExitWindowsEx( UINT flags, DWORD reserved )
298 /* We have to build a list of all windows first, as in EnumWindows */
300 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
302 WIN_ReleaseDesktop();
306 /* Send a WM_QUERYENDSESSION message to every window */
308 for (ppWnd = list, i = 0; *ppWnd; ppWnd++, i++)
310 /* Make sure that the window still exists */
311 if (!IsWindow( (*ppWnd)->hwndSelf )) continue;
312 if (!SendMessage16( (*ppWnd)->hwndSelf, WM_QUERYENDSESSION, 0, 0 ))
317 /* Now notify all windows that got a WM_QUERYENDSESSION of the result */
319 for (ppWnd = list; i > 0; i--, ppWnd++)
321 if (!IsWindow( (*ppWnd)->hwndSelf )) continue;
322 SendMessage16( (*ppWnd)->hwndSelf, WM_ENDSESSION, result, 0 );
324 WIN_ReleaseWinArray(list);
326 if (result) USER_ExitWindows();
327 WIN_ReleaseDesktop();
332 /***********************************************************************
333 * ChangeDisplaySettingA (USER32.589)
335 LONG WINAPI ChangeDisplaySettingsA( LPDEVMODEA devmode, DWORD flags )
337 FIXME(system, ": stub\n");
339 FIXME(system," devmode=NULL (return to default mode)\n");
340 else if ( (devmode->dmBitsPerPel != DESKTOP_GetScreenDepth())
341 || (devmode->dmPelsHeight != DESKTOP_GetScreenHeight())
342 || (devmode->dmPelsWidth != DESKTOP_GetScreenWidth()) )
346 if (devmode->dmFields & DM_BITSPERPEL)
347 FIXME(system," bpp=%ld\n",devmode->dmBitsPerPel);
348 if (devmode->dmFields & DM_PELSWIDTH)
349 FIXME(system," width=%ld\n",devmode->dmPelsWidth);
350 if (devmode->dmFields & DM_PELSHEIGHT)
351 FIXME(system," height=%ld\n",devmode->dmPelsHeight);
352 FIXME(system," (Putting X in this mode beforehand might help)\n");
353 /* we don't, but the program ... does not need to know */
354 return DISP_CHANGE_SUCCESSFUL;
356 return DISP_CHANGE_SUCCESSFUL;
359 /***********************************************************************
360 * EnumDisplaySettingsA (USER32.592)
361 * FIXME: Currently uses static list of modes.
364 * TRUE if nth setting exists found (described in the LPDEVMODE32A struct)
365 * FALSE if we do not have the nth setting
367 BOOL WINAPI EnumDisplaySettingsA(
368 LPCSTR name, /* [in] huh? */
369 DWORD n, /* [in] nth entry in display settings list*/
370 LPDEVMODEA devmode /* [out] devmode for that setting */
376 } modes[NRMODES]={{512,384},{640,400},{640,480},{800,600},{1024,768}};
377 int depths[4] = {8,16,24,32};
379 TRACE(system,"(%s,%ld,%p)\n",name,n,devmode);
381 devmode->dmBitsPerPel = DESKTOP_GetScreenDepth();
382 devmode->dmPelsHeight = DESKTOP_GetScreenHeight();
383 devmode->dmPelsWidth = DESKTOP_GetScreenWidth();
386 if ((n-1)<NRMODES*NRDEPTHS) {
387 devmode->dmBitsPerPel = depths[(n-1)/NRMODES];
388 devmode->dmPelsHeight = modes[(n-1)%NRMODES].h;
389 devmode->dmPelsWidth = modes[(n-1)%NRMODES].w;
395 /***********************************************************************
396 * EnumDisplaySettingsW (USER32.593)
398 BOOL WINAPI EnumDisplaySettingsW(LPCWSTR name,DWORD n,LPDEVMODEW devmode) {
399 LPSTR nameA = HEAP_strdupWtoA(GetProcessHeap(),0,name);
401 BOOL ret = EnumDisplaySettingsA(nameA,n,&devmodeA);
404 devmode->dmBitsPerPel = devmodeA.dmBitsPerPel;
405 devmode->dmPelsHeight = devmodeA.dmPelsHeight;
406 devmode->dmPelsWidth = devmodeA.dmPelsWidth;
407 /* FIXME: convert rest too, if they are ever returned */
409 HeapFree(GetProcessHeap(),0,nameA);
413 /***********************************************************************
414 * SetEventHook (USER.321)
416 * Used by Turbo Debugger for Windows
418 FARPROC16 WINAPI SetEventHook16(FARPROC16 lpfnEventHook)
420 FIXME(hook, "(lpfnEventHook=%08x): stub\n", (UINT)lpfnEventHook);
424 /***********************************************************************
425 * UserSeeUserDo (USER.216)
427 DWORD WINAPI UserSeeUserDo16(WORD wReqType, WORD wParam1, WORD wParam2, WORD wParam3)
431 case USUD_LOCALALLOC:
432 return LOCAL_Alloc(USER_HeapSel, wParam1, wParam3);
434 return LOCAL_Free(USER_HeapSel, wParam1);
435 case USUD_LOCALCOMPACT:
436 return LOCAL_Compact(USER_HeapSel, wParam3, 0);
439 case USUD_FIRSTCLASS:
440 FIXME(local, "return a pointer to the first window class.\n");
443 WARN(local, "wReqType %04x (unknown)", wReqType);
448 /***********************************************************************
449 * RegisterLogonProcess (USER32.434)
451 DWORD WINAPI RegisterLogonProcess(HANDLE hprocess,BOOL x) {
452 FIXME(win32,"(%d,%d),stub!\n",hprocess,x);
456 /***********************************************************************
457 * CreateWindowStation32W (USER32.86)
459 HWINSTA WINAPI CreateWindowStationW(
460 LPWSTR winstation,DWORD res1,DWORD desiredaccess,
461 LPSECURITY_ATTRIBUTES lpsa
463 FIXME(win32,"(%s,0x%08lx,0x%08lx,%p),stub!\n",debugstr_w(winstation),
464 res1,desiredaccess,lpsa
469 /***********************************************************************
470 * SetProcessWindowStation (USER32.496)
472 BOOL WINAPI SetProcessWindowStation(HWINSTA hWinSta) {
473 FIXME(win32,"(%d),stub!\n",hWinSta);
477 /***********************************************************************
478 * SetUserObjectSecurity (USER32.514)
480 BOOL WINAPI SetUserObjectSecurity(
482 /*LPSECURITY_INFORMATION*/LPVOID pSIRequested,
483 PSECURITY_DESCRIPTOR pSID
485 FIXME(win32,"(0x%08x,%p,%p),stub!\n",hObj,pSIRequested,pSID);
489 /***********************************************************************
490 * CreateDesktop32W (USER32.69)
492 HDESK WINAPI CreateDesktopW(
493 LPWSTR lpszDesktop,LPWSTR lpszDevice,LPDEVMODEW pDevmode,
494 DWORD dwFlags,DWORD dwDesiredAccess,LPSECURITY_ATTRIBUTES lpsa
496 FIXME(win32,"(%s,%s,%p,0x%08lx,0x%08lx,%p),stub!\n",
497 debugstr_w(lpszDesktop),debugstr_w(lpszDevice),pDevmode,
498 dwFlags,dwDesiredAccess,lpsa
503 BOOL WINAPI CloseWindowStation(HWINSTA hWinSta)
505 FIXME(win32, "(0x%08x)\n", hWinSta);
508 BOOL WINAPI CloseDesktop(HDESK hDesk)
510 FIXME(win32, "(0x%08x)\n", hDesk);
514 /***********************************************************************
515 * SetWindowStationUser (USER32.521)
517 DWORD WINAPI SetWindowStationUser(DWORD x1,DWORD x2) {
518 FIXME(win32,"(0x%08lx,0x%08lx),stub!\n",x1,x2);
522 /***********************************************************************
523 * SetLogonNotifyWindow (USER32.486)
525 DWORD WINAPI SetLogonNotifyWindow(HWINSTA hwinsta,HWND hwnd) {
526 FIXME(win32,"(0x%x,%04x),stub!\n",hwinsta,hwnd);
530 /***********************************************************************
531 * LoadLocalFonts (USER32.486)
533 VOID WINAPI LoadLocalFonts(VOID) {
537 /***********************************************************************
538 * GetUserObjectInformation32A (USER32.299)
540 BOOL WINAPI GetUserObjectInformationA( HANDLE hObj, int nIndex, LPVOID pvInfo, DWORD nLength, LPDWORD lpnLen )
541 { FIXME(win32,"(0x%x %i %p %ld %p),stub!\n", hObj, nIndex, pvInfo, nLength, lpnLen );
544 /***********************************************************************
545 * GetUserObjectInformation32W (USER32.300)
547 BOOL WINAPI GetUserObjectInformationW( HANDLE hObj, int nIndex, LPVOID pvInfo, DWORD nLength, LPDWORD lpnLen )
548 { FIXME(win32,"(0x%x %i %p %ld %p),stub!\n", hObj, nIndex, pvInfo, nLength, lpnLen );
551 /***********************************************************************
552 * GetUserObjectSecurity32 (USER32.300)
554 BOOL WINAPI GetUserObjectSecurity(HANDLE hObj, SECURITY_INFORMATION * pSIRequested,
555 PSECURITY_DESCRIPTOR pSID, DWORD nLength, LPDWORD lpnLengthNeeded)
556 { FIXME(win32,"(0x%x %p %p len=%ld %p),stub!\n", hObj, pSIRequested, pSID, nLength, lpnLengthNeeded);
560 /***********************************************************************
561 * SetSystemCursor (USER32.507)
563 BOOL WINAPI SetSystemCursor(HCURSOR hcur, DWORD id)
564 { FIXME(win32,"(%08x,%08x),stub!\n", hcur, id);