Added COMPOBJ.DllEntryPoint (Acrobat3 16bit needs it).
[wine.git] / windows / user.c
blob024c5a1e587a3f66f740cf08befd45469ed8a389
1 /*
2 * Misc. USER functions
4 * Copyright 1993 Robert J. Amstadt
5 * 1996 Alex Korobka
6 */
8 #include <stdlib.h>
9 #include "wine/winbase16.h"
10 #include "winuser.h"
11 #include "heap.h"
12 #include "user.h"
13 #include "gdi.h"
14 #include "task.h"
15 #include "queue.h"
16 #include "win.h"
17 #include "clipboard.h"
18 #include "menu.h"
19 #include "cursoricon.h"
20 #include "hook.h"
21 #include "toolhelp.h"
22 #include "message.h"
23 #include "module.h"
24 #include "miscemu.h"
25 #include "shell.h"
26 #include "callback.h"
27 #include "local.h"
28 #include "desktop.h"
29 #include "process.h"
30 #include "debugtools.h"
32 DECLARE_DEBUG_CHANNEL(hook)
33 DECLARE_DEBUG_CHANNEL(local)
34 DECLARE_DEBUG_CHANNEL(system)
35 DECLARE_DEBUG_CHANNEL(win)
36 DECLARE_DEBUG_CHANNEL(win32)
38 /***********************************************************************
39 * GetFreeSystemResources (USER.284)
41 WORD WINAPI GetFreeSystemResources16( WORD resType )
43 int userPercent, gdiPercent;
45 switch(resType)
47 case GFSR_USERRESOURCES:
48 userPercent = (int)LOCAL_CountFree( USER_HeapSel ) * 100 /
49 LOCAL_HeapSize( USER_HeapSel );
50 gdiPercent = 100;
51 break;
53 case GFSR_GDIRESOURCES:
54 gdiPercent = (int)LOCAL_CountFree( GDI_HeapSel ) * 100 /
55 LOCAL_HeapSize( GDI_HeapSel );
56 userPercent = 100;
57 break;
59 case GFSR_SYSTEMRESOURCES:
60 userPercent = (int)LOCAL_CountFree( USER_HeapSel ) * 100 /
61 LOCAL_HeapSize( USER_HeapSel );
62 gdiPercent = (int)LOCAL_CountFree( GDI_HeapSel ) * 100 /
63 LOCAL_HeapSize( GDI_HeapSel );
64 break;
66 default:
67 return 0;
69 return (WORD)MIN( userPercent, gdiPercent );
73 /***********************************************************************
74 * SystemHeapInfo (TOOLHELP.71)
76 BOOL16 WINAPI SystemHeapInfo16( SYSHEAPINFO *pHeapInfo )
78 pHeapInfo->wUserFreePercent = GetFreeSystemResources16( GFSR_USERRESOURCES );
79 pHeapInfo->wGDIFreePercent = GetFreeSystemResources16( GFSR_GDIRESOURCES );
80 pHeapInfo->hUserSegment = USER_HeapSel;
81 pHeapInfo->hGDISegment = GDI_HeapSel;
82 return TRUE;
86 /***********************************************************************
87 * TimerCount (TOOLHELP.80)
89 BOOL16 WINAPI TimerCount16( TIMERINFO *pTimerInfo )
91 /* FIXME
92 * In standard mode, dwmsSinceStart = dwmsThisVM
94 * I tested this, under Windows in enhanced mode, and
95 * if you never switch VM (ie start/stop DOS) these
96 * values should be the same as well.
98 * Also, Wine should adjust for the hardware timer
99 * to reduce the amount of error to ~1ms.
100 * I can't be bothered, can you?
102 pTimerInfo->dwmsSinceStart = pTimerInfo->dwmsThisVM = GetTickCount();
103 return TRUE;
106 /**********************************************************************
107 * InitApp (USER.5)
109 INT16 WINAPI InitApp16( HINSTANCE16 hInstance )
111 /* Hack: restore the divide-by-zero handler */
112 /* FIXME: should set a USER-specific handler that displays a msg box */
113 INT_SetPMHandler( 0, INT_GetPMHandler( 0xff ) );
115 /* Create task message queue */
116 if ( !GetFastQueue16() ) return 0;
118 return 1;
121 /**********************************************************************
122 * USER_ModuleUnload
124 static void USER_ModuleUnload( HMODULE16 hModule )
126 HOOK_FreeModuleHooks( hModule );
127 CLASS_FreeModuleClasses( hModule );
128 CURSORICON_FreeModuleIcons( hModule );
131 /**********************************************************************
132 * USER_QueueCleanup
134 static void USER_QueueCleanup( HQUEUE16 hQueue )
136 if ( hQueue )
138 WND* desktop = WIN_GetDesktop();
140 /* Patch desktop window */
141 if ( desktop->hmemTaskQ == hQueue )
143 HTASK16 nextTask = TASK_GetNextTask( GetCurrentTask() );
144 desktop->hmemTaskQ = GetTaskQueue16( nextTask );
147 /* Patch resident popup menu window */
148 MENU_PatchResidentPopup( hQueue, NULL );
150 TIMER_RemoveQueueTimers( hQueue );
152 HOOK_FreeQueueHooks( hQueue );
154 QUEUE_SetExitingQueue( hQueue );
155 WIN_ResetQueueWindows( desktop, hQueue, (HQUEUE16)0);
156 CLIPBOARD_ResetLock( hQueue, 0 );
157 QUEUE_SetExitingQueue( 0 );
159 /* Free the message queue */
160 QUEUE_DeleteMsgQueue( hQueue );
162 WIN_ReleaseDesktop();
166 /**********************************************************************
167 * USER_AppExit
169 static void USER_AppExit( HINSTANCE16 hInstance )
171 /* FIXME: empty clipboard if needed, maybe destroy menus (Windows
172 * only complains about them but does nothing);
175 /* ModuleUnload() in "Internals" */
177 hInstance = GetExePtr( hInstance );
178 if( GetModuleUsage16( hInstance ) <= 1 )
179 USER_ModuleUnload( hInstance );
183 /***********************************************************************
184 * USER_SignalProc (USER.314)
186 void WINAPI USER_SignalProc( HANDLE16 hTaskOrModule, UINT16 uCode,
187 UINT16 uExitFn, HINSTANCE16 hInstance,
188 HQUEUE16 hQueue )
190 FIXME_(win)("Win 3.1 USER signal %04x\n", uCode );
193 /***********************************************************************
194 * UserSignalProc (USER.610) (USER32.559)
196 * For comments about the meaning of uCode and dwFlags
197 * see PROCESS_CallUserSignalProc.
200 WORD WINAPI UserSignalProc( UINT uCode, DWORD dwThreadOrProcessID,
201 DWORD dwFlags, HMODULE16 hModule )
203 HINSTANCE16 hInst;
205 /* FIXME: Proper reaction to most signals still missing. */
207 switch ( uCode )
209 case USIG_DLL_UNLOAD_WIN16:
210 case USIG_DLL_UNLOAD_WIN32:
211 USER_ModuleUnload( hModule );
212 break;
214 case USIG_DLL_UNLOAD_ORPHANS:
215 break;
217 case USIG_FAULT_DIALOG_PUSH:
218 case USIG_FAULT_DIALOG_POP:
219 break;
221 case USIG_THREAD_INIT:
222 break;
224 case USIG_THREAD_EXIT:
225 USER_QueueCleanup( GetThreadQueue16( dwThreadOrProcessID ) );
226 SetThreadQueue16( dwThreadOrProcessID, 0 );
227 break;
229 case USIG_PROCESS_CREATE:
230 case USIG_PROCESS_INIT:
231 case USIG_PROCESS_LOADED:
232 case USIG_PROCESS_RUNNING:
233 break;
235 case USIG_PROCESS_EXIT:
236 break;
238 case USIG_PROCESS_DESTROY:
239 hInst = GetProcessDword( dwThreadOrProcessID, GPD_HINSTANCE16 );
240 USER_AppExit( hInst );
241 break;
243 default:
244 FIXME_(win)("(%04x, %08lx, %04lx, %04x)\n",
245 uCode, dwThreadOrProcessID, dwFlags, hModule );
246 break;
249 /* FIXME: Should chain to GdiSignalProc now. */
251 return 0;
256 /***********************************************************************
257 * ExitWindows16 (USER.7)
259 BOOL16 WINAPI ExitWindows16( DWORD dwReturnCode, UINT16 wReserved )
261 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
265 /***********************************************************************
266 * ExitWindowsExec16 (USER.246)
268 BOOL16 WINAPI ExitWindowsExec16( LPCSTR lpszExe, LPCSTR lpszParams )
270 TRACE_(system)("Should run the following in DOS-mode: \"%s %s\"\n",
271 lpszExe, lpszParams);
272 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
276 /***********************************************************************
277 * ExitWindowsEx (USER32.196)
279 BOOL WINAPI ExitWindowsEx( UINT flags, DWORD reserved )
281 int i;
282 BOOL result;
283 WND **list, **ppWnd;
285 /* We have to build a list of all windows first, as in EnumWindows */
287 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
289 WIN_ReleaseDesktop();
290 return FALSE;
293 /* Send a WM_QUERYENDSESSION message to every window */
295 for (ppWnd = list, i = 0; *ppWnd; ppWnd++, i++)
297 /* Make sure that the window still exists */
298 if (!IsWindow( (*ppWnd)->hwndSelf )) continue;
299 if (!SendMessage16( (*ppWnd)->hwndSelf, WM_QUERYENDSESSION, 0, 0 ))
300 break;
302 result = !(*ppWnd);
304 /* Now notify all windows that got a WM_QUERYENDSESSION of the result */
306 for (ppWnd = list; i > 0; i--, ppWnd++)
308 if (!IsWindow( (*ppWnd)->hwndSelf )) continue;
309 SendMessage16( (*ppWnd)->hwndSelf, WM_ENDSESSION, result, 0 );
311 WIN_ReleaseWinArray(list);
313 if (result) ExitKernel16();
314 WIN_ReleaseDesktop();
315 return FALSE;
319 /***********************************************************************
320 * ChangeDisplaySettingA (USER32.589)
322 LONG WINAPI ChangeDisplaySettingsA( LPDEVMODEA devmode, DWORD flags )
324 FIXME_(system)(": stub\n");
325 if (devmode==NULL)
326 FIXME_(system)(" devmode=NULL (return to default mode)\n");
327 else if ( (devmode->dmBitsPerPel != DESKTOP_GetScreenDepth())
328 || (devmode->dmPelsHeight != DESKTOP_GetScreenHeight())
329 || (devmode->dmPelsWidth != DESKTOP_GetScreenWidth()) )
333 if (devmode->dmFields & DM_BITSPERPEL)
334 FIXME_(system)(" bpp=%ld\n",devmode->dmBitsPerPel);
335 if (devmode->dmFields & DM_PELSWIDTH)
336 FIXME_(system)(" width=%ld\n",devmode->dmPelsWidth);
337 if (devmode->dmFields & DM_PELSHEIGHT)
338 FIXME_(system)(" height=%ld\n",devmode->dmPelsHeight);
339 FIXME_(system)(" (Putting X in this mode beforehand might help)\n");
340 /* we don't, but the program ... does not need to know */
341 return DISP_CHANGE_SUCCESSFUL;
343 return DISP_CHANGE_SUCCESSFUL;
346 /***********************************************************************
347 * EnumDisplaySettingsA (USER32.592)
348 * FIXME: Currently uses static list of modes.
350 * RETURNS
351 * TRUE if nth setting exists found (described in the LPDEVMODE32A struct)
352 * FALSE if we do not have the nth setting
354 BOOL WINAPI EnumDisplaySettingsA(
355 LPCSTR name, /* [in] huh? */
356 DWORD n, /* [in] nth entry in display settings list*/
357 LPDEVMODEA devmode /* [out] devmode for that setting */
359 #define NRMODES 5
360 #define NRDEPTHS 4
361 struct {
362 int w,h;
363 } modes[NRMODES]={{512,384},{640,400},{640,480},{800,600},{1024,768}};
364 int depths[4] = {8,16,24,32};
366 TRACE_(system)("(%s,%ld,%p)\n",name,n,devmode);
367 if (n==0) {
368 devmode->dmBitsPerPel = DESKTOP_GetScreenDepth();
369 devmode->dmPelsHeight = DESKTOP_GetScreenHeight();
370 devmode->dmPelsWidth = DESKTOP_GetScreenWidth();
371 return TRUE;
373 if ((n-1)<NRMODES*NRDEPTHS) {
374 devmode->dmBitsPerPel = depths[(n-1)/NRMODES];
375 devmode->dmPelsHeight = modes[(n-1)%NRMODES].h;
376 devmode->dmPelsWidth = modes[(n-1)%NRMODES].w;
377 return TRUE;
379 return FALSE;
382 /***********************************************************************
383 * EnumDisplaySettingsW (USER32.593)
385 BOOL WINAPI EnumDisplaySettingsW(LPCWSTR name,DWORD n,LPDEVMODEW devmode) {
386 LPSTR nameA = HEAP_strdupWtoA(GetProcessHeap(),0,name);
387 DEVMODEA devmodeA;
388 BOOL ret = EnumDisplaySettingsA(nameA,n,&devmodeA);
390 if (ret) {
391 devmode->dmBitsPerPel = devmodeA.dmBitsPerPel;
392 devmode->dmPelsHeight = devmodeA.dmPelsHeight;
393 devmode->dmPelsWidth = devmodeA.dmPelsWidth;
394 /* FIXME: convert rest too, if they are ever returned */
396 HeapFree(GetProcessHeap(),0,nameA);
397 return ret;
400 /***********************************************************************
401 * SetEventHook (USER.321)
403 * Used by Turbo Debugger for Windows
405 FARPROC16 WINAPI SetEventHook16(FARPROC16 lpfnEventHook)
407 FIXME_(hook)("(lpfnEventHook=%08x): stub\n", (UINT)lpfnEventHook);
408 return NULL;
411 /***********************************************************************
412 * UserSeeUserDo (USER.216)
414 DWORD WINAPI UserSeeUserDo16(WORD wReqType, WORD wParam1, WORD wParam2, WORD wParam3)
416 switch (wReqType)
418 case USUD_LOCALALLOC:
419 return LOCAL_Alloc(USER_HeapSel, wParam1, wParam3);
420 case USUD_LOCALFREE:
421 return LOCAL_Free(USER_HeapSel, wParam1);
422 case USUD_LOCALCOMPACT:
423 return LOCAL_Compact(USER_HeapSel, wParam3, 0);
424 case USUD_LOCALHEAP:
425 return USER_HeapSel;
426 case USUD_FIRSTCLASS:
427 FIXME_(local)("return a pointer to the first window class.\n");
428 return (DWORD)-1;
429 default:
430 WARN_(local)("wReqType %04x (unknown)", wReqType);
431 return (DWORD)-1;
435 /***********************************************************************
436 * RegisterLogonProcess (USER32.434)
438 DWORD WINAPI RegisterLogonProcess(HANDLE hprocess,BOOL x) {
439 FIXME_(win32)("(%d,%d),stub!\n",hprocess,x);
440 return 1;
443 /***********************************************************************
444 * CreateWindowStation32W (USER32.86)
446 HWINSTA WINAPI CreateWindowStationW(
447 LPWSTR winstation,DWORD res1,DWORD desiredaccess,
448 LPSECURITY_ATTRIBUTES lpsa
450 FIXME_(win32)("(%s,0x%08lx,0x%08lx,%p),stub!\n",debugstr_w(winstation),
451 res1,desiredaccess,lpsa
453 return 0xdeadcafe;
456 /***********************************************************************
457 * SetProcessWindowStation (USER32.496)
459 BOOL WINAPI SetProcessWindowStation(HWINSTA hWinSta) {
460 FIXME_(win32)("(%d),stub!\n",hWinSta);
461 return TRUE;
464 /***********************************************************************
465 * SetUserObjectSecurity (USER32.514)
467 BOOL WINAPI SetUserObjectSecurity(
468 HANDLE hObj,
469 /*LPSECURITY_INFORMATION*/LPVOID pSIRequested,
470 PSECURITY_DESCRIPTOR pSID
472 FIXME_(win32)("(0x%08x,%p,%p),stub!\n",hObj,pSIRequested,pSID);
473 return TRUE;
476 /***********************************************************************
477 * CreateDesktop32W (USER32.69)
479 HDESK WINAPI CreateDesktopW(
480 LPWSTR lpszDesktop,LPWSTR lpszDevice,LPDEVMODEW pDevmode,
481 DWORD dwFlags,DWORD dwDesiredAccess,LPSECURITY_ATTRIBUTES lpsa
483 FIXME_(win32)("(%s,%s,%p,0x%08lx,0x%08lx,%p),stub!\n",
484 debugstr_w(lpszDesktop),debugstr_w(lpszDevice),pDevmode,
485 dwFlags,dwDesiredAccess,lpsa
487 return 0xcafedead;
490 BOOL WINAPI CloseWindowStation(HWINSTA hWinSta)
492 FIXME_(win32)("(0x%08x)\n", hWinSta);
493 return TRUE;
495 BOOL WINAPI CloseDesktop(HDESK hDesk)
497 FIXME_(win32)("(0x%08x)\n", hDesk);
498 return TRUE;
501 /***********************************************************************
502 * SetWindowStationUser (USER32.521)
504 DWORD WINAPI SetWindowStationUser(DWORD x1,DWORD x2) {
505 FIXME_(win32)("(0x%08lx,0x%08lx),stub!\n",x1,x2);
506 return 1;
509 /***********************************************************************
510 * SetLogonNotifyWindow (USER32.486)
512 DWORD WINAPI SetLogonNotifyWindow(HWINSTA hwinsta,HWND hwnd) {
513 FIXME_(win32)("(0x%x,%04x),stub!\n",hwinsta,hwnd);
514 return 1;
517 /***********************************************************************
518 * LoadLocalFonts (USER32.486)
520 VOID WINAPI LoadLocalFonts(VOID) {
521 /* are loaded. */
522 return;
524 /***********************************************************************
525 * GetUserObjectInformation32A (USER32.299)
527 BOOL WINAPI GetUserObjectInformationA( HANDLE hObj, int nIndex, LPVOID pvInfo, DWORD nLength, LPDWORD lpnLen )
528 { FIXME_(win32)("(0x%x %i %p %ld %p),stub!\n", hObj, nIndex, pvInfo, nLength, lpnLen );
529 return TRUE;
531 /***********************************************************************
532 * GetUserObjectInformation32W (USER32.300)
534 BOOL WINAPI GetUserObjectInformationW( HANDLE hObj, int nIndex, LPVOID pvInfo, DWORD nLength, LPDWORD lpnLen )
535 { FIXME_(win32)("(0x%x %i %p %ld %p),stub!\n", hObj, nIndex, pvInfo, nLength, lpnLen );
536 return TRUE;
538 /***********************************************************************
539 * GetUserObjectSecurity32 (USER32.300)
541 BOOL WINAPI GetUserObjectSecurity(HANDLE hObj, SECURITY_INFORMATION * pSIRequested,
542 PSECURITY_DESCRIPTOR pSID, DWORD nLength, LPDWORD lpnLengthNeeded)
543 { FIXME_(win32)("(0x%x %p %p len=%ld %p),stub!\n", hObj, pSIRequested, pSID, nLength, lpnLengthNeeded);
544 return TRUE;
547 /***********************************************************************
548 * SetSystemCursor (USER32.507)
550 BOOL WINAPI SetSystemCursor(HCURSOR hcur, DWORD id)
551 { FIXME_(win32)("(%08x,%08lx),stub!\n", hcur, id);
552 return TRUE;
555 /***********************************************************************
556 * RegisterSystemThread (USER32.435)
558 void WINAPI RegisterSystemThread(DWORD flags, DWORD reserved)
560 FIXME_(win32)("(%08lx, %08lx)\n", flags, reserved);