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"
37 #include "wine/debug.h"
39 WINE_DECLARE_DEBUG_CHANNEL(hook);
40 WINE_DECLARE_DEBUG_CHANNEL(local);
41 WINE_DECLARE_DEBUG_CHANNEL(system);
42 WINE_DECLARE_DEBUG_CHANNEL(win);
43 WINE_DECLARE_DEBUG_CHANNEL(win32);
45 SYSLEVEL USER_SysLevel = { CRITICAL_SECTION_INIT("USER_SysLevel"), 2 };
48 /***********************************************************************
49 * GetFreeSystemResources (USER.284)
51 WORD WINAPI GetFreeSystemResources16( WORD resType )
55 int userPercent, gdiPercent;
57 if ((gdi_inst = LoadLibrary16( "GDI" )) < 32) return 0;
58 gdi_heap = gdi_inst | 7;
62 case GFSR_USERRESOURCES:
63 userPercent = (int)LOCAL_CountFree( USER_HeapSel ) * 100 /
64 LOCAL_HeapSize( USER_HeapSel );
68 case GFSR_GDIRESOURCES:
69 gdiPercent = (int)LOCAL_CountFree( gdi_inst ) * 100 /
70 LOCAL_HeapSize( gdi_inst );
74 case GFSR_SYSTEMRESOURCES:
75 userPercent = (int)LOCAL_CountFree( USER_HeapSel ) * 100 /
76 LOCAL_HeapSize( USER_HeapSel );
77 gdiPercent = (int)LOCAL_CountFree( gdi_inst ) * 100 /
78 LOCAL_HeapSize( gdi_inst );
82 userPercent = gdiPercent = 0;
85 FreeLibrary16( gdi_inst );
86 TRACE_(local)("<- userPercent %d, gdiPercent %d\n", userPercent, gdiPercent);
87 return (WORD)min( userPercent, gdiPercent );
91 /**********************************************************************
94 INT16 WINAPI InitApp16( HINSTANCE16 hInstance )
96 /* Create task message queue */
97 if ( !InitThreadInput16( 0, 0 ) ) return 0;
103 /***********************************************************************
108 _EnterSysLevel( &USER_SysLevel );
112 /***********************************************************************
115 void USER_Unlock(void)
117 _LeaveSysLevel( &USER_SysLevel );
121 /***********************************************************************
124 * Make sure that we don't hold the user lock.
126 void USER_CheckNotLock(void)
128 _CheckNotSysLevel( &USER_SysLevel );
132 /**********************************************************************
135 static void USER_ModuleUnload( HMODULE16 hModule )
137 /* HOOK_FreeModuleHooks( hModule ); */
138 CLASS_FreeModuleClasses( hModule );
139 CURSORICON_FreeModuleIcons( hModule );
142 /***********************************************************************
143 * SignalProc (USER.314)
145 void WINAPI USER_SignalProc( HANDLE16 hTaskOrModule, UINT16 uCode,
146 UINT16 uExitFn, HINSTANCE16 hInstance,
149 FIXME_(win)("Win 3.1 USER signal %04x\n", uCode );
152 /***********************************************************************
153 * FinalUserInit (USER.400)
155 void WINAPI FinalUserInit16( void )
157 /* FIXME: Should chain to FinalGdiInit now. */
160 /***********************************************************************
161 * SignalProc32 (USER.391)
162 * UserSignalProc (USER32.@)
164 * For comments about the meaning of uCode and dwFlags
165 * see PROCESS_CallUserSignalProc.
168 WORD WINAPI UserSignalProc( UINT uCode, DWORD dwThreadOrProcessID,
169 DWORD dwFlags, HMODULE16 hModule )
171 /* FIXME: Proper reaction to most signals still missing. */
175 case USIG_DLL_UNLOAD_WIN16:
176 case USIG_DLL_UNLOAD_WIN32:
177 USER_ModuleUnload( hModule );
180 case USIG_DLL_UNLOAD_ORPHANS:
181 case USIG_FAULT_DIALOG_PUSH:
182 case USIG_FAULT_DIALOG_POP:
183 case USIG_THREAD_INIT:
184 case USIG_THREAD_EXIT:
185 case USIG_PROCESS_CREATE:
186 case USIG_PROCESS_INIT:
187 case USIG_PROCESS_LOADED:
188 case USIG_PROCESS_RUNNING:
189 case USIG_PROCESS_EXIT:
190 case USIG_PROCESS_DESTROY:
194 FIXME_(win)("(%04x, %08lx, %04lx, %04x)\n",
195 uCode, dwThreadOrProcessID, dwFlags, hModule );
199 /* FIXME: Should chain to GdiSignalProc now. */
204 /***********************************************************************
205 * ExitWindows (USER.7)
207 BOOL16 WINAPI ExitWindows16( DWORD dwReturnCode, UINT16 wReserved )
209 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
213 /***********************************************************************
214 * ExitWindowsExec (USER.246)
216 BOOL16 WINAPI ExitWindowsExec16( LPCSTR lpszExe, LPCSTR lpszParams )
218 TRACE_(system)("Should run the following in DOS-mode: \"%s %s\"\n",
219 lpszExe, lpszParams);
220 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
224 /***********************************************************************
225 * ExitWindowsEx (USER32.@)
227 BOOL WINAPI ExitWindowsEx( UINT flags, DWORD reserved )
233 /* We have to build a list of all windows first, as in EnumWindows */
235 if (!(list = WIN_ListChildren( GetDesktopWindow() ))) return FALSE;
237 /* Send a WM_QUERYENDSESSION message to every window */
239 for (i = 0; list[i]; i++)
241 /* Make sure that the window still exists */
242 if (!IsWindow( list[i] )) continue;
243 if (!SendMessageW( list[i], WM_QUERYENDSESSION, 0, 0 )) break;
247 /* Now notify all windows that got a WM_QUERYENDSESSION of the result */
249 for (phwnd = list; i > 0; i--, phwnd++)
251 if (!IsWindow( *phwnd )) continue;
252 SendMessageW( *phwnd, WM_ENDSESSION, result, 0 );
254 HeapFree( GetProcessHeap(), 0, list );
256 if (result) ExitKernel16();
260 static void _dump_CDS_flags(DWORD flags) {
261 #define X(x) if (flags & CDS_##x) MESSAGE(""#x ",");
262 X(UPDATEREGISTRY);X(TEST);X(FULLSCREEN);X(GLOBAL);
263 X(SET_PRIMARY);X(RESET);X(SETRECT);X(NORESET);
267 /***********************************************************************
268 * ChangeDisplaySettingsA (USER32.@)
270 LONG WINAPI ChangeDisplaySettingsA( LPDEVMODEA devmode, DWORD flags )
272 FIXME_(system)("(%p,0x%08lx), stub\n",devmode,flags);
273 MESSAGE("\tflags=");_dump_CDS_flags(flags);MESSAGE("\n");
275 FIXME_(system)(" devmode=NULL (return to default mode)\n");
276 else if ( (devmode->dmBitsPerPel != GetSystemMetrics(SM_WINE_BPP))
277 || (devmode->dmPelsHeight != GetSystemMetrics(SM_CYSCREEN))
278 || (devmode->dmPelsWidth != GetSystemMetrics(SM_CXSCREEN)) )
282 if (devmode->dmFields & DM_BITSPERPEL)
283 FIXME_(system)(" bpp=%ld\n",devmode->dmBitsPerPel);
284 if (devmode->dmFields & DM_PELSWIDTH)
285 FIXME_(system)(" width=%ld\n",devmode->dmPelsWidth);
286 if (devmode->dmFields & DM_PELSHEIGHT)
287 FIXME_(system)(" height=%ld\n",devmode->dmPelsHeight);
288 FIXME_(system)(" (Putting X in this mode beforehand might help)\n");
289 /* we don't, but the program ... does not need to know */
290 return DISP_CHANGE_SUCCESSFUL;
292 return DISP_CHANGE_SUCCESSFUL;
295 /***********************************************************************
296 * ChangeDisplaySettings (USER.620)
298 LONG WINAPI ChangeDisplaySettings16( LPDEVMODEA devmode, DWORD flags )
300 TRACE_(system)("(%p,0x%08lx), stub\n",devmode,flags);
301 return ChangeDisplaySettingsA(devmode, flags);
304 /***********************************************************************
305 * ChangeDisplaySettingsExA (USER32.@)
307 LONG WINAPI ChangeDisplaySettingsExA(
308 LPCSTR devname, LPDEVMODEA devmode, HWND hwnd, DWORD flags,
311 FIXME_(system)("(%s,%p,%p,0x%08lx,0x%08lx), stub\n",devname,devmode,hwnd,flags,lparam);
312 MESSAGE("\tflags=");_dump_CDS_flags(flags);MESSAGE("\n");
314 FIXME_(system)(" devmode=NULL (return to default mode)\n");
315 else if ( (devmode->dmBitsPerPel != GetSystemMetrics(SM_WINE_BPP))
316 || (devmode->dmPelsHeight != GetSystemMetrics(SM_CYSCREEN))
317 || (devmode->dmPelsWidth != GetSystemMetrics(SM_CXSCREEN)) )
321 if (devmode->dmFields & DM_BITSPERPEL)
322 FIXME_(system)(" bpp=%ld\n",devmode->dmBitsPerPel);
323 if (devmode->dmFields & DM_PELSWIDTH)
324 FIXME_(system)(" width=%ld\n",devmode->dmPelsWidth);
325 if (devmode->dmFields & DM_PELSHEIGHT)
326 FIXME_(system)(" height=%ld\n",devmode->dmPelsHeight);
327 FIXME_(system)(" (Putting X in this mode beforehand might help)\n");
328 /* we don't, but the program ... does not need to know */
329 return DISP_CHANGE_SUCCESSFUL;
331 return DISP_CHANGE_SUCCESSFUL;
334 /***********************************************************************
335 * EnumDisplaySettingsW (USER32.@)
336 * FIXME: Currently uses static list of modes.
339 * TRUE if nth setting exists found (described in the LPDEVMODEW struct)
340 * FALSE if we do not have the nth setting
342 BOOL WINAPI EnumDisplaySettingsW(
343 LPCWSTR name, /* [in] huh? */
344 DWORD n, /* [in] nth entry in display settings list*/
345 LPDEVMODEW devmode /* [out] devmode for that setting */
351 } modes[NRMODES]={{512,384},{640,400},{640,480},{800,600},{1024,768}};
352 int depths[4] = {8,16,24,32};
354 TRACE_(system)("(%s,%ld,%p)\n",debugstr_w(name),n,devmode);
355 devmode->dmDisplayFlags = 0;
356 devmode->dmDisplayFrequency = 85;
357 if (n==0 || n == (DWORD)-1 || n == (DWORD)-2) {
358 devmode->dmBitsPerPel = GetSystemMetrics(SM_WINE_BPP);
359 devmode->dmPelsHeight = GetSystemMetrics(SM_CYSCREEN);
360 devmode->dmPelsWidth = GetSystemMetrics(SM_CXSCREEN);
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 * EnumDisplaySettingsA (USER32.@)
375 BOOL WINAPI EnumDisplaySettingsA(LPCSTR name,DWORD n,LPDEVMODEA devmode)
379 UNICODE_STRING nameW;
381 if (name) RtlCreateUnicodeStringFromAsciiz(&nameW, name);
382 else nameW.Buffer = NULL;
384 ret = EnumDisplaySettingsW(nameW.Buffer,n,&devmodeW);
387 devmode->dmBitsPerPel = devmodeW.dmBitsPerPel;
388 devmode->dmPelsHeight = devmodeW.dmPelsHeight;
389 devmode->dmPelsWidth = devmodeW.dmPelsWidth;
390 devmode->dmDisplayFlags = devmodeW.dmDisplayFlags;
391 devmode->dmDisplayFrequency = devmodeW.dmDisplayFrequency;
392 /* FIXME: convert rest too, if they are ever returned */
394 RtlFreeUnicodeString(&nameW);
398 /***********************************************************************
399 * EnumDisplaySettings (USER.621)
401 BOOL16 WINAPI EnumDisplaySettings16(
402 LPCSTR name, /* [in] huh? */
403 DWORD n, /* [in] nth entry in display settings list*/
404 LPDEVMODEA devmode /* [out] devmode for that setting */
406 TRACE_(system)("(%s, %ld, %p)\n", name, n, devmode);
407 return (BOOL16)EnumDisplaySettingsA(name, n, devmode);
410 /***********************************************************************
411 * EnumDisplaySettingsExA (USER32.@)
413 BOOL WINAPI EnumDisplaySettingsExA(LPCSTR lpszDeviceName, DWORD iModeNum,
414 LPDEVMODEA lpDevMode, DWORD dwFlags)
416 TRACE_(system)("(%s,%lu,%p,%08lx): stub\n",
417 debugstr_a(lpszDeviceName), iModeNum, lpDevMode, dwFlags);
419 return EnumDisplaySettingsA(lpszDeviceName, iModeNum, lpDevMode);
422 /***********************************************************************
423 * EnumDisplaySettingsExW (USER32.@)
425 BOOL WINAPI EnumDisplaySettingsExW(LPCWSTR lpszDeviceName, DWORD iModeNum,
426 LPDEVMODEW lpDevMode, DWORD dwFlags)
428 TRACE_(system)("(%s,%lu,%p,%08lx): stub\n",
429 debugstr_w(lpszDeviceName), iModeNum, lpDevMode, dwFlags);
431 return EnumDisplaySettingsW(lpszDeviceName, iModeNum, lpDevMode);
434 /***********************************************************************
435 * EnumDisplayDevicesA (USER32.@)
437 BOOL WINAPI EnumDisplayDevicesA(
438 LPVOID unused,DWORD i,LPDISPLAY_DEVICEA lpDisplayDevice,DWORD dwFlags
442 FIXME_(system)("(%p,%ld,%p,0x%08lx), stub!\n",unused,i,lpDisplayDevice,dwFlags);
443 strcpy(lpDisplayDevice->DeviceName,"X11");
444 strcpy(lpDisplayDevice->DeviceString,"X 11 Windowing System");
445 lpDisplayDevice->StateFlags =
446 DISPLAY_DEVICE_ATTACHED_TO_DESKTOP |
447 DISPLAY_DEVICE_PRIMARY_DEVICE |
448 DISPLAY_DEVICE_VGA_COMPATIBLE;
452 /***********************************************************************
453 * EnumDisplayDevicesW (USER32.@)
455 BOOL WINAPI EnumDisplayDevicesW(
456 LPVOID unused,DWORD i,LPDISPLAY_DEVICEW lpDisplayDevice,DWORD dwFlags
460 FIXME_(system)("(%p,%ld,%p,0x%08lx), stub!\n",unused,i,lpDisplayDevice,dwFlags);
461 MultiByteToWideChar( CP_ACP, 0, "X11", -1, lpDisplayDevice->DeviceName,
462 sizeof(lpDisplayDevice->DeviceName)/sizeof(WCHAR) );
463 MultiByteToWideChar( CP_ACP, 0, "X11 Windowing System", -1, lpDisplayDevice->DeviceString,
464 sizeof(lpDisplayDevice->DeviceString)/sizeof(WCHAR) );
465 lpDisplayDevice->StateFlags =
466 DISPLAY_DEVICE_ATTACHED_TO_DESKTOP |
467 DISPLAY_DEVICE_PRIMARY_DEVICE |
468 DISPLAY_DEVICE_VGA_COMPATIBLE;
472 /***********************************************************************
473 * SetEventHook (USER.321)
475 * Used by Turbo Debugger for Windows
477 FARPROC16 WINAPI SetEventHook16(FARPROC16 lpfnEventHook)
479 FIXME_(hook)("(lpfnEventHook=%08x): stub\n", (UINT)lpfnEventHook);
483 /***********************************************************************
484 * UserSeeUserDo (USER.216)
486 DWORD WINAPI UserSeeUserDo16(WORD wReqType, WORD wParam1, WORD wParam2, WORD wParam3)
490 case USUD_LOCALALLOC:
491 return LOCAL_Alloc(USER_HeapSel, wParam1, wParam3);
493 return LOCAL_Free(USER_HeapSel, wParam1);
494 case USUD_LOCALCOMPACT:
495 return LOCAL_Compact(USER_HeapSel, wParam3, 0);
498 case USUD_FIRSTCLASS:
499 FIXME_(local)("return a pointer to the first window class.\n");
502 WARN_(local)("wReqType %04x (unknown)", wReqType);
507 /***********************************************************************
508 * GetSystemDebugState (USER.231)
510 WORD WINAPI GetSystemDebugState16(void)
512 return 0; /* FIXME */
515 /***********************************************************************
516 * RegisterLogonProcess (USER32.@)
518 DWORD WINAPI RegisterLogonProcess(HANDLE hprocess,BOOL x) {
519 FIXME_(win32)("(%p,%d),stub!\n",hprocess,x);
523 /***********************************************************************
524 * CreateWindowStationW (USER32.@)
526 HWINSTA WINAPI CreateWindowStationW(
527 LPWSTR winstation,DWORD res1,DWORD desiredaccess,
528 LPSECURITY_ATTRIBUTES lpsa
530 FIXME_(win32)("(%s,0x%08lx,0x%08lx,%p),stub!\n",debugstr_w(winstation),
531 res1,desiredaccess,lpsa
533 return (HWINSTA)0xdeadcafe;
536 /***********************************************************************
537 * SetProcessWindowStation (USER32.@)
539 BOOL WINAPI SetProcessWindowStation(HWINSTA hWinSta) {
540 FIXME_(win32)("(%p),stub!\n",hWinSta);
544 /***********************************************************************
545 * SetUserObjectSecurity (USER32.@)
547 BOOL WINAPI SetUserObjectSecurity(
549 PSECURITY_INFORMATION pSIRequested,
550 PSECURITY_DESCRIPTOR pSID
552 FIXME_(win32)("(%p,%p,%p),stub!\n",hObj,pSIRequested,pSID);
556 /***********************************************************************
557 * CreateDesktopA (USER32.@)
559 HDESK WINAPI CreateDesktopA(
560 LPSTR lpszDesktop,LPSTR lpszDevice,LPDEVMODEA pDevmode,
561 DWORD dwFlags,DWORD dwDesiredAccess,LPSECURITY_ATTRIBUTES lpsa
563 FIXME_(win32)("(%s,%s,%p,0x%08lx,0x%08lx,%p),stub!\n",
564 lpszDesktop,lpszDevice,pDevmode,
565 dwFlags,dwDesiredAccess,lpsa
567 return (HDESK)0xcafedead;
570 /***********************************************************************
571 * CreateDesktopW (USER32.@)
573 HDESK WINAPI CreateDesktopW(
574 LPWSTR lpszDesktop,LPWSTR lpszDevice,LPDEVMODEW pDevmode,
575 DWORD dwFlags,DWORD dwDesiredAccess,LPSECURITY_ATTRIBUTES lpsa
577 FIXME_(win32)("(%s,%s,%p,0x%08lx,0x%08lx,%p),stub!\n",
578 debugstr_w(lpszDesktop),debugstr_w(lpszDevice),pDevmode,
579 dwFlags,dwDesiredAccess,lpsa
581 return (HDESK)0xcafedead;
584 /***********************************************************************
585 * EnumDesktopWindows (USER32.@)
587 BOOL WINAPI EnumDesktopWindows( HDESK hDesktop, WNDENUMPROC lpfn, LPARAM lParam ) {
588 FIXME_(win32)("(%p, %p, 0x%08lx), stub!\n", hDesktop, lpfn, lParam );
593 /***********************************************************************
594 * CloseWindowStation (USER32.@)
596 BOOL WINAPI CloseWindowStation(HWINSTA hWinSta)
598 FIXME_(win32)("(%p)\n", hWinSta);
602 /***********************************************************************
603 * CloseDesktop (USER32.@)
605 BOOL WINAPI CloseDesktop(HDESK hDesk)
607 FIXME_(win32)("(%p)\n", hDesk);
611 /***********************************************************************
612 * SetWindowStationUser (USER32.@)
614 DWORD WINAPI SetWindowStationUser(DWORD x1,DWORD x2) {
615 FIXME_(win32)("(0x%08lx,0x%08lx),stub!\n",x1,x2);
619 /***********************************************************************
620 * SetLogonNotifyWindow (USER32.@)
622 DWORD WINAPI SetLogonNotifyWindow(HWINSTA hwinsta,HWND hwnd) {
623 FIXME_(win32)("(%p,%p),stub!\n",hwinsta,hwnd);
627 /***********************************************************************
628 * LoadLocalFonts (USER32.@)
630 VOID WINAPI LoadLocalFonts(VOID) {
634 /***********************************************************************
635 * GetUserObjectInformationA (USER32.@)
637 BOOL WINAPI GetUserObjectInformationA( HANDLE hObj, INT nIndex, LPVOID pvInfo, DWORD nLength, LPDWORD lpnLen )
638 { FIXME_(win32)("(%p %i %p %ld %p),stub!\n", hObj, nIndex, pvInfo, nLength, lpnLen );
641 /***********************************************************************
642 * GetUserObjectInformationW (USER32.@)
644 BOOL WINAPI GetUserObjectInformationW( HANDLE hObj, INT nIndex, LPVOID pvInfo, DWORD nLength, LPDWORD lpnLen )
645 { FIXME_(win32)("(%p %i %p %ld %p),stub!\n", hObj, nIndex, pvInfo, nLength, lpnLen );
648 /***********************************************************************
649 * GetUserObjectSecurity (USER32.@)
651 BOOL WINAPI GetUserObjectSecurity(HANDLE hObj, PSECURITY_INFORMATION pSIRequested,
652 PSECURITY_DESCRIPTOR pSID, DWORD nLength, LPDWORD lpnLengthNeeded)
653 { FIXME_(win32)("(%p %p %p len=%ld %p),stub!\n", hObj, pSIRequested, pSID, nLength, lpnLengthNeeded);
657 /***********************************************************************
658 * SetSystemCursor (USER32.@)
660 BOOL WINAPI SetSystemCursor(HCURSOR hcur, DWORD id)
661 { FIXME_(win32)("(%p,%08lx),stub!\n", hcur, id);
665 /***********************************************************************
666 * RegisterSystemThread (USER32.@)
668 void WINAPI RegisterSystemThread(DWORD flags, DWORD reserved)
670 FIXME_(win32)("(%08lx, %08lx)\n", flags, reserved);
673 /***********************************************************************
674 * RegisterDeviceNotificationA (USER32.@)
676 HDEVNOTIFY WINAPI RegisterDeviceNotificationA(
677 HANDLE hnd, LPVOID notifyfilter, DWORD flags
679 FIXME_(win32)("(hwnd=%p, filter=%p,flags=0x%08lx), STUB!\n", hnd,notifyfilter,flags );