Release 960712
[wine/multimedia.git] / misc / exec.c
blobfb67a0b5c107d3087b58bf104889995e2307df0f
1 /*
2 * Windows Exec & Help
4 */
6 #include <stdlib.h>
7 #include <stdio.h>
8 #include <string.h>
9 #include <unistd.h>
10 #include "windows.h"
11 #include "heap.h"
12 #include "neexe.h"
13 #include "shell.h"
14 #include "callback.h"
15 #include "stddebug.h"
16 #include "debug.h"
17 #include "win.h"
19 #define HELP_CONTEXT 0x0001
20 #define HELP_QUIT 0x0002
21 #define HELP_INDEX 0x0003
22 #define HELP_CONTENTS 0x0003
23 #define HELP_HELPONHELP 0x0004
24 #define HELP_SETINDEX 0x0005
25 #define HELP_SETCONTENTS 0x0005
26 #define HELP_CONTEXTPOPUP 0x0008
27 #define HELP_FORCEFILE 0x0009
28 #define HELP_KEY 0x0101
29 #define HELP_COMMAND 0x0102
30 #define HELP_PARTIALKEY 0x0105
31 #define HELP_MULTIKEY 0x0201
32 #define HELP_SETWINPOS 0x0203
35 /***********************************************************************
36 * EXEC_ExitWindows
38 * Clean-up everything and exit the Wine process.
39 * This is the back-end of ExitWindows(), called when all windows
40 * have agreed to be terminated.
42 void EXEC_ExitWindows( int retCode )
44 /* Do the clean-up stuff */
46 WriteOutProfiles();
47 SHELL_SaveRegistry();
49 exit( retCode );
53 /***********************************************************************
54 * ExitWindows (USER.7)
56 BOOL ExitWindows( DWORD dwReturnCode, WORD wReserved )
58 int i;
59 BOOL16 result;
60 WND **list, **ppWnd;
62 api_assert("ExitWindows", wReserved == 0);
63 api_assert("ExitWindows", HIWORD(dwReturnCode) == 0);
65 /* We have to build a list of all windows first, as in EnumWindows */
67 if (!(list = WIN_BuildWinArray( WIN_GetDesktop() ))) return FALSE;
69 /* Send a WM_QUERYENDSESSION message to every window */
71 for (ppWnd = list, i = 0; *ppWnd; ppWnd++, i++)
73 /* Make sure that the window still exists */
74 if (!IsWindow( (*ppWnd)->hwndSelf )) continue;
75 if (!SendMessage16( (*ppWnd)->hwndSelf, WM_QUERYENDSESSION, 0, 0 ))
76 break;
78 result = !(*ppWnd);
80 /* Now notify all windows that got a WM_QUERYENDSESSION of the result */
82 for (ppWnd = list; i > 0; i--, ppWnd++)
84 if (!IsWindow( (*ppWnd)->hwndSelf )) continue;
85 SendMessage16( (*ppWnd)->hwndSelf, WM_ENDSESSION, result, 0 );
87 HeapFree( SystemHeap, 0, list );
89 if (result) EXEC_ExitWindows( LOWORD(dwReturnCode) );
90 return FALSE;
94 /**********************************************************************
95 * WinHelp [USER.171]
97 BOOL WinHelp(HWND hWnd, LPSTR lpHelpFile, WORD wCommand, DWORD dwData)
99 static WORD WM_WINHELP=0;
100 HWND hDest;
101 LPWINHELP lpwh;
102 HANDLE hwh;
103 void *data=0;
104 int size,dsize,nlen;
105 if (wCommand != HELP_QUIT) /* FIXME */
106 if(WinExec("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 return FALSE;
118 switch(wCommand)
120 case HELP_CONTEXT:
121 case HELP_CONTENTS:
122 case HELP_SETCONTENTS:
123 case HELP_CONTEXTPOPUP:
124 case HELP_FORCEFILE:
125 case HELP_HELPONHELP:
126 case HELP_QUIT:
127 dsize=0;
128 break;
129 case HELP_KEY:
130 case HELP_PARTIALKEY:
131 case HELP_COMMAND:
132 data = PTR_SEG_TO_LIN(dwData);
133 dsize = strlen(data)+1;
134 break;
135 case HELP_MULTIKEY:
136 data = PTR_SEG_TO_LIN(dwData);
137 dsize = ((LPMULTIKEYHELP)data) -> mkSize;
138 break;
139 case HELP_SETWINPOS:
140 data = PTR_SEG_TO_LIN(dwData);
141 dsize = ((LPHELPWININFO)data) -> 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,data,dsize);
162 lpwh->ofsData = sizeof(WINHELP)+nlen;
163 } else
164 lpwh->ofsData = 0;
165 GlobalUnlock16(hwh);
166 return SendMessage16(hDest,WM_WINHELP,hWnd,hwh);