4 * Copyright 1993 Robert J. Amstadt
9 #include "wine/winbase16.h"
20 #include "clipboard.h"
22 #include "cursoricon.h"
33 #include "debugtools.h"
35 DECLARE_DEBUG_CHANNEL(hook)
36 DECLARE_DEBUG_CHANNEL(local)
37 DECLARE_DEBUG_CHANNEL(system)
38 DECLARE_DEBUG_CHANNEL(win)
39 DECLARE_DEBUG_CHANNEL(win32)
41 /***********************************************************************
42 * GetFreeSystemResources (USER.284)
44 WORD WINAPI GetFreeSystemResources16( WORD resType )
46 int userPercent, gdiPercent;
50 case GFSR_USERRESOURCES:
51 userPercent = (int)LOCAL_CountFree( USER_HeapSel ) * 100 /
52 LOCAL_HeapSize( USER_HeapSel );
56 case GFSR_GDIRESOURCES:
57 gdiPercent = (int)LOCAL_CountFree( GDI_HeapSel ) * 100 /
58 LOCAL_HeapSize( GDI_HeapSel );
62 case GFSR_SYSTEMRESOURCES:
63 userPercent = (int)LOCAL_CountFree( USER_HeapSel ) * 100 /
64 LOCAL_HeapSize( USER_HeapSel );
65 gdiPercent = (int)LOCAL_CountFree( GDI_HeapSel ) * 100 /
66 LOCAL_HeapSize( GDI_HeapSel );
72 return (WORD)min( userPercent, gdiPercent );
76 /***********************************************************************
77 * SystemHeapInfo (TOOLHELP.71)
79 BOOL16 WINAPI SystemHeapInfo16( SYSHEAPINFO *pHeapInfo )
81 pHeapInfo->wUserFreePercent = GetFreeSystemResources16( GFSR_USERRESOURCES );
82 pHeapInfo->wGDIFreePercent = GetFreeSystemResources16( GFSR_GDIRESOURCES );
83 pHeapInfo->hUserSegment = USER_HeapSel;
84 pHeapInfo->hGDISegment = GDI_HeapSel;
89 /***********************************************************************
90 * TimerCount (TOOLHELP.80)
92 BOOL16 WINAPI TimerCount16( TIMERINFO *pTimerInfo )
95 * In standard mode, dwmsSinceStart = dwmsThisVM
97 * I tested this, under Windows in enhanced mode, and
98 * if you never switch VM (ie start/stop DOS) these
99 * values should be the same as well.
101 * Also, Wine should adjust for the hardware timer
102 * to reduce the amount of error to ~1ms.
103 * I can't be bothered, can you?
105 pTimerInfo->dwmsSinceStart = pTimerInfo->dwmsThisVM = GetTickCount();
109 /**********************************************************************
112 INT16 WINAPI InitApp16( HINSTANCE16 hInstance )
114 /* Hack: restore the divide-by-zero handler */
115 /* FIXME: should set a USER-specific handler that displays a msg box */
116 INT_SetPMHandler( 0, INT_GetPMHandler( 0xff ) );
118 /* Create task message queue */
119 if ( !GetFastQueue16() ) return 0;
124 /**********************************************************************
127 static void USER_ModuleUnload( HMODULE16 hModule )
129 HOOK_FreeModuleHooks( hModule );
130 CLASS_FreeModuleClasses( hModule );
131 CURSORICON_FreeModuleIcons( hModule );
134 /**********************************************************************
137 static void USER_QueueCleanup( HQUEUE16 hQueue )
141 WND* desktop = WIN_GetDesktop();
143 /* Patch desktop window */
144 if ( desktop->hmemTaskQ == hQueue )
146 HTASK16 nextTask = TASK_GetNextTask( GetCurrentTask() );
147 desktop->hmemTaskQ = GetTaskQueue16( nextTask );
150 /* Patch resident popup menu window */
151 MENU_PatchResidentPopup( hQueue, NULL );
153 TIMER_RemoveQueueTimers( hQueue );
155 HOOK_FreeQueueHooks( hQueue );
157 QUEUE_SetExitingQueue( hQueue );
158 WIN_ResetQueueWindows( desktop, hQueue, (HQUEUE16)0);
159 QUEUE_SetExitingQueue( 0 );
161 /* Free the message queue */
162 QUEUE_DeleteMsgQueue( hQueue );
164 WIN_ReleaseDesktop();
168 /**********************************************************************
171 static void USER_AppExit( HINSTANCE16 hInstance )
173 /* FIXME: maybe destroy menus (Windows only complains about them
177 /* ModuleUnload() in "Internals" */
179 hInstance = GetExePtr( hInstance );
180 if( GetModuleUsage16( hInstance ) <= 1 )
181 USER_ModuleUnload( hInstance );
185 /***********************************************************************
186 * USER_SignalProc (USER.314)
188 void WINAPI USER_SignalProc( HANDLE16 hTaskOrModule, UINT16 uCode,
189 UINT16 uExitFn, HINSTANCE16 hInstance,
192 FIXME_(win)("Win 3.1 USER signal %04x\n", uCode );
195 /***********************************************************************
196 * FinalUserInit (USER.400)
198 void WINAPI FinalUserInit16( void )
200 /* FIXME: Should chain to FinalGdiInit now. */
203 /***********************************************************************
204 * UserSignalProc (USER.610) (USER32.559)
206 * For comments about the meaning of uCode and dwFlags
207 * see PROCESS_CallUserSignalProc.
210 WORD WINAPI UserSignalProc( UINT uCode, DWORD dwThreadOrProcessID,
211 DWORD dwFlags, HMODULE16 hModule )
213 static HANDLE win16_idle_event;
217 /* FIXME: Proper reaction to most signals still missing. */
221 case USIG_DLL_UNLOAD_WIN16:
222 case USIG_DLL_UNLOAD_WIN32:
223 USER_ModuleUnload( hModule );
226 case USIG_DLL_UNLOAD_ORPHANS:
229 case USIG_FAULT_DIALOG_PUSH:
230 case USIG_FAULT_DIALOG_POP:
233 case USIG_THREAD_INIT:
236 case USIG_THREAD_EXIT:
237 USER_QueueCleanup( GetThreadQueue16( dwThreadOrProcessID ) );
238 SetThreadQueue16( dwThreadOrProcessID, 0 );
241 case USIG_PROCESS_CREATE:
242 pdb = PROCESS_Current();
244 /* Create the idle event for the process. We have just one idle_event for all
245 win16 processes, while each win32 process has its own */
247 if ( pdb->flags & PDB32_WIN16_PROC )
249 if (!win16_idle_event)
251 win16_idle_event = CreateEventA ( NULL, TRUE, FALSE, NULL );
252 win16_idle_event = ConvertToGlobalHandle ( win16_idle_event );
254 pdb->idle_event = win16_idle_event;
256 else { /* win32 process */
257 pdb->idle_event = CreateEventA ( NULL, TRUE, FALSE, NULL );
258 pdb->idle_event = ConvertToGlobalHandle ( pdb->idle_event );
259 TRACE_(win)("created win32 idle event: %x\n", pdb->idle_event );
263 case USIG_PROCESS_INIT:
264 case USIG_PROCESS_LOADED:
266 case USIG_PROCESS_RUNNING:
267 SetEvent ( PROCESS_Current()->idle_event );
270 case USIG_PROCESS_EXIT:
273 case USIG_PROCESS_DESTROY:
274 hInst = GetProcessDword( dwThreadOrProcessID, GPD_HINSTANCE16 );
275 USER_AppExit( hInst );
277 pdb = PROCESS_Current();
278 if ( ! (pdb->flags & PDB32_WIN16_PROC) ) {
279 TRACE_(win)("destroying win32 idle event: %x\n", pdb->idle_event );
280 CloseHandle ( pdb->idle_event );
285 FIXME_(win)("(%04x, %08lx, %04lx, %04x)\n",
286 uCode, dwThreadOrProcessID, dwFlags, hModule );
290 /* FIXME: Should chain to GdiSignalProc now. */
295 /***********************************************************************
296 * USER_DllEntryPoint (USER.374)
298 BOOL WINAPI USER_DllEntryPoint( DWORD dwReason, HINSTANCE hInstDLL, WORD ds,
299 WORD wHeapSize, DWORD dwReserved1, WORD wReserved2 )
303 case DLL_PROCESS_ATTACH:
305 * We need to load the 32-bit library so as to be able
306 * to access the system resources stored there!
308 if ( !LoadLibraryA("USER32.DLL") )
310 ERR_(win)( "Could not load USER32.DLL\n" );
319 /***********************************************************************
320 * ExitWindows16 (USER.7)
322 BOOL16 WINAPI ExitWindows16( DWORD dwReturnCode, UINT16 wReserved )
324 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
328 /***********************************************************************
329 * ExitWindowsExec16 (USER.246)
331 BOOL16 WINAPI ExitWindowsExec16( LPCSTR lpszExe, LPCSTR lpszParams )
333 TRACE_(system)("Should run the following in DOS-mode: \"%s %s\"\n",
334 lpszExe, lpszParams);
335 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
339 /***********************************************************************
340 * ExitWindowsEx (USER32.196)
342 BOOL WINAPI ExitWindowsEx( UINT flags, DWORD reserved )
348 /* We have to build a list of all windows first, as in EnumWindows */
350 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
352 WIN_ReleaseDesktop();
356 /* Send a WM_QUERYENDSESSION message to every window */
358 for (ppWnd = list, i = 0; *ppWnd; ppWnd++, i++)
360 /* Make sure that the window still exists */
361 if (!IsWindow( (*ppWnd)->hwndSelf )) continue;
362 if (!SendMessage16( (*ppWnd)->hwndSelf, WM_QUERYENDSESSION, 0, 0 ))
367 /* Now notify all windows that got a WM_QUERYENDSESSION of the result */
369 for (ppWnd = list; i > 0; i--, ppWnd++)
371 if (!IsWindow( (*ppWnd)->hwndSelf )) continue;
372 SendMessage16( (*ppWnd)->hwndSelf, WM_ENDSESSION, result, 0 );
374 WIN_ReleaseWinArray(list);
376 if (result) ExitKernel16();
377 WIN_ReleaseDesktop();
381 static void _dump_CDS_flags(DWORD flags) {
382 #define X(x) if (flags & CDS_##x) MESSAGE(""#x ",");
383 X(UPDATEREGISTRY);X(TEST);X(FULLSCREEN);X(GLOBAL);
384 X(SET_PRIMARY);X(RESET);X(SETRECT);X(NORESET);
388 /***********************************************************************
389 * ChangeDisplaySettingsA (USER32.589)
391 LONG WINAPI ChangeDisplaySettingsA( LPDEVMODEA devmode, DWORD flags )
393 FIXME_(system)("(%p,0x%08lx), stub\n",devmode,flags);
394 MESSAGE("\tflags=");_dump_CDS_flags(flags);MESSAGE("\n");
396 FIXME_(system)(" devmode=NULL (return to default mode)\n");
397 else if ( (devmode->dmBitsPerPel != MONITOR_GetDepth(&MONITOR_PrimaryMonitor))
398 || (devmode->dmPelsHeight != MONITOR_GetHeight(&MONITOR_PrimaryMonitor))
399 || (devmode->dmPelsWidth != MONITOR_GetWidth(&MONITOR_PrimaryMonitor)) )
403 if (devmode->dmFields & DM_BITSPERPEL)
404 FIXME_(system)(" bpp=%ld\n",devmode->dmBitsPerPel);
405 if (devmode->dmFields & DM_PELSWIDTH)
406 FIXME_(system)(" width=%ld\n",devmode->dmPelsWidth);
407 if (devmode->dmFields & DM_PELSHEIGHT)
408 FIXME_(system)(" height=%ld\n",devmode->dmPelsHeight);
409 FIXME_(system)(" (Putting X in this mode beforehand might help)\n");
410 /* we don't, but the program ... does not need to know */
411 return DISP_CHANGE_SUCCESSFUL;
413 return DISP_CHANGE_SUCCESSFUL;
416 /***********************************************************************
417 * ChangeDisplaySettingsExA (USER32.604)
419 LONG WINAPI ChangeDisplaySettingsExA(
420 LPCSTR devname, LPDEVMODEA devmode, HWND hwnd, DWORD flags,
423 FIXME_(system)("(%s,%p,0x%04x,0x%08lx,0x%08lx), stub\n",devname,devmode,hwnd,flags,lparam);
424 MESSAGE("\tflags=");_dump_CDS_flags(flags);MESSAGE("\n");
426 FIXME_(system)(" devmode=NULL (return to default mode)\n");
427 else if ( (devmode->dmBitsPerPel != MONITOR_GetDepth(&MONITOR_PrimaryMonitor))
428 || (devmode->dmPelsHeight != MONITOR_GetHeight(&MONITOR_PrimaryMonitor))
429 || (devmode->dmPelsWidth != MONITOR_GetWidth(&MONITOR_PrimaryMonitor)) )
433 if (devmode->dmFields & DM_BITSPERPEL)
434 FIXME_(system)(" bpp=%ld\n",devmode->dmBitsPerPel);
435 if (devmode->dmFields & DM_PELSWIDTH)
436 FIXME_(system)(" width=%ld\n",devmode->dmPelsWidth);
437 if (devmode->dmFields & DM_PELSHEIGHT)
438 FIXME_(system)(" height=%ld\n",devmode->dmPelsHeight);
439 FIXME_(system)(" (Putting X in this mode beforehand might help)\n");
440 /* we don't, but the program ... does not need to know */
441 return DISP_CHANGE_SUCCESSFUL;
443 return DISP_CHANGE_SUCCESSFUL;
446 /***********************************************************************
447 * EnumDisplaySettingsA (USER32.592)
448 * FIXME: Currently uses static list of modes.
451 * TRUE if nth setting exists found (described in the LPDEVMODEA struct)
452 * FALSE if we do not have the nth setting
454 BOOL WINAPI EnumDisplaySettingsA(
455 LPCSTR name, /* [in] huh? */
456 DWORD n, /* [in] nth entry in display settings list*/
457 LPDEVMODEA devmode /* [out] devmode for that setting */
463 } modes[NRMODES]={{512,384},{640,400},{640,480},{800,600},{1024,768}};
464 int depths[4] = {8,16,24,32};
466 TRACE_(system)("(%s,%ld,%p)\n",name,n,devmode);
468 devmode->dmBitsPerPel = MONITOR_GetDepth(&MONITOR_PrimaryMonitor);
469 devmode->dmPelsHeight = MONITOR_GetHeight(&MONITOR_PrimaryMonitor);
470 devmode->dmPelsWidth = MONITOR_GetWidth(&MONITOR_PrimaryMonitor);
473 if ((n-1)<NRMODES*NRDEPTHS) {
474 devmode->dmBitsPerPel = depths[(n-1)/NRMODES];
475 devmode->dmPelsHeight = modes[(n-1)%NRMODES].h;
476 devmode->dmPelsWidth = modes[(n-1)%NRMODES].w;
482 /***********************************************************************
483 * EnumDisplaySettingsW (USER32.593)
485 BOOL WINAPI EnumDisplaySettingsW(LPCWSTR name,DWORD n,LPDEVMODEW devmode) {
486 LPSTR nameA = HEAP_strdupWtoA(GetProcessHeap(),0,name);
488 BOOL ret = EnumDisplaySettingsA(nameA,n,&devmodeA);
491 devmode->dmBitsPerPel = devmodeA.dmBitsPerPel;
492 devmode->dmPelsHeight = devmodeA.dmPelsHeight;
493 devmode->dmPelsWidth = devmodeA.dmPelsWidth;
494 /* FIXME: convert rest too, if they are ever returned */
496 HeapFree(GetProcessHeap(),0,nameA);
500 /***********************************************************************
501 * EnumDisplayDevicesA (USER32.184)
503 BOOL WINAPI EnumDisplayDevicesA(
504 LPVOID unused,DWORD i,LPDISPLAY_DEVICEA lpDisplayDevice,DWORD dwFlags
508 FIXME_(system)("(%p,%ld,%p,0x%08lx), stub!\n",unused,i,lpDisplayDevice,dwFlags);
509 strcpy(lpDisplayDevice->DeviceName,"X11");
510 strcpy(lpDisplayDevice->DeviceString,"X 11 Windowing System");
511 lpDisplayDevice->StateFlags =
512 DISPLAY_DEVICE_ATTACHED_TO_DESKTOP |
513 DISPLAY_DEVICE_PRIMARY_DEVICE |
514 DISPLAY_DEVICE_VGA_COMPATIBLE;
518 /***********************************************************************
519 * EnumDisplayDevicesW (USER32.185)
521 BOOL WINAPI EnumDisplayDevicesW(
522 LPVOID unused,DWORD i,LPDISPLAY_DEVICEW lpDisplayDevice,DWORD dwFlags
526 FIXME_(system)("(%p,%ld,%p,0x%08lx), stub!\n",unused,i,lpDisplayDevice,dwFlags);
527 lstrcpyAtoW(lpDisplayDevice->DeviceName,"X11");
528 lstrcpyAtoW(lpDisplayDevice->DeviceString,"X 11 Windowing System");
529 lpDisplayDevice->StateFlags =
530 DISPLAY_DEVICE_ATTACHED_TO_DESKTOP |
531 DISPLAY_DEVICE_PRIMARY_DEVICE |
532 DISPLAY_DEVICE_VGA_COMPATIBLE;
536 /***********************************************************************
537 * SetEventHook (USER.321)
539 * Used by Turbo Debugger for Windows
541 FARPROC16 WINAPI SetEventHook16(FARPROC16 lpfnEventHook)
543 FIXME_(hook)("(lpfnEventHook=%08x): stub\n", (UINT)lpfnEventHook);
547 /***********************************************************************
548 * UserSeeUserDo (USER.216)
550 DWORD WINAPI UserSeeUserDo16(WORD wReqType, WORD wParam1, WORD wParam2, WORD wParam3)
554 case USUD_LOCALALLOC:
555 return LOCAL_Alloc(USER_HeapSel, wParam1, wParam3);
557 return LOCAL_Free(USER_HeapSel, wParam1);
558 case USUD_LOCALCOMPACT:
559 return LOCAL_Compact(USER_HeapSel, wParam3, 0);
562 case USUD_FIRSTCLASS:
563 FIXME_(local)("return a pointer to the first window class.\n");
566 WARN_(local)("wReqType %04x (unknown)", wReqType);
571 /***********************************************************************
572 * GetSystemDebugState16 (USER.231)
574 WORD WINAPI GetSystemDebugState16(void)
576 return 0; /* FIXME */
579 /***********************************************************************
580 * RegisterLogonProcess (USER32.434)
582 DWORD WINAPI RegisterLogonProcess(HANDLE hprocess,BOOL x) {
583 FIXME_(win32)("(%d,%d),stub!\n",hprocess,x);
587 /***********************************************************************
588 * CreateWindowStationW (USER32.86)
590 HWINSTA WINAPI CreateWindowStationW(
591 LPWSTR winstation,DWORD res1,DWORD desiredaccess,
592 LPSECURITY_ATTRIBUTES lpsa
594 FIXME_(win32)("(%s,0x%08lx,0x%08lx,%p),stub!\n",debugstr_w(winstation),
595 res1,desiredaccess,lpsa
600 /***********************************************************************
601 * SetProcessWindowStation (USER32.496)
603 BOOL WINAPI SetProcessWindowStation(HWINSTA hWinSta) {
604 FIXME_(win32)("(%d),stub!\n",hWinSta);
608 /***********************************************************************
609 * SetUserObjectSecurity (USER32.514)
611 BOOL WINAPI SetUserObjectSecurity(
613 /*LPSECURITY_INFORMATION*/LPVOID pSIRequested,
614 PSECURITY_DESCRIPTOR pSID
616 FIXME_(win32)("(0x%08x,%p,%p),stub!\n",hObj,pSIRequested,pSID);
620 /***********************************************************************
621 * CreateDesktopW (USER32.69)
623 HDESK WINAPI CreateDesktopW(
624 LPWSTR lpszDesktop,LPWSTR lpszDevice,LPDEVMODEW pDevmode,
625 DWORD dwFlags,DWORD dwDesiredAccess,LPSECURITY_ATTRIBUTES lpsa
627 FIXME_(win32)("(%s,%s,%p,0x%08lx,0x%08lx,%p),stub!\n",
628 debugstr_w(lpszDesktop),debugstr_w(lpszDevice),pDevmode,
629 dwFlags,dwDesiredAccess,lpsa
634 /***********************************************************************
637 BOOL WINAPI CloseWindowStation(HWINSTA hWinSta)
639 FIXME_(win32)("(0x%08x)\n", hWinSta);
643 /***********************************************************************
646 BOOL WINAPI CloseDesktop(HDESK hDesk)
648 FIXME_(win32)("(0x%08x)\n", hDesk);
652 /***********************************************************************
653 * SetWindowStationUser (USER32.521)
655 DWORD WINAPI SetWindowStationUser(DWORD x1,DWORD x2) {
656 FIXME_(win32)("(0x%08lx,0x%08lx),stub!\n",x1,x2);
660 /***********************************************************************
661 * SetLogonNotifyWindow (USER32.486)
663 DWORD WINAPI SetLogonNotifyWindow(HWINSTA hwinsta,HWND hwnd) {
664 FIXME_(win32)("(0x%x,%04x),stub!\n",hwinsta,hwnd);
668 /***********************************************************************
669 * LoadLocalFonts (USER32.486)
671 VOID WINAPI LoadLocalFonts(VOID) {
675 /***********************************************************************
676 * GetUserObjectInformationA (USER32.299)
678 BOOL WINAPI GetUserObjectInformationA( HANDLE hObj, INT nIndex, LPVOID pvInfo, DWORD nLength, LPDWORD lpnLen )
679 { FIXME_(win32)("(0x%x %i %p %ld %p),stub!\n", hObj, nIndex, pvInfo, nLength, lpnLen );
682 /***********************************************************************
683 * GetUserObjectInformationW (USER32.300)
685 BOOL WINAPI GetUserObjectInformationW( HANDLE hObj, INT nIndex, LPVOID pvInfo, DWORD nLength, LPDWORD lpnLen )
686 { FIXME_(win32)("(0x%x %i %p %ld %p),stub!\n", hObj, nIndex, pvInfo, nLength, lpnLen );
689 /***********************************************************************
690 * GetUserObjectSecurity (USER32.300)
692 BOOL WINAPI GetUserObjectSecurity(HANDLE hObj, SECURITY_INFORMATION * pSIRequested,
693 PSECURITY_DESCRIPTOR pSID, DWORD nLength, LPDWORD lpnLengthNeeded)
694 { FIXME_(win32)("(0x%x %p %p len=%ld %p),stub!\n", hObj, pSIRequested, pSID, nLength, lpnLengthNeeded);
698 /***********************************************************************
699 * SetSystemCursor (USER32.507)
701 BOOL WINAPI SetSystemCursor(HCURSOR hcur, DWORD id)
702 { FIXME_(win32)("(%08x,%08lx),stub!\n", hcur, id);
706 /***********************************************************************
707 * RegisterSystemThread (USER32.435)
709 void WINAPI RegisterSystemThread(DWORD flags, DWORD reserved)
711 FIXME_(win32)("(%08lx, %08lx)\n", flags, reserved);