msvcrt: Forward functions to ntdll instead of libc where possible.
[wine/multimedia.git] / programs / winecfg / main.c
bloba49d9395c1be089c0697563e37fdf16aab0daf0b
1 /*
2 * WineCfg main entry point
4 * Copyright 2002 Jaco Greeff
5 * Copyright 2003 Dimitrie O. Paun
6 * Copyright 2003 Mike Hearn
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "config.h"
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <stdarg.h>
29 #ifdef HAVE_UNISTD_H
30 #include <unistd.h>
31 #endif
33 #define NONAMELESSUNION
34 #define NONAMELESSSTRUCT
36 #include <windef.h>
37 #include <winbase.h>
38 #include <winuser.h>
39 #include <commctrl.h>
40 #include <objbase.h>
41 #include <wine/debug.h>
43 #include "properties.h"
44 #include "resource.h"
45 #include "winecfg.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
49 static void CALLBACK
50 PropSheetCallback (HWND hWnd, UINT uMsg, LPARAM lParam)
52 switch (uMsg)
55 * hWnd = NULL, lParam == dialog resource
57 case PSCB_PRECREATE:
58 break;
60 case PSCB_INITIALIZED:
61 break;
63 default:
64 break;
68 static INT_PTR CALLBACK
69 AboutDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
71 switch (uMsg) {
73 case WM_NOTIFY:
74 if (((LPNMHDR)lParam)->code != PSN_SETACTIVE) break;
75 /* otherwise fall through, we want to refresh the page as well */
76 case WM_INITDIALOG:
77 break;
79 case WM_COMMAND:
80 break;
82 default:
83 break;
86 return FALSE;
89 static WCHAR* load_string (UINT id)
91 WCHAR buf[100];
92 int len;
93 WCHAR* newStr;
95 LoadStringW (GetModuleHandle (NULL), id, buf, sizeof(buf)/sizeof(buf[0]));
97 len = lstrlenW (buf);
98 newStr = HeapAlloc (GetProcessHeap(), 0, (len + 1) * sizeof (WCHAR));
99 memcpy (newStr, buf, len * sizeof (WCHAR));
100 newStr[len] = 0;
101 return newStr;
104 #define NUM_PROPERTY_PAGES 7
106 static INT_PTR
107 doPropertySheet (HINSTANCE hInstance, HWND hOwner)
109 PROPSHEETPAGEW psp[NUM_PROPERTY_PAGES];
110 PROPSHEETHEADERW psh;
111 int pg = 0; /* start with page 0 */
114 * Fill out the (Applications) PROPSHEETPAGE data structure
115 * for the property sheet
117 psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
118 psp[pg].dwFlags = PSP_USETITLE;
119 psp[pg].hInstance = hInstance;
120 psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_APPCFG);
121 psp[pg].u2.pszIcon = NULL;
122 psp[pg].pfnDlgProc = AppDlgProc;
123 psp[pg].pszTitle = load_string (IDS_TAB_APPLICATIONS);
124 psp[pg].lParam = 0;
125 pg++;
128 * Fill out the (Libraries) PROPSHEETPAGE data structure
129 * for the property sheet
131 psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
132 psp[pg].dwFlags = PSP_USETITLE;
133 psp[pg].hInstance = hInstance;
134 psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_DLLCFG);
135 psp[pg].u2.pszIcon = NULL;
136 psp[pg].pfnDlgProc = LibrariesDlgProc;
137 psp[pg].pszTitle = load_string (IDS_TAB_DLLS);
138 psp[pg].lParam = 0;
139 pg++;
142 * Fill out the (X11Drv) PROPSHEETPAGE data structure
143 * for the property sheet
145 psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
146 psp[pg].dwFlags = PSP_USETITLE;
147 psp[pg].hInstance = hInstance;
148 psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_GRAPHCFG);
149 psp[pg].u2.pszIcon = NULL;
150 psp[pg].pfnDlgProc = GraphDlgProc;
151 psp[pg].pszTitle = load_string (IDS_TAB_GRAPHICS);
152 psp[pg].lParam = 0;
153 pg++;
155 psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
156 psp[pg].dwFlags = PSP_USETITLE;
157 psp[pg].hInstance = hInstance;
158 psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_APPEARANCE);
159 psp[pg].u2.pszIcon = NULL;
160 psp[pg].pfnDlgProc = ThemeDlgProc;
161 psp[pg].pszTitle = load_string (IDS_TAB_APPEARANCE);
162 psp[pg].lParam = 0;
163 pg++;
165 psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
166 psp[pg].dwFlags = PSP_USETITLE;
167 psp[pg].hInstance = hInstance;
168 psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_DRIVECFG);
169 psp[pg].u2.pszIcon = NULL;
170 psp[pg].pfnDlgProc = DriveDlgProc;
171 psp[pg].pszTitle = load_string (IDS_TAB_DRIVES);
172 psp[pg].lParam = 0;
173 pg++;
175 psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
176 psp[pg].dwFlags = PSP_USETITLE;
177 psp[pg].hInstance = hInstance;
178 psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_AUDIOCFG);
179 psp[pg].u2.pszIcon = NULL;
180 psp[pg].pfnDlgProc = AudioDlgProc;
181 psp[pg].pszTitle = load_string (IDS_TAB_AUDIO);
182 psp[pg].lParam = 0;
183 pg++;
186 * Fill out the (General) PROPSHEETPAGE data structure
187 * for the property sheet
189 psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
190 psp[pg].dwFlags = PSP_USETITLE;
191 psp[pg].hInstance = hInstance;
192 psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_ABOUTCFG);
193 psp[pg].u2.pszIcon = NULL;
194 psp[pg].pfnDlgProc = AboutDlgProc;
195 psp[pg].pszTitle = load_string (IDS_TAB_ABOUT);
196 psp[pg].lParam = 0;
197 pg++;
200 * Fill out the PROPSHEETHEADER
202 psh.dwSize = sizeof (PROPSHEETHEADERW);
203 psh.dwFlags = PSH_PROPSHEETPAGE | PSH_USEICONID | PSH_USECALLBACK;
204 psh.hwndParent = hOwner;
205 psh.hInstance = hInstance;
206 psh.u.pszIcon = NULL;
207 psh.pszCaption = load_string (IDS_WINECFG_TITLE);
208 psh.nPages = NUM_PROPERTY_PAGES;
209 psh.u3.ppsp = (LPCPROPSHEETPAGEW) & psp;
210 psh.pfnCallback = (PFNPROPSHEETCALLBACK) PropSheetCallback;
211 psh.u2.nStartPage = 0;
214 * Display the modal property sheet
216 return PropertySheetW (&psh);
219 /******************************************************************************
220 * Name : ProcessCmdLine
221 * Description: Checks command line parameters for 'autodetect drives' option
222 * Parameters : lpCmdLine - the command line
223 * Returns : TRUE - if '/D' was found. Drive autodetection was carried out.
224 * FALSE - no '/D' option found in command line
225 * Notes : This is a very simple implementation, which only works
226 * correctly if the one and only cmd line option is '/D' or
227 * no option at all. Has to be reworked, if more options are to
228 * be supported.
230 static BOOL
231 ProcessCmdLine(LPSTR lpCmdLine)
233 if ((lpCmdLine[0] == '/' || lpCmdLine[0] == '-') &&
234 (lpCmdLine[1] == 'D' || lpCmdLine[1] == 'd'))
236 gui_mode = FALSE;
237 if (autodetect_drives()) {
238 apply_drive_changes();
240 return TRUE;
243 return FALSE;
246 /*****************************************************************************
247 * Name : WinMain
248 * Description: Main windows entry point
249 * Parameters : hInstance
250 * hPrev
251 * szCmdLine
252 * nShow
253 * Returns : Program exit code
255 int WINAPI
256 WinMain (HINSTANCE hInstance, HINSTANCE hPrev, LPSTR szCmdLine, int nShow)
258 if (ProcessCmdLine(szCmdLine)) {
259 return 0;
262 if (initialize(hInstance) != 0) {
263 WINE_ERR("initialization failed, aborting\n");
264 ExitProcess(1);
268 * The next 9 lines should be all that is needed
269 * for the Wine Configuration property sheet
271 InitCommonControls ();
272 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
273 if (doPropertySheet (hInstance, NULL) > 0) {
274 WINE_TRACE("OK\n");
275 } else {
276 WINE_TRACE("Cancel\n");
278 CoUninitialize();
279 ExitProcess (0);
281 return 0;