Release 970329
[wine/multimedia.git] / misc / exec.c
blobe793f8b4f9dde17714017670b7d432c0861b3c39
1 /*
2 * Windows Exec & Help
3 */
5 #include <stdlib.h>
6 #include <stdio.h>
7 #include <string.h>
8 #include <unistd.h>
9 #include "windows.h"
10 #include "heap.h"
11 #include "neexe.h"
12 #include "shell.h"
13 #include "stddebug.h"
14 #include "debug.h"
15 #include "win.h"
18 /***********************************************************************
19 * EXEC_ExitWindows
21 * Clean-up everything and exit the Wine process.
22 * This is the back-end of ExitWindows(), called when all windows
23 * have agreed to be terminated.
25 void EXEC_ExitWindows(void)
27 /* Do the clean-up stuff */
29 WriteOutProfiles();
30 SHELL_SaveRegistry();
32 exit(0);
36 /***********************************************************************
37 * ExitWindows16 (USER.7)
39 BOOL16 ExitWindows16( DWORD dwReturnCode, UINT16 wReserved )
41 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
45 /***********************************************************************
46 * ExitWindowsEx (USER32.195)
48 BOOL32 ExitWindowsEx( UINT32 flags, DWORD reserved )
50 int i;
51 BOOL32 result;
52 WND **list, **ppWnd;
54 /* We have to build a list of all windows first, as in EnumWindows */
56 if (!(list = WIN_BuildWinArray( WIN_GetDesktop() ))) return FALSE;
58 /* Send a WM_QUERYENDSESSION message to every window */
60 for (ppWnd = list, i = 0; *ppWnd; ppWnd++, i++)
62 /* Make sure that the window still exists */
63 if (!IsWindow32( (*ppWnd)->hwndSelf )) continue;
64 if (!SendMessage16( (*ppWnd)->hwndSelf, WM_QUERYENDSESSION, 0, 0 ))
65 break;
67 result = !(*ppWnd);
69 /* Now notify all windows that got a WM_QUERYENDSESSION of the result */
71 for (ppWnd = list; i > 0; i--, ppWnd++)
73 if (!IsWindow32( (*ppWnd)->hwndSelf )) continue;
74 SendMessage16( (*ppWnd)->hwndSelf, WM_ENDSESSION, result, 0 );
76 HeapFree( SystemHeap, 0, list );
78 if (result) EXEC_ExitWindows();
79 return FALSE;
83 /**********************************************************************
84 * WinHelp16 (USER.171)
86 BOOL16 WinHelp16( HWND16 hWnd, LPCSTR lpHelpFile, UINT16 wCommand,
87 DWORD dwData )
89 return WinHelp32A( hWnd, lpHelpFile, wCommand,
90 (DWORD)PTR_SEG_TO_LIN(dwData) );
94 /**********************************************************************
95 * WinHelp32A (USER32.578)
97 BOOL32 WinHelp32A( HWND32 hWnd, LPCSTR lpHelpFile, UINT32 wCommand,
98 DWORD dwData )
100 static WORD WM_WINHELP=0;
101 HWND32 hDest;
102 LPWINHELP lpwh;
103 HGLOBAL16 hwh;
104 int size,dsize,nlen;
105 if (wCommand != HELP_QUIT) /* FIXME */
106 if(WinExec32("winhelp.exe -x",SW_SHOWNORMAL)<=32)
107 return FALSE;
108 /* FIXME: Should be directed yield, to let winhelp open the window */
109 Yield();
110 if(!WM_WINHELP) {
111 WM_WINHELP=RegisterWindowMessage32A("WM_WINHELP");
112 if(!WM_WINHELP)
113 return FALSE;
115 hDest = FindWindow32A( "MS_WINHELP", NULL );
116 if(!hDest)
117 if(wCommand == HELP_QUIT)
118 return TRUE;
119 else
120 return FALSE;
121 switch(wCommand)
123 case HELP_CONTEXT:
124 case HELP_CONTENTS:
125 case HELP_SETCONTENTS:
126 case HELP_CONTEXTPOPUP:
127 case HELP_FORCEFILE:
128 case HELP_HELPONHELP:
129 case HELP_QUIT:
130 dsize=0;
131 break;
132 case HELP_KEY:
133 case HELP_PARTIALKEY:
134 case HELP_COMMAND:
135 dsize = strlen( (LPSTR)dwData )+1;
136 break;
137 case HELP_MULTIKEY:
138 dsize = ((LPMULTIKEYHELP)dwData)->mkSize;
139 break;
140 case HELP_SETWINPOS:
141 dsize = ((LPHELPWININFO)dwData)->wStructSize;
142 break;
143 default:
144 fprintf(stderr,"Unknown help command %d\n",wCommand);
145 return FALSE;
147 if(lpHelpFile)
148 nlen = strlen(lpHelpFile)+1;
149 else
150 nlen = 0;
151 size = sizeof(WINHELP) + nlen + dsize;
152 hwh = GlobalAlloc16(0,size);
153 lpwh = GlobalLock16(hwh);
154 lpwh->size = size;
155 lpwh->command = wCommand;
156 if(nlen) {
157 lpwh->ofsFilename = sizeof(WINHELP);
158 strcpy(((char*)lpwh) + sizeof(WINHELP),lpHelpFile);
160 if(dsize) {
161 memcpy(((char*)lpwh)+sizeof(WINHELP)+nlen,(LPSTR)dwData,dsize);
162 lpwh->ofsData = sizeof(WINHELP)+nlen;
163 } else
164 lpwh->ofsData = 0;
165 GlobalUnlock16(hwh);
166 return SendMessage16(hDest,WM_WINHELP,hWnd,hwh);
170 /**********************************************************************
171 * WinHelp32W (USER32.579)
173 BOOL32 WinHelp32W( HWND32 hWnd, LPCWSTR helpFile, UINT32 command,
174 DWORD dwData )
176 LPSTR file = HEAP_strdupWtoA( GetProcessHeap(), 0, helpFile );
177 BOOL32 ret = WinHelp32A( hWnd, file, command, dwData );
178 HeapFree( GetProcessHeap(), 0, file );
179 return ret;