query: Add a stub implementation for LocateCatalogs.
[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 "properties.h"
35 #include "resource.h"
36 #include "winecfg.h"
37
38 WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
39
40 static INT CALLBACK
41 PropSheetCallback (HWND hWnd, UINT uMsg, LPARAM lParam)
42 {
43     switch (uMsg)
44     {
45         /*
46          * hWnd = NULL, lParam == dialog resource
47          */
48     case PSCB_PRECREATE:
49         break;
50
51     case PSCB_INITIALIZED:
52         break;
53
54     default:
55         break;
56     }
57     return 0;
58 }
59
60 static INT_PTR CALLBACK
61 AboutDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
62 {
63     switch (uMsg) {
64
65         case WM_NOTIFY:
66             if (((LPNMHDR)lParam)->code != PSN_SETACTIVE) break;
67             /* otherwise fall through, we want to refresh the page as well */
68         case WM_INITDIALOG:
69             break;
70
71         case WM_COMMAND:
72             break;
73             
74         default:
75             break;
76             
77     }
78     return FALSE;
79 }
80
81 static WCHAR* load_string (UINT id)
82 {
83     WCHAR buf[100];
84     int len;
85     WCHAR* newStr;
86
87     LoadStringW (GetModuleHandle (NULL), id, buf, sizeof(buf)/sizeof(buf[0]));
88
89     len = lstrlenW (buf);
90     newStr = HeapAlloc (GetProcessHeap(), 0, (len + 1) * sizeof (WCHAR));
91     memcpy (newStr, buf, len * sizeof (WCHAR));
92     newStr[len] = 0;
93     return newStr;
94 }
95
96 #define NUM_PROPERTY_PAGES 7
97
98 static INT_PTR
99 doPropertySheet (HINSTANCE hInstance, HWND hOwner)
100 {
101     PROPSHEETPAGEW psp[NUM_PROPERTY_PAGES];
102     PROPSHEETHEADERW psh;
103     int pg = 0; /* start with page 0 */
104
105     /*
106      * Fill out the (Applications) PROPSHEETPAGE data structure 
107      * for the property sheet
108      */
109     psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
110     psp[pg].dwFlags = PSP_USETITLE;
111     psp[pg].hInstance = hInstance;
112     psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_APPCFG);
113     psp[pg].u2.pszIcon = NULL;
114     psp[pg].pfnDlgProc = AppDlgProc;
115     psp[pg].pszTitle = load_string (IDS_TAB_APPLICATIONS);
116     psp[pg].lParam = 0;
117     pg++;
118
119     /*
120      * Fill out the (Libraries) PROPSHEETPAGE data structure 
121      * for the property sheet
122      */
123     psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
124     psp[pg].dwFlags = PSP_USETITLE;
125     psp[pg].hInstance = hInstance;
126     psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_DLLCFG);
127     psp[pg].u2.pszIcon = NULL;
128     psp[pg].pfnDlgProc = LibrariesDlgProc;
129     psp[pg].pszTitle = load_string (IDS_TAB_DLLS);
130     psp[pg].lParam = 0;
131     pg++;
132     
133     /*
134      * Fill out the (X11Drv) PROPSHEETPAGE data structure 
135      * for the property sheet
136      */
137     psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
138     psp[pg].dwFlags = PSP_USETITLE;
139     psp[pg].hInstance = hInstance;
140     psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_GRAPHCFG);
141     psp[pg].u2.pszIcon = NULL;
142     psp[pg].pfnDlgProc = GraphDlgProc;
143     psp[pg].pszTitle =  load_string (IDS_TAB_GRAPHICS);
144     psp[pg].lParam = 0;
145     pg++;
146
147     psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
148     psp[pg].dwFlags = PSP_USETITLE;
149     psp[pg].hInstance = hInstance;
150     psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_DESKTOP_INTEGRATION);
151     psp[pg].u2.pszIcon = NULL;
152     psp[pg].pfnDlgProc = ThemeDlgProc;
153     psp[pg].pszTitle =  load_string (IDS_TAB_DESKTOP_INTEGRATION);
154     psp[pg].lParam = 0;
155     pg++;
156
157     psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
158     psp[pg].dwFlags = PSP_USETITLE;
159     psp[pg].hInstance = hInstance;
160     psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_DRIVECFG);
161     psp[pg].u2.pszIcon = NULL;
162     psp[pg].pfnDlgProc = DriveDlgProc;
163     psp[pg].pszTitle =  load_string (IDS_TAB_DRIVES);
164     psp[pg].lParam = 0;
165     pg++;
166
167     psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
168     psp[pg].dwFlags = PSP_USETITLE;
169     psp[pg].hInstance = hInstance;
170     psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_AUDIOCFG);
171     psp[pg].u2.pszIcon = NULL;
172     psp[pg].pfnDlgProc = AudioDlgProc;
173     psp[pg].pszTitle =  load_string (IDS_TAB_AUDIO);
174     psp[pg].lParam = 0;
175     pg++;
176
177     /*
178      * Fill out the (General) PROPSHEETPAGE data structure 
179      * for the property sheet
180      */
181     psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
182     psp[pg].dwFlags = PSP_USETITLE;
183     psp[pg].hInstance = hInstance;
184     psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_ABOUTCFG);
185     psp[pg].u2.pszIcon = NULL;
186     psp[pg].pfnDlgProc = AboutDlgProc;
187     psp[pg].pszTitle =  load_string (IDS_TAB_ABOUT);
188     psp[pg].lParam = 0;
189     pg++;
190
191     /*
192      * Fill out the PROPSHEETHEADER
193      */
194     psh.dwSize = sizeof (PROPSHEETHEADERW);
195     psh.dwFlags = PSH_PROPSHEETPAGE | PSH_USEICONID | PSH_USECALLBACK;
196     psh.hwndParent = hOwner;
197     psh.hInstance = hInstance;
198     psh.u.pszIcon = NULL;
199     psh.pszCaption =  load_string (IDS_WINECFG_TITLE);
200     psh.nPages = NUM_PROPERTY_PAGES;
201     psh.u3.ppsp = psp;
202     psh.pfnCallback = PropSheetCallback;
203     psh.u2.nStartPage = 0;
204
205     /*
206      * Display the modal property sheet
207      */
208     return PropertySheetW (&psh);
209 }
210
211 /******************************************************************************
212  * Name       : ProcessCmdLine
213  * Description: Checks command line parameters for 'autodetect drives' option
214  * Parameters : lpCmdLine - the command line
215  * Returns    : TRUE - if '/D' was found. Drive autodetection was carried out.
216  *              FALSE - no '/D' option found in command line
217  * Notes      : This is a very simple implementation, which only works 
218  *              correctly if the one and only cmd line option is '/D' or
219  *              no option at all. Has to be reworked, if more options are to
220  *              be supported.
221  */
222 static BOOL
223 ProcessCmdLine(LPSTR lpCmdLine)
224 {
225     if ((lpCmdLine[0] == '/' || lpCmdLine[0] == '-') && 
226         (lpCmdLine[1] == 'D' || lpCmdLine[1] == 'd')) 
227     {
228         gui_mode = FALSE;
229         if (autodetect_drives()) {
230             apply_drive_changes();
231         }
232         return TRUE;
233     }
234
235     return FALSE;
236 }
237
238 /*****************************************************************************
239  * Name       : WinMain
240  * Description: Main windows entry point
241  * Parameters : hInstance
242  *              hPrev
243  *              szCmdLine
244  *              nShow
245  * Returns    : Program exit code
246  */
247 int WINAPI
248 WinMain (HINSTANCE hInstance, HINSTANCE hPrev, LPSTR szCmdLine, int nShow)
249 {
250     if (ProcessCmdLine(szCmdLine)) {
251         return 0;
252     }
253
254     if (initialize(hInstance) != 0) {
255         WINE_ERR("initialization failed, aborting\n");
256         ExitProcess(1);
257     }
258     
259     /*
260      * The next 9 lines should be all that is needed
261      * for the Wine Configuration property sheet
262      */
263     InitCommonControls ();
264     CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
265     if (doPropertySheet (hInstance, NULL) > 0) {
266         WINE_TRACE("OK\n");
267     } else {
268         WINE_TRACE("Cancel\n");
269     }
270     CoUninitialize(); 
271     ExitProcess (0);
272
273     return 0;
274 }