main.c 7.78 KB
Newer Older
1 2 3 4 5
/*
 * WineCfg main entry point
 *
 * Copyright 2002 Jaco Greeff
 * Copyright 2003 Dimitrie O. Paun
6
 * Copyright 2003 Mike Hearn
7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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
#include <windows.h>
28
#include <commctrl.h>
29
#include <objbase.h>
30 31
#include <wine/debug.h>

32 33 34
#include "resource.h"
#include "winecfg.h"

35 36
WINE_DEFAULT_DEBUG_CHANNEL(winecfg);

37
static INT CALLBACK
38 39 40 41 42 43 44 45 46 47 48
PropSheetCallback (HWND hWnd, UINT uMsg, LPARAM lParam)
{
    switch (uMsg)
    {
	/*
	 * hWnd = NULL, lParam == dialog resource
	 */
    case PSCB_PRECREATE:
	break;

    case PSCB_INITIALIZED:
49 50 51 52
        /* Set the window icon */
        SendMessageW( hWnd, WM_SETICON, ICON_BIG,
                      (LPARAM)LoadIconW( (HINSTANCE)GetWindowLongPtrW(hWnd, GWLP_HINSTANCE),
                                         MAKEINTRESOURCEW(IDI_WINECFG) ));
53 54 55 56 57
	break;

    default:
	break;
    }
58
    return 0;
59 60
}

61
#define NUM_PROPERTY_PAGES 7
62

63
static INT_PTR
64 65
doPropertySheet (HINSTANCE hInstance, HWND hOwner)
{
66 67
    PROPSHEETPAGEW psp[NUM_PROPERTY_PAGES];
    PROPSHEETHEADERW psh;
68
    int pg = 0; /* start with page 0 */
69 70

    /*
71
     * Fill out the (Applications) PROPSHEETPAGE data structure 
72 73
     * for the property sheet
     */
74
    psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
75 76
    psp[pg].dwFlags = PSP_USETITLE;
    psp[pg].hInstance = hInstance;
77
    psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_APPCFG);
78 79
    psp[pg].u2.pszIcon = NULL;
    psp[pg].pfnDlgProc = AppDlgProc;
80
    psp[pg].pszTitle = load_string (IDS_TAB_APPLICATIONS);
81 82
    psp[pg].lParam = 0;
    pg++;
83 84

    /*
85
     * Fill out the (Libraries) PROPSHEETPAGE data structure 
86 87
     * for the property sheet
     */
88
    psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
89 90
    psp[pg].dwFlags = PSP_USETITLE;
    psp[pg].hInstance = hInstance;
91
    psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_DLLCFG);
92 93
    psp[pg].u2.pszIcon = NULL;
    psp[pg].pfnDlgProc = LibrariesDlgProc;
94
    psp[pg].pszTitle = load_string (IDS_TAB_DLLS);
95 96
    psp[pg].lParam = 0;
    pg++;
97
    
98 99 100 101
    /*
     * Fill out the (X11Drv) PROPSHEETPAGE data structure 
     * for the property sheet
     */
102
    psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
103 104
    psp[pg].dwFlags = PSP_USETITLE;
    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 110 111
    psp[pg].lParam = 0;
    pg++;

112
    psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
113 114
    psp[pg].dwFlags = PSP_USETITLE;
    psp[pg].hInstance = hInstance;
115
    psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_DESKTOP_INTEGRATION);
116 117
    psp[pg].u2.pszIcon = NULL;
    psp[pg].pfnDlgProc = ThemeDlgProc;
118
    psp[pg].pszTitle =  load_string (IDS_TAB_DESKTOP_INTEGRATION);
119 120 121
    psp[pg].lParam = 0;
    pg++;

122
    psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
123 124
    psp[pg].dwFlags = PSP_USETITLE;
    psp[pg].hInstance = hInstance;
125
    psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_DRIVECFG);
126 127
    psp[pg].u2.pszIcon = NULL;
    psp[pg].pfnDlgProc = DriveDlgProc;
128
    psp[pg].pszTitle =  load_string (IDS_TAB_DRIVES);
129 130 131
    psp[pg].lParam = 0;
    pg++;

132
    psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
133 134
    psp[pg].dwFlags = PSP_USETITLE;
    psp[pg].hInstance = hInstance;
135
    psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_AUDIOCFG);
136 137
    psp[pg].u2.pszIcon = NULL;
    psp[pg].pfnDlgProc = AudioDlgProc;
138
    psp[pg].pszTitle =  load_string (IDS_TAB_AUDIO);
139 140
    psp[pg].lParam = 0;
    pg++;
141

142 143 144 145
    /*
     * Fill out the (General) PROPSHEETPAGE data structure 
     * for the property sheet
     */
146
    psp[pg].dwSize = sizeof (PROPSHEETPAGEW);
147 148
    psp[pg].dwFlags = PSP_USETITLE;
    psp[pg].hInstance = hInstance;
149
    psp[pg].u.pszTemplate = MAKEINTRESOURCEW (IDD_ABOUTCFG);
150 151
    psp[pg].u2.pszIcon = NULL;
    psp[pg].pfnDlgProc = AboutDlgProc;
152
    psp[pg].pszTitle =  load_string (IDS_TAB_ABOUT);
153 154
    psp[pg].lParam = 0;
    pg++;
155

156 157 158
    /*
     * Fill out the PROPSHEETHEADER
     */
159
    psh.dwSize = sizeof (PROPSHEETHEADERW);
160 161 162
    psh.dwFlags = PSH_PROPSHEETPAGE | PSH_USEICONID | PSH_USECALLBACK;
    psh.hwndParent = hOwner;
    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 167
    psh.u3.ppsp = psp;
    psh.pfnCallback = PropSheetCallback;
168
    psh.u2.nStartPage = 0;
169 170 171 172

    /*
     * Display the modal property sheet
     */
173
    return PropertySheetW (&psh);
174 175
}

176 177 178 179 180 181 182 183 184 185 186
/******************************************************************************
 * Name       : ProcessCmdLine
 * Description: Checks command line parameters for 'autodetect drives' option
 * Parameters : lpCmdLine - the command line
 * Returns    : TRUE - if '/D' was found. Drive autodetection was carried out.
 *              FALSE - no '/D' option found in command line
 * Notes      : This is a very simple implementation, which only works 
 *              correctly if the one and only cmd line option is '/D' or
 *              no option at all. Has to be reworked, if more options are to
 *              be supported.
 */
187
static BOOL
188 189 190 191 192 193 194 195 196 197 198 199 200 201
ProcessCmdLine(LPSTR lpCmdLine)
{
    if ((lpCmdLine[0] == '/' || lpCmdLine[0] == '-') && 
        (lpCmdLine[1] == 'D' || lpCmdLine[1] == 'd')) 
    {
        gui_mode = FALSE;
        if (autodetect_drives()) {
            apply_drive_changes();
        }
        return TRUE;
    }

    return FALSE;
}
202 203 204 205

/*****************************************************************************
 * Name       : WinMain
 * Description: Main windows entry point
Francois Gouget's avatar
Francois Gouget committed
206
 * Parameters : hInstance
207 208 209 210 211 212 213 214
 *              hPrev
 *              szCmdLine
 *              nShow
 * Returns    : Program exit code
 */
int WINAPI
WinMain (HINSTANCE hInstance, HINSTANCE hPrev, LPSTR szCmdLine, int nShow)
{
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
    BOOL is_wow64;

    if (IsWow64Process( GetCurrentProcess(), &is_wow64 ) && is_wow64)
    {
        STARTUPINFOW si;
        PROCESS_INFORMATION pi;
        WCHAR filename[MAX_PATH];
        void *redir;
        DWORD exit_code;

        memset( &si, 0, sizeof(si) );
        si.cb = sizeof(si);
        GetModuleFileNameW( 0, filename, MAX_PATH );

        Wow64DisableWow64FsRedirection( &redir );
        if (CreateProcessW( filename, GetCommandLineW(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi ))
        {
            WINE_TRACE( "restarting %s\n", wine_dbgstr_w(filename) );
            WaitForSingleObject( pi.hProcess, INFINITE );
            GetExitCodeProcess( pi.hProcess, &exit_code );
            ExitProcess( exit_code );
        }
        else WINE_ERR( "failed to restart 64-bit %s, err %d\n", wine_dbgstr_w(filename), GetLastError() );
        Wow64RevertWow64FsRedirection( redir );
    }

241 242 243
    if (ProcessCmdLine(szCmdLine)) {
        return 0;
    }
244

245
    if (initialize(hInstance)) {
246 247 248 249
	WINE_ERR("initialization failed, aborting\n");
	ExitProcess(1);
    }
    
250
    /*
251
     * The next 9 lines should be all that is needed
252 253 254
     * for the Wine Configuration property sheet
     */
    InitCommonControls ();
255
    CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
256
    if (doPropertySheet (hInstance, NULL) > 0) {
257
	WINE_TRACE("OK\n");
258
    } else {
259
	WINE_TRACE("Cancel\n");
260
    }
261
    CoUninitialize(); 
262 263 264 265
    ExitProcess (0);

    return 0;
}