Release 960506
[wine/multimedia.git] / misc / exec.c
blobad53f6b762105b5f8446c56e820dffd27551fe07
1 /*
2 * Windows Exec & Help
4 */
6 #include <stdlib.h>
7 #include <stdio.h>
8 #include <string.h>
9 #include <unistd.h>
10 #include "neexe.h"
11 #include "shell.h"
12 #include "windows.h"
13 #include "callback.h"
14 #include "stddebug.h"
15 #include "debug.h"
16 #include "win.h"
18 #define HELP_CONTEXT 0x0001
19 #define HELP_QUIT 0x0002
20 #define HELP_INDEX 0x0003
21 #define HELP_CONTENTS 0x0003
22 #define HELP_HELPONHELP 0x0004
23 #define HELP_SETINDEX 0x0005
24 #define HELP_SETCONTENTS 0x0005
25 #define HELP_CONTEXTPOPUP 0x0008
26 #define HELP_FORCEFILE 0x0009
27 #define HELP_KEY 0x0101
28 #define HELP_COMMAND 0x0102
29 #define HELP_PARTIALKEY 0x0105
30 #define HELP_MULTIKEY 0x0201
31 #define HELP_SETWINPOS 0x0203
34 /***********************************************************************
35 * EXEC_ExitWindows
37 * Clean-up everything and exit the Wine process.
38 * This is the back-end of ExitWindows(), called when all windows
39 * have agreed to be terminated.
41 void EXEC_ExitWindows( int retCode )
43 /* Do the clean-up stuff */
45 WriteOutProfiles();
46 SHELL_SaveRegistry();
48 exit( retCode );
52 /***********************************************************************
53 * ExitWindows (USER.7)
55 BOOL ExitWindows( DWORD dwReturnCode, WORD wReserved )
57 HWND hwndDesktop;
58 WND *wndPtr;
59 HWND *list, *pWnd;
60 int count, i;
61 BOOL result;
63 api_assert("ExitWindows", wReserved == 0);
64 api_assert("ExitWindows", HIWORD(dwReturnCode) == 0);
66 /* We have to build a list of all windows first, as in EnumWindows */
68 /* First count the windows */
70 hwndDesktop = GetDesktopWindow();
71 count = 0;
72 for (wndPtr = WIN_GetDesktop()->child; wndPtr; wndPtr = wndPtr->next)
73 count++;
74 if (!count) /* No windows, we can exit at once */
75 EXEC_ExitWindows( LOWORD(dwReturnCode) );
77 /* Now build the list of all windows */
79 if (!(pWnd = list = (HWND *)malloc( sizeof(HWND) * count ))) return FALSE;
80 for (wndPtr = WIN_GetDesktop()->child; wndPtr; wndPtr = wndPtr->next)
81 *pWnd++ = wndPtr->hwndSelf;
83 /* Now send a WM_QUERYENDSESSION message to every window */
85 for (pWnd = list, i = 0; i < count; i++, pWnd++)
87 /* Make sure that window still exists */
88 if (!IsWindow(*pWnd)) continue;
89 if (!SendMessage( *pWnd, WM_QUERYENDSESSION, 0, 0 )) break;
91 result = (i == count);
93 /* Now notify all windows that got a WM_QUERYENDSESSION of the result */
95 for (pWnd = list; i > 0; i--, pWnd++)
97 if (!IsWindow(*pWnd)) continue;
98 SendMessage( *pWnd, WM_ENDSESSION, result, 0 );
100 free( list );
102 if (result) EXEC_ExitWindows( LOWORD(dwReturnCode) );
103 return FALSE;
107 /**********************************************************************
108 * WinHelp [USER.171]
110 BOOL WinHelp(HWND hWnd, LPSTR lpHelpFile, WORD wCommand, DWORD dwData)
112 static WORD WM_WINHELP=0;
113 HWND hDest;
114 char szBuf[20];
115 LPWINHELP lpwh;
116 HANDLE hwh;
117 void *data=0;
118 int size,dsize,nlen;
119 if (wCommand != HELP_QUIT) /* FIXME */
120 if(WinExec("winhelp.exe -x",SW_SHOWNORMAL)<=32)
121 return FALSE;
122 /* FIXME: Should be directed yield, to let winhelp open the window */
123 Yield();
124 if(!WM_WINHELP) {
125 strcpy(szBuf,"WM_WINHELP");
126 WM_WINHELP=RegisterWindowMessage(MAKE_SEGPTR(szBuf));
127 if(!WM_WINHELP)
128 return FALSE;
130 strcpy(szBuf,"MS_WINHELP");
131 hDest = FindWindow(MAKE_SEGPTR(szBuf),0);
132 if(!hDest)
133 return FALSE;
134 switch(wCommand)
136 case HELP_CONTEXT:
137 case HELP_CONTENTS:
138 case HELP_SETCONTENTS:
139 case HELP_CONTEXTPOPUP:
140 case HELP_FORCEFILE:
141 case HELP_HELPONHELP:
142 case HELP_QUIT:
143 dsize=0;
144 break;
145 case HELP_KEY:
146 case HELP_PARTIALKEY:
147 case HELP_COMMAND:
148 data = PTR_SEG_TO_LIN(dwData);
149 dsize = strlen(data)+1;
150 break;
151 case HELP_MULTIKEY:
152 data = PTR_SEG_TO_LIN(dwData);
153 dsize = ((LPMULTIKEYHELP)data) -> mkSize;
154 break;
155 case HELP_SETWINPOS:
156 data = PTR_SEG_TO_LIN(dwData);
157 dsize = ((LPHELPWININFO)data) -> wStructSize;
158 break;
159 default:
160 fprintf(stderr,"Unknown help command %d\n",wCommand);
161 return FALSE;
163 if(lpHelpFile)
164 nlen = strlen(lpHelpFile)+1;
165 else
166 nlen = 0;
167 size = sizeof(WINHELP) + nlen + dsize;
168 hwh = GlobalAlloc16(0,size);
169 lpwh = GlobalLock16(hwh);
170 lpwh->size = size;
171 lpwh->command = wCommand;
172 if(nlen) {
173 lpwh->ofsFilename = sizeof(WINHELP);
174 strcpy(((char*)lpwh) + sizeof(WINHELP),lpHelpFile);
176 if(dsize) {
177 memcpy(((char*)lpwh)+sizeof(WINHELP)+nlen,data,dsize);
178 lpwh->ofsData = sizeof(WINHELP)+nlen;
179 } else
180 lpwh->ofsData = 0;
181 GlobalUnlock16(hwh);
182 return SendMessage(hDest,WM_WINHELP,hWnd,hwh);