explorer.exe: Create the top-level message window along with the desktop window.
[wine] / programs / winecfg / main.c
1 /*
2  * WineCfg main entry point
3  *
4  * Copyright 2002 Jaco Greeff
5  * Copyright 2003 Dimitrie O. Paun
6  * Copyright 2003 Mike Hearn
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21  *
22  */
23
24 #define WIN32_LEAN_AND_MEAN
25
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
28
29 #include <windows.h>
30 #include <commctrl.h>
31 #include <objbase.h>
32 #include <wine/debug.h>
33
34 #include "resource.h"
35 #include "winecfg.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
38
39 static INT CALLBACK
40 PropSheetCallback (HWND hWnd, UINT uMsg, LPARAM lParam)
41 {
42     switch (uMsg)
43     {
44         /*
45          * hWnd = NULL, lParam == dialog resource
46          */
47     case PSCB_PRECREATE:
48         break;
49
50     case PSCB_INITIALIZED:
51         break;
52
53     default:
54         break;
55     }
56     return 0;
57 }
58
59 static INT_PTR CALLBACK
60 AboutDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
61 {
62     switch (uMsg) {
63
64         case WM_NOTIFY:
65             if (((LPNMHDR)lParam)->code != PSN_SETACTIVE) break;
66             /* otherwise fall through, we want to refresh the page as well */
67         case WM_INITDIALOG:
68             break;
69
70         case WM_COMMAND:
71             break;
72             
73         default:
74             break;
75             
76     }
77     return FALSE;
78 }
79
80 #define NUM_PROPERTY_PAGES 7
81
82 static INT_PTR
83 doPropertySheet (HINSTANCE hInstance, HWND hOwner)
84 {
85     PROPSHEETPAGEW psp[NUM_PROPERTY_PAGES];
86     PROPSHEETHEADERW psh;
87     int pg = 0; /* start with page 0 */
88
89     /*
90      * Fill out the (Applications) PROPSHEETPAGE data structure 
91      * for the property sheet
92      */
93     psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
94     psp[pg].dwFlags = PSP_USETITLE;
95     psp[pg].hInstance = hInstance;
96     psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_APPCFG);
97     psp[pg].u2.pszIcon = NULL;
98     psp[pg].pfnDlgProc = AppDlgProc;
99     psp[pg].pszTitle = load_string (IDS_TAB_APPLICATIONS);
100     psp[pg].lParam = 0;
101     pg++;
102
103     /*
104      * Fill out the (Libraries) PROPSHEETPAGE data structure 
105      * for the property sheet
106      */
107     psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
108     psp[pg].dwFlags = PSP_USETITLE;
109     psp[pg].hInstance = hInstance;
110     psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_DLLCFG);
111     psp[pg].u2.pszIcon = NULL;
112     psp[pg].pfnDlgProc = LibrariesDlgProc;
113     psp[pg].pszTitle = load_string (IDS_TAB_DLLS);
114     psp[pg].lParam = 0;
115     pg++;
116     
117     /*
118      * Fill out the (X11Drv) PROPSHEETPAGE data structure 
119      * for the property sheet
120      */
121     psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
122     psp[pg].dwFlags = PSP_USETITLE;
123     psp[pg].hInstance = hInstance;
124     psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_GRAPHCFG);
125     psp[pg].u2.pszIcon = NULL;
126     psp[pg].pfnDlgProc = GraphDlgProc;
127     psp[pg].pszTitle =  load_string (IDS_TAB_GRAPHICS);
128     psp[pg].lParam = 0;
129     pg++;
130
131     psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
132     psp[pg].dwFlags = PSP_USETITLE;
133     psp[pg].hInstance = hInstance;
134     psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_DESKTOP_INTEGRATION);
135     psp[pg].u2.pszIcon = NULL;
136     psp[pg].pfnDlgProc = ThemeDlgProc;
137     psp[pg].pszTitle =  load_string (IDS_TAB_DESKTOP_INTEGRATION);
138     psp[pg].lParam = 0;
139     pg++;
140
141     psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
142     psp[pg].dwFlags = PSP_USETITLE;
143     psp[pg].hInstance = hInstance;
144     psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_DRIVECFG);
145     psp[pg].u2.pszIcon = NULL;
146     psp[pg].pfnDlgProc = DriveDlgProc;
147     psp[pg].pszTitle =  load_string (IDS_TAB_DRIVES);
148     psp[pg].lParam = 0;
149     pg++;
150
151     psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
152     psp[pg].dwFlags = PSP_USETITLE;
153     psp[pg].hInstance = hInstance;
154     psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_AUDIOCFG);
155     psp[pg].u2.pszIcon = NULL;
156     psp[pg].pfnDlgProc = AudioDlgProc;
157     psp[pg].pszTitle =  load_string (IDS_TAB_AUDIO);
158     psp[pg].lParam = 0;
159     pg++;
160
161     /*
162      * Fill out the (General) PROPSHEETPAGE data structure 
163      * for the property sheet
164      */
165     psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
166     psp[pg].dwFlags = PSP_USETITLE;
167     psp[pg].hInstance = hInstance;
168     psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_ABOUTCFG);
169     psp[pg].u2.pszIcon = NULL;
170     psp[pg].pfnDlgProc = AboutDlgProc;
171     psp[pg].pszTitle =  load_string (IDS_TAB_ABOUT);
172     psp[pg].lParam = 0;
173     pg++;
174
175     /*
176      * Fill out the PROPSHEETHEADER
177      */
178     psh.dwSize = sizeof (PROPSHEETHEADERW);
179     psh.dwFlags = PSH_PROPSHEETPAGE | PSH_USEICONID | PSH_USECALLBACK;
180     psh.hwndParent = hOwner;
181     psh.hInstance = hInstance;
182     psh.u.pszIcon = NULL;
183     psh.pszCaption =  load_string (IDS_WINECFG_TITLE);
184     psh.nPages = NUM_PROPERTY_PAGES;
185     psh.u3.ppsp = psp;
186     psh.pfnCallback = PropSheetCallback;
187     psh.u2.nStartPage = 0;
188
189     /*
190      * Display the modal property sheet
191      */
192     return PropertySheetW (&psh);
193 }
194
195 /******************************************************************************
196  * Name       : ProcessCmdLine
197  * Description: Checks command line parameters for 'autodetect drives' option
198  * Parameters : lpCmdLine - the command line
199  * Returns    : TRUE - if '/D' was found. Drive autodetection was carried out.
200  *              FALSE - no '/D' option found in command line
201  * Notes      : This is a very simple implementation, which only works 
202  *              correctly if the one and only cmd line option is '/D' or
203  *              no option at all. Has to be reworked, if more options are to
204  *              be supported.
205  */
206 static BOOL
207 ProcessCmdLine(LPSTR lpCmdLine)
208 {
209     if ((lpCmdLine[0] == '/' || lpCmdLine[0] == '-') && 
210         (lpCmdLine[1] == 'D' || lpCmdLine[1] == 'd')) 
211     {
212         gui_mode = FALSE;
213         if (autodetect_drives()) {
214             apply_drive_changes();
215         }
216         return TRUE;
217     }
218
219     return FALSE;
220 }
221
222 /*****************************************************************************
223  * Name       : WinMain
224  * Description: Main windows entry point
225  * Parameters : hInstance
226  *              hPrev
227  *              szCmdLine
228  *              nShow
229  * Returns    : Program exit code
230  */
231 int WINAPI
232 WinMain (HINSTANCE hInstance, HINSTANCE hPrev, LPSTR szCmdLine, int nShow)
233 {
234     if (ProcessCmdLine(szCmdLine)) {
235         return 0;
236     }
237
238     if (initialize(hInstance) != 0) {
239         WINE_ERR("initialization failed, aborting\n");
240         ExitProcess(1);
241     }
242     
243     /*
244      * The next 9 lines should be all that is needed
245      * for the Wine Configuration property sheet
246      */
247     InitCommonControls ();
248     CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
249     if (doPropertySheet (hInstance, NULL) > 0) {
250         WINE_TRACE("OK\n");
251     } else {
252         WINE_TRACE("Cancel\n");
253     }
254     CoUninitialize(); 
255     ExitProcess (0);
256
257     return 0;
258 }