msvcrt: Add explicit 32- and 64-bit versions of the utime functions.
[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     char *owner, *org;
63
64     switch (uMsg) {
65
66         case WM_NOTIFY:
67             switch(((LPNMHDR)lParam)->code)
68             {
69             case PSN_APPLY:
70                 /*save registration info to registry */
71                 owner = get_text(hDlg, IDC_ABT_OWNER);
72                 org   = get_text(hDlg, IDC_ABT_ORG);
73
74                 set_reg_key(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion",
75                             "RegisteredOwner", owner ? owner : "");
76                 set_reg_key(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion",
77                             "RegisteredOrganization", org ? org : "");
78                 set_reg_key(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows NT\\CurrentVersion",
79                             "RegisteredOwner", owner ? owner : "");
80                 set_reg_key(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows NT\\CurrentVersion",
81                             "RegisteredOrganization", org ? org : "");
82                 apply();
83
84                 HeapFree(GetProcessHeap(), 0, owner);
85                 HeapFree(GetProcessHeap(), 0, org);
86                 break;
87             }
88             break;
89
90         case WM_INITDIALOG:
91             /* read owner and organization info from registry, load it into text box */
92             owner = get_reg_key(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows NT\\CurrentVersion",
93                                 "RegisteredOwner", "");
94             org =   get_reg_key(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows NT\\CurrentVersion",
95                                 "RegisteredOrganization", "");
96
97             SetDlgItemText(hDlg, IDC_ABT_OWNER, owner);
98             SetDlgItemText(hDlg, IDC_ABT_ORG, org);
99
100             SendMessage(GetParent(hDlg), PSM_UNCHANGED, 0, 0);
101
102             HeapFree(GetProcessHeap(), 0, owner);
103             HeapFree(GetProcessHeap(), 0, org);
104             break;
105
106         case WM_COMMAND:
107             switch(HIWORD(wParam))
108             {
109             case EN_CHANGE:
110                 /* enable apply button */
111                 SendMessage(GetParent(hDlg), PSM_CHANGED, 0, 0);
112                 break;
113             }
114             break;
115     }
116     return FALSE;
117 }
118
119 #define NUM_PROPERTY_PAGES 7
120
121 static INT_PTR
122 doPropertySheet (HINSTANCE hInstance, HWND hOwner)
123 {
124     PROPSHEETPAGEW psp[NUM_PROPERTY_PAGES];
125     PROPSHEETHEADERW psh;
126     int pg = 0; /* start with page 0 */
127
128     /*
129      * Fill out the (Applications) PROPSHEETPAGE data structure 
130      * for the property sheet
131      */
132     psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
133     psp[pg].dwFlags = PSP_USETITLE;
134     psp[pg].hInstance = hInstance;
135     psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_APPCFG);
136     psp[pg].u2.pszIcon = NULL;
137     psp[pg].pfnDlgProc = AppDlgProc;
138     psp[pg].pszTitle = load_string (IDS_TAB_APPLICATIONS);
139     psp[pg].lParam = 0;
140     pg++;
141
142     /*
143      * Fill out the (Libraries) PROPSHEETPAGE data structure 
144      * for the property sheet
145      */
146     psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
147     psp[pg].dwFlags = PSP_USETITLE;
148     psp[pg].hInstance = hInstance;
149     psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_DLLCFG);
150     psp[pg].u2.pszIcon = NULL;
151     psp[pg].pfnDlgProc = LibrariesDlgProc;
152     psp[pg].pszTitle = load_string (IDS_TAB_DLLS);
153     psp[pg].lParam = 0;
154     pg++;
155     
156     /*
157      * Fill out the (X11Drv) PROPSHEETPAGE data structure 
158      * for the property sheet
159      */
160     psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
161     psp[pg].dwFlags = PSP_USETITLE;
162     psp[pg].hInstance = hInstance;
163     psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_GRAPHCFG);
164     psp[pg].u2.pszIcon = NULL;
165     psp[pg].pfnDlgProc = GraphDlgProc;
166     psp[pg].pszTitle =  load_string (IDS_TAB_GRAPHICS);
167     psp[pg].lParam = 0;
168     pg++;
169
170     psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
171     psp[pg].dwFlags = PSP_USETITLE;
172     psp[pg].hInstance = hInstance;
173     psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_DESKTOP_INTEGRATION);
174     psp[pg].u2.pszIcon = NULL;
175     psp[pg].pfnDlgProc = ThemeDlgProc;
176     psp[pg].pszTitle =  load_string (IDS_TAB_DESKTOP_INTEGRATION);
177     psp[pg].lParam = 0;
178     pg++;
179
180     psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
181     psp[pg].dwFlags = PSP_USETITLE;
182     psp[pg].hInstance = hInstance;
183     psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_DRIVECFG);
184     psp[pg].u2.pszIcon = NULL;
185     psp[pg].pfnDlgProc = DriveDlgProc;
186     psp[pg].pszTitle =  load_string (IDS_TAB_DRIVES);
187     psp[pg].lParam = 0;
188     pg++;
189
190     psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
191     psp[pg].dwFlags = PSP_USETITLE;
192     psp[pg].hInstance = hInstance;
193     psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_AUDIOCFG);
194     psp[pg].u2.pszIcon = NULL;
195     psp[pg].pfnDlgProc = AudioDlgProc;
196     psp[pg].pszTitle =  load_string (IDS_TAB_AUDIO);
197     psp[pg].lParam = 0;
198     pg++;
199
200     /*
201      * Fill out the (General) PROPSHEETPAGE data structure 
202      * for the property sheet
203      */
204     psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
205     psp[pg].dwFlags = PSP_USETITLE;
206     psp[pg].hInstance = hInstance;
207     psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_ABOUTCFG);
208     psp[pg].u2.pszIcon = NULL;
209     psp[pg].pfnDlgProc = AboutDlgProc;
210     psp[pg].pszTitle =  load_string (IDS_TAB_ABOUT);
211     psp[pg].lParam = 0;
212     pg++;
213
214     /*
215      * Fill out the PROPSHEETHEADER
216      */
217     psh.dwSize = sizeof (PROPSHEETHEADERW);
218     psh.dwFlags = PSH_PROPSHEETPAGE | PSH_USEICONID | PSH_USECALLBACK;
219     psh.hwndParent = hOwner;
220     psh.hInstance = hInstance;
221     psh.u.pszIcon = NULL;
222     psh.pszCaption =  load_string (IDS_WINECFG_TITLE);
223     psh.nPages = NUM_PROPERTY_PAGES;
224     psh.u3.ppsp = psp;
225     psh.pfnCallback = PropSheetCallback;
226     psh.u2.nStartPage = 0;
227
228     /*
229      * Display the modal property sheet
230      */
231     return PropertySheetW (&psh);
232 }
233
234 /******************************************************************************
235  * Name       : ProcessCmdLine
236  * Description: Checks command line parameters for 'autodetect drives' option
237  * Parameters : lpCmdLine - the command line
238  * Returns    : TRUE - if '/D' was found. Drive autodetection was carried out.
239  *              FALSE - no '/D' option found in command line
240  * Notes      : This is a very simple implementation, which only works 
241  *              correctly if the one and only cmd line option is '/D' or
242  *              no option at all. Has to be reworked, if more options are to
243  *              be supported.
244  */
245 static BOOL
246 ProcessCmdLine(LPSTR lpCmdLine)
247 {
248     if ((lpCmdLine[0] == '/' || lpCmdLine[0] == '-') && 
249         (lpCmdLine[1] == 'D' || lpCmdLine[1] == 'd')) 
250     {
251         gui_mode = FALSE;
252         if (autodetect_drives()) {
253             apply_drive_changes();
254         }
255         return TRUE;
256     }
257
258     return FALSE;
259 }
260
261 /*****************************************************************************
262  * Name       : WinMain
263  * Description: Main windows entry point
264  * Parameters : hInstance
265  *              hPrev
266  *              szCmdLine
267  *              nShow
268  * Returns    : Program exit code
269  */
270 int WINAPI
271 WinMain (HINSTANCE hInstance, HINSTANCE hPrev, LPSTR szCmdLine, int nShow)
272 {
273     if (ProcessCmdLine(szCmdLine)) {
274         return 0;
275     }
276
277     if (initialize(hInstance) != 0) {
278         WINE_ERR("initialization failed, aborting\n");
279         ExitProcess(1);
280     }
281     
282     /*
283      * The next 9 lines should be all that is needed
284      * for the Wine Configuration property sheet
285      */
286     InitCommonControls ();
287     CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
288     if (doPropertySheet (hInstance, NULL) > 0) {
289         WINE_TRACE("OK\n");
290     } else {
291         WINE_TRACE("Cancel\n");
292     }
293     CoUninitialize(); 
294     ExitProcess (0);
295
296     return 0;
297 }