appdefaults.c 18.8 KB
Newer Older
1
/*
2
 * WineCfg app settings tabsheet
3
 *
4
 * Copyright 2004 Robert van Herk
5 6
 * Copyright 2004 Chris Morgan
 * Copyright 2004 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 27
#include <windows.h>
#include <commdlg.h>
#include <wine/debug.h>
28
#include <stdio.h>
29
#include <stdlib.h>
30
#include <assert.h>
31
#include "wine/unicode.h"
32 33 34 35 36
#include "winecfg.h"
#include "resource.h"

WINE_DEFAULT_DEBUG_CHANNEL(winecfg);

37 38 39 40 41 42 43 44 45 46 47 48 49 50
static const struct
{
    const char *szVersion;
    const char *szDescription;
    DWORD       dwMajorVersion;
    DWORD       dwMinorVersion;
    DWORD       dwBuildNumber;
    DWORD       dwPlatformId;
    const char *szCSDVersion;
    WORD        wServicePackMajor;
    WORD        wServicePackMinor;
    const char *szProductType;
} win_versions[] =
{
51
    { "win10",       "Windows 10",       10,  0, 0x42EE,VER_PLATFORM_WIN32_NT, "", 0, 0, "WinNT"},
52 53
    { "win81",       "Windows 8.1",       6,  3, 0x2580,VER_PLATFORM_WIN32_NT, "", 0, 0, "WinNT"},
    { "win8",        "Windows 8",         6,  2, 0x23F0,VER_PLATFORM_WIN32_NT, "", 0, 0, "WinNT"},
54 55
    { "win2008r2",   "Windows 2008 R2",   6,  1, 0x1DB1,VER_PLATFORM_WIN32_NT, "Service Pack 1", 1, 0, "ServerNT"},
    { "win7",        "Windows 7",         6,  1, 0x1DB1,VER_PLATFORM_WIN32_NT, "Service Pack 1", 1, 0, "WinNT"},
56
    { "win2008",     "Windows 2008",      6,  0, 0x1772,VER_PLATFORM_WIN32_NT, "Service Pack 2", 2, 0, "ServerNT"},
57 58
    { "vista",       "Windows Vista",     6,  0, 0x1772,VER_PLATFORM_WIN32_NT, "Service Pack 2", 2, 0, "WinNT"},
    { "win2003",     "Windows 2003",      5,  2, 0xECE, VER_PLATFORM_WIN32_NT, "Service Pack 2", 2, 0, "ServerNT"},
59
#ifdef _WIN64
60
    { "winxp64",     "Windows XP",        5,  2, 0xECE, VER_PLATFORM_WIN32_NT, "Service Pack 2", 2, 0, "WinNT"},
61
#else
62 63 64 65 66 67
    { "winxp",       "Windows XP",        5,  1, 0xA28, VER_PLATFORM_WIN32_NT, "Service Pack 3", 3, 0, "WinNT"},
    { "win2k",       "Windows 2000",      5,  0, 0x893, VER_PLATFORM_WIN32_NT, "Service Pack 4", 4, 0, "WinNT"},
    { "winme",       "Windows ME",        4, 90, 0xBB8, VER_PLATFORM_WIN32_WINDOWS, " ", 0, 0, ""},
    { "win98",       "Windows 98",        4, 10, 0x8AE, VER_PLATFORM_WIN32_WINDOWS, " A ", 0, 0, ""},
    { "win95",       "Windows 95",        4,  0, 0x3B6, VER_PLATFORM_WIN32_WINDOWS, "", 0, 0, ""},
    { "nt40",        "Windows NT 4.0",    4,  0, 0x565, VER_PLATFORM_WIN32_NT, "Service Pack 6a", 6, 0, "WinNT"},
68
    { "nt351",       "Windows NT 3.51",   3, 51, 0x421, VER_PLATFORM_WIN32_NT, "Service Pack 5", 5, 0, "WinNT"},
69
    { "win31",       "Windows 3.1",       3, 10,     0, VER_PLATFORM_WIN32s, "Win32s 1.3", 0, 0, ""},
70 71
    { "win30",       "Windows 3.0",       3,  0,     0, VER_PLATFORM_WIN32s, "Win32s 1.3", 0, 0, ""},
    { "win20",       "Windows 2.0",       2,  0,     0, VER_PLATFORM_WIN32s, "Win32s 1.3", 0, 0, ""}
72
#endif
73 74
};

75 76
static const char szKey9x[] = "Software\\Microsoft\\Windows\\CurrentVersion";
static const char szKeyNT[] = "Software\\Microsoft\\Windows NT\\CurrentVersion";
77
static const char szKeyProdNT[] = "System\\CurrentControlSet\\Control\\ProductOptions";
78 79

static int get_registry_version(void)
80
{
81
    int i, best = -1, platform, major, minor = 0, build = 0;
82
    char *p, *ver, *type = NULL;
83 84

    if ((ver = get_reg_key( HKEY_LOCAL_MACHINE, szKeyNT, "CurrentVersion", NULL )))
85 86 87
    {
        char *build_str;

88
        platform = VER_PLATFORM_WIN32_NT;
89

90
        build_str = get_reg_key( HKEY_LOCAL_MACHINE, szKeyNT, "CurrentBuildNumber", NULL );
91
        build = atoi(build_str);
92 93

        type = get_reg_key( HKEY_LOCAL_MACHINE, szKeyProdNT, "ProductType", NULL );
94
    }
95 96 97 98 99 100 101
    else if ((ver = get_reg_key( HKEY_LOCAL_MACHINE, szKey9x, "VersionNumber", NULL )))
        platform = VER_PLATFORM_WIN32_WINDOWS;
    else
        return -1;

    if ((p = strchr( ver, '.' )))
    {
102 103 104 105 106 107 108 109 110
        char *minor_str = p;
        *minor_str++ = 0;
        if ((p = strchr( minor_str, '.' )))
        {
            char *build_str = p;
            *build_str++ = 0;
            build = atoi(build_str);
        }
        minor = atoi(minor_str);
111 112 113
    }
    major = atoi(ver);

114
    for (i = 0; i < ARRAY_SIZE(win_versions); i++)
115 116 117
    {
        if (win_versions[i].dwPlatformId != platform) continue;
        if (win_versions[i].dwMajorVersion != major) continue;
118
        if (type && strcasecmp(win_versions[i].szProductType, type)) continue;
119
        best = i;
120 121 122
        if ((win_versions[i].dwMinorVersion == minor) &&
            (win_versions[i].dwBuildNumber == build))
            return i;
123 124 125
    }
    return best;
}
126

127 128 129
static void update_comboboxes(HWND dialog)
{
    int i, ver;
130
    char *winver;
131

132 133
    /* retrieve the registry values */
    winver = get_reg_key(config_key, keypath(""), "Version", "");
134
    ver = get_registry_version();
135

136
    if (!winver || !winver[0])
137 138
    {
        HeapFree(GetProcessHeap(), 0, winver);
139

140 141 142
        if (current_app) /* no explicit setting */
        {
            WINE_TRACE("setting winver combobox to default\n");
143
            SendDlgItemMessageW(dialog, IDC_WINVER, CB_SETCURSEL, 0, 0);
144 145
            return;
        }
146
        if (ver != -1) winver = strdupA( win_versions[ver].szVersion );
147
        else winver = strdupA("win7");
148 149 150 151
    }
    WINE_TRACE("winver is %s\n", winver);

    /* normalize the version strings */
152
    for (i = 0; i < ARRAY_SIZE(win_versions); i++)
153 154 155
    {
        if (!strcasecmp (win_versions[i].szVersion, winver))
        {
156
            SendDlgItemMessageW(dialog, IDC_WINVER, CB_SETCURSEL,
157
                                i + (current_app?1:0), 0);
158 159
            WINE_TRACE("match with %s\n", win_versions[i].szVersion);
            break;
160
	}
161
    }
162

163
    HeapFree(GetProcessHeap(), 0, winver);
164 165
}

166
static void
167
init_comboboxes (HWND dialog)
168
{
169
    int i;
170

171
    SendDlgItemMessageW(dialog, IDC_WINVER, CB_RESETCONTENT, 0, 0);
172

173 174
    /* add the default entries (automatic) which correspond to no setting  */
    if (current_app)
175 176
    {
        WCHAR str[256];
177
        LoadStringW(GetModuleHandleW(NULL), IDS_USE_GLOBAL_SETTINGS, str, ARRAY_SIZE(str));
178 179
        SendDlgItemMessageW (dialog, IDC_WINVER, CB_ADDSTRING, 0, (LPARAM)str);
    }
180

181
    for (i = 0; i < ARRAY_SIZE(win_versions); i++)
182
    {
183
      SendDlgItemMessageA(dialog, IDC_WINVER, CB_ADDSTRING,
184
                          0, (LPARAM) win_versions[i].szDescription);
185
    }
186 187
}

188
static void add_listview_item(HWND listview, WCHAR *text, void *association)
189
{
190
  LVITEMW item;
191 192

  item.mask = LVIF_TEXT | LVIF_PARAM;
193
  item.pszText = text;
194
  item.cchTextMax = lstrlenW(text);
195
  item.lParam = (LPARAM) association;
196
  item.iItem = SendMessageW( listview, LVM_GETITEMCOUNT, 0, 0 );
197
  item.iSubItem = 0;
198

199
  SendMessageW(listview, LVM_INSERTITEMW, 0, (LPARAM) &item);
200
}
201

202
/* Called when the application is initialized (cannot reinit!)  */
203
static void init_appsheet(HWND dialog)
204
{
205
  HWND listview;
206
  LVITEMW item;
207
  HKEY key;
208 209
  int i;
  DWORD size;
210
  WCHAR appname[1024];
211

212
  WINE_TRACE("()\n");
213

214 215 216 217
  listview = GetDlgItem(dialog, IDC_APP_LISTVIEW);

  /* we use the lparam field of the item so we can alter the presentation later and not change code
   * for instance, to use the tile view or to display the EXEs embedded 'display name' */
218
  LoadStringW(GetModuleHandleW(NULL), IDS_DEFAULT_SETTINGS, appname, ARRAY_SIZE(appname));
219
  add_listview_item(listview, appname, NULL);
220 221

  /* because this list is only populated once, it's safe to bypass the settings list here  */
222
  if (RegOpenKeyA(config_key, "AppDefaults", &key) == ERROR_SUCCESS)
223
  {
224
      i = 0;
225
      size = ARRAY_SIZE(appname);
226
      while (RegEnumKeyExW (key, i, appname, &size, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
227
      {
228
          add_listview_item(listview, appname, strdupW(appname));
229 230

          i++;
231
          size = ARRAY_SIZE(appname);
232 233 234 235 236 237 238 239
      }

      RegCloseKey(key);
  }

  init_comboboxes(dialog);
  
  /* Select the default settings listview item  */
240 241 242 243 244
  item.iItem = 0;
  item.iSubItem = 0;
  item.mask = LVIF_STATE;
  item.state = LVIS_SELECTED | LVIS_FOCUSED;
  item.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
245

246
  SendMessageW(listview, LVM_SETITEMW, 0, (LPARAM) &item);
247 248
}

249 250
/* there has to be an easier way than this  */
static int get_listview_selection(HWND listview)
251
{
252
  int count = SendMessageW(listview, LVM_GETITEMCOUNT, 0, 0);
253
  int i;
254

255
  for (i = 0; i < count; i++)
256
  {
257
      if (SendMessageW( listview, LVM_GETITEMSTATE, i, LVIS_SELECTED )) return i;
258
  }
259 260

  return -1;
261 262
}

263

264 265
/* called when the user selects a different application */
static void on_selection_change(HWND dialog, HWND listview)
266
{
267
  LVITEMW item;
268
  WCHAR* oldapp = current_app;
269

270
  WINE_TRACE("()\n");
271

272
  item.iItem = get_listview_selection(listview);
273
  item.iSubItem = 0;
274
  item.mask = LVIF_PARAM;
275 276

  WINE_TRACE("item.iItem=%d\n", item.iItem);
277 278
  
  if (item.iItem == -1) return;
279 280

  SendMessageW(listview, LVM_GETITEMW, 0, (LPARAM) &item);
281

282
  current_app = (WCHAR*) item.lParam;
283

Mike Hearn's avatar
Mike Hearn committed
284
  if (current_app)
285
  {
286
      WINE_TRACE("current_app is now %s\n", wine_dbgstr_w (current_app));
287 288 289 290
      enable(IDC_APP_REMOVEAPP);
  }
  else
  {
Mike Hearn's avatar
Mike Hearn committed
291
      WINE_TRACE("current_app=NULL, editing global settings\n");
292 293 294 295 296 297
      /* focus will never be on the button in this callback so it's safe  */
      disable(IDC_APP_REMOVEAPP);
  }

  /* reset the combo boxes if we changed from/to global/app-specific  */

Mike Hearn's avatar
Mike Hearn committed
298
  if ((oldapp && !current_app) || (!oldapp && current_app))
299 300 301
      init_comboboxes(dialog);
  
  update_comboboxes(dialog);
302 303

  set_window_title(dialog);
304 305
}

306
static BOOL list_contains_file(HWND listview, WCHAR *filename)
307
{
308
  LVFINDINFOW find_info = { LVFI_STRING, filename, 0, {0, 0}, 0 };
309 310
  int index;

311
  index = ListView_FindItemW(listview, -1, &find_info);
312 313 314 315

  return (index != -1);
}

316
static void on_add_app_click(HWND dialog)
317
{
318
  static const WCHAR filterW[] = {'%','s','%','c','*','.','e','x','e',';','*','.','e','x','e','.','s','o','%','c',0};
319 320
  WCHAR filetitle[MAX_PATH];
  WCHAR file[MAX_PATH];
321
  WCHAR programsFilter[100], filter[MAX_PATH];
322 323 324 325
  WCHAR selectExecutableStr[100];
  static const WCHAR pathC[] = { 'c',':','\\',0 };

  OPENFILENAMEW ofn = { sizeof(OPENFILENAMEW),
326
		       dialog, /*hInst*/0, 0, NULL, 0, 0, NULL,
327
		       0, NULL, 0, pathC, 0,
328 329
		       OFN_SHOWHELP | OFN_HIDEREADONLY | OFN_ENABLESIZING,
                       0, 0, NULL, 0, NULL };
330

331
  LoadStringW (GetModuleHandleW(NULL), IDS_SELECT_EXECUTABLE, selectExecutableStr,
332
      ARRAY_SIZE(selectExecutableStr));
333
  LoadStringW (GetModuleHandleW(NULL), IDS_EXECUTABLE_FILTER, programsFilter,
334
      ARRAY_SIZE(programsFilter));
335
  snprintfW( filter, MAX_PATH, filterW, programsFilter, 0, 0 );
336 337

  ofn.lpstrTitle = selectExecutableStr;
338
  ofn.lpstrFilter = filter;
339
  ofn.lpstrFileTitle = filetitle;
340
  ofn.lpstrFileTitle[0] = '\0';
341
  ofn.nMaxFileTitle = ARRAY_SIZE(filetitle);
342
  ofn.lpstrFile = file;
343
  ofn.lpstrFile[0] = '\0';
344
  ofn.nMaxFile = ARRAY_SIZE(file);
345

346
  if (GetOpenFileNameW (&ofn))
347
  {
348
      HWND listview = GetDlgItem(dialog, IDC_APP_LISTVIEW);
349
      int count = SendMessageW(listview, LVM_GETITEMCOUNT, 0, 0);
350
      WCHAR* new_app;
351 352
      LVITEMW item;

353
      if (list_contains_file(listview, filetitle))
354
          return;
355

356 357
      new_app = strdupW(filetitle);

358
      WINE_TRACE("adding %s\n", wine_dbgstr_w (new_app));
359

360
      add_listview_item(listview, new_app, new_app);
361

362 363 364 365
      item.mask = LVIF_STATE;
      item.state = LVIS_SELECTED | LVIS_FOCUSED;
      item.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
      SendMessageW(listview, LVM_SETITEMSTATE, count, (LPARAM)&item );
366 367

      SetFocus(listview);
368
  }
369
  else WINE_TRACE("user cancelled\n");
370 371
}

372
static void on_remove_app_click(HWND dialog)
373
{
374 375
    HWND listview = GetDlgItem(dialog, IDC_APP_LISTVIEW);
    int selection = get_listview_selection(listview);
376 377 378
    LVITEMW item;

    item.iItem = selection;
379
    item.iSubItem = 0;
380
    item.mask = LVIF_PARAM;
381

382 383
    WINE_TRACE("selection=%d\n", selection);

384
    assert( selection != 0 ); /* user cannot click this button when "default settings" is selected  */
385

386
    set_reg_key(config_key, keypath(""), NULL, NULL); /* delete the section  */
387
    SendMessageW(listview, LVM_GETITEMW, 0, (LPARAM) &item);
388
    HeapFree (GetProcessHeap(), 0, (void*)item.lParam);
389 390 391 392
    SendMessageW(listview, LVM_DELETEITEM, selection, 0);
    item.mask = LVIF_STATE;
    item.state = LVIS_SELECTED | LVIS_FOCUSED;
    item.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
393
    SendMessageW(listview, LVM_SETITEMSTATE, 0, (LPARAM)&item);
394

395
    SetFocus(listview);
396
    SendMessageW(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0);
397 398
}

399
static void on_winver_change(HWND dialog)
400
{
401
    int selection = SendDlgItemMessageW(dialog, IDC_WINVER, CB_GETCURSEL, 0, 0);
402

403
    if (current_app)
404
    {
405 406 407 408 409 410 411 412 413 414
        if (!selection)
        {
            WINE_TRACE("default selected so removing current setting\n");
            set_reg_key(config_key, keypath(""), "Version", NULL);
        }
        else
        {
            WINE_TRACE("setting Version key to value '%s'\n", win_versions[selection-1].szVersion);
            set_reg_key(config_key, keypath(""), "Version", win_versions[selection-1].szVersion);
        }
415
    }
416
    else /* global version only */
417 418
    {
        static const char szKeyWindNT[] = "System\\CurrentControlSet\\Control\\Windows";
419
        static const char szKeyEnvNT[]  = "System\\CurrentControlSet\\Control\\Session Manager\\Environment";
420 421
        char Buffer[40];

422
        switch (win_versions[selection].dwPlatformId)
423 424
        {
        case VER_PLATFORM_WIN32_WINDOWS:
425
            snprintf(Buffer, sizeof(Buffer), "%d.%d.%d", win_versions[selection].dwMajorVersion,
426
                     win_versions[selection].dwMinorVersion, win_versions[selection].dwBuildNumber);
427
            set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, "VersionNumber", Buffer);
428
            set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, "SubVersionNumber", win_versions[selection].szCSDVersion);
429 430
            snprintf(Buffer, sizeof(Buffer), "Microsoft %s", win_versions[selection].szDescription);
            set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, "ProductName", Buffer);
431 432 433

            set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "CSDVersion", NULL);
            set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "CurrentVersion", NULL);
434
            set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "CurrentBuild", NULL);
435
            set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "CurrentBuildNumber", NULL);
436
            set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "ProductName", NULL);
437 438
            set_reg_key(HKEY_LOCAL_MACHINE, szKeyProdNT, "ProductType", NULL);
            set_reg_key(HKEY_LOCAL_MACHINE, szKeyWindNT, "CSDVersion", NULL);
439
            set_reg_key(HKEY_LOCAL_MACHINE, szKeyEnvNT, "OS", NULL);
440
            set_reg_key(config_key, keypath(""), "Version", NULL);
441 442 443
            break;

        case VER_PLATFORM_WIN32_NT:
444
            snprintf(Buffer, sizeof(Buffer), "%d.%d", win_versions[selection].dwMajorVersion,
445
                     win_versions[selection].dwMinorVersion);
446
            set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "CurrentVersion", Buffer);
447
            set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "CSDVersion", win_versions[selection].szCSDVersion);
448
            snprintf(Buffer, sizeof(Buffer), "%d", win_versions[selection].dwBuildNumber);
449
            set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "CurrentBuild", Buffer);
450
            set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "CurrentBuildNumber", Buffer);
451 452
            snprintf(Buffer, sizeof(Buffer), "Microsoft %s", win_versions[selection].szDescription);
            set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "ProductName", Buffer);
453
            set_reg_key(HKEY_LOCAL_MACHINE, szKeyProdNT, "ProductType", win_versions[selection].szProductType);
454
            set_reg_key_dword(HKEY_LOCAL_MACHINE, szKeyWindNT, "CSDVersion",
455 456
                              MAKEWORD( win_versions[selection].wServicePackMinor,
                                        win_versions[selection].wServicePackMajor ));
457
            set_reg_key(HKEY_LOCAL_MACHINE, szKeyEnvNT, "OS", "Windows_NT");
458 459 460

            set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, "VersionNumber", NULL);
            set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, "SubVersionNumber", NULL);
461
            set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, "ProductName", NULL);
462
            set_reg_key(config_key, keypath(""), "Version", NULL);
463 464 465 466 467
            break;

        case VER_PLATFORM_WIN32s:
            set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "CSDVersion", NULL);
            set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "CurrentVersion", NULL);
468
            set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "CurrentBuild", NULL);
469
            set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "CurrentBuildNumber", NULL);
470
            set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "ProductName", NULL);
471 472
            set_reg_key(HKEY_LOCAL_MACHINE, szKeyProdNT, "ProductType", NULL);
            set_reg_key(HKEY_LOCAL_MACHINE, szKeyWindNT, "CSDVersion", NULL);
473
            set_reg_key(HKEY_LOCAL_MACHINE, szKeyEnvNT, "OS", NULL);
474 475
            set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, "VersionNumber", NULL);
            set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, "SubVersionNumber", NULL);
476
            set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, "ProductName", NULL);
477
            set_reg_key(config_key, keypath(""), "Version", win_versions[selection].szVersion);
478 479
            break;
        }
480
    }
481 482

    /* enable the apply button  */
483
    SendMessageW(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0);
484
}
485

486 487 488
INT_PTR CALLBACK
AppDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
489 490
  switch (uMsg)
  {
491
    case WM_INITDIALOG:
492 493 494 495 496 497
        init_appsheet(hDlg);
        break;

    case WM_SHOWWINDOW:
        set_window_title(hDlg);
        break;
498 499 500 501 502

    case WM_NOTIFY:
      switch (((LPNMHDR)lParam)->code)
      {
        case LVN_ITEMCHANGED:
503 504 505 506
            on_selection_change(hDlg, GetDlgItem(hDlg, IDC_APP_LISTVIEW));
            break;
        case PSN_APPLY:
            apply();
507
            SetWindowLongPtrW(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
508
            break;
509
      }
510
      
511 512 513
      break;
    
    case WM_COMMAND:
Mike Hearn's avatar
Mike Hearn committed
514 515
      switch(HIWORD(wParam))
      {
516
        case CBN_SELCHANGE:
Mike Hearn's avatar
Mike Hearn committed
517 518
          switch(LOWORD(wParam))
          {
519 520 521 522 523
            case IDC_WINVER:
              on_winver_change(hDlg);
              break;
          }
        case BN_CLICKED:
Mike Hearn's avatar
Mike Hearn committed
524 525
          switch(LOWORD(wParam))
          {
526 527 528 529 530 531 532 533
            case IDC_APP_ADDAPP:
              on_add_app_click(hDlg);
              break;
            case IDC_APP_REMOVEAPP:
              on_remove_app_click(hDlg);
              break;
          }
          break;
534
      }
535

536 537
      break;
  }
538
  
539
  return 0;
540
}