1 /* 2 * PROJECT: ReactOS System Control Panel Applet 3 * LICENSE: GPL - See COPYING in the top level directory 4 * FILE: dll/cpl/sysdm/hardprof.c 5 * PURPOSE: Modify hardware profiles 6 * COPYRIGHT: Copyright 2006 Ged Murphy <gedmurphy@gmail.com> 7 * 8 */ 9 10 #include "precomp.h" 11 12 #include <debug.h> 13 14 #define PROFILE_NAME_LENGTH 80 15 16 typedef struct _PROFILE 17 { 18 WCHAR szFriendlyName[PROFILE_NAME_LENGTH]; 19 WCHAR szName[5]; 20 DWORD dwProfileNumber; 21 DWORD dwPreferenceOrder; 22 } PROFILE, *PPROFILE; 23 24 typedef struct _PROFILEDATA 25 { 26 DWORD dwProfileCount; 27 DWORD dwLastProfile; 28 DWORD dwSelectedProfile; 29 DWORD dwSelectedProfileIndex; 30 PPROFILE pProfiles; 31 } PROFILEDATA, *PPROFILEDATA; 32 33 typedef struct _PROFILENAMES 34 { 35 WCHAR szSourceName[PROFILE_NAME_LENGTH]; 36 WCHAR szDestinationName[PROFILE_NAME_LENGTH]; 37 PPROFILEDATA pProfileData; 38 } PROFILENAMES, *PPROFILENAMES; 39 40 41 static 42 VOID 43 UpdateButtons( 44 HWND hwndDlg, 45 PPROFILEDATA pProfileData) 46 { 47 EnableWindow(GetDlgItem(hwndDlg, IDC_HRDPROFPROP), (pProfileData->dwSelectedProfileIndex != (DWORD)-1) ? TRUE : FALSE); 48 EnableWindow(GetDlgItem(hwndDlg, IDC_HRDPROFCOPY), (pProfileData->dwSelectedProfileIndex != (DWORD)-1) ? TRUE : FALSE); 49 EnableWindow(GetDlgItem(hwndDlg, IDC_HRDPROFRENAME), (pProfileData->dwSelectedProfileIndex != (DWORD)-1) ? TRUE : FALSE); 50 EnableWindow(GetDlgItem(hwndDlg, IDC_HRDPROFDEL), (pProfileData->dwSelectedProfileIndex != (DWORD)-1) ? TRUE : FALSE); 51 52 if (pProfileData->dwProfileCount < 2) 53 { 54 EnableWindow(GetDlgItem(hwndDlg, IDC_HRDPROFUP), FALSE); 55 EnableWindow(GetDlgItem(hwndDlg, IDC_HRDPROFDWN), FALSE); 56 } 57 else 58 { 59 EnableWindow(GetDlgItem(hwndDlg, IDC_HRDPROFUP), 60 (pProfileData->dwSelectedProfileIndex > 0) ? TRUE : FALSE); 61 EnableWindow(GetDlgItem(hwndDlg, IDC_HRDPROFDWN), 62 (pProfileData->dwSelectedProfileIndex < pProfileData->dwProfileCount - 1) ? TRUE : FALSE); 63 } 64 } 65 66 67 static 68 BOOL 69 IsProfileNameInUse( 70 PPROFILENAMES pProfileNames, 71 BOOL bIgnoreCurrent) 72 { 73 DWORD i; 74 75 for (i = 0; i < pProfileNames->pProfileData->dwProfileCount; i++) 76 { 77 if (bIgnoreCurrent == TRUE && i == pProfileNames->pProfileData->dwSelectedProfileIndex) 78 continue; 79 80 if (wcscmp(pProfileNames->pProfileData->pProfiles[i].szFriendlyName, pProfileNames->szDestinationName) == 0) 81 return TRUE; 82 } 83 84 return FALSE; 85 } 86 87 88 static 89 INT_PTR 90 CALLBACK 91 CopyProfileDlgProc( 92 HWND hwndDlg, 93 UINT uMsg, 94 WPARAM wParam, 95 LPARAM lParam) 96 { 97 PPROFILENAMES pProfileNames; 98 99 pProfileNames = (PPROFILENAMES)GetWindowLongPtr(hwndDlg, DWLP_USER); 100 101 switch (uMsg) 102 { 103 case WM_INITDIALOG: 104 SetWindowLongPtr(hwndDlg, DWLP_USER, lParam); 105 pProfileNames = (PPROFILENAMES)lParam; 106 107 /* Set the old name */ 108 SetDlgItemText(hwndDlg, IDC_COPYPROFILEFROM, pProfileNames->szSourceName); 109 110 /* Set the new name */ 111 SendDlgItemMessageW(hwndDlg, IDC_COPYPROFILETO, EM_SETLIMITTEXT, PROFILE_NAME_LENGTH - 1, 0); 112 SetDlgItemText(hwndDlg, IDC_COPYPROFILETO, pProfileNames->szDestinationName); 113 break; 114 115 case WM_COMMAND: 116 switch (LOWORD(wParam)) 117 { 118 case IDOK: 119 GetDlgItemText(hwndDlg, 120 IDC_COPYPROFILETO, 121 pProfileNames->szDestinationName, 122 PROFILE_NAME_LENGTH); 123 if (IsProfileNameInUse(pProfileNames, FALSE)) 124 ResourceMessageBox(hApplet, 125 NULL, 126 MB_OK | MB_ICONERROR, 127 IDS_HWPROFILE_WARNING, 128 IDS_HWPROFILE_ALREADY_IN_USE); 129 else 130 EndDialog(hwndDlg, IDOK); 131 return TRUE; 132 133 case IDCANCEL: 134 EndDialog(hwndDlg, IDCANCEL); 135 return TRUE; 136 } 137 break; 138 } 139 140 return FALSE; 141 } 142 143 144 static 145 VOID 146 CopyHardwareProfile( 147 HWND hwndDlg, 148 PPROFILEDATA pProfileData) 149 { 150 PROFILENAMES ProfileNames; 151 PPROFILE pProfile, pNewProfiles, pNewProfile; 152 WCHAR szBuffer[80]; 153 154 pProfile = &pProfileData->pProfiles[pProfileData->dwSelectedProfileIndex]; 155 156 LoadStringW(hApplet, IDS_HWPROFILE_PROFILE, szBuffer, sizeof(szBuffer) / sizeof(WCHAR)); 157 158 wcscpy(ProfileNames.szSourceName, pProfile->szFriendlyName); 159 swprintf(ProfileNames.szDestinationName, L"%s %lu", szBuffer, pProfileData->dwProfileCount); 160 161 ProfileNames.pProfileData = pProfileData; 162 163 if (DialogBoxParam(hApplet, 164 MAKEINTRESOURCE(IDD_COPYPROFILE), 165 hwndDlg, 166 CopyProfileDlgProc, 167 (LPARAM)&ProfileNames) != IDOK) 168 return; 169 170 /* Apply new name only if it has been changed */ 171 if (wcscmp(ProfileNames.szSourceName, ProfileNames.szDestinationName) == 0) 172 return; 173 174 /* Allocate memory for the new profile */ 175 pNewProfiles = HeapReAlloc(GetProcessHeap(), 176 HEAP_ZERO_MEMORY, 177 pProfileData->pProfiles, 178 (pProfileData->dwProfileCount + 1) * sizeof(PROFILE)); 179 if (pNewProfiles == NULL) 180 { 181 DPRINT1("HeapReAlloc() failed!\n"); 182 return; 183 } 184 185 pProfileData->dwProfileCount++; 186 pProfileData->pProfiles = pNewProfiles; 187 188 pNewProfile = &pProfileData->pProfiles[pProfileData->dwProfileCount - 1]; 189 190 CopyMemory(pNewProfile, pProfile, sizeof(PROFILE)); 191 192 wcscpy(pNewProfile->szFriendlyName, ProfileNames.szDestinationName); 193 194 pNewProfile->dwProfileNumber = ++pProfileData->dwLastProfile; 195 swprintf(pNewProfile->szName, L"%04lu", pNewProfile->dwProfileNumber); 196 197 pNewProfile->dwPreferenceOrder = pNewProfile->dwProfileNumber; 198 199 SendDlgItemMessageW(hwndDlg, IDC_HRDPROFLSTBOX, LB_ADDSTRING, 0, (LPARAM)pNewProfile->szFriendlyName); 200 201 UpdateButtons(hwndDlg, pProfileData); 202 } 203 204 205 static 206 INT_PTR 207 CALLBACK 208 RenameProfileDlgProc( 209 HWND hwndDlg, 210 UINT uMsg, 211 WPARAM wParam, 212 LPARAM lParam) 213 { 214 PPROFILENAMES pProfileNames; 215 216 pProfileNames = (PPROFILENAMES)GetWindowLongPtr(hwndDlg, DWLP_USER); 217 218 switch (uMsg) 219 { 220 case WM_INITDIALOG: 221 SetWindowLongPtr(hwndDlg, DWLP_USER, lParam); 222 pProfileNames = (PPROFILENAMES)lParam; 223 224 /* Set the old name */ 225 SetDlgItemText(hwndDlg, IDC_RENPROFEDITFROM, pProfileNames->szSourceName); 226 227 /* Set the new name */ 228 SendDlgItemMessageW(hwndDlg, IDC_RENPROFEDITTO, EM_SETLIMITTEXT, PROFILE_NAME_LENGTH - 1, 0); 229 SetDlgItemText(hwndDlg, IDC_RENPROFEDITTO, pProfileNames->szDestinationName); 230 break; 231 232 case WM_COMMAND: 233 switch (LOWORD(wParam)) 234 { 235 case IDOK: 236 GetDlgItemText(hwndDlg, 237 IDC_RENPROFEDITTO, 238 pProfileNames->szDestinationName, 239 PROFILE_NAME_LENGTH); 240 if (IsProfileNameInUse(pProfileNames, TRUE)) 241 ResourceMessageBox(hApplet, 242 NULL, 243 MB_OK | MB_ICONERROR, 244 IDS_HWPROFILE_WARNING, 245 IDS_HWPROFILE_ALREADY_IN_USE); 246 else 247 EndDialog(hwndDlg, IDOK); 248 return TRUE; 249 250 case IDCANCEL: 251 EndDialog(hwndDlg, IDCANCEL); 252 return TRUE; 253 } 254 break; 255 } 256 257 return FALSE; 258 } 259 260 261 static 262 VOID 263 RenameHardwareProfile( 264 HWND hwndDlg, 265 PPROFILEDATA pProfileData) 266 { 267 PROFILENAMES ProfileNames; 268 PPROFILE pProfile; 269 WCHAR szBuffer[80]; 270 271 pProfile = &pProfileData->pProfiles[pProfileData->dwSelectedProfileIndex]; 272 273 LoadStringW(hApplet, IDS_HWPROFILE_PROFILE, szBuffer, sizeof(szBuffer) / sizeof(WCHAR)); 274 275 wcscpy(ProfileNames.szSourceName, pProfile->szFriendlyName); 276 swprintf(ProfileNames.szDestinationName, L"%s %lu", szBuffer, pProfileData->dwProfileCount); 277 278 ProfileNames.pProfileData = pProfileData; 279 280 if (DialogBoxParam(hApplet, 281 MAKEINTRESOURCE(IDD_RENAMEPROFILE), 282 hwndDlg, 283 RenameProfileDlgProc, 284 (LPARAM)&ProfileNames) != IDOK) 285 return; 286 287 /* Apply new name only if it has been changed */ 288 if (wcscmp(pProfile->szFriendlyName, ProfileNames.szDestinationName) == 0) 289 return; 290 291 /* Replace the profile name in the profile list */ 292 wcscpy(pProfile->szFriendlyName, ProfileNames.szDestinationName); 293 294 /* Replace the profile name in the listbox */ 295 SendDlgItemMessageW(hwndDlg, IDC_HRDPROFLSTBOX, LB_DELETESTRING, pProfileData->dwSelectedProfileIndex, 0); 296 SendDlgItemMessageW(hwndDlg, IDC_HRDPROFLSTBOX, LB_INSERTSTRING, pProfileData->dwSelectedProfileIndex, (LPARAM)pProfile->szFriendlyName); 297 } 298 299 300 static 301 VOID 302 DeleteHardwareProfile( 303 HWND hwndDlg, 304 PPROFILEDATA pProfileData) 305 { 306 WCHAR szMessage[256]; 307 WCHAR szBuffer[128]; 308 WCHAR szCaption[80]; 309 PPROFILE pProfiles; 310 PPROFILE pProfile; 311 312 pProfile = &pProfileData->pProfiles[pProfileData->dwSelectedProfileIndex]; 313 314 LoadStringW(hApplet, IDS_HWPROFILE_CONFIRM_DELETE_TITLE, szCaption, sizeof(szCaption) / sizeof(WCHAR)); 315 LoadStringW(hApplet, IDS_HWPROFILE_CONFIRM_DELETE, szBuffer, sizeof(szBuffer) / sizeof(WCHAR)); 316 swprintf(szMessage, szBuffer, pProfile->szFriendlyName); 317 318 if (MessageBox(NULL, 319 szMessage, 320 szCaption, 321 MB_YESNO | MB_ICONQUESTION) != IDYES) 322 return; 323 324 SendDlgItemMessageW(hwndDlg, IDC_HRDPROFLSTBOX, LB_DELETESTRING, pProfileData->dwSelectedProfileIndex, 0); 325 326 if (pProfileData->dwSelectedProfileIndex != pProfileData->dwProfileCount - 1) 327 { 328 RtlMoveMemory(&pProfileData->pProfiles[pProfileData->dwSelectedProfileIndex], 329 &pProfileData->pProfiles[pProfileData->dwSelectedProfileIndex + 1], 330 (pProfileData->dwProfileCount - pProfileData->dwSelectedProfileIndex - 1) * sizeof(PROFILE)); 331 } 332 else 333 { 334 pProfileData->dwSelectedProfileIndex--; 335 } 336 337 pProfiles = HeapReAlloc(GetProcessHeap(), 338 HEAP_ZERO_MEMORY, 339 pProfileData->pProfiles, 340 (pProfileData->dwProfileCount - 1) * sizeof(PROFILE)); 341 if (pProfiles == NULL) 342 { 343 DPRINT1("HeapReAlloc() failed!\n"); 344 return; 345 } 346 347 pProfileData->dwProfileCount--; 348 pProfileData->pProfiles = pProfiles; 349 350 SendDlgItemMessageW(hwndDlg, IDC_HRDPROFLSTBOX, LB_SETCURSEL, pProfileData->dwSelectedProfileIndex, 0); 351 352 UpdateButtons(hwndDlg, pProfileData); 353 } 354 355 356 static 357 VOID 358 MoveHardwareProfile( 359 HWND hwndDlg, 360 PPROFILEDATA pProfileData, 361 BOOL bMoveUp) 362 { 363 PROFILE TempProfile; 364 PPROFILE pSrcProfile, pDstProfile; 365 DWORD dwSrcIndex, dwDstIndex; 366 367 dwSrcIndex = pProfileData->dwSelectedProfileIndex; 368 dwDstIndex = bMoveUp ? (dwSrcIndex - 1) : (dwSrcIndex + 1); 369 370 pSrcProfile = &pProfileData->pProfiles[dwSrcIndex]; 371 pDstProfile = &pProfileData->pProfiles[dwDstIndex]; 372 373 CopyMemory(&TempProfile, pDstProfile, sizeof(PROFILE)); 374 CopyMemory(pDstProfile, pSrcProfile, sizeof(PROFILE)); 375 CopyMemory(pSrcProfile, &TempProfile, sizeof(PROFILE)); 376 377 SendDlgItemMessageW(hwndDlg, IDC_HRDPROFLSTBOX, LB_DELETESTRING, dwSrcIndex, 0); 378 SendDlgItemMessageW(hwndDlg, IDC_HRDPROFLSTBOX, LB_INSERTSTRING, dwDstIndex, (LPARAM)pDstProfile->szFriendlyName); 379 380 pProfileData->dwSelectedProfileIndex = dwDstIndex; 381 SendDlgItemMessageW(hwndDlg, IDC_HRDPROFLSTBOX, LB_SETCURSEL, pProfileData->dwSelectedProfileIndex, 0); 382 383 UpdateButtons(hwndDlg, pProfileData); 384 } 385 386 387 static 388 INT_PTR 389 CALLBACK 390 HardwareProfilePropertiesDlgProc( 391 HWND hwndDlg, 392 UINT uMsg, 393 WPARAM wParam, 394 LPARAM lParam) 395 { 396 UNREFERENCED_PARAMETER(hwndDlg); 397 UNREFERENCED_PARAMETER(lParam); 398 UNREFERENCED_PARAMETER(wParam); 399 400 switch (uMsg) 401 { 402 case WM_INITDIALOG: 403 return TRUE; 404 405 } 406 407 return FALSE; 408 } 409 410 411 static 412 VOID 413 HardwareProfileProperties( 414 HWND hwndDlg, 415 PPROFILEDATA pProfileData) 416 { 417 HPROPSHEETPAGE hpsp; 418 PROPSHEETHEADER psh; 419 PROPSHEETPAGE psp; 420 421 ZeroMemory(&psp, sizeof(psp)); 422 psp.dwSize = sizeof(psp); 423 psp.dwFlags = PSP_DEFAULT; 424 psp.hInstance = hApplet; 425 psp.pszTemplate = MAKEINTRESOURCE(IDD_HARDWAREPROFILE); 426 psp.pfnDlgProc = HardwareProfilePropertiesDlgProc; 427 428 hpsp = CreatePropertySheetPage(&psp); 429 if (hpsp == NULL) 430 { 431 return; 432 } 433 434 ZeroMemory(&psh, sizeof(PROPSHEETHEADER)); 435 psh.dwSize = sizeof(PROPSHEETHEADER); 436 psh.dwFlags = PSH_PROPTITLE; 437 psh.hwndParent = hwndDlg; 438 psh.hInstance = hApplet; 439 psh.hIcon = NULL; 440 psh.pszCaption = pProfileData->pProfiles[pProfileData->dwSelectedProfileIndex].szFriendlyName; 441 psh.nPages = 1; 442 psh.nStartPage = 0; 443 psh.phpage = &hpsp; 444 psh.pfnCallback = NULL; 445 446 PropertySheet(&psh); 447 } 448 449 450 static 451 DWORD 452 GetUserWaitInterval(VOID) 453 { 454 DWORD dwWaitInterval = 30; 455 DWORD dwSize; 456 HKEY hKey; 457 458 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, 459 L"System\\CurrentControlSet\\Control\\IDConfigDB", 460 0, 461 KEY_QUERY_VALUE, 462 &hKey)) 463 return dwWaitInterval; 464 465 dwSize = sizeof(DWORD); 466 RegQueryValueExW(hKey, 467 L"UserWaitInterval", 468 NULL, 469 NULL, 470 (LPBYTE)&dwWaitInterval, 471 &dwSize); 472 473 RegCloseKey(hKey); 474 475 return dwWaitInterval; 476 } 477 478 479 static 480 VOID 481 SetUserWaitInterval(DWORD dwWaitInterval) 482 { 483 HKEY hKey; 484 485 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, 486 L"System\\CurrentControlSet\\Control\\IDConfigDB", 487 0, 488 KEY_SET_VALUE, 489 &hKey)) 490 return; 491 492 RegSetValueExW(hKey, 493 L"UserWaitInterval", 494 0, 495 REG_DWORD, 496 (LPBYTE)&dwWaitInterval, 497 sizeof(DWORD)); 498 499 RegCloseKey(hKey); 500 } 501 502 503 static 504 BOOL 505 GetProfileCount(LPDWORD lpProfileCount) 506 { 507 HKEY hKey; 508 LONG lError; 509 510 *lpProfileCount = 0; 511 512 lError = RegOpenKeyExW(HKEY_LOCAL_MACHINE, 513 L"System\\CurrentControlSet\\Control\\IDConfigDB\\Hardware Profiles", 514 0, 515 KEY_READ, 516 &hKey); 517 if (lError != ERROR_SUCCESS) 518 return FALSE; 519 520 lError = RegQueryInfoKeyW(hKey, NULL, NULL, NULL, lpProfileCount, 521 NULL, NULL, NULL, NULL, NULL, NULL, NULL); 522 523 RegCloseKey(hKey); 524 525 if (lError != ERROR_SUCCESS) 526 return FALSE; 527 528 return TRUE; 529 } 530 531 532 static 533 VOID 534 GetProfile( 535 HWND hwndDlg, 536 HKEY hKey, 537 LPWSTR lpName, 538 DWORD dwProfileNumber, 539 PPROFILE pProfile) 540 { 541 HKEY hProfileKey; 542 DWORD dwSize; 543 LONG lError; 544 545 lError = RegOpenKeyExW(hKey, 546 lpName, 547 0, 548 KEY_READ, 549 &hProfileKey); 550 if (lError != ERROR_SUCCESS) 551 return; 552 553 dwSize = PROFILE_NAME_LENGTH * sizeof(WCHAR); 554 lError = RegQueryValueExW(hProfileKey, 555 L"FriendlyName", 556 NULL, 557 NULL, 558 (LPBYTE)pProfile->szFriendlyName, 559 &dwSize); 560 if (lError == ERROR_SUCCESS) 561 { 562 DPRINT1("Profile: %S\n", pProfile->szFriendlyName); 563 } 564 565 dwSize = sizeof(DWORD); 566 lError = RegQueryValueExW(hProfileKey, 567 L"PreferenceOrder", 568 NULL, 569 NULL, 570 (LPBYTE)&pProfile->dwPreferenceOrder, 571 &dwSize); 572 if (lError == ERROR_SUCCESS) 573 { 574 DPRINT1("PreferenceOrder: %lu\n", pProfile->dwPreferenceOrder); 575 } 576 577 pProfile->dwProfileNumber = dwProfileNumber; 578 579 SendDlgItemMessageW(hwndDlg, IDC_HRDPROFLSTBOX, LB_ADDSTRING, 0, (LPARAM)pProfile->szFriendlyName); 580 581 RegCloseKey(hProfileKey); 582 } 583 584 585 static 586 BOOL 587 GetProfiles(HWND hwndDlg) 588 { 589 PPROFILEDATA pProfileData; 590 WCHAR szName[8]; 591 DWORD dwNameLength; 592 DWORD dwProfileNumber; 593 DWORD dwIndex = 0; 594 HKEY hKey; 595 LONG lError; 596 597 pProfileData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PROFILEDATA)); 598 if (pProfileData == NULL) 599 return FALSE; 600 601 pProfileData->dwLastProfile = (DWORD)-1; 602 pProfileData->dwSelectedProfileIndex = (DWORD)-1; 603 604 if (!GetProfileCount(&pProfileData->dwProfileCount)) 605 { 606 HeapFree(GetProcessHeap(), 0, pProfileData); 607 return FALSE; 608 } 609 610 pProfileData->pProfiles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 611 pProfileData->dwProfileCount * sizeof(PROFILE)); 612 if (pProfileData->pProfiles == NULL) 613 { 614 HeapFree(GetProcessHeap(), 0, pProfileData); 615 return FALSE; 616 } 617 618 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pProfileData); 619 620 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, 621 L"System\\CurrentControlSet\\Control\\IDConfigDB\\Hardware Profiles", 622 0, 623 KEY_READ, 624 &hKey) != ERROR_SUCCESS) 625 return FALSE; 626 627 for (dwIndex = 0; dwIndex < pProfileData->dwProfileCount; dwIndex++) 628 { 629 dwNameLength = 8; 630 lError = RegEnumKeyExW(hKey, 631 dwIndex, 632 szName, 633 &dwNameLength, 634 NULL, 635 NULL, 636 NULL, 637 NULL); 638 if (lError != ERROR_SUCCESS) 639 break; 640 641 dwProfileNumber = wcstoul(szName, NULL, 10); 642 DPRINT("Profile name: %S\n", szName); 643 DPRINT("Profile number: %lu\n", dwProfileNumber); 644 645 if ((pProfileData->dwLastProfile == (DWORD)-1) || 646 (pProfileData->dwLastProfile < dwProfileNumber)) 647 pProfileData->dwLastProfile = dwProfileNumber; 648 649 DPRINT("Last Profile number: %lu\n", pProfileData->dwLastProfile); 650 651 GetProfile(hwndDlg, hKey, szName, dwProfileNumber, &pProfileData->pProfiles[dwIndex]); 652 } 653 654 RegCloseKey(hKey); 655 656 return TRUE; 657 } 658 659 660 static 661 BOOL 662 OnInitHardProfDialog(HWND hwndDlg) 663 { 664 DWORD dwWaitInterval; 665 666 DPRINT("OnInitHardProfDialog()\n"); 667 668 SendMessage(GetDlgItem(hwndDlg, IDC_HRDPROFUP), 669 BM_SETIMAGE,(WPARAM)IMAGE_ICON, 670 (LPARAM)(HANDLE)LoadIcon(hApplet, MAKEINTRESOURCE(IDI_UP))); 671 SendMessage(GetDlgItem(hwndDlg, IDC_HRDPROFDWN), 672 BM_SETIMAGE,(WPARAM)IMAGE_ICON, 673 (LPARAM)(HANDLE)LoadIcon(hApplet, MAKEINTRESOURCE(IDI_DOWN))); 674 675 if (!GetProfiles(hwndDlg)) 676 return FALSE; 677 678 SendDlgItemMessageW(hwndDlg, IDC_HRDPROFUPDWN, UDM_SETRANGE, (WPARAM)0, (LPARAM)MAKELONG((SHORT)500, 0)); 679 680 dwWaitInterval = GetUserWaitInterval(); 681 if (dwWaitInterval == (DWORD)-1) 682 { 683 CheckDlgButton(hwndDlg, IDC_HRDPROFWAIT, BST_CHECKED); 684 SendDlgItemMessageW(hwndDlg, IDC_HRDPROFUPDWN, UDM_SETPOS, 0, 30); 685 EnableWindow(GetDlgItem(hwndDlg, IDC_HRDPROFEDIT), FALSE); 686 } 687 else 688 { 689 CheckDlgButton(hwndDlg, IDC_HRDPROFSELECT, BST_CHECKED); 690 SendDlgItemMessageW(hwndDlg, IDC_HRDPROFUPDWN, UDM_SETPOS, 0, dwWaitInterval); 691 } 692 693 return TRUE; 694 } 695 696 697 static 698 VOID 699 OnOk(HWND hwndDlg) 700 { 701 DWORD dwWaitInterval; 702 703 if (IsDlgButtonChecked(hwndDlg, IDC_HRDPROFWAIT) == BST_CHECKED) 704 { 705 dwWaitInterval = (DWORD)-1; 706 } 707 else 708 { 709 dwWaitInterval = LOWORD(SendDlgItemMessageW(hwndDlg, IDC_HRDPROFUPDWN, UDM_GETPOS, 0, 0)); 710 } 711 712 SetUserWaitInterval(dwWaitInterval); 713 } 714 715 716 /* Property page dialog callback */ 717 INT_PTR 718 CALLBACK 719 HardProfDlgProc(HWND hwndDlg, 720 UINT uMsg, 721 WPARAM wParam, 722 LPARAM lParam) 723 { 724 PPROFILEDATA pProfileData; 725 726 UNREFERENCED_PARAMETER(lParam); 727 UNREFERENCED_PARAMETER(wParam); 728 UNREFERENCED_PARAMETER(hwndDlg); 729 730 pProfileData = (PPROFILEDATA)GetWindowLongPtr(hwndDlg, DWLP_USER); 731 732 switch (uMsg) 733 { 734 case WM_INITDIALOG: 735 return OnInitHardProfDialog(hwndDlg); 736 737 case WM_DESTROY: 738 if (pProfileData != NULL) 739 { 740 if (pProfileData->pProfiles != NULL) 741 HeapFree(GetProcessHeap(), 0, pProfileData->pProfiles); 742 HeapFree(GetProcessHeap(), 0, pProfileData); 743 } 744 break; 745 746 case WM_COMMAND: 747 switch (LOWORD(wParam)) 748 { 749 case IDC_HRDPROFPROP: 750 HardwareProfileProperties(hwndDlg, pProfileData); 751 break; 752 753 case IDC_HRDPROFCOPY: 754 CopyHardwareProfile(hwndDlg, pProfileData); 755 break; 756 757 case IDC_HRDPROFRENAME: 758 RenameHardwareProfile(hwndDlg, pProfileData); 759 break; 760 761 case IDC_HRDPROFDEL: 762 DeleteHardwareProfile(hwndDlg, pProfileData); 763 break; 764 765 case IDC_HRDPROFUP: 766 MoveHardwareProfile(hwndDlg, pProfileData, TRUE); 767 break; 768 769 case IDC_HRDPROFDWN: 770 MoveHardwareProfile(hwndDlg, pProfileData, FALSE); 771 break; 772 773 case IDC_HRDPROFWAIT: 774 EnableWindow(GetDlgItem(hwndDlg, IDC_HRDPROFEDIT), FALSE); 775 return TRUE; 776 777 case IDC_HRDPROFSELECT: 778 EnableWindow(GetDlgItem(hwndDlg, IDC_HRDPROFEDIT), TRUE); 779 return TRUE; 780 781 case IDC_HRDPROFLSTBOX: 782 if (HIWORD(wParam) == LBN_SELCHANGE) 783 { 784 pProfileData->dwSelectedProfileIndex = (DWORD)SendDlgItemMessage(hwndDlg, IDC_HRDPROFLSTBOX, LB_GETCURSEL, 0, 0); 785 UpdateButtons(hwndDlg, pProfileData); 786 } 787 return TRUE; 788 789 case IDOK: 790 OnOk(hwndDlg); 791 792 case IDCANCEL: 793 EndDialog(hwndDlg, LOWORD(wParam)); 794 return TRUE; 795 } 796 break; 797 } 798 799 return FALSE; 800 } 801