shell32/tests: Add tests for FolderItems_Item and FolderItems_get_Count.
[wine.git] / programs / winecfg / main.c
blobb8a85fe71753e36e1bc11a18ef354dcc3c89b38b
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 for 'autodetect drives' option
179 * Parameters : lpCmdLine - the command line
180 * Returns : TRUE - if '/D' was found. Drive autodetection was carried out.
181 * FALSE - no '/D' option found in command line
182 * Notes : This is a very simple implementation, which only works
183 * correctly if the one and only cmd line option is '/D' or
184 * no option at all. Has to be reworked, if more options are to
185 * be supported.
187 static BOOL
188 ProcessCmdLine(LPSTR lpCmdLine)
190 if ((lpCmdLine[0] == '/' || lpCmdLine[0] == '-') &&
191 (lpCmdLine[1] == 'D' || lpCmdLine[1] == 'd'))
193 gui_mode = FALSE;
194 if (autodetect_drives()) {
195 apply_drive_changes();
197 return TRUE;
200 return FALSE;
203 /*****************************************************************************
204 * Name : WinMain
205 * Description: Main windows entry point
206 * Parameters : hInstance
207 * hPrev
208 * szCmdLine
209 * nShow
210 * Returns : Program exit code
212 int WINAPI
213 WinMain (HINSTANCE hInstance, HINSTANCE hPrev, LPSTR szCmdLine, int nShow)
215 BOOL is_wow64;
217 if (IsWow64Process( GetCurrentProcess(), &is_wow64 ) && is_wow64)
219 STARTUPINFOW si;
220 PROCESS_INFORMATION pi;
221 WCHAR filename[MAX_PATH];
222 void *redir;
223 DWORD exit_code;
225 memset( &si, 0, sizeof(si) );
226 si.cb = sizeof(si);
227 GetModuleFileNameW( 0, filename, MAX_PATH );
229 Wow64DisableWow64FsRedirection( &redir );
230 if (CreateProcessW( filename, GetCommandLineW(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi ))
232 WINE_TRACE( "restarting %s\n", wine_dbgstr_w(filename) );
233 WaitForSingleObject( pi.hProcess, INFINITE );
234 GetExitCodeProcess( pi.hProcess, &exit_code );
235 ExitProcess( exit_code );
237 else WINE_ERR( "failed to restart 64-bit %s, err %d\n", wine_dbgstr_w(filename), GetLastError() );
238 Wow64RevertWow64FsRedirection( redir );
241 if (ProcessCmdLine(szCmdLine)) {
242 return 0;
245 if (initialize(hInstance)) {
246 WINE_ERR("initialization failed, aborting\n");
247 ExitProcess(1);
251 * The next 9 lines should be all that is needed
252 * for the Wine Configuration property sheet
254 InitCommonControls ();
255 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
256 if (doPropertySheet (hInstance, NULL) > 0) {
257 WINE_TRACE("OK\n");
258 } else {
259 WINE_TRACE("Cancel\n");
261 CoUninitialize();
262 ExitProcess (0);
264 return 0;