Release 960302
[wine] / misc / exec.c
1 /*
2 *     Windows Exec & Help
3 *
4 */
5
6 #include <stdlib.h>
7 #include <stdio.h>
8 #include <string.h>
9 #include <unistd.h>
10 #include "neexe.h"
11 #include "dlls.h"
12 #include "shell.h"
13 #include "windows.h"
14 #include "callback.h"
15 #include "stddebug.h"
16 #include "debug.h"
17 #include "win.h"
18
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
33
34
35 /***********************************************************************
36  *           EXEC_ExitWindows
37  *
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.
41  */
42 void EXEC_ExitWindows( int retCode )
43 {
44     /* Do the clean-up stuff */
45
46     WriteOutProfiles();
47     SHELL_SaveRegistry();
48
49     exit( retCode );
50 }
51
52
53 /***********************************************************************
54  *           ExitWindows   (USER.7)
55  */
56 BOOL ExitWindows( DWORD dwReturnCode, WORD wReserved )
57 {
58     HWND hwnd, hwndDesktop;
59     WND *wndPtr;
60     HWND *list, *pWnd;
61     int count, i;
62     BOOL result;
63         
64     api_assert("ExitWindows", wReserved == 0);
65     api_assert("ExitWindows", HIWORD(dwReturnCode) == 0);
66
67     /* We have to build a list of all windows first, as in EnumWindows */
68
69     /* First count the windows */
70
71     hwndDesktop = GetDesktopWindow();
72     count = 0;
73     for (hwnd = GetTopWindow(hwndDesktop); hwnd != 0; hwnd = wndPtr->hwndNext)
74     {
75         if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return FALSE;
76         count++;
77     }
78     if (!count) /* No windows, we can exit at once */
79         EXEC_ExitWindows( LOWORD(dwReturnCode) );
80
81       /* Now build the list of all windows */
82
83     if (!(list = (HWND *)malloc( sizeof(HWND) * count ))) return FALSE;
84     for (hwnd = GetTopWindow(hwndDesktop), pWnd = list; hwnd != 0; hwnd = wndPtr->hwndNext)
85     {
86         wndPtr = WIN_FindWndPtr( hwnd );
87         *pWnd++ = hwnd;
88     }
89
90       /* Now send a WM_QUERYENDSESSION message to every window */
91
92     for (pWnd = list, i = 0; i < count; i++, pWnd++)
93     {
94           /* Make sure that window still exists */
95         if (!IsWindow(*pWnd)) continue;
96         if (!SendMessage( *pWnd, WM_QUERYENDSESSION, 0, 0 )) break;
97     }
98     result = (i == count);
99
100     /* Now notify all windows that got a WM_QUERYENDSESSION of the result */
101
102     for (pWnd = list; i > 0; i--, pWnd++)
103     {
104         if (!IsWindow(*pWnd)) continue;
105         SendMessage( *pWnd, WM_ENDSESSION, result, 0 );
106     }
107     free( list );
108
109     if (result) EXEC_ExitWindows( LOWORD(dwReturnCode) );
110     return FALSE;
111 }
112
113
114 /**********************************************************************
115  *                              WinHelp         [USER.171]
116  */
117 BOOL WinHelp(HWND hWnd, LPSTR lpHelpFile, WORD wCommand, DWORD dwData)
118 {
119         char    str[256];
120         dprintf_exec(stddeb,"WinHelp(%s, %u, %lu)\n", 
121                 lpHelpFile, wCommand, dwData);
122         switch(wCommand) {
123         case 0:
124         case HELP_HELPONHELP:
125                 GetWindowsDirectory(str, sizeof(str));
126                 strcat(str, "\\winhelp.exe winhelp.hlp");
127         dprintf_exec(stddeb,"'%s'\n", str);
128                 break;
129         case HELP_INDEX:
130                 GetWindowsDirectory(str, sizeof(str));
131                 strcat(str, "\\winhelp.exe ");
132                 strcat(str, lpHelpFile);
133         dprintf_exec(stddeb,"'%s'\n", str);
134                 break;
135         case HELP_QUIT:
136             return TRUE;
137         default:
138                 return FALSE;
139         }
140         WinExec(str, SW_SHOWNORMAL);
141         return(TRUE);
142 }