4 * Copyright 1993 Robert J. Amstadt
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "wine/winbase16.h"
28 #include "wine/winuser16.h"
32 #include "cursoricon.h"
35 #include "sysmetrics.h"
39 #include "wine/debug.h"
41 WINE_DECLARE_DEBUG_CHANNEL(hook);
42 WINE_DECLARE_DEBUG_CHANNEL(local);
43 WINE_DECLARE_DEBUG_CHANNEL(system);
44 WINE_DECLARE_DEBUG_CHANNEL(win);
45 WINE_DECLARE_DEBUG_CHANNEL(win32);
47 SYSLEVEL USER_SysLevel = { CRITICAL_SECTION_INIT("USER_SysLevel"), 2 };
50 /***********************************************************************
51 * GetFreeSystemResources (USER.284)
53 WORD WINAPI GetFreeSystemResources16( WORD resType )
57 int userPercent, gdiPercent;
59 if ((gdi_inst = LoadLibrary16( "GDI" )) < 32) return 0;
60 gdi_heap = gdi_inst | 7;
64 case GFSR_USERRESOURCES:
65 userPercent = (int)LOCAL_CountFree( USER_HeapSel ) * 100 /
66 LOCAL_HeapSize( USER_HeapSel );
70 case GFSR_GDIRESOURCES:
71 gdiPercent = (int)LOCAL_CountFree( gdi_inst ) * 100 /
72 LOCAL_HeapSize( gdi_inst );
76 case GFSR_SYSTEMRESOURCES:
77 userPercent = (int)LOCAL_CountFree( USER_HeapSel ) * 100 /
78 LOCAL_HeapSize( USER_HeapSel );
79 gdiPercent = (int)LOCAL_CountFree( gdi_inst ) * 100 /
80 LOCAL_HeapSize( gdi_inst );
84 userPercent = gdiPercent = 0;
87 FreeLibrary16( gdi_inst );
88 TRACE_(local)("<- userPercent %d, gdiPercent %d\n", userPercent, gdiPercent);
89 return (WORD)min( userPercent, gdiPercent );
93 /**********************************************************************
96 INT16 WINAPI InitApp16( HINSTANCE16 hInstance )
98 /* Create task message queue */
99 if ( !InitThreadInput16( 0, 0 ) ) return 0;
105 /***********************************************************************
110 _EnterSysLevel( &USER_SysLevel );
114 /***********************************************************************
117 void USER_Unlock(void)
119 _LeaveSysLevel( &USER_SysLevel );
123 /***********************************************************************
126 * Make sure that we don't hold the user lock.
128 void USER_CheckNotLock(void)
130 _CheckNotSysLevel( &USER_SysLevel );
134 /**********************************************************************
137 static void USER_ModuleUnload( HMODULE16 hModule )
139 /* HOOK_FreeModuleHooks( hModule ); */
140 CLASS_FreeModuleClasses( hModule );
141 CURSORICON_FreeModuleIcons( hModule );
144 /***********************************************************************
145 * SignalProc (USER.314)
147 void WINAPI USER_SignalProc( HANDLE16 hTaskOrModule, UINT16 uCode,
148 UINT16 uExitFn, HINSTANCE16 hInstance,
151 FIXME_(win)("Win 3.1 USER signal %04x\n", uCode );
154 /***********************************************************************
155 * FinalUserInit (USER.400)
157 void WINAPI FinalUserInit16( void )
159 /* FIXME: Should chain to FinalGdiInit now. */
162 /***********************************************************************
163 * SignalProc32 (USER.391)
164 * UserSignalProc (USER32.@)
166 * For comments about the meaning of uCode and dwFlags
167 * see PROCESS_CallUserSignalProc.
170 WORD WINAPI UserSignalProc( UINT uCode, DWORD dwThreadOrProcessID,
171 DWORD dwFlags, HMODULE16 hModule )
173 /* FIXME: Proper reaction to most signals still missing. */
177 case USIG_DLL_UNLOAD_WIN16:
178 case USIG_DLL_UNLOAD_WIN32:
179 USER_ModuleUnload( hModule );
182 case USIG_DLL_UNLOAD_ORPHANS:
183 case USIG_FAULT_DIALOG_PUSH:
184 case USIG_FAULT_DIALOG_POP:
185 case USIG_THREAD_INIT:
186 case USIG_THREAD_EXIT:
187 case USIG_PROCESS_CREATE:
188 case USIG_PROCESS_INIT:
189 case USIG_PROCESS_LOADED:
190 case USIG_PROCESS_RUNNING:
191 case USIG_PROCESS_EXIT:
192 case USIG_PROCESS_DESTROY:
196 FIXME_(win)("(%04x, %08lx, %04lx, %04x)\n",
197 uCode, dwThreadOrProcessID, dwFlags, hModule );
201 /* FIXME: Should chain to GdiSignalProc now. */
206 /***********************************************************************
207 * ExitWindows (USER.7)
209 BOOL16 WINAPI ExitWindows16( DWORD dwReturnCode, UINT16 wReserved )
211 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
215 /***********************************************************************
216 * ExitWindowsExec (USER.246)
218 BOOL16 WINAPI ExitWindowsExec16( LPCSTR lpszExe, LPCSTR lpszParams )
220 TRACE_(system)("Should run the following in DOS-mode: \"%s %s\"\n",
221 lpszExe, lpszParams);
222 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
226 /***********************************************************************
227 * ExitWindowsEx (USER32.@)
229 BOOL WINAPI ExitWindowsEx( UINT flags, DWORD reserved )
235 /* We have to build a list of all windows first, as in EnumWindows */
237 if (!(list = WIN_ListChildren( GetDesktopWindow() ))) return FALSE;
239 /* Send a WM_QUERYENDSESSION message to every window */
241 for (i = 0; list[i]; i++)
243 /* Make sure that the window still exists */
244 if (!IsWindow( list[i] )) continue;
245 if (!SendMessageW( list[i], WM_QUERYENDSESSION, 0, 0 )) break;
249 /* Now notify all windows that got a WM_QUERYENDSESSION of the result */
251 for (phwnd = list; i > 0; i--, phwnd++)
253 if (!IsWindow( *phwnd )) continue;
254 SendMessageW( *phwnd, WM_ENDSESSION, result, 0 );
256 HeapFree( GetProcessHeap(), 0, list );
258 if (result) ExitKernel16();
262 static void _dump_CDS_flags(DWORD flags) {
263 #define X(x) if (flags & CDS_##x) MESSAGE(""#x ",");
264 X(UPDATEREGISTRY);X(TEST);X(FULLSCREEN);X(GLOBAL);
265 X(SET_PRIMARY);X(RESET);X(SETRECT);X(NORESET);
269 /***********************************************************************
270 * ChangeDisplaySettingsA (USER32.@)
272 LONG WINAPI ChangeDisplaySettingsA( LPDEVMODEA devmode, DWORD flags )
274 FIXME_(system)("(%p,0x%08lx), stub\n",devmode,flags);
275 MESSAGE("\tflags=");_dump_CDS_flags(flags);MESSAGE("\n");
277 FIXME_(system)(" devmode=NULL (return to default mode)\n");
278 else if ( (devmode->dmBitsPerPel != GetSystemMetrics(SM_WINE_BPP))
279 || (devmode->dmPelsHeight != GetSystemMetrics(SM_CYSCREEN))
280 || (devmode->dmPelsWidth != GetSystemMetrics(SM_CXSCREEN)) )
284 if (devmode->dmFields & DM_BITSPERPEL)
285 FIXME_(system)(" bpp=%ld\n",devmode->dmBitsPerPel);
286 if (devmode->dmFields & DM_PELSWIDTH)
287 FIXME_(system)(" width=%ld\n",devmode->dmPelsWidth);
288 if (devmode->dmFields & DM_PELSHEIGHT)
289 FIXME_(system)(" height=%ld\n",devmode->dmPelsHeight);
290 FIXME_(system)(" (Putting X in this mode beforehand might help)\n");
291 /* we don't, but the program ... does not need to know */
292 return DISP_CHANGE_SUCCESSFUL;
294 return DISP_CHANGE_SUCCESSFUL;
297 /***********************************************************************
298 * ChangeDisplaySettings (USER.620)
300 LONG WINAPI ChangeDisplaySettings16( LPDEVMODEA devmode, DWORD flags )
302 TRACE_(system)("(%p,0x%08lx), stub\n",devmode,flags);
303 return ChangeDisplaySettingsA(devmode, flags);
306 /***********************************************************************
307 * ChangeDisplaySettingsExA (USER32.@)
309 LONG WINAPI ChangeDisplaySettingsExA(
310 LPCSTR devname, LPDEVMODEA devmode, HWND hwnd, DWORD flags,
313 FIXME_(system)("(%s,%p,%p,0x%08lx,0x%08lx), stub\n",devname,devmode,hwnd,flags,lparam);
314 MESSAGE("\tflags=");_dump_CDS_flags(flags);MESSAGE("\n");
316 FIXME_(system)(" devmode=NULL (return to default mode)\n");
317 else if ( (devmode->dmBitsPerPel != GetSystemMetrics(SM_WINE_BPP))
318 || (devmode->dmPelsHeight != GetSystemMetrics(SM_CYSCREEN))
319 || (devmode->dmPelsWidth != GetSystemMetrics(SM_CXSCREEN)) )
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 * EnumDisplaySettingsW (USER32.@)
338 * FIXME: Currently uses static list of modes.
341 * TRUE if nth setting exists found (described in the LPDEVMODEW struct)
342 * FALSE if we do not have the nth setting
344 BOOL WINAPI EnumDisplaySettingsW(
345 LPCWSTR name, /* [in] huh? */
346 DWORD n, /* [in] nth entry in display settings list*/
347 LPDEVMODEW 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",debugstr_w(name),n,devmode);
357 devmode->dmDisplayFlags = 0;
358 devmode->dmDisplayFrequency = 85;
359 if (n==0 || n == (DWORD)-1 || n == (DWORD)-2) {
360 devmode->dmBitsPerPel = GetSystemMetrics(SM_WINE_BPP);
361 devmode->dmPelsHeight = GetSystemMetrics(SM_CYSCREEN);
362 devmode->dmPelsWidth = GetSystemMetrics(SM_CXSCREEN);
365 if ((n-1)<NRMODES*NRDEPTHS) {
366 devmode->dmBitsPerPel = depths[(n-1)/NRMODES];
367 devmode->dmPelsHeight = modes[(n-1)%NRMODES].h;
368 devmode->dmPelsWidth = modes[(n-1)%NRMODES].w;
374 /***********************************************************************
375 * EnumDisplaySettingsA (USER32.@)
377 BOOL WINAPI EnumDisplaySettingsA(LPCSTR name,DWORD n,LPDEVMODEA devmode)
381 UNICODE_STRING nameW;
383 if (name) RtlCreateUnicodeStringFromAsciiz(&nameW, name);
384 else nameW.Buffer = NULL;
386 ret = EnumDisplaySettingsW(nameW.Buffer,n,&devmodeW);
389 devmode->dmBitsPerPel = devmodeW.dmBitsPerPel;
390 devmode->dmPelsHeight = devmodeW.dmPelsHeight;
391 devmode->dmPelsWidth = devmodeW.dmPelsWidth;
392 devmode->dmDisplayFlags = devmodeW.dmDisplayFlags;
393 devmode->dmDisplayFrequency = devmodeW.dmDisplayFrequency;
394 /* FIXME: convert rest too, if they are ever returned */
396 RtlFreeUnicodeString(&nameW);
400 /***********************************************************************
401 * EnumDisplaySettings (USER.621)
403 BOOL16 WINAPI EnumDisplaySettings16(
404 LPCSTR name, /* [in] huh? */
405 DWORD n, /* [in] nth entry in display settings list*/
406 LPDEVMODEA devmode /* [out] devmode for that setting */
408 TRACE_(system)("(%s, %ld, %p)\n", name, n, devmode);
409 return (BOOL16)EnumDisplaySettingsA(name, n, devmode);
412 /***********************************************************************
413 * EnumDisplaySettingsExA (USER32.@)
415 BOOL WINAPI EnumDisplaySettingsExA(LPCSTR lpszDeviceName, DWORD iModeNum,
416 LPDEVMODEA lpDevMode, DWORD dwFlags)
418 TRACE_(system)("(%s,%lu,%p,%08lx): stub\n",
419 debugstr_a(lpszDeviceName), iModeNum, lpDevMode, dwFlags);
421 return EnumDisplaySettingsA(lpszDeviceName, iModeNum, lpDevMode);
424 /***********************************************************************
425 * EnumDisplaySettingsExW (USER32.@)
427 BOOL WINAPI EnumDisplaySettingsExW(LPCWSTR lpszDeviceName, DWORD iModeNum,
428 LPDEVMODEW lpDevMode, DWORD dwFlags)
430 TRACE_(system)("(%s,%lu,%p,%08lx): stub\n",
431 debugstr_w(lpszDeviceName), iModeNum, lpDevMode, dwFlags);
433 return EnumDisplaySettingsW(lpszDeviceName, iModeNum, lpDevMode);
436 /***********************************************************************
437 * EnumDisplayDevicesA (USER32.@)
439 BOOL WINAPI EnumDisplayDevicesA(
440 LPVOID unused,DWORD i,LPDISPLAY_DEVICEA lpDisplayDevice,DWORD dwFlags
444 FIXME_(system)("(%p,%ld,%p,0x%08lx), stub!\n",unused,i,lpDisplayDevice,dwFlags);
445 strcpy(lpDisplayDevice->DeviceName,"X11");
446 strcpy(lpDisplayDevice->DeviceString,"X 11 Windowing System");
447 lpDisplayDevice->StateFlags =
448 DISPLAY_DEVICE_ATTACHED_TO_DESKTOP |
449 DISPLAY_DEVICE_PRIMARY_DEVICE |
450 DISPLAY_DEVICE_VGA_COMPATIBLE;
454 /***********************************************************************
455 * EnumDisplayDevicesW (USER32.@)
457 BOOL WINAPI EnumDisplayDevicesW(
458 LPVOID unused,DWORD i,LPDISPLAY_DEVICEW lpDisplayDevice,DWORD dwFlags
462 FIXME_(system)("(%p,%ld,%p,0x%08lx), stub!\n",unused,i,lpDisplayDevice,dwFlags);
463 MultiByteToWideChar( CP_ACP, 0, "X11", -1, lpDisplayDevice->DeviceName,
464 sizeof(lpDisplayDevice->DeviceName)/sizeof(WCHAR) );
465 MultiByteToWideChar( CP_ACP, 0, "X11 Windowing System", -1, lpDisplayDevice->DeviceString,
466 sizeof(lpDisplayDevice->DeviceString)/sizeof(WCHAR) );
467 lpDisplayDevice->StateFlags =
468 DISPLAY_DEVICE_ATTACHED_TO_DESKTOP |
469 DISPLAY_DEVICE_PRIMARY_DEVICE |
470 DISPLAY_DEVICE_VGA_COMPATIBLE;
474 /***********************************************************************
475 * SetEventHook (USER.321)
477 * Used by Turbo Debugger for Windows
479 FARPROC16 WINAPI SetEventHook16(FARPROC16 lpfnEventHook)
481 FIXME_(hook)("(lpfnEventHook=%08x): stub\n", (UINT)lpfnEventHook);
485 /***********************************************************************
486 * UserSeeUserDo (USER.216)
488 DWORD WINAPI UserSeeUserDo16(WORD wReqType, WORD wParam1, WORD wParam2, WORD wParam3)
492 case USUD_LOCALALLOC:
493 return LOCAL_Alloc(USER_HeapSel, wParam1, wParam3);
495 return LOCAL_Free(USER_HeapSel, wParam1);
496 case USUD_LOCALCOMPACT:
497 return LOCAL_Compact(USER_HeapSel, wParam3, 0);
500 case USUD_FIRSTCLASS:
501 FIXME_(local)("return a pointer to the first window class.\n");
504 WARN_(local)("wReqType %04x (unknown)", wReqType);
509 /***********************************************************************
510 * GetSystemDebugState (USER.231)
512 WORD WINAPI GetSystemDebugState16(void)
514 return 0; /* FIXME */
517 /***********************************************************************
518 * RegisterLogonProcess (USER32.@)
520 DWORD WINAPI RegisterLogonProcess(HANDLE hprocess,BOOL x) {
521 FIXME_(win32)("(%p,%d),stub!\n",hprocess,x);
525 /***********************************************************************
526 * CreateWindowStationW (USER32.@)
528 HWINSTA WINAPI CreateWindowStationW(
529 LPWSTR winstation,DWORD res1,DWORD desiredaccess,
530 LPSECURITY_ATTRIBUTES lpsa
532 FIXME_(win32)("(%s,0x%08lx,0x%08lx,%p),stub!\n",debugstr_w(winstation),
533 res1,desiredaccess,lpsa
535 return (HWINSTA)0xdeadcafe;
538 /***********************************************************************
539 * SetProcessWindowStation (USER32.@)
541 BOOL WINAPI SetProcessWindowStation(HWINSTA hWinSta) {
542 FIXME_(win32)("(%p),stub!\n",hWinSta);
546 /***********************************************************************
547 * SetUserObjectSecurity (USER32.@)
549 BOOL WINAPI SetUserObjectSecurity(
551 PSECURITY_INFORMATION pSIRequested,
552 PSECURITY_DESCRIPTOR pSID
554 FIXME_(win32)("(%p,%p,%p),stub!\n",hObj,pSIRequested,pSID);
558 /***********************************************************************
559 * CreateDesktopA (USER32.@)
561 HDESK WINAPI CreateDesktopA(
562 LPSTR lpszDesktop,LPSTR lpszDevice,LPDEVMODEA pDevmode,
563 DWORD dwFlags,DWORD dwDesiredAccess,LPSECURITY_ATTRIBUTES lpsa
565 FIXME_(win32)("(%s,%s,%p,0x%08lx,0x%08lx,%p),stub!\n",
566 lpszDesktop,lpszDevice,pDevmode,
567 dwFlags,dwDesiredAccess,lpsa
569 return (HDESK)0xcafedead;
572 /***********************************************************************
573 * CreateDesktopW (USER32.@)
575 HDESK WINAPI CreateDesktopW(
576 LPWSTR lpszDesktop,LPWSTR lpszDevice,LPDEVMODEW pDevmode,
577 DWORD dwFlags,DWORD dwDesiredAccess,LPSECURITY_ATTRIBUTES lpsa
579 FIXME_(win32)("(%s,%s,%p,0x%08lx,0x%08lx,%p),stub!\n",
580 debugstr_w(lpszDesktop),debugstr_w(lpszDevice),pDevmode,
581 dwFlags,dwDesiredAccess,lpsa
583 return (HDESK)0xcafedead;
586 /***********************************************************************
587 * EnumDesktopWindows (USER32.@)
589 BOOL WINAPI EnumDesktopWindows( HDESK hDesktop, WNDENUMPROC lpfn, LPARAM lParam ) {
590 FIXME_(win32)("(%p, %p, 0x%08lx), stub!\n", hDesktop, lpfn, lParam );
595 /***********************************************************************
596 * CloseWindowStation (USER32.@)
598 BOOL WINAPI CloseWindowStation(HWINSTA hWinSta)
600 FIXME_(win32)("(%p)\n", hWinSta);
604 /***********************************************************************
605 * CloseDesktop (USER32.@)
607 BOOL WINAPI CloseDesktop(HDESK hDesk)
609 FIXME_(win32)("(%p)\n", hDesk);
613 /***********************************************************************
614 * SetWindowStationUser (USER32.@)
616 DWORD WINAPI SetWindowStationUser(DWORD x1,DWORD x2) {
617 FIXME_(win32)("(0x%08lx,0x%08lx),stub!\n",x1,x2);
621 /***********************************************************************
622 * SetLogonNotifyWindow (USER32.@)
624 DWORD WINAPI SetLogonNotifyWindow(HWINSTA hwinsta,HWND hwnd) {
625 FIXME_(win32)("(%p,%p),stub!\n",hwinsta,hwnd);
629 /***********************************************************************
630 * LoadLocalFonts (USER32.@)
632 VOID WINAPI LoadLocalFonts(VOID) {
636 /***********************************************************************
637 * GetUserObjectInformationA (USER32.@)
639 BOOL WINAPI GetUserObjectInformationA( HANDLE hObj, INT nIndex, LPVOID pvInfo, DWORD nLength, LPDWORD lpnLen )
640 { FIXME_(win32)("(%p %i %p %ld %p),stub!\n", hObj, nIndex, pvInfo, nLength, lpnLen );
643 /***********************************************************************
644 * GetUserObjectInformationW (USER32.@)
646 BOOL WINAPI GetUserObjectInformationW( HANDLE hObj, INT nIndex, LPVOID pvInfo, DWORD nLength, LPDWORD lpnLen )
647 { FIXME_(win32)("(%p %i %p %ld %p),stub!\n", hObj, nIndex, pvInfo, nLength, lpnLen );
650 /***********************************************************************
651 * GetUserObjectSecurity (USER32.@)
653 BOOL WINAPI GetUserObjectSecurity(HANDLE hObj, PSECURITY_INFORMATION pSIRequested,
654 PSECURITY_DESCRIPTOR pSID, DWORD nLength, LPDWORD lpnLengthNeeded)
655 { FIXME_(win32)("(%p %p %p len=%ld %p),stub!\n", hObj, pSIRequested, pSID, nLength, lpnLengthNeeded);
659 /***********************************************************************
660 * SetSystemCursor (USER32.@)
662 BOOL WINAPI SetSystemCursor(HCURSOR hcur, DWORD id)
663 { FIXME_(win32)("(%p,%08lx),stub!\n", hcur, id);
667 /***********************************************************************
668 * RegisterSystemThread (USER32.@)
670 void WINAPI RegisterSystemThread(DWORD flags, DWORD reserved)
672 FIXME_(win32)("(%08lx, %08lx)\n", flags, reserved);
675 /***********************************************************************
676 * RegisterDeviceNotificationA (USER32.@)
678 HDEVNOTIFY WINAPI RegisterDeviceNotificationA(
679 HANDLE hnd, LPVOID notifyfilter, DWORD flags
681 FIXME_(win32)("(hwnd=%p, filter=%p,flags=0x%08lx), STUB!\n", hnd,notifyfilter,flags );