wldap32/tests: Add ber_printf/scanf tests.
[wine/zf.git] / programs / winecfg / main.c
blob9b30ed6e8e0601a9cdc0c3db3004430c29339695
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define WIN32_LEAN_AND_MEAN
25 #define NONAMELESSUNION
27 #include <windows.h>
28 #include <commctrl.h>
29 #include <objbase.h>
30 #include <wine/debug.h>
32 #include "resource.h"
33 #include "winecfg.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
37 static INT CALLBACK
38 PropSheetCallback (HWND hWnd, UINT uMsg, LPARAM lParam)
40 switch (uMsg)
43 * hWnd = NULL, lParam == dialog resource
45 case PSCB_PRECREATE:
46 break;
48 case PSCB_INITIALIZED:
49 /* Set the window icon */
50 SendMessageW( hWnd, WM_SETICON, ICON_BIG,
51 (LPARAM)LoadIconW( (HINSTANCE)GetWindowLongPtrW(hWnd, GWLP_HINSTANCE),
52 MAKEINTRESOURCEW(IDI_WINECFG) ));
53 break;
55 default:
56 break;
58 return 0;
61 #define NUM_PROPERTY_PAGES 7
63 static INT_PTR
64 doPropertySheet (HINSTANCE hInstance, HWND hOwner)
66 PROPSHEETPAGEW psp[NUM_PROPERTY_PAGES];
67 PROPSHEETHEADERW psh;
68 int pg = 0; /* start with page 0 */
71 * Fill out the (Applications) PROPSHEETPAGE data structure
72 * for the property sheet
74 psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
75 psp[pg].dwFlags = PSP_USETITLE;
76 psp[pg].hInstance = hInstance;
77 psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_APPCFG);
78 psp[pg].u2.pszIcon = NULL;
79 psp[pg].pfnDlgProc = AppDlgProc;
80 psp[pg].pszTitle = load_string (IDS_TAB_APPLICATIONS);
81 psp[pg].lParam = 0;
82 pg++;
85 * Fill out the (Libraries) PROPSHEETPAGE data structure
86 * for the property sheet
88 psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
89 psp[pg].dwFlags = PSP_USETITLE;
90 psp[pg].hInstance = hInstance;
91 psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_DLLCFG);
92 psp[pg].u2.pszIcon = NULL;
93 psp[pg].pfnDlgProc = LibrariesDlgProc;
94 psp[pg].pszTitle = load_string (IDS_TAB_DLLS);
95 psp[pg].lParam = 0;
96 pg++;
99 * Fill out the (X11Drv) PROPSHEETPAGE data structure
100 * for the property sheet
102 psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
103 psp[pg].dwFlags = PSP_USETITLE;
104 psp[pg].hInstance = hInstance;
105 psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_GRAPHCFG);
106 psp[pg].u2.pszIcon = NULL;
107 psp[pg].pfnDlgProc = GraphDlgProc;
108 psp[pg].pszTitle = load_string (IDS_TAB_GRAPHICS);
109 psp[pg].lParam = 0;
110 pg++;
112 psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
113 psp[pg].dwFlags = PSP_USETITLE;
114 psp[pg].hInstance = hInstance;
115 psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_DESKTOP_INTEGRATION);
116 psp[pg].u2.pszIcon = NULL;
117 psp[pg].pfnDlgProc = ThemeDlgProc;
118 psp[pg].pszTitle = load_string (IDS_TAB_DESKTOP_INTEGRATION);
119 psp[pg].lParam = 0;
120 pg++;
122 psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
123 psp[pg].dwFlags = PSP_USETITLE;
124 psp[pg].hInstance = hInstance;
125 psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_DRIVECFG);
126 psp[pg].u2.pszIcon = NULL;
127 psp[pg].pfnDlgProc = DriveDlgProc;
128 psp[pg].pszTitle = load_string (IDS_TAB_DRIVES);
129 psp[pg].lParam = 0;
130 pg++;
132 psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
133 psp[pg].dwFlags = PSP_USETITLE;
134 psp[pg].hInstance = hInstance;
135 psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_AUDIOCFG);
136 psp[pg].u2.pszIcon = NULL;
137 psp[pg].pfnDlgProc = AudioDlgProc;
138 psp[pg].pszTitle = load_string (IDS_TAB_AUDIO);
139 psp[pg].lParam = 0;
140 pg++;
143 * Fill out the (General) PROPSHEETPAGE data structure
144 * for the property sheet
146 psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
147 psp[pg].dwFlags = PSP_USETITLE;
148 psp[pg].hInstance = hInstance;
149 psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_ABOUTCFG);
150 psp[pg].u2.pszIcon = NULL;
151 psp[pg].pfnDlgProc = AboutDlgProc;
152 psp[pg].pszTitle = load_string (IDS_TAB_ABOUT);
153 psp[pg].lParam = 0;
154 pg++;
157 * Fill out the PROPSHEETHEADER
159 psh.dwSize = sizeof (PROPSHEETHEADERW);
160 psh.dwFlags = PSH_PROPSHEETPAGE | PSH_USEICONID | PSH_USECALLBACK;
161 psh.hwndParent = hOwner;
162 psh.hInstance = hInstance;
163 psh.u.pszIcon = MAKEINTRESOURCEW (IDI_WINECFG);
164 psh.pszCaption = load_string (IDS_WINECFG_TITLE);
165 psh.nPages = NUM_PROPERTY_PAGES;
166 psh.u3.ppsp = psp;
167 psh.pfnCallback = PropSheetCallback;
168 psh.u2.nStartPage = 0;
171 * Display the modal property sheet
173 return PropertySheetW (&psh);
176 /******************************************************************************
177 * Name : ProcessCmdLine
178 * Description: Checks command line parameters
179 * Parameters : lpCmdLine - the command line
180 * Returns : The return value to return from WinMain, or -1 to continue
181 * program execution.
183 static int
184 ProcessCmdLine(LPSTR lpCmdLine)
186 if (!(lpCmdLine[0] == '/' || lpCmdLine[0] == '-'))
188 return -1;
190 if (lpCmdLine[1] == 'V' || lpCmdLine[1] == 'v')
192 if (lstrlenA(lpCmdLine) > 4)
193 return set_winver_from_string(&lpCmdLine[3]) ? 0 : 1;
195 print_current_winver();
196 return 0;
199 if (lpCmdLine[1] == '?')
201 printf("Usage: winecfg [options]\n\n");
202 printf("Options:\n");
203 printf(" [no option] Launch the graphical version of this program.\n");
204 printf(" /v Display the current global Windows version.\n");
205 printf(" /v version Set global Windows version to 'version'.\n");
206 printf(" /? Display this information and exit.\n\n");
207 printf("Valid versions for 'version':\n\n");
208 print_windows_versions();
210 return 0;
213 return -1;
216 /*****************************************************************************
217 * Name : WinMain
218 * Description: Main windows entry point
219 * Parameters : hInstance
220 * hPrev
221 * szCmdLine
222 * nShow
223 * Returns : Program exit code
225 int WINAPI
226 WinMain (HINSTANCE hInstance, HINSTANCE hPrev, LPSTR szCmdLine, int nShow)
228 BOOL is_wow64;
229 int cmd_ret;
231 if (IsWow64Process( GetCurrentProcess(), &is_wow64 ) && is_wow64)
233 STARTUPINFOW si;
234 PROCESS_INFORMATION pi;
235 WCHAR filename[MAX_PATH];
236 void *redir;
237 DWORD exit_code;
239 memset( &si, 0, sizeof(si) );
240 si.cb = sizeof(si);
241 GetModuleFileNameW( 0, filename, MAX_PATH );
243 Wow64DisableWow64FsRedirection( &redir );
244 if (CreateProcessW( filename, GetCommandLineW(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi ))
246 WINE_TRACE( "restarting %s\n", wine_dbgstr_w(filename) );
247 WaitForSingleObject( pi.hProcess, INFINITE );
248 GetExitCodeProcess( pi.hProcess, &exit_code );
249 ExitProcess( exit_code );
251 else WINE_ERR( "failed to restart 64-bit %s, err %d\n", wine_dbgstr_w(filename), GetLastError() );
252 Wow64RevertWow64FsRedirection( redir );
255 if (initialize(hInstance)) {
256 WINE_ERR("initialization failed, aborting\n");
257 ExitProcess(1);
260 cmd_ret = ProcessCmdLine(szCmdLine);
261 if (cmd_ret >= 0) return cmd_ret;
264 * The next 9 lines should be all that is needed
265 * for the Wine Configuration property sheet
267 InitCommonControls ();
268 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
269 if (doPropertySheet (hInstance, NULL) > 0) {
270 WINE_TRACE("OK\n");
271 } else {
272 WINE_TRACE("Cancel\n");
274 CoUninitialize();
275 ExitProcess (0);
277 return 0;