aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Hall <r.sean.hall@gmail.com>2020-06-22 19:07:25 +1000
committerSean Hall <r.sean.hall@gmail.com>2020-06-24 20:23:44 +1000
commit4725cea30832be9113269ef567f196ea3d91cb78 (patch)
tree8e3fa64e69b7da9e8e554bbd70c8876f81e3206d
parent7fc25bc32547277c38bbedceb39c454843af8aac (diff)
downloadwix-4725cea30832be9113269ef567f196ea3d91cb78.tar.gz
wix-4725cea30832be9113269ef567f196ea3d91cb78.tar.bz2
wix-4725cea30832be9113269ef567f196ea3d91cb78.zip
Add ThmExit macros to allow capturing thmutil specific errors.
-rw-r--r--src/dutil/dutil.vcxproj1
-rw-r--r--src/dutil/dutil.vcxproj.filters3
-rw-r--r--src/dutil/inc/dutil.h8
-rw-r--r--src/dutil/inc/dutilsources.h64
-rw-r--r--src/dutil/precomp.h1
-rw-r--r--src/dutil/thmutil.cpp554
6 files changed, 354 insertions, 277 deletions
diff --git a/src/dutil/dutil.vcxproj b/src/dutil/dutil.vcxproj
index d6374f19..af8385d1 100644
--- a/src/dutil/dutil.vcxproj
+++ b/src/dutil/dutil.vcxproj
@@ -140,6 +140,7 @@
140 <ClInclude Include="inc\dirutil.h" /> 140 <ClInclude Include="inc\dirutil.h" />
141 <ClInclude Include="inc\dlutil.h" /> 141 <ClInclude Include="inc\dlutil.h" />
142 <ClInclude Include="inc\dutil.h" /> 142 <ClInclude Include="inc\dutil.h" />
143 <ClInclude Include="inc\dutilsources.h" />
143 <ClInclude Include="inc\eseutil.h" /> 144 <ClInclude Include="inc\eseutil.h" />
144 <ClInclude Include="inc\fileutil.h" /> 145 <ClInclude Include="inc\fileutil.h" />
145 <ClInclude Include="inc\gdiputil.h" /> 146 <ClInclude Include="inc\gdiputil.h" />
diff --git a/src/dutil/dutil.vcxproj.filters b/src/dutil/dutil.vcxproj.filters
index acf7591c..4dd90fdd 100644
--- a/src/dutil/dutil.vcxproj.filters
+++ b/src/dutil/dutil.vcxproj.filters
@@ -344,6 +344,9 @@
344 <ClInclude Include="inc\deputil.h"> 344 <ClInclude Include="inc\deputil.h">
345 <Filter>Header Files</Filter> 345 <Filter>Header Files</Filter>
346 </ClInclude> 346 </ClInclude>
347 <ClInclude Include="inc\dutilsources.h">
348 <Filter>Header Files</Filter>
349 </ClInclude>
347 </ItemGroup> 350 </ItemGroup>
348 <ItemGroup> 351 <ItemGroup>
349 <None Include="xsd\thmutil.xsd"> 352 <None Include="xsd\thmutil.xsd">
diff --git a/src/dutil/inc/dutil.h b/src/dutil/inc/dutil.h
index efaeb5a9..6b57b48a 100644
--- a/src/dutil/inc/dutil.h
+++ b/src/dutil/inc/dutil.h
@@ -1,6 +1,7 @@
1#pragma once 1#pragma once
2// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. 2// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
3 3
4#include "dutilsources.h"
4 5
5#define DAPI __stdcall 6#define DAPI __stdcall
6#define DAPIV __cdecl // used only for functions taking variable length arguments 7#define DAPIV __cdecl // used only for functions taking variable length arguments
@@ -20,13 +21,6 @@ typedef enum REPORT_LEVEL
20 REPORT_ERROR, // always gets reported, but can never be specified 21 REPORT_ERROR, // always gets reported, but can never be specified
21} REPORT_LEVEL; 22} REPORT_LEVEL;
22 23
23typedef enum DUTIL_SOURCE
24{
25 DUTIL_SOURCE_UNKNOWN,
26
27 DUTIL_SOURCE_EXTERNAL = 256,
28} DUTIL_SOURCE;
29
30// asserts and traces 24// asserts and traces
31typedef BOOL (DAPI *DUTIL_ASSERTDISPLAYFUNCTION)(__in_z LPCSTR sz); 25typedef BOOL (DAPI *DUTIL_ASSERTDISPLAYFUNCTION)(__in_z LPCSTR sz);
32 26
diff --git a/src/dutil/inc/dutilsources.h b/src/dutil/inc/dutilsources.h
new file mode 100644
index 00000000..c88ada37
--- /dev/null
+++ b/src/dutil/inc/dutilsources.h
@@ -0,0 +1,64 @@
1#pragma once
2// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
3
4typedef enum DUTIL_SOURCE
5{
6 DUTIL_SOURCE_UNKNOWN,
7 DUTIL_SOURCE_ACLUTIL,
8 DUTIL_SOURCE_APPUTIL,
9 DUTIL_SOURCE_APUPUTIL,
10 DUTIL_SOURCE_ATOMUTIL,
11 DUTIL_SOURCE_BUFFUTIL,
12 DUTIL_SOURCE_BUTIL,
13 DUTIL_SOURCE_CABCUTIL,
14 DUTIL_SOURCE_CABUTIL,
15 DUTIL_SOURCE_CERTUTIL,
16 DUTIL_SOURCE_CONUTIL,
17 DUTIL_SOURCE_CRYPUTIL,
18 DUTIL_SOURCE_DEPUTIL,
19 DUTIL_SOURCE_DICTUTIL,
20 DUTIL_SOURCE_DIRUTIL,
21 DUTIL_SOURCE_DLUTIL,
22 DUTIL_SOURCE_DUTIL,
23 DUTIL_SOURCE_ESEUTIL,
24 DUTIL_SOURCE_FILEUTIL,
25 DUTIL_SOURCE_GDIPUTIL,
26 DUTIL_SOURCE_GUIDUTIL,
27 DUTIL_SOURCE_IIS7UTIL,
28 DUTIL_SOURCE_INETUTIL,
29 DUTIL_SOURCE_INIUTIL,
30 DUTIL_SOURCE_JSONUTIL,
31 DUTIL_SOURCE_LOCUTIL,
32 DUTIL_SOURCE_LOGUTIL,
33 DUTIL_SOURCE_MEMUTIL,
34 DUTIL_SOURCE_METAUTIL,
35 DUTIL_SOURCE_MONUTIL,
36 DUTIL_SOURCE_OSUTIL,
37 DUTIL_SOURCE_PATHUTIL,
38 DUTIL_SOURCE_PERFUTIL,
39 DUTIL_SOURCE_POLCUTIL,
40 DUTIL_SOURCE_PROCUTIL,
41 DUTIL_SOURCE_REGUTIL,
42 DUTIL_SOURCE_RESRUTIL,
43 DUTIL_SOURCE_RESWUTIL,
44 DUTIL_SOURCE_REXUTIL,
45 DUTIL_SOURCE_RMUTIL,
46 DUTIL_SOURCE_RSSUTIL,
47 DUTIL_SOURCE_SCEUTIL,
48 DUTIL_SOURCE_SCZUTIL,
49 DUTIL_SOURCE_SHELUTIL,
50 DUTIL_SOURCE_SQLUTIL,
51 DUTIL_SOURCE_SRPUTIL,
52 DUTIL_SOURCE_STRUTIL,
53 DUTIL_SOURCE_SVCUTIL,
54 DUTIL_SOURCE_THMUTIL,
55 DUTIL_SOURCE_TIMEUTIL,
56 DUTIL_SOURCE_UNCUTIL,
57 DUTIL_SOURCE_URIUTIL,
58 DUTIL_SOURCE_USERUTIL,
59 DUTIL_SOURCE_WIUTIL,
60 DUTIL_SOURCE_WUAUTIL,
61 DUTIL_SOURCE_XMLUTIL,
62
63 DUTIL_SOURCE_EXTERNAL = 256,
64} DUTIL_SOURCE;
diff --git a/src/dutil/precomp.h b/src/dutil/precomp.h
index 374d0fc1..eebdd160 100644
--- a/src/dutil/precomp.h
+++ b/src/dutil/precomp.h
@@ -40,6 +40,7 @@
40#include <commctrl.h> 40#include <commctrl.h>
41#include <dbt.h> 41#include <dbt.h>
42 42
43#include "dutilsources.h"
43#include "dutil.h" 44#include "dutil.h"
44#include "aclutil.h" 45#include "aclutil.h"
45#include "atomutil.h" 46#include "atomutil.h"
diff --git a/src/dutil/thmutil.cpp b/src/dutil/thmutil.cpp
index cae92d92..1939c64d 100644
--- a/src/dutil/thmutil.cpp
+++ b/src/dutil/thmutil.cpp
@@ -3,6 +3,20 @@
3#include "precomp.h" 3#include "precomp.h"
4 4
5 5
6// Exit macros
7#define ThmExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_THMUTIL, x, s, __VA_ARGS__)
8#define ThmExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_THMUTIL, x, s, __VA_ARGS__)
9#define ThmExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_THMUTIL, x, s, __VA_ARGS__)
10#define ThmExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_THMUTIL, x, s, __VA_ARGS__)
11#define ThmExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_THMUTIL, x, s, __VA_ARGS__)
12#define ThmExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_THMUTIL, x, s, __VA_ARGS__)
13#define ThmExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_THMUTIL, p, x, e, s, __VA_ARGS__)
14#define ThmExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_THMUTIL, p, x, s, __VA_ARGS__)
15#define ThmExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_THMUTIL, p, x, e, s, __VA_ARGS__)
16#define ThmExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_THMUTIL, p, x, s, __VA_ARGS__)
17#define ThmExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_THMUTIL, e, x, s, __VA_ARGS__)
18#define ThmExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_THMUTIL, g, x, s, __VA_ARGS__)
19
6#ifndef BS_COMMANDLINK 20#ifndef BS_COMMANDLINK
7#define BS_COMMANDLINK 0x0000000EL 21#define BS_COMMANDLINK 0x0000000EL
8#endif 22#endif
@@ -362,16 +376,16 @@ DAPI_(HRESULT) ThemeInitialize(
362 INITCOMMONCONTROLSEX icex = { }; 376 INITCOMMONCONTROLSEX icex = { };
363 377
364 hr = XmlInitialize(); 378 hr = XmlInitialize();
365 ExitOnFailure(hr, "Failed to initialize XML."); 379 ThmExitOnFailure(hr, "Failed to initialize XML.");
366 380
367 hr = RegisterWindowClasses(hModule); 381 hr = RegisterWindowClasses(hModule);
368 ExitOnFailure(hr, "Failed to register theme window classes."); 382 ThmExitOnFailure(hr, "Failed to register theme window classes.");
369 383
370 // Initialize GDI+ and common controls. 384 // Initialize GDI+ and common controls.
371 vgsi.SuppressBackgroundThread = TRUE; 385 vgsi.SuppressBackgroundThread = TRUE;
372 386
373 hr = GdipInitialize(&vgsi, &vgdiToken, &vgso); 387 hr = GdipInitialize(&vgsi, &vgdiToken, &vgso);
374 ExitOnFailure(hr, "Failed to initialize GDI+."); 388 ThmExitOnFailure(hr, "Failed to initialize GDI+.");
375 389
376 icex.dwSize = sizeof(INITCOMMONCONTROLSEX); 390 icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
377 icex.dwICC = ICC_STANDARD_CLASSES | ICC_PROGRESS_CLASS | ICC_LISTVIEW_CLASSES | ICC_TREEVIEW_CLASSES | ICC_TAB_CLASSES | ICC_LINK_CLASS; 391 icex.dwICC = ICC_STANDARD_CLASSES | ICC_PROGRESS_CLASS | ICC_LISTVIEW_CLASSES | ICC_TREEVIEW_CLASSES | ICC_TAB_CLASSES | ICC_LINK_CLASS;
@@ -424,13 +438,13 @@ DAPI_(HRESULT) ThemeLoadFromFile(
424 LPWSTR sczRelativePath = NULL; 438 LPWSTR sczRelativePath = NULL;
425 439
426 hr = XmlLoadDocumentFromFile(wzThemeFile, &pixd); 440 hr = XmlLoadDocumentFromFile(wzThemeFile, &pixd);
427 ExitOnFailure(hr, "Failed to load theme resource as XML document."); 441 ThmExitOnFailure(hr, "Failed to load theme resource as XML document.");
428 442
429 hr = PathGetDirectory(wzThemeFile, &sczRelativePath); 443 hr = PathGetDirectory(wzThemeFile, &sczRelativePath);
430 ExitOnFailure(hr, "Failed to get relative path from theme file."); 444 ThmExitOnFailure(hr, "Failed to get relative path from theme file.");
431 445
432 hr = ParseTheme(NULL, sczRelativePath, pixd, ppTheme); 446 hr = ParseTheme(NULL, sczRelativePath, pixd, ppTheme);
433 ExitOnFailure(hr, "Failed to parse theme."); 447 ThmExitOnFailure(hr, "Failed to parse theme.");
434 448
435LExit: 449LExit:
436 ReleaseStr(sczRelativePath); 450 ReleaseStr(sczRelativePath);
@@ -453,16 +467,16 @@ DAPI_(HRESULT) ThemeLoadFromResource(
453 IXMLDOMDocument* pixd = NULL; 467 IXMLDOMDocument* pixd = NULL;
454 468
455 hr = ResReadData(hModule, szResource, &pvResource, &cbResource); 469 hr = ResReadData(hModule, szResource, &pvResource, &cbResource);
456 ExitOnFailure(hr, "Failed to read theme from resource."); 470 ThmExitOnFailure(hr, "Failed to read theme from resource.");
457 471
458 hr = StrAllocStringAnsi(&sczXml, reinterpret_cast<LPCSTR>(pvResource), cbResource, CP_UTF8); 472 hr = StrAllocStringAnsi(&sczXml, reinterpret_cast<LPCSTR>(pvResource), cbResource, CP_UTF8);
459 ExitOnFailure(hr, "Failed to convert XML document data from UTF-8 to unicode string."); 473 ThmExitOnFailure(hr, "Failed to convert XML document data from UTF-8 to unicode string.");
460 474
461 hr = XmlLoadDocument(sczXml, &pixd); 475 hr = XmlLoadDocument(sczXml, &pixd);
462 ExitOnFailure(hr, "Failed to load theme resource as XML document."); 476 ThmExitOnFailure(hr, "Failed to load theme resource as XML document.");
463 477
464 hr = ParseTheme(hModule, NULL, pixd, ppTheme); 478 hr = ParseTheme(hModule, NULL, pixd, ppTheme);
465 ExitOnFailure(hr, "Failed to parse theme."); 479 ThmExitOnFailure(hr, "Failed to parse theme.");
466 480
467LExit: 481LExit:
468 ReleaseObject(pixd); 482 ReleaseObject(pixd);
@@ -524,7 +538,7 @@ DAPI_(HRESULT) ThemeRegisterVariableCallbacks(
524 ) 538 )
525{ 539{
526 HRESULT hr = S_OK; 540 HRESULT hr = S_OK;
527 ExitOnNull(pTheme, hr, S_FALSE, "Theme must be loaded first."); 541 ThmExitOnNull(pTheme, hr, S_FALSE, "Theme must be loaded first.");
528 542
529 pTheme->pfnEvaluateCondition = pfnEvaluateCondition; 543 pTheme->pfnEvaluateCondition = pfnEvaluateCondition;
530 pTheme->pfnFormatString = pfnFormatString; 544 pTheme->pfnFormatString = pfnFormatString;
@@ -569,7 +583,7 @@ DAPI_(HRESULT) ThemeLocalize(
569 LPWSTR sczCaption = NULL; 583 LPWSTR sczCaption = NULL;
570 584
571 hr = LocLocalizeString(pWixLoc, &pTheme->sczCaption); 585 hr = LocLocalizeString(pWixLoc, &pTheme->sczCaption);
572 ExitOnFailure(hr, "Failed to localize theme caption."); 586 ThmExitOnFailure(hr, "Failed to localize theme caption.");
573 587
574 if (pTheme->pfnFormatString) 588 if (pTheme->pfnFormatString)
575 { 589 {
@@ -599,12 +613,12 @@ DAPI_(HRESULT) ThemeLoadStrings(
599 ) 613 )
600{ 614{
601 HRESULT hr = S_OK; 615 HRESULT hr = S_OK;
602 ExitOnNull(pTheme, hr, S_FALSE, "Theme must be loaded first."); 616 ThmExitOnNull(pTheme, hr, S_FALSE, "Theme must be loaded first.");
603 617
604 if (UINT_MAX != pTheme->uStringId) 618 if (UINT_MAX != pTheme->uStringId)
605 { 619 {
606 hr = ResReadString(hResModule, pTheme->uStringId, &pTheme->sczCaption); 620 hr = ResReadString(hResModule, pTheme->uStringId, &pTheme->sczCaption);
607 ExitOnFailure(hr, "Failed to load theme caption."); 621 ThmExitOnFailure(hr, "Failed to load theme caption.");
608 } 622 }
609 623
610 hr = LoadControlsString(pTheme->cControls, pTheme->rgControls, hResModule); 624 hr = LoadControlsString(pTheme->cControls, pTheme->rgControls, hResModule);
@@ -627,12 +641,12 @@ DAPI_(HRESULT) ThemeLoadRichEditFromFile(
627 HWND hWnd = ::GetDlgItem(pTheme->hwndParent, dwControl); 641 HWND hWnd = ::GetDlgItem(pTheme->hwndParent, dwControl);
628 642
629 hr = PathRelativeToModule(&sczFile, wzFileName, hModule); 643 hr = PathRelativeToModule(&sczFile, wzFileName, hModule);
630 ExitOnFailure(hr, "Failed to read resource data."); 644 ThmExitOnFailure(hr, "Failed to read resource data.");
631 645
632 hFile = ::CreateFileW(sczFile, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL); 646 hFile = ::CreateFileW(sczFile, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
633 if (INVALID_HANDLE_VALUE == hFile) 647 if (INVALID_HANDLE_VALUE == hFile)
634 { 648 {
635 ExitWithLastError(hr, "Failed to open RTF file."); 649 ThmExitWithLastError(hr, "Failed to open RTF file.");
636 } 650 }
637 else 651 else
638 { 652 {
@@ -649,7 +663,7 @@ DAPI_(HRESULT) ThemeLoadRichEditFromFile(
649 663
650 ::SendMessageW(hWnd, EM_STREAMIN, SF_RTF, reinterpret_cast<LPARAM>(&es)); 664 ::SendMessageW(hWnd, EM_STREAMIN, SF_RTF, reinterpret_cast<LPARAM>(&es));
651 hr = es.dwError; 665 hr = es.dwError;
652 ExitOnFailure(hr, "Failed to update RTF stream."); 666 ThmExitOnFailure(hr, "Failed to update RTF stream.");
653 } 667 }
654 668
655LExit: 669LExit:
@@ -682,14 +696,14 @@ DAPI_(HRESULT) ThemeLoadRichEditFromResourceToHWnd(
682 EDITSTREAM es = { }; 696 EDITSTREAM es = { };
683 697
684 hr = ResReadData(hModule, szResourceName, reinterpret_cast<LPVOID*>(&buffer.rgbData), &buffer.cbData); 698 hr = ResReadData(hModule, szResourceName, reinterpret_cast<LPVOID*>(&buffer.rgbData), &buffer.cbData);
685 ExitOnFailure(hr, "Failed to read resource data."); 699 ThmExitOnFailure(hr, "Failed to read resource data.");
686 700
687 es.pfnCallback = RichEditStreamFromMemoryCallback; 701 es.pfnCallback = RichEditStreamFromMemoryCallback;
688 es.dwCookie = reinterpret_cast<DWORD_PTR>(&buffer); 702 es.dwCookie = reinterpret_cast<DWORD_PTR>(&buffer);
689 703
690 ::SendMessageW(hWnd, EM_STREAMIN, SF_RTF, reinterpret_cast<LPARAM>(&es)); 704 ::SendMessageW(hWnd, EM_STREAMIN, SF_RTF, reinterpret_cast<LPARAM>(&es));
691 hr = es.dwError; 705 hr = es.dwError;
692 ExitOnFailure(hr, "Failed to update RTF stream."); 706 ThmExitOnFailure(hr, "Failed to update RTF stream.");
693 707
694LExit: 708LExit:
695 return hr; 709 return hr;
@@ -985,7 +999,7 @@ DAPI_(HRESULT) ThemeShowPageEx(
985 else 999 else
986 { 1000 {
987 hr = MemEnsureArraySize(reinterpret_cast<LPVOID*>(&pPage->rgSavedVariables), pPage->cControlIndices, sizeof(THEME_SAVEDVARIABLE), pPage->cControlIndices); 1001 hr = MemEnsureArraySize(reinterpret_cast<LPVOID*>(&pPage->rgSavedVariables), pPage->cControlIndices, sizeof(THEME_SAVEDVARIABLE), pPage->cControlIndices);
988 ExitOnNull(pPage->rgSavedVariables, hr, E_OUTOFMEMORY, "Failed to allocate memory for saved variables."); 1002 ThmExitOnNull(pPage->rgSavedVariables, hr, E_OUTOFMEMORY, "Failed to allocate memory for saved variables.");
989 1003
990 SecureZeroMemory(pPage->rgSavedVariables, MemSize(pPage->rgSavedVariables)); 1004 SecureZeroMemory(pPage->rgSavedVariables, MemSize(pPage->rgSavedVariables));
991 pPage->cSavedVariables = pPage->cControlIndices; 1005 pPage->cSavedVariables = pPage->cControlIndices;
@@ -998,7 +1012,7 @@ DAPI_(HRESULT) ThemeShowPageEx(
998 } 1012 }
999 1013
1000 hr = ShowControls(pTheme, NULL, nCmdShow, fSaveEditboxes, reason, dwPage); 1014 hr = ShowControls(pTheme, NULL, nCmdShow, fSaveEditboxes, reason, dwPage);
1001 ExitOnFailure(hr, "Failed to show page controls."); 1015 ThmExitOnFailure(hr, "Failed to show page controls.");
1002 1016
1003LExit: 1017LExit:
1004 return hr; 1018 return hr;
@@ -1184,27 +1198,27 @@ DAPI_(HRESULT) ThemeDrawControl(
1184 { 1198 {
1185 case THEME_CONTROL_TYPE_BUTTON: 1199 case THEME_CONTROL_TYPE_BUTTON:
1186 hr = DrawButton(pTheme, pdis, pControl); 1200 hr = DrawButton(pTheme, pdis, pControl);
1187 ExitOnFailure(hr, "Failed to draw button."); 1201 ThmExitOnFailure(hr, "Failed to draw button.");
1188 break; 1202 break;
1189 1203
1190 case THEME_CONTROL_TYPE_HYPERLINK: 1204 case THEME_CONTROL_TYPE_HYPERLINK:
1191 hr = DrawHyperlink(pTheme, pdis, pControl); 1205 hr = DrawHyperlink(pTheme, pdis, pControl);
1192 ExitOnFailure(hr, "Failed to draw hyperlink."); 1206 ThmExitOnFailure(hr, "Failed to draw hyperlink.");
1193 break; 1207 break;
1194 1208
1195 case THEME_CONTROL_TYPE_IMAGE: 1209 case THEME_CONTROL_TYPE_IMAGE:
1196 hr = DrawImage(pTheme, pdis, pControl); 1210 hr = DrawImage(pTheme, pdis, pControl);
1197 ExitOnFailure(hr, "Failed to draw image."); 1211 ThmExitOnFailure(hr, "Failed to draw image.");
1198 break; 1212 break;
1199 1213
1200 case THEME_CONTROL_TYPE_PROGRESSBAR: 1214 case THEME_CONTROL_TYPE_PROGRESSBAR:
1201 hr = DrawProgressBar(pTheme, pdis, pControl); 1215 hr = DrawProgressBar(pTheme, pdis, pControl);
1202 ExitOnFailure(hr, "Failed to draw progress bar."); 1216 ThmExitOnFailure(hr, "Failed to draw progress bar.");
1203 break; 1217 break;
1204 1218
1205 default: 1219 default:
1206 hr = E_UNEXPECTED; 1220 hr = E_UNEXPECTED;
1207 ExitOnRootFailure(hr, "Did not specify an owner draw control to draw."); 1221 ThmExitOnRootFailure(hr, "Did not specify an owner draw control to draw.");
1208 } 1222 }
1209 1223
1210LExit: 1224LExit:
@@ -1321,7 +1335,7 @@ DAPI_(HRESULT) ThemeSetProgressControl(
1321 { 1335 {
1322 if (!::InvalidateRect(hWnd, NULL, FALSE)) 1336 if (!::InvalidateRect(hWnd, NULL, FALSE))
1323 { 1337 {
1324 ExitWithLastError(hr, "Failed to invalidate progress bar window."); 1338 ThmExitWithLastError(hr, "Failed to invalidate progress bar window.");
1325 } 1339 }
1326 } 1340 }
1327 else 1341 else
@@ -1367,7 +1381,7 @@ DAPI_(HRESULT) ThemeSetProgressControlColor(
1367 1381
1368 if (!::InvalidateRect(hWnd, NULL, FALSE)) 1382 if (!::InvalidateRect(hWnd, NULL, FALSE))
1369 { 1383 {
1370 ExitWithLastError(hr, "Failed to invalidate progress bar window."); 1384 ThmExitWithLastError(hr, "Failed to invalidate progress bar window.");
1371 } 1385 }
1372 1386
1373 hr = S_OK; 1387 hr = S_OK;
@@ -1409,7 +1423,7 @@ DAPI_(HRESULT) ThemeSetTextControlEx(
1409 1423
1410 if (!::SetWindowTextW(hWnd, wzText)) 1424 if (!::SetWindowTextW(hWnd, wzText))
1411 { 1425 {
1412 ExitWithLastError(hr, "Failed to set control text."); 1426 ThmExitWithLastError(hr, "Failed to set control text.");
1413 } 1427 }
1414 1428
1415 if (fUpdate) 1429 if (fUpdate)
@@ -1436,14 +1450,14 @@ DAPI_(HRESULT) ThemeGetTextControl(
1436 1450
1437 // Ensure the string has room for at least one character. 1451 // Ensure the string has room for at least one character.
1438 hr = StrMaxLength(*psczText, reinterpret_cast<DWORD_PTR*>(&cchText)); 1452 hr = StrMaxLength(*psczText, reinterpret_cast<DWORD_PTR*>(&cchText));
1439 ExitOnFailure(hr, "Failed to get text buffer length."); 1453 ThmExitOnFailure(hr, "Failed to get text buffer length.");
1440 1454
1441 if (!cchText) 1455 if (!cchText)
1442 { 1456 {
1443 cchText = GROW_WINDOW_TEXT; 1457 cchText = GROW_WINDOW_TEXT;
1444 1458
1445 hr = StrAlloc(psczText, cchText); 1459 hr = StrAlloc(psczText, cchText);
1446 ExitOnFailure(hr, "Failed to grow text buffer."); 1460 ThmExitOnFailure(hr, "Failed to grow text buffer.");
1447 } 1461 }
1448 1462
1449 // Read (and keep growing buffer) until we finally read less than there 1463 // Read (and keep growing buffer) until we finally read less than there
@@ -1460,7 +1474,7 @@ DAPI_(HRESULT) ThemeGetTextControl(
1460 cchText = cchTextRead + GROW_WINDOW_TEXT; 1474 cchText = cchTextRead + GROW_WINDOW_TEXT;
1461 1475
1462 hr = StrAlloc(psczText, cchText); 1476 hr = StrAlloc(psczText, cchText);
1463 ExitOnFailure(hr, "Failed to grow text buffer again."); 1477 ThmExitOnFailure(hr, "Failed to grow text buffer again.");
1464 } 1478 }
1465 } 1479 }
1466 1480
@@ -1477,7 +1491,7 @@ DAPI_(HRESULT) ThemeUpdateCaption(
1477 HRESULT hr = S_OK; 1491 HRESULT hr = S_OK;
1478 1492
1479 hr = StrAllocString(&pTheme->sczCaption, wzCaption, 0); 1493 hr = StrAllocString(&pTheme->sczCaption, wzCaption, 0);
1480 ExitOnFailure(hr, "Failed to update theme caption."); 1494 ThmExitOnFailure(hr, "Failed to update theme caption.");
1481 1495
1482LExit: 1496LExit:
1483 return hr; 1497 return hr;
@@ -1532,7 +1546,7 @@ static HRESULT RegisterWindowClasses(
1532 // Base the theme hyperlink class on a button but give it the "hand" icon. 1546 // Base the theme hyperlink class on a button but give it the "hand" icon.
1533 if (!::GetClassInfoW(NULL, WC_BUTTONW, &wcHyperlink)) 1547 if (!::GetClassInfoW(NULL, WC_BUTTONW, &wcHyperlink))
1534 { 1548 {
1535 ExitWithLastError(hr, "Failed to get button window class."); 1549 ThmExitWithLastError(hr, "Failed to get button window class.");
1536 } 1550 }
1537 1551
1538 wcHyperlink.lpszClassName = THEME_WC_HYPERLINK; 1552 wcHyperlink.lpszClassName = THEME_WC_HYPERLINK;
@@ -1543,7 +1557,7 @@ static HRESULT RegisterWindowClasses(
1543 1557
1544 if (!::RegisterClassW(&wcHyperlink)) 1558 if (!::RegisterClassW(&wcHyperlink))
1545 { 1559 {
1546 ExitWithLastError(hr, "Failed to get button window class."); 1560 ThmExitWithLastError(hr, "Failed to get button window class.");
1547 } 1561 }
1548 vhHyperlinkRegisteredModule = hModule; 1562 vhHyperlinkRegisteredModule = hModule;
1549 1563
@@ -1554,7 +1568,7 @@ static HRESULT RegisterWindowClasses(
1554 wcPanel.lpszClassName = THEME_WC_PANEL; 1568 wcPanel.lpszClassName = THEME_WC_PANEL;
1555 if (!::RegisterClassW(&wcPanel)) 1569 if (!::RegisterClassW(&wcPanel))
1556 { 1570 {
1557 ExitWithLastError(hr, "Failed to register window."); 1571 ThmExitWithLastError(hr, "Failed to register window.");
1558 } 1572 }
1559 vhPanelRegisteredModule = hModule; 1573 vhPanelRegisteredModule = hModule;
1560 1574
@@ -1577,24 +1591,24 @@ static HRESULT ParseTheme(
1577 IXMLDOMElement *pThemeElement = NULL; 1591 IXMLDOMElement *pThemeElement = NULL;
1578 1592
1579 hr = pixd->get_documentElement(&pThemeElement); 1593 hr = pixd->get_documentElement(&pThemeElement);
1580 ExitOnFailure(hr, "Failed to get theme element."); 1594 ThmExitOnFailure(hr, "Failed to get theme element.");
1581 1595
1582 pTheme = static_cast<THEME*>(MemAlloc(sizeof(THEME), TRUE)); 1596 pTheme = static_cast<THEME*>(MemAlloc(sizeof(THEME), TRUE));
1583 ExitOnNull(pTheme, hr, E_OUTOFMEMORY, "Failed to allocate memory for theme."); 1597 ThmExitOnNull(pTheme, hr, E_OUTOFMEMORY, "Failed to allocate memory for theme.");
1584 1598
1585 pTheme->wId = ++wThemeId; 1599 pTheme->wId = ++wThemeId;
1586 1600
1587 // Parse the optional background resource image. 1601 // Parse the optional background resource image.
1588 hr = ParseImage(hModule, wzRelativePath, pThemeElement, &pTheme->hImage); 1602 hr = ParseImage(hModule, wzRelativePath, pThemeElement, &pTheme->hImage);
1589 ExitOnFailure(hr, "Failed while parsing theme image."); 1603 ThmExitOnFailure(hr, "Failed while parsing theme image.");
1590 1604
1591 // Parse the fonts. 1605 // Parse the fonts.
1592 hr = ParseFonts(pThemeElement, pTheme); 1606 hr = ParseFonts(pThemeElement, pTheme);
1593 ExitOnFailure(hr, "Failed to parse theme fonts."); 1607 ThmExitOnFailure(hr, "Failed to parse theme fonts.");
1594 1608
1595 // Parse the window element. 1609 // Parse the window element.
1596 hr = ParseWindow(hModule, wzRelativePath, pThemeElement, pTheme); 1610 hr = ParseWindow(hModule, wzRelativePath, pThemeElement, pTheme);
1597 ExitOnFailure(hr, "Failed to parse theme window element."); 1611 ThmExitOnFailure(hr, "Failed to parse theme window element.");
1598 1612
1599 *ppTheme = pTheme; 1613 *ppTheme = pTheme;
1600 pTheme = NULL; 1614 pTheme = NULL;
@@ -1624,7 +1638,7 @@ static HRESULT ParseImage(
1624 Gdiplus::Bitmap* pBitmap = NULL; 1638 Gdiplus::Bitmap* pBitmap = NULL;
1625 1639
1626 hr = XmlGetAttribute(pElement, L"ImageResource", &bstr); 1640 hr = XmlGetAttribute(pElement, L"ImageResource", &bstr);
1627 ExitOnFailure(hr, "Failed to get image resource attribute."); 1641 ThmExitOnFailure(hr, "Failed to get image resource attribute.");
1628 1642
1629 if (S_OK == hr) 1643 if (S_OK == hr)
1630 { 1644 {
@@ -1640,19 +1654,19 @@ static HRESULT ParseImage(
1640 if (!pBitmap) 1654 if (!pBitmap)
1641 { 1655 {
1642 hr = XmlGetAttribute(pElement, L"ImageFile", &bstr); 1656 hr = XmlGetAttribute(pElement, L"ImageFile", &bstr);
1643 ExitOnFailure(hr, "Failed to get image file attribute."); 1657 ThmExitOnFailure(hr, "Failed to get image file attribute.");
1644 1658
1645 if (S_OK == hr) 1659 if (S_OK == hr)
1646 { 1660 {
1647 if (wzRelativePath) 1661 if (wzRelativePath)
1648 { 1662 {
1649 hr = PathConcat(wzRelativePath, bstr, &sczImageFile); 1663 hr = PathConcat(wzRelativePath, bstr, &sczImageFile);
1650 ExitOnFailure(hr, "Failed to combine image file path."); 1664 ThmExitOnFailure(hr, "Failed to combine image file path.");
1651 } 1665 }
1652 else 1666 else
1653 { 1667 {
1654 hr = PathRelativeToModule(&sczImageFile, bstr, hModule); 1668 hr = PathRelativeToModule(&sczImageFile, bstr, hModule);
1655 ExitOnFailure(hr, "Failed to get image filename."); 1669 ThmExitOnFailure(hr, "Failed to get image filename.");
1656 } 1670 }
1657 1671
1658 hr = GdipBitmapFromFile(sczImageFile, &pBitmap); 1672 hr = GdipBitmapFromFile(sczImageFile, &pBitmap);
@@ -1665,7 +1679,7 @@ static HRESULT ParseImage(
1665 { 1679 {
1666 Gdiplus::Color black; 1680 Gdiplus::Color black;
1667 Gdiplus::Status gs = pBitmap->GetHBITMAP(black, phImage); 1681 Gdiplus::Status gs = pBitmap->GetHBITMAP(black, phImage);
1668 ExitOnGdipFailure(gs, hr, "Failed to convert GDI+ bitmap into HBITMAP."); 1682 ThmExitOnGdipFailure(gs, hr, "Failed to convert GDI+ bitmap into HBITMAP.");
1669 } 1683 }
1670 1684
1671 hr = S_OK; 1685 hr = S_OK;
@@ -1696,37 +1710,37 @@ static HRESULT ParseIcon(
1696 int iResourceId = 0; 1710 int iResourceId = 0;
1697 1711
1698 hr = XmlGetAttribute(pElement, L"IconResource", &bstr); 1712 hr = XmlGetAttribute(pElement, L"IconResource", &bstr);
1699 ExitOnFailure(hr, "Failed to get icon resource attribute."); 1713 ThmExitOnFailure(hr, "Failed to get icon resource attribute.");
1700 1714
1701 if (S_OK == hr) 1715 if (S_OK == hr)
1702 { 1716 {
1703 iResourceId = wcstol(bstr, NULL, 10); 1717 iResourceId = wcstol(bstr, NULL, 10);
1704 1718
1705 *phIcon = reinterpret_cast<HICON>(::LoadImageW(hModule, MAKEINTRESOURCEW(iResourceId), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE)); 1719 *phIcon = reinterpret_cast<HICON>(::LoadImageW(hModule, MAKEINTRESOURCEW(iResourceId), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE));
1706 ExitOnNullWithLastError(*phIcon, hr, "Failed to load icon."); 1720 ThmExitOnNullWithLastError(*phIcon, hr, "Failed to load icon.");
1707 } 1721 }
1708 else 1722 else
1709 { 1723 {
1710 ReleaseNullBSTR(bstr); 1724 ReleaseNullBSTR(bstr);
1711 1725
1712 hr = XmlGetAttribute(pElement, L"IconFile", &bstr); 1726 hr = XmlGetAttribute(pElement, L"IconFile", &bstr);
1713 ExitOnFailure(hr, "Failed to get icon file attribute."); 1727 ThmExitOnFailure(hr, "Failed to get icon file attribute.");
1714 1728
1715 if (S_OK == hr) 1729 if (S_OK == hr)
1716 { 1730 {
1717 if (wzRelativePath) 1731 if (wzRelativePath)
1718 { 1732 {
1719 hr = PathConcat(wzRelativePath, bstr, &sczImageFile); 1733 hr = PathConcat(wzRelativePath, bstr, &sczImageFile);
1720 ExitOnFailure(hr, "Failed to combine image file path."); 1734 ThmExitOnFailure(hr, "Failed to combine image file path.");
1721 } 1735 }
1722 else 1736 else
1723 { 1737 {
1724 hr = PathRelativeToModule(&sczImageFile, bstr, hModule); 1738 hr = PathRelativeToModule(&sczImageFile, bstr, hModule);
1725 ExitOnFailure(hr, "Failed to get image filename."); 1739 ThmExitOnFailure(hr, "Failed to get image filename.");
1726 } 1740 }
1727 1741
1728 *phIcon = reinterpret_cast<HICON>(::LoadImageW(NULL, sczImageFile, IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE)); 1742 *phIcon = reinterpret_cast<HICON>(::LoadImageW(NULL, sczImageFile, IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE));
1729 ExitOnNullWithLastError(*phIcon, hr, "Failed to load icon: %ls.", sczImageFile); 1743 ThmExitOnNullWithLastError(*phIcon, hr, "Failed to load icon: %ls.", sczImageFile);
1730 } 1744 }
1731 } 1745 }
1732 1746
@@ -1755,84 +1769,84 @@ static HRESULT ParseWindow(
1755 { 1769 {
1756 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); 1770 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
1757 } 1771 }
1758 ExitOnFailure(hr, "Failed to find window element."); 1772 ThmExitOnFailure(hr, "Failed to find window element.");
1759 1773
1760 hr = XmlGetYesNoAttribute(pixn, L"AutoResize", &pTheme->fAutoResize); 1774 hr = XmlGetYesNoAttribute(pixn, L"AutoResize", &pTheme->fAutoResize);
1761 if (E_NOTFOUND == hr) 1775 if (E_NOTFOUND == hr)
1762 { 1776 {
1763 hr = S_OK; 1777 hr = S_OK;
1764 } 1778 }
1765 ExitOnFailure(hr, "Failed to get window AutoResize attribute."); 1779 ThmExitOnFailure(hr, "Failed to get window AutoResize attribute.");
1766 1780
1767 hr = XmlGetAttributeNumber(pixn, L"Width", reinterpret_cast<DWORD*>(&pTheme->nWidth)); 1781 hr = XmlGetAttributeNumber(pixn, L"Width", reinterpret_cast<DWORD*>(&pTheme->nWidth));
1768 if (S_FALSE == hr) 1782 if (S_FALSE == hr)
1769 { 1783 {
1770 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); 1784 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
1771 ExitOnRootFailure(hr, "Failed to find window Width attribute."); 1785 ThmExitOnRootFailure(hr, "Failed to find window Width attribute.");
1772 } 1786 }
1773 ExitOnFailure(hr, "Failed to get window Width attribute."); 1787 ThmExitOnFailure(hr, "Failed to get window Width attribute.");
1774 1788
1775 hr = XmlGetAttributeNumber(pixn, L"Height", reinterpret_cast<DWORD*>(&pTheme->nHeight)); 1789 hr = XmlGetAttributeNumber(pixn, L"Height", reinterpret_cast<DWORD*>(&pTheme->nHeight));
1776 if (S_FALSE == hr) 1790 if (S_FALSE == hr)
1777 { 1791 {
1778 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); 1792 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
1779 ExitOnRootFailure(hr, "Failed to find window Height attribute."); 1793 ThmExitOnRootFailure(hr, "Failed to find window Height attribute.");
1780 } 1794 }
1781 ExitOnFailure(hr, "Failed to get window Height attribute."); 1795 ThmExitOnFailure(hr, "Failed to get window Height attribute.");
1782 1796
1783 hr = XmlGetAttributeNumber(pixn, L"MinimumWidth", reinterpret_cast<DWORD*>(&pTheme->nMinimumWidth)); 1797 hr = XmlGetAttributeNumber(pixn, L"MinimumWidth", reinterpret_cast<DWORD*>(&pTheme->nMinimumWidth));
1784 if (S_FALSE == hr) 1798 if (S_FALSE == hr)
1785 { 1799 {
1786 hr = S_OK; 1800 hr = S_OK;
1787 } 1801 }
1788 ExitOnFailure(hr, "Failed to get window MinimumWidth attribute."); 1802 ThmExitOnFailure(hr, "Failed to get window MinimumWidth attribute.");
1789 1803
1790 hr = XmlGetAttributeNumber(pixn, L"MinimumHeight", reinterpret_cast<DWORD*>(&pTheme->nMinimumHeight)); 1804 hr = XmlGetAttributeNumber(pixn, L"MinimumHeight", reinterpret_cast<DWORD*>(&pTheme->nMinimumHeight));
1791 if (S_FALSE == hr) 1805 if (S_FALSE == hr)
1792 { 1806 {
1793 hr = S_OK; 1807 hr = S_OK;
1794 } 1808 }
1795 ExitOnFailure(hr, "Failed to get window MinimumHeight attribute."); 1809 ThmExitOnFailure(hr, "Failed to get window MinimumHeight attribute.");
1796 1810
1797 hr = XmlGetAttributeNumber(pixn, L"FontId", &pTheme->dwFontId); 1811 hr = XmlGetAttributeNumber(pixn, L"FontId", &pTheme->dwFontId);
1798 if (S_FALSE == hr) 1812 if (S_FALSE == hr)
1799 { 1813 {
1800 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); 1814 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
1801 ExitOnRootFailure(hr, "Failed to find window FontId attribute."); 1815 ThmExitOnRootFailure(hr, "Failed to find window FontId attribute.");
1802 } 1816 }
1803 ExitOnFailure(hr, "Failed to get window FontId attribute."); 1817 ThmExitOnFailure(hr, "Failed to get window FontId attribute.");
1804 1818
1805 // Get the optional window icon from a resource. 1819 // Get the optional window icon from a resource.
1806 hr = XmlGetAttribute(pixn, L"IconResource", &bstr); 1820 hr = XmlGetAttribute(pixn, L"IconResource", &bstr);
1807 ExitOnFailure(hr, "Failed to get window IconResource attribute."); 1821 ThmExitOnFailure(hr, "Failed to get window IconResource attribute.");
1808 1822
1809 if (S_OK == hr) 1823 if (S_OK == hr)
1810 { 1824 {
1811 pTheme->hIcon = ::LoadIconW(hModule, bstr); 1825 pTheme->hIcon = ::LoadIconW(hModule, bstr);
1812 ExitOnNullWithLastError(pTheme->hIcon, hr, "Failed to load window icon from IconResource."); 1826 ThmExitOnNullWithLastError(pTheme->hIcon, hr, "Failed to load window icon from IconResource.");
1813 1827
1814 ReleaseNullBSTR(bstr); 1828 ReleaseNullBSTR(bstr);
1815 } 1829 }
1816 1830
1817 // Get the optional window icon from a file. 1831 // Get the optional window icon from a file.
1818 hr = XmlGetAttribute(pixn, L"IconFile", &bstr); 1832 hr = XmlGetAttribute(pixn, L"IconFile", &bstr);
1819 ExitOnFailure(hr, "Failed to get window IconFile attribute."); 1833 ThmExitOnFailure(hr, "Failed to get window IconFile attribute.");
1820 1834
1821 if (S_OK == hr) 1835 if (S_OK == hr)
1822 { 1836 {
1823 if (wzRelativePath) 1837 if (wzRelativePath)
1824 { 1838 {
1825 hr = PathConcat(wzRelativePath, bstr, &sczIconFile); 1839 hr = PathConcat(wzRelativePath, bstr, &sczIconFile);
1826 ExitOnFailure(hr, "Failed to combine icon file path."); 1840 ThmExitOnFailure(hr, "Failed to combine icon file path.");
1827 } 1841 }
1828 else 1842 else
1829 { 1843 {
1830 hr = PathRelativeToModule(&sczIconFile, bstr, hModule); 1844 hr = PathRelativeToModule(&sczIconFile, bstr, hModule);
1831 ExitOnFailure(hr, "Failed to get icon filename."); 1845 ThmExitOnFailure(hr, "Failed to get icon filename.");
1832 } 1846 }
1833 1847
1834 pTheme->hIcon = ::LoadImageW(NULL, sczIconFile, IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE); 1848 pTheme->hIcon = ::LoadImageW(NULL, sczIconFile, IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE);
1835 ExitOnNullWithLastError(pTheme->hIcon, hr, "Failed to load window icon from IconFile: %ls.", bstr); 1849 ThmExitOnNullWithLastError(pTheme->hIcon, hr, "Failed to load window icon from IconFile: %ls.", bstr);
1836 1850
1837 ReleaseNullBSTR(bstr); 1851 ReleaseNullBSTR(bstr);
1838 } 1852 }
@@ -1842,18 +1856,18 @@ static HRESULT ParseWindow(
1842 { 1856 {
1843 pTheme->nSourceX = -1; 1857 pTheme->nSourceX = -1;
1844 } 1858 }
1845 ExitOnFailure(hr, "Failed to get window SourceX attribute."); 1859 ThmExitOnFailure(hr, "Failed to get window SourceX attribute.");
1846 1860
1847 hr = XmlGetAttributeNumber(pixn, L"SourceY", reinterpret_cast<DWORD*>(&pTheme->nSourceY)); 1861 hr = XmlGetAttributeNumber(pixn, L"SourceY", reinterpret_cast<DWORD*>(&pTheme->nSourceY));
1848 if (S_FALSE == hr) 1862 if (S_FALSE == hr)
1849 { 1863 {
1850 pTheme->nSourceY = -1; 1864 pTheme->nSourceY = -1;
1851 } 1865 }
1852 ExitOnFailure(hr, "Failed to get window SourceY attribute."); 1866 ThmExitOnFailure(hr, "Failed to get window SourceY attribute.");
1853 1867
1854 // Parse the optional window style. 1868 // Parse the optional window style.
1855 hr = XmlGetAttributeNumberBase(pixn, L"HexStyle", 16, &pTheme->dwStyle); 1869 hr = XmlGetAttributeNumberBase(pixn, L"HexStyle", 16, &pTheme->dwStyle);
1856 ExitOnFailure(hr, "Failed to get theme window style (Window@HexStyle) attribute."); 1870 ThmExitOnFailure(hr, "Failed to get theme window style (Window@HexStyle) attribute.");
1857 1871
1858 if (S_FALSE == hr) 1872 if (S_FALSE == hr)
1859 { 1873 {
@@ -1862,36 +1876,36 @@ static HRESULT ParseWindow(
1862 } 1876 }
1863 1877
1864 hr = XmlGetAttributeNumber(pixn, L"StringId", reinterpret_cast<DWORD*>(&pTheme->uStringId)); 1878 hr = XmlGetAttributeNumber(pixn, L"StringId", reinterpret_cast<DWORD*>(&pTheme->uStringId));
1865 ExitOnFailure(hr, "Failed to get window StringId attribute."); 1879 ThmExitOnFailure(hr, "Failed to get window StringId attribute.");
1866 1880
1867 if (S_FALSE == hr) 1881 if (S_FALSE == hr)
1868 { 1882 {
1869 pTheme->uStringId = UINT_MAX; 1883 pTheme->uStringId = UINT_MAX;
1870 1884
1871 hr = XmlGetAttribute(pixn, L"Caption", &bstr); 1885 hr = XmlGetAttribute(pixn, L"Caption", &bstr);
1872 ExitOnFailure(hr, "Failed to get window Caption attribute."); 1886 ThmExitOnFailure(hr, "Failed to get window Caption attribute.");
1873 1887
1874 if (S_FALSE == hr) 1888 if (S_FALSE == hr)
1875 { 1889 {
1876 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); 1890 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
1877 ExitOnRootFailure(hr, "Window elements must contain the Caption or StringId attribute."); 1891 ThmExitOnRootFailure(hr, "Window elements must contain the Caption or StringId attribute.");
1878 } 1892 }
1879 1893
1880 hr = StrAllocString(&pTheme->sczCaption, bstr, 0); 1894 hr = StrAllocString(&pTheme->sczCaption, bstr, 0);
1881 ExitOnFailure(hr, "Failed to copy window Caption attribute."); 1895 ThmExitOnFailure(hr, "Failed to copy window Caption attribute.");
1882 } 1896 }
1883 1897
1884 // Parse any image lists. 1898 // Parse any image lists.
1885 hr = ParseImageLists(hModule, wzRelativePath, pixn, pTheme); 1899 hr = ParseImageLists(hModule, wzRelativePath, pixn, pTheme);
1886 ExitOnFailure(hr, "Failed to parse image lists."); 1900 ThmExitOnFailure(hr, "Failed to parse image lists.");
1887 1901
1888 // Parse the pages. 1902 // Parse the pages.
1889 hr = ParsePages(hModule, wzRelativePath, pixn, pTheme); 1903 hr = ParsePages(hModule, wzRelativePath, pixn, pTheme);
1890 ExitOnFailure(hr, "Failed to parse theme pages."); 1904 ThmExitOnFailure(hr, "Failed to parse theme pages.");
1891 1905
1892 // Parse the non-paged controls. 1906 // Parse the non-paged controls.
1893 hr = ParseControls(hModule, wzRelativePath, pixn, pTheme, NULL, NULL); 1907 hr = ParseControls(hModule, wzRelativePath, pixn, pTheme, NULL, NULL);
1894 ExitOnFailure(hr, "Failed to parse theme controls."); 1908 ThmExitOnFailure(hr, "Failed to parse theme controls.");
1895 1909
1896LExit: 1910LExit:
1897 ReleaseStr(sczIconFile); 1911 ReleaseStr(sczIconFile);
@@ -1919,10 +1933,10 @@ static HRESULT ParseFonts(
1919 DWORD dwSystemBackgroundColor = FALSE; 1933 DWORD dwSystemBackgroundColor = FALSE;
1920 1934
1921 hr = XmlSelectNodes(pElement, L"Font", &pixnl); 1935 hr = XmlSelectNodes(pElement, L"Font", &pixnl);
1922 ExitOnFailure(hr, "Failed to find font elements."); 1936 ThmExitOnFailure(hr, "Failed to find font elements.");
1923 1937
1924 hr = pixnl->get_length(reinterpret_cast<long*>(&pTheme->cFonts)); 1938 hr = pixnl->get_length(reinterpret_cast<long*>(&pTheme->cFonts));
1925 ExitOnFailure(hr, "Failed to count the number of theme fonts."); 1939 ThmExitOnFailure(hr, "Failed to count the number of theme fonts.");
1926 1940
1927 if (!pTheme->cFonts) 1941 if (!pTheme->cFonts)
1928 { 1942 {
@@ -1930,7 +1944,7 @@ static HRESULT ParseFonts(
1930 } 1944 }
1931 1945
1932 pTheme->rgFonts = static_cast<THEME_FONT*>(MemAlloc(sizeof(THEME_FONT) * pTheme->cFonts, TRUE)); 1946 pTheme->rgFonts = static_cast<THEME_FONT*>(MemAlloc(sizeof(THEME_FONT) * pTheme->cFonts, TRUE));
1933 ExitOnNull(pTheme->rgFonts, hr, E_OUTOFMEMORY, "Failed to allocate theme fonts."); 1947 ThmExitOnNull(pTheme->rgFonts, hr, E_OUTOFMEMORY, "Failed to allocate theme fonts.");
1934 1948
1935 lf.lfQuality = CLEARTYPE_QUALITY; 1949 lf.lfQuality = CLEARTYPE_QUALITY;
1936 1950
@@ -1941,12 +1955,12 @@ static HRESULT ParseFonts(
1941 { 1955 {
1942 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); 1956 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
1943 } 1957 }
1944 ExitOnFailure(hr, "Failed to find font id."); 1958 ThmExitOnFailure(hr, "Failed to find font id.");
1945 1959
1946 if (pTheme->cFonts <= dwId) 1960 if (pTheme->cFonts <= dwId)
1947 { 1961 {
1948 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); 1962 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
1949 ExitOnRootFailure(hr, "Invalid theme font id."); 1963 ThmExitOnRootFailure(hr, "Invalid theme font id.");
1950 } 1964 }
1951 1965
1952 hr = XmlGetText(pixn, &bstrName); 1966 hr = XmlGetText(pixn, &bstrName);
@@ -1954,17 +1968,17 @@ static HRESULT ParseFonts(
1954 { 1968 {
1955 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); 1969 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
1956 } 1970 }
1957 ExitOnFailure(hr, "Failed to get font name."); 1971 ThmExitOnFailure(hr, "Failed to get font name.");
1958 1972
1959 hr = ::StringCchCopyW(lf.lfFaceName, countof(lf.lfFaceName), bstrName); 1973 hr = ::StringCchCopyW(lf.lfFaceName, countof(lf.lfFaceName), bstrName);
1960 ExitOnFailure(hr, "Failed to copy font name."); 1974 ThmExitOnFailure(hr, "Failed to copy font name.");
1961 1975
1962 hr = XmlGetAttributeNumber(pixn, L"Height", reinterpret_cast<DWORD*>(&lf.lfHeight)); 1976 hr = XmlGetAttributeNumber(pixn, L"Height", reinterpret_cast<DWORD*>(&lf.lfHeight));
1963 if (S_FALSE == hr) 1977 if (S_FALSE == hr)
1964 { 1978 {
1965 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); 1979 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
1966 } 1980 }
1967 ExitOnFailure(hr, "Failed to find font height attribute."); 1981 ThmExitOnFailure(hr, "Failed to find font height attribute.");
1968 1982
1969 hr = XmlGetAttributeNumber(pixn, L"Weight", reinterpret_cast<DWORD*>(&lf.lfWeight)); 1983 hr = XmlGetAttributeNumber(pixn, L"Weight", reinterpret_cast<DWORD*>(&lf.lfWeight));
1970 if (S_FALSE == hr) 1984 if (S_FALSE == hr)
@@ -1972,7 +1986,7 @@ static HRESULT ParseFonts(
1972 lf.lfWeight = FW_DONTCARE; 1986 lf.lfWeight = FW_DONTCARE;
1973 hr = S_OK; 1987 hr = S_OK;
1974 } 1988 }
1975 ExitOnFailure(hr, "Failed to find font weight attribute."); 1989 ThmExitOnFailure(hr, "Failed to find font weight attribute.");
1976 1990
1977 hr = XmlGetYesNoAttribute(pixn, L"Underline", reinterpret_cast<BOOL*>(&lf.lfUnderline)); 1991 hr = XmlGetYesNoAttribute(pixn, L"Underline", reinterpret_cast<BOOL*>(&lf.lfUnderline));
1978 if (E_NOTFOUND == hr) 1992 if (E_NOTFOUND == hr)
@@ -1980,42 +1994,42 @@ static HRESULT ParseFonts(
1980 lf.lfUnderline = FALSE; 1994 lf.lfUnderline = FALSE;
1981 hr = S_OK; 1995 hr = S_OK;
1982 } 1996 }
1983 ExitOnFailure(hr, "Failed to find font underline attribute."); 1997 ThmExitOnFailure(hr, "Failed to find font underline attribute.");
1984 1998
1985 hr = GetFontColor(pixn, L"Foreground", &crForeground, &dwSystemForegroundColor); 1999 hr = GetFontColor(pixn, L"Foreground", &crForeground, &dwSystemForegroundColor);
1986 ExitOnFailure(hr, "Failed to find font foreground color."); 2000 ThmExitOnFailure(hr, "Failed to find font foreground color.");
1987 2001
1988 hr = GetFontColor(pixn, L"Background", &crBackground, &dwSystemBackgroundColor); 2002 hr = GetFontColor(pixn, L"Background", &crBackground, &dwSystemBackgroundColor);
1989 ExitOnFailure(hr, "Failed to find font background color."); 2003 ThmExitOnFailure(hr, "Failed to find font background color.");
1990 2004
1991 THEME_FONT* pFont = pTheme->rgFonts + dwId; 2005 THEME_FONT* pFont = pTheme->rgFonts + dwId;
1992 if (pFont->hFont) 2006 if (pFont->hFont)
1993 { 2007 {
1994 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); 2008 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
1995 ExitOnRootFailure(hr, "Theme font id duplicated."); 2009 ThmExitOnRootFailure(hr, "Theme font id duplicated.");
1996 } 2010 }
1997 2011
1998 pFont->hFont = ::CreateFontIndirectW(&lf); 2012 pFont->hFont = ::CreateFontIndirectW(&lf);
1999 ExitOnNullWithLastError(pFont->hFont, hr, "Failed to create font %u.", dwId); 2013 ThmExitOnNullWithLastError(pFont->hFont, hr, "Failed to create font %u.", dwId);
2000 2014
2001 pFont->crForeground = crForeground; 2015 pFont->crForeground = crForeground;
2002 if (THEME_INVISIBLE_COLORREF != pFont->crForeground) 2016 if (THEME_INVISIBLE_COLORREF != pFont->crForeground)
2003 { 2017 {
2004 pFont->hForeground = dwSystemForegroundColor ? ::GetSysColorBrush(dwSystemForegroundColor) : ::CreateSolidBrush(pFont->crForeground); 2018 pFont->hForeground = dwSystemForegroundColor ? ::GetSysColorBrush(dwSystemForegroundColor) : ::CreateSolidBrush(pFont->crForeground);
2005 ExitOnNullWithLastError(pFont->hForeground, hr, "Failed to create text foreground brush."); 2019 ThmExitOnNullWithLastError(pFont->hForeground, hr, "Failed to create text foreground brush.");
2006 } 2020 }
2007 2021
2008 pFont->crBackground = crBackground; 2022 pFont->crBackground = crBackground;
2009 if (THEME_INVISIBLE_COLORREF != pFont->crBackground) 2023 if (THEME_INVISIBLE_COLORREF != pFont->crBackground)
2010 { 2024 {
2011 pFont->hBackground = dwSystemBackgroundColor ? ::GetSysColorBrush(dwSystemBackgroundColor) : ::CreateSolidBrush(pFont->crBackground); 2025 pFont->hBackground = dwSystemBackgroundColor ? ::GetSysColorBrush(dwSystemBackgroundColor) : ::CreateSolidBrush(pFont->crBackground);
2012 ExitOnNullWithLastError(pFont->hBackground, hr, "Failed to create text background brush."); 2026 ThmExitOnNullWithLastError(pFont->hBackground, hr, "Failed to create text background brush.");
2013 } 2027 }
2014 2028
2015 ReleaseNullBSTR(bstrName); 2029 ReleaseNullBSTR(bstrName);
2016 ReleaseNullObject(pixn); 2030 ReleaseNullObject(pixn);
2017 } 2031 }
2018 ExitOnFailure(hr, "Failed to enumerate all fonts."); 2032 ThmExitOnFailure(hr, "Failed to enumerate all fonts.");
2019 2033
2020 if (S_FALSE == hr) 2034 if (S_FALSE == hr)
2021 { 2035 {
@@ -2049,7 +2063,7 @@ static HRESULT GetFontColor(
2049 *pColorRef = THEME_INVISIBLE_COLORREF; 2063 *pColorRef = THEME_INVISIBLE_COLORREF;
2050 ExitFunction1(hr = S_OK); 2064 ExitFunction1(hr = S_OK);
2051 } 2065 }
2052 ExitOnFailure(hr, "Failed to find font %ls color.", wzAttributeName); 2066 ThmExitOnFailure(hr, "Failed to find font %ls color.", wzAttributeName);
2053 2067
2054 if (pdwSystemColor) 2068 if (pdwSystemColor)
2055 { 2069 {
@@ -2117,10 +2131,10 @@ static HRESULT ParsePages(
2117 DWORD iPage = 0; 2131 DWORD iPage = 0;
2118 2132
2119 hr = XmlSelectNodes(pElement, L"Page", &pixnl); 2133 hr = XmlSelectNodes(pElement, L"Page", &pixnl);
2120 ExitOnFailure(hr, "Failed to find page elements."); 2134 ThmExitOnFailure(hr, "Failed to find page elements.");
2121 2135
2122 hr = pixnl->get_length(reinterpret_cast<long*>(&pTheme->cPages)); 2136 hr = pixnl->get_length(reinterpret_cast<long*>(&pTheme->cPages));
2123 ExitOnFailure(hr, "Failed to count the number of theme pages."); 2137 ThmExitOnFailure(hr, "Failed to count the number of theme pages.");
2124 2138
2125 if (!pTheme->cPages) 2139 if (!pTheme->cPages)
2126 { 2140 {
@@ -2128,7 +2142,7 @@ static HRESULT ParsePages(
2128 } 2142 }
2129 2143
2130 pTheme->rgPages = static_cast<THEME_PAGE*>(MemAlloc(sizeof(THEME_PAGE) * pTheme->cPages, TRUE)); 2144 pTheme->rgPages = static_cast<THEME_PAGE*>(MemAlloc(sizeof(THEME_PAGE) * pTheme->cPages, TRUE));
2131 ExitOnNull(pTheme->rgPages, hr, E_OUTOFMEMORY, "Failed to allocate theme pages."); 2145 ThmExitOnNull(pTheme->rgPages, hr, E_OUTOFMEMORY, "Failed to allocate theme pages.");
2132 2146
2133 while (S_OK == (hr = XmlNextElement(pixnl, &pixn, &bstrType))) 2147 while (S_OK == (hr = XmlNextElement(pixnl, &pixn, &bstrType)))
2134 { 2148 {
@@ -2141,17 +2155,17 @@ static HRESULT ParsePages(
2141 { 2155 {
2142 hr = S_OK; 2156 hr = S_OK;
2143 } 2157 }
2144 ExitOnFailure(hr, "Failed when querying page Name."); 2158 ThmExitOnFailure(hr, "Failed when querying page Name.");
2145 2159
2146 hr = ParseControls(hModule, wzRelativePath, pixn, pTheme, NULL, pPage); 2160 hr = ParseControls(hModule, wzRelativePath, pixn, pTheme, NULL, pPage);
2147 ExitOnFailure(hr, "Failed to parse page controls."); 2161 ThmExitOnFailure(hr, "Failed to parse page controls.");
2148 2162
2149 ++iPage; 2163 ++iPage;
2150 2164
2151 ReleaseNullBSTR(bstrType); 2165 ReleaseNullBSTR(bstrType);
2152 ReleaseNullObject(pixn); 2166 ReleaseNullObject(pixn);
2153 } 2167 }
2154 ExitOnFailure(hr, "Failed to enumerate all pages."); 2168 ThmExitOnFailure(hr, "Failed to enumerate all pages.");
2155 2169
2156 if (S_FALSE == hr) 2170 if (S_FALSE == hr)
2157 { 2171 {
@@ -2188,10 +2202,10 @@ static HRESULT ParseImageLists(
2188 int iRetVal = 0; 2202 int iRetVal = 0;
2189 2203
2190 hr = XmlSelectNodes(pElement, L"ImageList", &pixnlImageLists); 2204 hr = XmlSelectNodes(pElement, L"ImageList", &pixnlImageLists);
2191 ExitOnFailure(hr, "Failed to find ImageList elements."); 2205 ThmExitOnFailure(hr, "Failed to find ImageList elements.");
2192 2206
2193 hr = pixnlImageLists->get_length(reinterpret_cast<long*>(&pTheme->cImageLists)); 2207 hr = pixnlImageLists->get_length(reinterpret_cast<long*>(&pTheme->cImageLists));
2194 ExitOnFailure(hr, "Failed to count the number of image lists."); 2208 ThmExitOnFailure(hr, "Failed to count the number of image lists.");
2195 2209
2196 if (!pTheme->cImageLists) 2210 if (!pTheme->cImageLists)
2197 { 2211 {
@@ -2199,7 +2213,7 @@ static HRESULT ParseImageLists(
2199 } 2213 }
2200 2214
2201 pTheme->rgImageLists = static_cast<THEME_IMAGELIST*>(MemAlloc(sizeof(THEME_IMAGELIST) * pTheme->cImageLists, TRUE)); 2215 pTheme->rgImageLists = static_cast<THEME_IMAGELIST*>(MemAlloc(sizeof(THEME_IMAGELIST) * pTheme->cImageLists, TRUE));
2202 ExitOnNull(pTheme->rgImageLists, hr, E_OUTOFMEMORY, "Failed to allocate theme image lists."); 2216 ThmExitOnNull(pTheme->rgImageLists, hr, E_OUTOFMEMORY, "Failed to allocate theme image lists.");
2203 2217
2204 while (S_OK == (hr = XmlNextElement(pixnlImageLists, &pixnImageList, NULL))) 2218 while (S_OK == (hr = XmlNextElement(pixnlImageLists, &pixnImageList, NULL)))
2205 { 2219 {
@@ -2208,16 +2222,16 @@ static HRESULT ParseImageLists(
2208 { 2222 {
2209 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); 2223 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
2210 } 2224 }
2211 ExitOnFailure(hr, "Failed to find ImageList/@Name attribute."); 2225 ThmExitOnFailure(hr, "Failed to find ImageList/@Name attribute.");
2212 2226
2213 hr = StrAllocString(&pTheme->rgImageLists[dwImageListIndex].sczName, bstr, 0); 2227 hr = StrAllocString(&pTheme->rgImageLists[dwImageListIndex].sczName, bstr, 0);
2214 ExitOnFailure(hr, "Failed to make copy of ImageList name."); 2228 ThmExitOnFailure(hr, "Failed to make copy of ImageList name.");
2215 2229
2216 hr = XmlSelectNodes(pixnImageList, L"Image", &pixnlImages); 2230 hr = XmlSelectNodes(pixnImageList, L"Image", &pixnlImages);
2217 ExitOnFailure(hr, "Failed to select child Image nodes."); 2231 ThmExitOnFailure(hr, "Failed to select child Image nodes.");
2218 2232
2219 hr = pixnlImages->get_length(reinterpret_cast<long*>(&dwImageCount)); 2233 hr = pixnlImages->get_length(reinterpret_cast<long*>(&dwImageCount));
2220 ExitOnFailure(hr, "Failed to count the number of images in list."); 2234 ThmExitOnFailure(hr, "Failed to count the number of images in list.");
2221 2235
2222 if (0 < dwImageCount) 2236 if (0 < dwImageCount)
2223 { 2237 {
@@ -2230,20 +2244,20 @@ static HRESULT ParseImageLists(
2230 hBitmap = NULL; 2244 hBitmap = NULL;
2231 } 2245 }
2232 hr = ParseImage(hModule, wzRelativePath, pixnImage, &hBitmap); 2246 hr = ParseImage(hModule, wzRelativePath, pixnImage, &hBitmap);
2233 ExitOnFailure(hr, "Failed to parse image: %u", i); 2247 ThmExitOnFailure(hr, "Failed to parse image: %u", i);
2234 2248
2235 if (0 == i) 2249 if (0 == i)
2236 { 2250 {
2237 ::GetObjectW(hBitmap, sizeof(BITMAP), &bm); 2251 ::GetObjectW(hBitmap, sizeof(BITMAP), &bm);
2238 2252
2239 pTheme->rgImageLists[dwImageListIndex].hImageList = ImageList_Create(bm.bmWidth, bm.bmHeight, ILC_COLOR24, dwImageCount, 0); 2253 pTheme->rgImageLists[dwImageListIndex].hImageList = ImageList_Create(bm.bmWidth, bm.bmHeight, ILC_COLOR24, dwImageCount, 0);
2240 ExitOnNullWithLastError(pTheme->rgImageLists[dwImageListIndex].hImageList, hr, "Failed to create image list."); 2254 ThmExitOnNullWithLastError(pTheme->rgImageLists[dwImageListIndex].hImageList, hr, "Failed to create image list.");
2241 } 2255 }
2242 2256
2243 iRetVal = ImageList_Add(pTheme->rgImageLists[dwImageListIndex].hImageList, hBitmap, NULL); 2257 iRetVal = ImageList_Add(pTheme->rgImageLists[dwImageListIndex].hImageList, hBitmap, NULL);
2244 if (-1 == iRetVal) 2258 if (-1 == iRetVal)
2245 { 2259 {
2246 ExitWithLastError(hr, "Failed to add image %u to image list.", i); 2260 ThmExitWithLastError(hr, "Failed to add image %u to image list.", i);
2247 } 2261 }
2248 2262
2249 ++i; 2263 ++i;
@@ -2326,13 +2340,13 @@ static HRESULT ParseControls(
2326 GetControls(pTheme, pParentControl, &pcControls, &prgControls); 2340 GetControls(pTheme, pParentControl, &pcControls, &prgControls);
2327 2341
2328 hr = ParseRadioButtons(hModule, wzRelativePath, pElement, pTheme, pParentControl, pPage); 2342 hr = ParseRadioButtons(hModule, wzRelativePath, pElement, pTheme, pParentControl, pPage);
2329 ExitOnFailure(hr, "Failed to parse radio buttons."); 2343 ThmExitOnFailure(hr, "Failed to parse radio buttons.");
2330 2344
2331 hr = XmlSelectNodes(pElement, L"Billboard|Button|Checkbox|Combobox|CommandLink|Editbox|Hyperlink|Hypertext|ImageControl|Label|ListView|Panel|Progressbar|Richedit|Static|Tabs|TreeView", &pixnl); 2345 hr = XmlSelectNodes(pElement, L"Billboard|Button|Checkbox|Combobox|CommandLink|Editbox|Hyperlink|Hypertext|ImageControl|Label|ListView|Panel|Progressbar|Richedit|Static|Tabs|TreeView", &pixnl);
2332 ExitOnFailure(hr, "Failed to find control elements."); 2346 ThmExitOnFailure(hr, "Failed to find control elements.");
2333 2347
2334 hr = pixnl->get_length(reinterpret_cast<long*>(&cNewControls)); 2348 hr = pixnl->get_length(reinterpret_cast<long*>(&cNewControls));
2335 ExitOnFailure(hr, "Failed to count the number of theme controls."); 2349 ThmExitOnFailure(hr, "Failed to count the number of theme controls.");
2336 2350
2337 if (!cNewControls) 2351 if (!cNewControls)
2338 { 2352 {
@@ -2340,7 +2354,7 @@ static HRESULT ParseControls(
2340 } 2354 }
2341 2355
2342 hr = MemReAllocArray(reinterpret_cast<LPVOID*>(prgControls), *pcControls, sizeof(THEME_CONTROL), cNewControls); 2356 hr = MemReAllocArray(reinterpret_cast<LPVOID*>(prgControls), *pcControls, sizeof(THEME_CONTROL), cNewControls);
2343 ExitOnFailure(hr, "Failed to reallocate theme controls."); 2357 ThmExitOnFailure(hr, "Failed to reallocate theme controls.");
2344 2358
2345 cNewControls += *pcControls; 2359 cNewControls += *pcControls;
2346 2360
@@ -2360,7 +2374,7 @@ static HRESULT ParseControls(
2360 if (!bstrType) 2374 if (!bstrType)
2361 { 2375 {
2362 hr = E_UNEXPECTED; 2376 hr = E_UNEXPECTED;
2363 ExitOnFailure(hr, "Null element encountered!"); 2377 ThmExitOnFailure(hr, "Null element encountered!");
2364 } 2378 }
2365 2379
2366 if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrType, -1, L"Billboard", -1)) 2380 if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrType, -1, L"Billboard", -1))
@@ -2441,7 +2455,7 @@ static HRESULT ParseControls(
2441 BOOL fBillboardSizing = pParentControl && THEME_CONTROL_TYPE_BILLBOARD == pParentControl->type; 2455 BOOL fBillboardSizing = pParentControl && THEME_CONTROL_TYPE_BILLBOARD == pParentControl->type;
2442 2456
2443 hr = ParseControl(hModule, wzRelativePath, pixn, pTheme, pControl, fBillboardSizing, pPage); 2457 hr = ParseControl(hModule, wzRelativePath, pixn, pTheme, pControl, fBillboardSizing, pPage);
2444 ExitOnFailure(hr, "Failed to parse control."); 2458 ThmExitOnFailure(hr, "Failed to parse control.");
2445 2459
2446 if (fBillboardSizing) 2460 if (fBillboardSizing)
2447 { 2461 {
@@ -2463,7 +2477,7 @@ static HRESULT ParseControls(
2463 ReleaseNullBSTR(bstrType); 2477 ReleaseNullBSTR(bstrType);
2464 ReleaseNullObject(pixn); 2478 ReleaseNullObject(pixn);
2465 } 2479 }
2466 ExitOnFailure(hr, "Failed to enumerate all controls."); 2480 ThmExitOnFailure(hr, "Failed to enumerate all controls.");
2467 2481
2468 if (S_FALSE == hr) 2482 if (S_FALSE == hr)
2469 { 2483 {
@@ -2503,21 +2517,21 @@ static HRESULT ParseControl(
2503 { 2517 {
2504 hr = S_OK; 2518 hr = S_OK;
2505 } 2519 }
2506 ExitOnFailure(hr, "Failed when querying control Name attribute."); 2520 ThmExitOnFailure(hr, "Failed when querying control Name attribute.");
2507 2521
2508 hr = XmlGetAttributeEx(pixn, L"EnableCondition", &pControl->sczEnableCondition); 2522 hr = XmlGetAttributeEx(pixn, L"EnableCondition", &pControl->sczEnableCondition);
2509 if (E_NOTFOUND == hr) 2523 if (E_NOTFOUND == hr)
2510 { 2524 {
2511 hr = S_OK; 2525 hr = S_OK;
2512 } 2526 }
2513 ExitOnFailure(hr, "Failed when querying control EnableCondition attribute."); 2527 ThmExitOnFailure(hr, "Failed when querying control EnableCondition attribute.");
2514 2528
2515 hr = XmlGetAttributeEx(pixn, L"VisibleCondition", &pControl->sczVisibleCondition); 2529 hr = XmlGetAttributeEx(pixn, L"VisibleCondition", &pControl->sczVisibleCondition);
2516 if (E_NOTFOUND == hr) 2530 if (E_NOTFOUND == hr)
2517 { 2531 {
2518 hr = S_OK; 2532 hr = S_OK;
2519 } 2533 }
2520 ExitOnFailure(hr, "Failed when querying control VisibleCondition attribute."); 2534 ThmExitOnFailure(hr, "Failed when querying control VisibleCondition attribute.");
2521 2535
2522 if (!fSkipDimensions) 2536 if (!fSkipDimensions)
2523 { 2537 {
@@ -2526,58 +2540,58 @@ static HRESULT ParseControl(
2526 { 2540 {
2527 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); 2541 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
2528 } 2542 }
2529 ExitOnFailure(hr, "Failed to find control X attribute."); 2543 ThmExitOnFailure(hr, "Failed to find control X attribute.");
2530 2544
2531 hr = XmlGetAttributeNumber(pixn, L"Y", reinterpret_cast<DWORD*>(&pControl->nY)); 2545 hr = XmlGetAttributeNumber(pixn, L"Y", reinterpret_cast<DWORD*>(&pControl->nY));
2532 if (S_FALSE == hr) 2546 if (S_FALSE == hr)
2533 { 2547 {
2534 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); 2548 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
2535 } 2549 }
2536 ExitOnFailure(hr, "Failed to find control Y attribute."); 2550 ThmExitOnFailure(hr, "Failed to find control Y attribute.");
2537 2551
2538 hr = XmlGetAttributeNumber(pixn, L"Height", reinterpret_cast<DWORD*>(&pControl->nHeight)); 2552 hr = XmlGetAttributeNumber(pixn, L"Height", reinterpret_cast<DWORD*>(&pControl->nHeight));
2539 if (S_FALSE == hr) 2553 if (S_FALSE == hr)
2540 { 2554 {
2541 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); 2555 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
2542 } 2556 }
2543 ExitOnFailure(hr, "Failed to find control Height attribute."); 2557 ThmExitOnFailure(hr, "Failed to find control Height attribute.");
2544 2558
2545 hr = XmlGetAttributeNumber(pixn, L"Width", reinterpret_cast<DWORD*>(&pControl->nWidth)); 2559 hr = XmlGetAttributeNumber(pixn, L"Width", reinterpret_cast<DWORD*>(&pControl->nWidth));
2546 if (S_FALSE == hr) 2560 if (S_FALSE == hr)
2547 { 2561 {
2548 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); 2562 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
2549 } 2563 }
2550 ExitOnFailure(hr, "Failed to find control Width attribute."); 2564 ThmExitOnFailure(hr, "Failed to find control Width attribute.");
2551 } 2565 }
2552 2566
2553 // Parse the optional background resource image. 2567 // Parse the optional background resource image.
2554 hr = ParseImage(hModule, wzRelativePath, pixn, &pControl->hImage); 2568 hr = ParseImage(hModule, wzRelativePath, pixn, &pControl->hImage);
2555 ExitOnFailure(hr, "Failed while parsing control image."); 2569 ThmExitOnFailure(hr, "Failed while parsing control image.");
2556 2570
2557 hr = XmlGetAttributeNumber(pixn, L"SourceX", reinterpret_cast<DWORD*>(&pControl->nSourceX)); 2571 hr = XmlGetAttributeNumber(pixn, L"SourceX", reinterpret_cast<DWORD*>(&pControl->nSourceX));
2558 if (S_FALSE == hr) 2572 if (S_FALSE == hr)
2559 { 2573 {
2560 pControl->nSourceX = -1; 2574 pControl->nSourceX = -1;
2561 } 2575 }
2562 ExitOnFailure(hr, "Failed when querying control SourceX attribute."); 2576 ThmExitOnFailure(hr, "Failed when querying control SourceX attribute.");
2563 2577
2564 hr = XmlGetAttributeNumber(pixn, L"SourceY", reinterpret_cast<DWORD*>(&pControl->nSourceY)); 2578 hr = XmlGetAttributeNumber(pixn, L"SourceY", reinterpret_cast<DWORD*>(&pControl->nSourceY));
2565 if (S_FALSE == hr) 2579 if (S_FALSE == hr)
2566 { 2580 {
2567 pControl->nSourceY = -1; 2581 pControl->nSourceY = -1;
2568 } 2582 }
2569 ExitOnFailure(hr, "Failed when querying control SourceY attribute."); 2583 ThmExitOnFailure(hr, "Failed when querying control SourceY attribute.");
2570 2584
2571 hr = XmlGetAttributeNumber(pixn, L"FontId", &pControl->dwFontId); 2585 hr = XmlGetAttributeNumber(pixn, L"FontId", &pControl->dwFontId);
2572 if (S_FALSE == hr) 2586 if (S_FALSE == hr)
2573 { 2587 {
2574 pControl->dwFontId = THEME_INVALID_ID; 2588 pControl->dwFontId = THEME_INVALID_ID;
2575 } 2589 }
2576 ExitOnFailure(hr, "Failed when querying control FontId attribute."); 2590 ThmExitOnFailure(hr, "Failed when querying control FontId attribute.");
2577 2591
2578 // Parse the optional window style. 2592 // Parse the optional window style.
2579 hr = XmlGetAttributeNumberBase(pixn, L"HexStyle", 16, &pControl->dwStyle); 2593 hr = XmlGetAttributeNumberBase(pixn, L"HexStyle", 16, &pControl->dwStyle);
2580 ExitOnFailure(hr, "Failed when querying control HexStyle attribute."); 2594 ThmExitOnFailure(hr, "Failed when querying control HexStyle attribute.");
2581 2595
2582 // Parse the tabstop bit "shortcut nomenclature", this could have been set with the style above. 2596 // Parse the tabstop bit "shortcut nomenclature", this could have been set with the style above.
2583 hr = XmlGetYesNoAttribute(pixn, L"TabStop", &fValue); 2597 hr = XmlGetYesNoAttribute(pixn, L"TabStop", &fValue);
@@ -2587,7 +2601,7 @@ static HRESULT ParseControl(
2587 } 2601 }
2588 else 2602 else
2589 { 2603 {
2590 ExitOnFailure(hr, "Failed when querying control TabStop attribute."); 2604 ThmExitOnFailure(hr, "Failed when querying control TabStop attribute.");
2591 2605
2592 if (fValue) 2606 if (fValue)
2593 { 2607 {
@@ -2602,7 +2616,7 @@ static HRESULT ParseControl(
2602 } 2616 }
2603 else 2617 else
2604 { 2618 {
2605 ExitOnFailure(hr, "Failed when querying control Visible attribute."); 2619 ThmExitOnFailure(hr, "Failed when querying control Visible attribute.");
2606 2620
2607 if (fValue) 2621 if (fValue)
2608 { 2622 {
@@ -2617,7 +2631,7 @@ static HRESULT ParseControl(
2617 } 2631 }
2618 else 2632 else
2619 { 2633 {
2620 ExitOnFailure(hr, "Failed when querying control HideWhenDisabled attribute."); 2634 ThmExitOnFailure(hr, "Failed when querying control HideWhenDisabled attribute.");
2621 2635
2622 if (fValue) 2636 if (fValue)
2623 { 2637 {
@@ -2632,22 +2646,22 @@ static HRESULT ParseControl(
2632 } 2646 }
2633 else 2647 else
2634 { 2648 {
2635 ExitOnFailure(hr, "Failed when querying control DisableAutomaticBehavior attribute."); 2649 ThmExitOnFailure(hr, "Failed when querying control DisableAutomaticBehavior attribute.");
2636 } 2650 }
2637 2651
2638 hr = ParseActions(pixn, pControl); 2652 hr = ParseActions(pixn, pControl);
2639 ExitOnFailure(hr, "Failed to parse action nodes of the control."); 2653 ThmExitOnFailure(hr, "Failed to parse action nodes of the control.");
2640 2654
2641 hr = ParseText(pixn, pControl, &fAnyTextChildren); 2655 hr = ParseText(pixn, pControl, &fAnyTextChildren);
2642 ExitOnFailure(hr, "Failed to parse text nodes of the control."); 2656 ThmExitOnFailure(hr, "Failed to parse text nodes of the control.");
2643 2657
2644 hr = ParseTooltips(pixn, pControl, &fAnyTextChildren); 2658 hr = ParseTooltips(pixn, pControl, &fAnyTextChildren);
2645 ExitOnFailure(hr, "Failed to parse control Tooltip."); 2659 ThmExitOnFailure(hr, "Failed to parse control Tooltip.");
2646 2660
2647 if (THEME_CONTROL_TYPE_COMMANDLINK == pControl->type) 2661 if (THEME_CONTROL_TYPE_COMMANDLINK == pControl->type)
2648 { 2662 {
2649 hr = ParseNotes(pixn, pControl, &fAnyNoteChildren); 2663 hr = ParseNotes(pixn, pControl, &fAnyNoteChildren);
2650 ExitOnFailure(hr, "Failed to parse note text nodes of the control."); 2664 ThmExitOnFailure(hr, "Failed to parse note text nodes of the control.");
2651 } 2665 }
2652 2666
2653 if (fAnyTextChildren || fAnyNoteChildren) 2667 if (fAnyTextChildren || fAnyNoteChildren)
@@ -2657,7 +2671,7 @@ static HRESULT ParseControl(
2657 else 2671 else
2658 { 2672 {
2659 hr = XmlGetAttributeNumber(pixn, L"StringId", reinterpret_cast<DWORD*>(&pControl->uStringId)); 2673 hr = XmlGetAttributeNumber(pixn, L"StringId", reinterpret_cast<DWORD*>(&pControl->uStringId));
2660 ExitOnFailure(hr, "Failed when querying control StringId attribute."); 2674 ThmExitOnFailure(hr, "Failed when querying control StringId attribute.");
2661 2675
2662 if (S_FALSE == hr) 2676 if (S_FALSE == hr)
2663 { 2677 {
@@ -2671,12 +2685,12 @@ static HRESULT ParseControl(
2671 else 2685 else
2672 { 2686 {
2673 hr = XmlGetText(pixn, &bstrText); 2687 hr = XmlGetText(pixn, &bstrText);
2674 ExitOnFailure(hr, "Failed to get control inner text."); 2688 ThmExitOnFailure(hr, "Failed to get control inner text.");
2675 2689
2676 if (S_OK == hr) 2690 if (S_OK == hr)
2677 { 2691 {
2678 hr = StrAllocString(&pControl->sczText, bstrText, 0); 2692 hr = StrAllocString(&pControl->sczText, bstrText, 0);
2679 ExitOnFailure(hr, "Failed to copy control text."); 2693 ThmExitOnFailure(hr, "Failed to copy control text.");
2680 2694
2681 ReleaseNullBSTR(bstrText); 2695 ReleaseNullBSTR(bstrText);
2682 } 2696 }
@@ -2695,7 +2709,7 @@ static HRESULT ParseControl(
2695 { 2709 {
2696 hr = S_OK; 2710 hr = S_OK;
2697 } 2711 }
2698 ExitOnFailure(hr, "Failed when querying Billboard/@Loop attribute."); 2712 ThmExitOnFailure(hr, "Failed when querying Billboard/@Loop attribute.");
2699 2713
2700 pControl->wBillboardInterval = 5000; 2714 pControl->wBillboardInterval = 5000;
2701 hr = XmlGetAttributeNumber(pixn, L"Interval", &dwValue); 2715 hr = XmlGetAttributeNumber(pixn, L"Interval", &dwValue);
@@ -2703,15 +2717,15 @@ static HRESULT ParseControl(
2703 { 2717 {
2704 pControl->wBillboardInterval = static_cast<WORD>(dwValue & 0xFFFF); 2718 pControl->wBillboardInterval = static_cast<WORD>(dwValue & 0xFFFF);
2705 } 2719 }
2706 ExitOnFailure(hr, "Failed when querying Billboard/@Interval attribute."); 2720 ThmExitOnFailure(hr, "Failed when querying Billboard/@Interval attribute.");
2707 2721
2708 hr = ParseControls(hModule, wzRelativePath, pixn, pTheme, pControl, pPage); 2722 hr = ParseControls(hModule, wzRelativePath, pixn, pTheme, pControl, pPage);
2709 ExitOnFailure(hr, "Failed to parse billboard children."); 2723 ThmExitOnFailure(hr, "Failed to parse billboard children.");
2710 } 2724 }
2711 else if (THEME_CONTROL_TYPE_COMMANDLINK == pControl->type) 2725 else if (THEME_CONTROL_TYPE_COMMANDLINK == pControl->type)
2712 { 2726 {
2713 hr = ParseIcon(hModule, wzRelativePath, pixn, &pControl->hIcon); 2727 hr = ParseIcon(hModule, wzRelativePath, pixn, &pControl->hIcon);
2714 ExitOnFailure(hr, "Failed while parsing control icon."); 2728 ThmExitOnFailure(hr, "Failed while parsing control icon.");
2715 } 2729 }
2716 else if (THEME_CONTROL_TYPE_EDITBOX == pControl->type) 2730 else if (THEME_CONTROL_TYPE_EDITBOX == pControl->type)
2717 { 2731 {
@@ -2722,7 +2736,7 @@ static HRESULT ParseControl(
2722 } 2736 }
2723 else 2737 else
2724 { 2738 {
2725 ExitOnFailure(hr, "Failed when querying Editbox/@FileSystemAutoComplete attribute."); 2739 ThmExitOnFailure(hr, "Failed when querying Editbox/@FileSystemAutoComplete attribute.");
2726 2740
2727 if (fValue) 2741 if (fValue)
2728 { 2742 {
@@ -2737,14 +2751,14 @@ static HRESULT ParseControl(
2737 { 2751 {
2738 pControl->dwFontHoverId = THEME_INVALID_ID; 2752 pControl->dwFontHoverId = THEME_INVALID_ID;
2739 } 2753 }
2740 ExitOnFailure(hr, "Failed when querying control HoverFontId attribute."); 2754 ThmExitOnFailure(hr, "Failed when querying control HoverFontId attribute.");
2741 2755
2742 hr = XmlGetAttributeNumber(pixn, L"SelectedFontId", &pControl->dwFontSelectedId); 2756 hr = XmlGetAttributeNumber(pixn, L"SelectedFontId", &pControl->dwFontSelectedId);
2743 if (S_FALSE == hr) 2757 if (S_FALSE == hr)
2744 { 2758 {
2745 pControl->dwFontSelectedId = THEME_INVALID_ID; 2759 pControl->dwFontSelectedId = THEME_INVALID_ID;
2746 } 2760 }
2747 ExitOnFailure(hr, "Failed when querying control SelectedFontId attribute."); 2761 ThmExitOnFailure(hr, "Failed when querying control SelectedFontId attribute.");
2748 } 2762 }
2749 else if (THEME_CONTROL_TYPE_LABEL == pControl->type) 2763 else if (THEME_CONTROL_TYPE_LABEL == pControl->type)
2750 { 2764 {
@@ -2757,7 +2771,7 @@ static HRESULT ParseControl(
2757 { 2771 {
2758 pControl->dwStyle |= SS_CENTER; 2772 pControl->dwStyle |= SS_CENTER;
2759 } 2773 }
2760 ExitOnFailure(hr, "Failed when querying Label/@Center attribute."); 2774 ThmExitOnFailure(hr, "Failed when querying Label/@Center attribute.");
2761 2775
2762 hr = XmlGetYesNoAttribute(pixn, L"DisablePrefix", &fValue); 2776 hr = XmlGetYesNoAttribute(pixn, L"DisablePrefix", &fValue);
2763 if (E_NOTFOUND == hr) 2777 if (E_NOTFOUND == hr)
@@ -2768,57 +2782,57 @@ static HRESULT ParseControl(
2768 { 2782 {
2769 pControl->dwStyle |= SS_NOPREFIX; 2783 pControl->dwStyle |= SS_NOPREFIX;
2770 } 2784 }
2771 ExitOnFailure(hr, "Failed when querying Label/@DisablePrefix attribute."); 2785 ThmExitOnFailure(hr, "Failed when querying Label/@DisablePrefix attribute.");
2772 } 2786 }
2773 else if (THEME_CONTROL_TYPE_LISTVIEW == pControl->type) 2787 else if (THEME_CONTROL_TYPE_LISTVIEW == pControl->type)
2774 { 2788 {
2775 // Parse the optional extended window style. 2789 // Parse the optional extended window style.
2776 hr = XmlGetAttributeNumberBase(pixn, L"HexExtendedStyle", 16, &pControl->dwExtendedStyle); 2790 hr = XmlGetAttributeNumberBase(pixn, L"HexExtendedStyle", 16, &pControl->dwExtendedStyle);
2777 ExitOnFailure(hr, "Failed when querying ListView/@HexExtendedStyle attribute."); 2791 ThmExitOnFailure(hr, "Failed when querying ListView/@HexExtendedStyle attribute.");
2778 2792
2779 hr = XmlGetAttribute(pixn, L"ImageList", &bstrText); 2793 hr = XmlGetAttribute(pixn, L"ImageList", &bstrText);
2780 if (S_FALSE != hr) 2794 if (S_FALSE != hr)
2781 { 2795 {
2782 ExitOnFailure(hr, "Failed when querying ListView/@ImageList attribute."); 2796 ThmExitOnFailure(hr, "Failed when querying ListView/@ImageList attribute.");
2783 2797
2784 hr = FindImageList(pTheme, bstrText, &pControl->rghImageList[0]); 2798 hr = FindImageList(pTheme, bstrText, &pControl->rghImageList[0]);
2785 ExitOnFailure(hr, "Failed to find image list %ls while setting ImageList for ListView.", bstrText); 2799 ThmExitOnFailure(hr, "Failed to find image list %ls while setting ImageList for ListView.", bstrText);
2786 } 2800 }
2787 2801
2788 hr = XmlGetAttribute(pixn, L"ImageListSmall", &bstrText); 2802 hr = XmlGetAttribute(pixn, L"ImageListSmall", &bstrText);
2789 if (S_FALSE != hr) 2803 if (S_FALSE != hr)
2790 { 2804 {
2791 ExitOnFailure(hr, "Failed when querying ListView/@ImageListSmall attribute."); 2805 ThmExitOnFailure(hr, "Failed when querying ListView/@ImageListSmall attribute.");
2792 2806
2793 hr = FindImageList(pTheme, bstrText, &pControl->rghImageList[1]); 2807 hr = FindImageList(pTheme, bstrText, &pControl->rghImageList[1]);
2794 ExitOnFailure(hr, "Failed to find image list %ls while setting ImageListSmall for ListView.", bstrText); 2808 ThmExitOnFailure(hr, "Failed to find image list %ls while setting ImageListSmall for ListView.", bstrText);
2795 } 2809 }
2796 2810
2797 hr = XmlGetAttribute(pixn, L"ImageListState", &bstrText); 2811 hr = XmlGetAttribute(pixn, L"ImageListState", &bstrText);
2798 if (S_FALSE != hr) 2812 if (S_FALSE != hr)
2799 { 2813 {
2800 ExitOnFailure(hr, "Failed when querying ListView/@ImageListState attribute."); 2814 ThmExitOnFailure(hr, "Failed when querying ListView/@ImageListState attribute.");
2801 2815
2802 hr = FindImageList(pTheme, bstrText, &pControl->rghImageList[2]); 2816 hr = FindImageList(pTheme, bstrText, &pControl->rghImageList[2]);
2803 ExitOnFailure(hr, "Failed to find image list %ls while setting ImageListState for ListView.", bstrText); 2817 ThmExitOnFailure(hr, "Failed to find image list %ls while setting ImageListState for ListView.", bstrText);
2804 } 2818 }
2805 2819
2806 hr = XmlGetAttribute(pixn, L"ImageListGroupHeader", &bstrText); 2820 hr = XmlGetAttribute(pixn, L"ImageListGroupHeader", &bstrText);
2807 if (S_FALSE != hr) 2821 if (S_FALSE != hr)
2808 { 2822 {
2809 ExitOnFailure(hr, "Failed when querying ListView/@ImageListGroupHeader attribute."); 2823 ThmExitOnFailure(hr, "Failed when querying ListView/@ImageListGroupHeader attribute.");
2810 2824
2811 hr = FindImageList(pTheme, bstrText, &pControl->rghImageList[3]); 2825 hr = FindImageList(pTheme, bstrText, &pControl->rghImageList[3]);
2812 ExitOnFailure(hr, "Failed to find image list %ls while setting ImageListGroupHeader for ListView.", bstrText); 2826 ThmExitOnFailure(hr, "Failed to find image list %ls while setting ImageListGroupHeader for ListView.", bstrText);
2813 } 2827 }
2814 2828
2815 hr = ParseColumns(pixn, pControl); 2829 hr = ParseColumns(pixn, pControl);
2816 ExitOnFailure(hr, "Failed to parse columns."); 2830 ThmExitOnFailure(hr, "Failed to parse columns.");
2817 } 2831 }
2818 else if (THEME_CONTROL_TYPE_PANEL == pControl->type) 2832 else if (THEME_CONTROL_TYPE_PANEL == pControl->type)
2819 { 2833 {
2820 hr = ParseControls(hModule, wzRelativePath, pixn, pTheme, pControl, pPage); 2834 hr = ParseControls(hModule, wzRelativePath, pixn, pTheme, pControl, pPage);
2821 ExitOnFailure(hr, "Failed to parse panel children."); 2835 ThmExitOnFailure(hr, "Failed to parse panel children.");
2822 } 2836 }
2823 else if (THEME_CONTROL_TYPE_RADIOBUTTON == pControl->type) 2837 else if (THEME_CONTROL_TYPE_RADIOBUTTON == pControl->type)
2824 { 2838 {
@@ -2827,12 +2841,12 @@ static HRESULT ParseControl(
2827 { 2841 {
2828 hr = S_OK; 2842 hr = S_OK;
2829 } 2843 }
2830 ExitOnFailure(hr, "Failed when querying RadioButton/@Value attribute."); 2844 ThmExitOnFailure(hr, "Failed when querying RadioButton/@Value attribute.");
2831 } 2845 }
2832 else if (THEME_CONTROL_TYPE_TAB == pControl->type) 2846 else if (THEME_CONTROL_TYPE_TAB == pControl->type)
2833 { 2847 {
2834 hr = ParseTabs(pixn, pControl); 2848 hr = ParseTabs(pixn, pControl);
2835 ExitOnFailure(hr, "Failed to parse tabs"); 2849 ThmExitOnFailure(hr, "Failed to parse tabs");
2836 } 2850 }
2837 else if (THEME_CONTROL_TYPE_TREEVIEW == pControl->type) 2851 else if (THEME_CONTROL_TYPE_TREEVIEW == pControl->type)
2838 { 2852 {
@@ -2847,7 +2861,7 @@ static HRESULT ParseControl(
2847 { 2861 {
2848 pControl->dwStyle &= ~TVS_DISABLEDRAGDROP; 2862 pControl->dwStyle &= ~TVS_DISABLEDRAGDROP;
2849 } 2863 }
2850 ExitOnFailure(hr, "Failed when querying TreeView/@EnableDragDrop attribute."); 2864 ThmExitOnFailure(hr, "Failed when querying TreeView/@EnableDragDrop attribute.");
2851 2865
2852 hr = XmlGetYesNoAttribute(pixn, L"FullRowSelect", &fValue); 2866 hr = XmlGetYesNoAttribute(pixn, L"FullRowSelect", &fValue);
2853 if (E_NOTFOUND == hr) 2867 if (E_NOTFOUND == hr)
@@ -2858,7 +2872,7 @@ static HRESULT ParseControl(
2858 { 2872 {
2859 pControl->dwStyle |= TVS_FULLROWSELECT; 2873 pControl->dwStyle |= TVS_FULLROWSELECT;
2860 } 2874 }
2861 ExitOnFailure(hr, "Failed when querying TreeView/@FullRowSelect attribute."); 2875 ThmExitOnFailure(hr, "Failed when querying TreeView/@FullRowSelect attribute.");
2862 2876
2863 hr = XmlGetYesNoAttribute(pixn, L"HasButtons", &fValue); 2877 hr = XmlGetYesNoAttribute(pixn, L"HasButtons", &fValue);
2864 if (E_NOTFOUND == hr) 2878 if (E_NOTFOUND == hr)
@@ -2869,7 +2883,7 @@ static HRESULT ParseControl(
2869 { 2883 {
2870 pControl->dwStyle |= TVS_HASBUTTONS; 2884 pControl->dwStyle |= TVS_HASBUTTONS;
2871 } 2885 }
2872 ExitOnFailure(hr, "Failed when querying TreeView/@HasButtons attribute."); 2886 ThmExitOnFailure(hr, "Failed when querying TreeView/@HasButtons attribute.");
2873 2887
2874 hr = XmlGetYesNoAttribute(pixn, L"AlwaysShowSelect", &fValue); 2888 hr = XmlGetYesNoAttribute(pixn, L"AlwaysShowSelect", &fValue);
2875 if (E_NOTFOUND == hr) 2889 if (E_NOTFOUND == hr)
@@ -2880,7 +2894,7 @@ static HRESULT ParseControl(
2880 { 2894 {
2881 pControl->dwStyle |= TVS_SHOWSELALWAYS; 2895 pControl->dwStyle |= TVS_SHOWSELALWAYS;
2882 } 2896 }
2883 ExitOnFailure(hr, "Failed when querying TreeView/@AlwaysShowSelect attribute."); 2897 ThmExitOnFailure(hr, "Failed when querying TreeView/@AlwaysShowSelect attribute.");
2884 2898
2885 hr = XmlGetYesNoAttribute(pixn, L"LinesAtRoot", &fValue); 2899 hr = XmlGetYesNoAttribute(pixn, L"LinesAtRoot", &fValue);
2886 if (E_NOTFOUND == hr) 2900 if (E_NOTFOUND == hr)
@@ -2891,7 +2905,7 @@ static HRESULT ParseControl(
2891 { 2905 {
2892 pControl->dwStyle |= TVS_LINESATROOT; 2906 pControl->dwStyle |= TVS_LINESATROOT;
2893 } 2907 }
2894 ExitOnFailure(hr, "Failed when querying TreeView/@LinesAtRoot attribute."); 2908 ThmExitOnFailure(hr, "Failed when querying TreeView/@LinesAtRoot attribute.");
2895 2909
2896 hr = XmlGetYesNoAttribute(pixn, L"HasLines", &fValue); 2910 hr = XmlGetYesNoAttribute(pixn, L"HasLines", &fValue);
2897 if (E_NOTFOUND == hr) 2911 if (E_NOTFOUND == hr)
@@ -2902,7 +2916,7 @@ static HRESULT ParseControl(
2902 { 2916 {
2903 pControl->dwStyle |= TVS_HASLINES; 2917 pControl->dwStyle |= TVS_HASLINES;
2904 } 2918 }
2905 ExitOnFailure(hr, "Failed when querying TreeView/@HasLines attribute."); 2919 ThmExitOnFailure(hr, "Failed when querying TreeView/@HasLines attribute.");
2906 } 2920 }
2907 2921
2908LExit: 2922LExit:
@@ -2924,15 +2938,15 @@ static HRESULT ParseActions(
2924 BSTR bstrType = NULL; 2938 BSTR bstrType = NULL;
2925 2939
2926 hr = XmlSelectNodes(pixn, L"BrowseDirectoryAction|ChangePageAction|CloseWindowAction", &pixnl); 2940 hr = XmlSelectNodes(pixn, L"BrowseDirectoryAction|ChangePageAction|CloseWindowAction", &pixnl);
2927 ExitOnFailure(hr, "Failed to select child action nodes."); 2941 ThmExitOnFailure(hr, "Failed to select child action nodes.");
2928 2942
2929 hr = pixnl->get_length(reinterpret_cast<long*>(&pControl->cActions)); 2943 hr = pixnl->get_length(reinterpret_cast<long*>(&pControl->cActions));
2930 ExitOnFailure(hr, "Failed to count the number of action nodes."); 2944 ThmExitOnFailure(hr, "Failed to count the number of action nodes.");
2931 2945
2932 if (0 < pControl->cActions) 2946 if (0 < pControl->cActions)
2933 { 2947 {
2934 MemAllocArray(reinterpret_cast<LPVOID*>(&pControl->rgActions), sizeof(THEME_ACTION), pControl->cActions); 2948 MemAllocArray(reinterpret_cast<LPVOID*>(&pControl->rgActions), sizeof(THEME_ACTION), pControl->cActions);
2935 ExitOnNull(pControl->rgActions, hr, E_OUTOFMEMORY, "Failed to allocate THEME_ACTION structs."); 2949 ThmExitOnNull(pControl->rgActions, hr, E_OUTOFMEMORY, "Failed to allocate THEME_ACTION structs.");
2936 2950
2937 i = 0; 2951 i = 0;
2938 while (S_OK == (hr = XmlNextElement(pixnl, &pixnChild, &bstrType))) 2952 while (S_OK == (hr = XmlNextElement(pixnl, &pixnChild, &bstrType)))
@@ -2940,7 +2954,7 @@ static HRESULT ParseActions(
2940 if (!bstrType) 2954 if (!bstrType)
2941 { 2955 {
2942 hr = E_UNEXPECTED; 2956 hr = E_UNEXPECTED;
2943 ExitOnFailure(hr, "Null element encountered!"); 2957 ThmExitOnFailure(hr, "Null element encountered!");
2944 } 2958 }
2945 2959
2946 THEME_ACTION* pAction = pControl->rgActions + i; 2960 THEME_ACTION* pAction = pControl->rgActions + i;
@@ -2950,19 +2964,19 @@ static HRESULT ParseActions(
2950 pAction->type = THEME_ACTION_TYPE_BROWSE_DIRECTORY; 2964 pAction->type = THEME_ACTION_TYPE_BROWSE_DIRECTORY;
2951 2965
2952 hr = XmlGetAttributeEx(pixnChild, L"VariableName", &pAction->BrowseDirectory.sczVariableName); 2966 hr = XmlGetAttributeEx(pixnChild, L"VariableName", &pAction->BrowseDirectory.sczVariableName);
2953 ExitOnFailure(hr, "Failed when querying BrowseDirectoryAction/@VariableName attribute."); 2967 ThmExitOnFailure(hr, "Failed when querying BrowseDirectoryAction/@VariableName attribute.");
2954 } 2968 }
2955 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrType, -1, L"ChangePageAction", -1)) 2969 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrType, -1, L"ChangePageAction", -1))
2956 { 2970 {
2957 pAction->type = THEME_ACTION_TYPE_CHANGE_PAGE; 2971 pAction->type = THEME_ACTION_TYPE_CHANGE_PAGE;
2958 2972
2959 hr = XmlGetAttributeEx(pixnChild, L"Page", &pAction->ChangePage.sczPageName); 2973 hr = XmlGetAttributeEx(pixnChild, L"Page", &pAction->ChangePage.sczPageName);
2960 ExitOnFailure(hr, "Failed when querying ChangePageAction/@Page attribute."); 2974 ThmExitOnFailure(hr, "Failed when querying ChangePageAction/@Page attribute.");
2961 2975
2962 hr = XmlGetYesNoAttribute(pixnChild, L"Cancel", &pAction->ChangePage.fCancel); 2976 hr = XmlGetYesNoAttribute(pixnChild, L"Cancel", &pAction->ChangePage.fCancel);
2963 if (E_NOTFOUND != hr) 2977 if (E_NOTFOUND != hr)
2964 { 2978 {
2965 ExitOnFailure(hr, "Failed when querying ChangePageAction/@Cancel attribute."); 2979 ThmExitOnFailure(hr, "Failed when querying ChangePageAction/@Cancel attribute.");
2966 } 2980 }
2967 } 2981 }
2968 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrType, -1, L"CloseWindowAction", -1)) 2982 else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrType, -1, L"CloseWindowAction", -1))
@@ -2972,13 +2986,13 @@ static HRESULT ParseActions(
2972 else 2986 else
2973 { 2987 {
2974 hr = E_UNEXPECTED; 2988 hr = E_UNEXPECTED;
2975 ExitOnFailure(hr, "Unexpected element encountered: %ls", bstrType); 2989 ThmExitOnFailure(hr, "Unexpected element encountered: %ls", bstrType);
2976 } 2990 }
2977 2991
2978 hr = XmlGetAttributeEx(pixnChild, L"Condition", &pAction->sczCondition); 2992 hr = XmlGetAttributeEx(pixnChild, L"Condition", &pAction->sczCondition);
2979 if (E_NOTFOUND != hr) 2993 if (E_NOTFOUND != hr)
2980 { 2994 {
2981 ExitOnFailure(hr, "Failed when querying %ls/@Condition attribute.", bstrType); 2995 ThmExitOnFailure(hr, "Failed when querying %ls/@Condition attribute.", bstrType);
2982 } 2996 }
2983 2997
2984 if (!pAction->sczCondition) 2998 if (!pAction->sczCondition)
@@ -2986,7 +3000,7 @@ static HRESULT ParseActions(
2986 if (pControl->pDefaultAction) 3000 if (pControl->pDefaultAction)
2987 { 3001 {
2988 hr = E_INVALIDDATA; 3002 hr = E_INVALIDDATA;
2989 ExitOnFailure(hr, "Control '%ls' has multiple actions without a condition.", pControl->sczName); 3003 ThmExitOnFailure(hr, "Control '%ls' has multiple actions without a condition.", pControl->sczName);
2990 } 3004 }
2991 3005
2992 pControl->pDefaultAction = pAction; 3006 pControl->pDefaultAction = pAction;
@@ -3019,38 +3033,38 @@ static HRESULT ParseColumns(
3019 BSTR bstrText = NULL; 3033 BSTR bstrText = NULL;
3020 3034
3021 hr = XmlSelectNodes(pixn, L"Column", &pixnl); 3035 hr = XmlSelectNodes(pixn, L"Column", &pixnl);
3022 ExitOnFailure(hr, "Failed to select child column nodes."); 3036 ThmExitOnFailure(hr, "Failed to select child column nodes.");
3023 3037
3024 hr = pixnl->get_length(reinterpret_cast<long*>(&pControl->cColumns)); 3038 hr = pixnl->get_length(reinterpret_cast<long*>(&pControl->cColumns));
3025 ExitOnFailure(hr, "Failed to count the number of control columns."); 3039 ThmExitOnFailure(hr, "Failed to count the number of control columns.");
3026 3040
3027 if (0 < pControl->cColumns) 3041 if (0 < pControl->cColumns)
3028 { 3042 {
3029 hr = MemAllocArray(reinterpret_cast<LPVOID*>(&pControl->ptcColumns), sizeof(THEME_COLUMN), pControl->cColumns); 3043 hr = MemAllocArray(reinterpret_cast<LPVOID*>(&pControl->ptcColumns), sizeof(THEME_COLUMN), pControl->cColumns);
3030 ExitOnFailure(hr, "Failed to allocate column structs."); 3044 ThmExitOnFailure(hr, "Failed to allocate column structs.");
3031 3045
3032 i = 0; 3046 i = 0;
3033 while (S_OK == (hr = XmlNextElement(pixnl, &pixnChild, NULL))) 3047 while (S_OK == (hr = XmlNextElement(pixnl, &pixnChild, NULL)))
3034 { 3048 {
3035 hr = XmlGetText(pixnChild, &bstrText); 3049 hr = XmlGetText(pixnChild, &bstrText);
3036 ExitOnFailure(hr, "Failed to get inner text of column element."); 3050 ThmExitOnFailure(hr, "Failed to get inner text of column element.");
3037 3051
3038 hr = XmlGetAttributeNumber(pixnChild, L"Width", reinterpret_cast<DWORD*>(&pControl->ptcColumns[i].nBaseWidth)); 3052 hr = XmlGetAttributeNumber(pixnChild, L"Width", reinterpret_cast<DWORD*>(&pControl->ptcColumns[i].nBaseWidth));
3039 if (S_FALSE == hr) 3053 if (S_FALSE == hr)
3040 { 3054 {
3041 pControl->ptcColumns[i].nBaseWidth = 100; 3055 pControl->ptcColumns[i].nBaseWidth = 100;
3042 } 3056 }
3043 ExitOnFailure(hr, "Failed to get column width attribute."); 3057 ThmExitOnFailure(hr, "Failed to get column width attribute.");
3044 3058
3045 hr = XmlGetYesNoAttribute(pixnChild, L"Expands", reinterpret_cast<BOOL*>(&pControl->ptcColumns[i].fExpands)); 3059 hr = XmlGetYesNoAttribute(pixnChild, L"Expands", reinterpret_cast<BOOL*>(&pControl->ptcColumns[i].fExpands));
3046 if (E_NOTFOUND == hr) 3060 if (E_NOTFOUND == hr)
3047 { 3061 {
3048 hr = S_OK; 3062 hr = S_OK;
3049 } 3063 }
3050 ExitOnFailure(hr, "Failed to get expands attribute."); 3064 ThmExitOnFailure(hr, "Failed to get expands attribute.");
3051 3065
3052 hr = StrAllocString(&(pControl->ptcColumns[i].pszName), bstrText, 0); 3066 hr = StrAllocString(&(pControl->ptcColumns[i].pszName), bstrText, 0);
3053 ExitOnFailure(hr, "Failed to copy column name."); 3067 ThmExitOnFailure(hr, "Failed to copy column name.");
3054 3068
3055 ++i; 3069 ++i;
3056 ReleaseNullBSTR(bstrText); 3070 ReleaseNullBSTR(bstrText);
@@ -3092,7 +3106,7 @@ static HRESULT ParseRadioButtons(
3092 GetControls(pTheme, pParentControl, &pcControls, &prgControls); 3106 GetControls(pTheme, pParentControl, &pcControls, &prgControls);
3093 3107
3094 hr = XmlSelectNodes(pixn, L"RadioButtons", &pixnlRadioButtons); 3108 hr = XmlSelectNodes(pixn, L"RadioButtons", &pixnlRadioButtons);
3095 ExitOnFailure(hr, "Failed to select RadioButtons nodes."); 3109 ThmExitOnFailure(hr, "Failed to select RadioButtons nodes.");
3096 3110
3097 while (S_OK == (hr = XmlNextElement(pixnlRadioButtons, &pixnRadioButtons, NULL))) 3111 while (S_OK == (hr = XmlNextElement(pixnlRadioButtons, &pixnRadioButtons, NULL)))
3098 { 3112 {
@@ -3101,13 +3115,13 @@ static HRESULT ParseRadioButtons(
3101 { 3115 {
3102 hr = S_OK; 3116 hr = S_OK;
3103 } 3117 }
3104 ExitOnFailure(hr, "Failed when querying RadioButtons Name."); 3118 ThmExitOnFailure(hr, "Failed when querying RadioButtons Name.");
3105 3119
3106 hr = XmlSelectNodes(pixnRadioButtons, L"RadioButton", &pixnl); 3120 hr = XmlSelectNodes(pixnRadioButtons, L"RadioButton", &pixnl);
3107 ExitOnFailure(hr, "Failed to select RadioButton nodes."); 3121 ThmExitOnFailure(hr, "Failed to select RadioButton nodes.");
3108 3122
3109 hr = pixnl->get_length(reinterpret_cast<long*>(&cRadioButtons)); 3123 hr = pixnl->get_length(reinterpret_cast<long*>(&cRadioButtons));
3110 ExitOnFailure(hr, "Failed to count the number of RadioButton nodes."); 3124 ThmExitOnFailure(hr, "Failed to count the number of RadioButton nodes.");
3111 3125
3112 if (cRadioButtons) 3126 if (cRadioButtons)
3113 { 3127 {
@@ -3118,7 +3132,7 @@ static HRESULT ParseRadioButtons(
3118 } 3132 }
3119 3133
3120 hr = MemReAllocArray(reinterpret_cast<LPVOID*>(prgControls), *pcControls, sizeof(THEME_CONTROL), cRadioButtons); 3134 hr = MemReAllocArray(reinterpret_cast<LPVOID*>(prgControls), *pcControls, sizeof(THEME_CONTROL), cRadioButtons);
3121 ExitOnFailure(hr, "Failed to reallocate theme controls."); 3135 ThmExitOnFailure(hr, "Failed to reallocate theme controls.");
3122 3136
3123 iControl = *pcControls; 3137 iControl = *pcControls;
3124 *pcControls += cRadioButtons; 3138 *pcControls += cRadioButtons;
@@ -3131,7 +3145,7 @@ static HRESULT ParseRadioButtons(
3131 pControl->type = THEME_CONTROL_TYPE_RADIOBUTTON; 3145 pControl->type = THEME_CONTROL_TYPE_RADIOBUTTON;
3132 3146
3133 hr = ParseControl(hModule, wzRelativePath, pixnChild, pTheme, pControl, FALSE, pPage); 3147 hr = ParseControl(hModule, wzRelativePath, pixnChild, pTheme, pControl, FALSE, pPage);
3134 ExitOnFailure(hr, "Failed to parse control."); 3148 ThmExitOnFailure(hr, "Failed to parse control.");
3135 3149
3136 if (fFirst) 3150 if (fFirst)
3137 { 3151 {
@@ -3140,7 +3154,7 @@ static HRESULT ParseRadioButtons(
3140 } 3154 }
3141 3155
3142 hr = StrAllocString(&pControl->sczVariable, sczName, 0); 3156 hr = StrAllocString(&pControl->sczVariable, sczName, 0);
3143 ExitOnFailure(hr, "Failed to copy radio button variable."); 3157 ThmExitOnFailure(hr, "Failed to copy radio button variable.");
3144 3158
3145 if (pPage) 3159 if (pPage)
3146 { 3160 {
@@ -3181,24 +3195,24 @@ static HRESULT ParseTabs(
3181 BSTR bstrText = NULL; 3195 BSTR bstrText = NULL;
3182 3196
3183 hr = XmlSelectNodes(pixn, L"Tab", &pixnl); 3197 hr = XmlSelectNodes(pixn, L"Tab", &pixnl);
3184 ExitOnFailure(hr, "Failed to select child tab nodes."); 3198 ThmExitOnFailure(hr, "Failed to select child tab nodes.");
3185 3199
3186 hr = pixnl->get_length(reinterpret_cast<long*>(&pControl->cTabs)); 3200 hr = pixnl->get_length(reinterpret_cast<long*>(&pControl->cTabs));
3187 ExitOnFailure(hr, "Failed to count the number of tabs."); 3201 ThmExitOnFailure(hr, "Failed to count the number of tabs.");
3188 3202
3189 if (0 < pControl->cTabs) 3203 if (0 < pControl->cTabs)
3190 { 3204 {
3191 hr = MemAllocArray(reinterpret_cast<LPVOID*>(&pControl->pttTabs), sizeof(THEME_TAB), pControl->cTabs); 3205 hr = MemAllocArray(reinterpret_cast<LPVOID*>(&pControl->pttTabs), sizeof(THEME_TAB), pControl->cTabs);
3192 ExitOnFailure(hr, "Failed to allocate tab structs."); 3206 ThmExitOnFailure(hr, "Failed to allocate tab structs.");
3193 3207
3194 i = 0; 3208 i = 0;
3195 while (S_OK == (hr = XmlNextElement(pixnl, &pixnChild, NULL))) 3209 while (S_OK == (hr = XmlNextElement(pixnl, &pixnChild, NULL)))
3196 { 3210 {
3197 hr = XmlGetText(pixnChild, &bstrText); 3211 hr = XmlGetText(pixnChild, &bstrText);
3198 ExitOnFailure(hr, "Failed to get inner text of tab element."); 3212 ThmExitOnFailure(hr, "Failed to get inner text of tab element.");
3199 3213
3200 hr = StrAllocString(&(pControl->pttTabs[i].pszName), bstrText, 0); 3214 hr = StrAllocString(&(pControl->pttTabs[i].pszName), bstrText, 0);
3201 ExitOnFailure(hr, "Failed to copy tab name."); 3215 ThmExitOnFailure(hr, "Failed to copy tab name.");
3202 3216
3203 ++i; 3217 ++i;
3204 ReleaseNullBSTR(bstrText); 3218 ReleaseNullBSTR(bstrText);
@@ -3227,17 +3241,17 @@ static HRESULT ParseText(
3227 BSTR bstrText = NULL; 3241 BSTR bstrText = NULL;
3228 3242
3229 hr = XmlSelectNodes(pixn, L"Text", &pixnl); 3243 hr = XmlSelectNodes(pixn, L"Text", &pixnl);
3230 ExitOnFailure(hr, "Failed to select child Text nodes."); 3244 ThmExitOnFailure(hr, "Failed to select child Text nodes.");
3231 3245
3232 hr = pixnl->get_length(reinterpret_cast<long*>(&pControl->cConditionalText)); 3246 hr = pixnl->get_length(reinterpret_cast<long*>(&pControl->cConditionalText));
3233 ExitOnFailure(hr, "Failed to count the number of Text nodes."); 3247 ThmExitOnFailure(hr, "Failed to count the number of Text nodes.");
3234 3248
3235 *pfAnyChildren |= 0 < pControl->cConditionalText; 3249 *pfAnyChildren |= 0 < pControl->cConditionalText;
3236 3250
3237 if (0 < pControl->cConditionalText) 3251 if (0 < pControl->cConditionalText)
3238 { 3252 {
3239 MemAllocArray(reinterpret_cast<LPVOID*>(&pControl->rgConditionalText), sizeof(THEME_CONDITIONAL_TEXT), pControl->cConditionalText); 3253 MemAllocArray(reinterpret_cast<LPVOID*>(&pControl->rgConditionalText), sizeof(THEME_CONDITIONAL_TEXT), pControl->cConditionalText);
3240 ExitOnNull(pControl->rgConditionalText, hr, E_OUTOFMEMORY, "Failed to allocate THEME_CONDITIONAL_TEXT structs."); 3254 ThmExitOnNull(pControl->rgConditionalText, hr, E_OUTOFMEMORY, "Failed to allocate THEME_CONDITIONAL_TEXT structs.");
3241 3255
3242 i = 0; 3256 i = 0;
3243 while (S_OK == (hr = XmlNextElement(pixnl, &pixnChild, NULL))) 3257 while (S_OK == (hr = XmlNextElement(pixnl, &pixnChild, NULL)))
@@ -3249,17 +3263,17 @@ static HRESULT ParseText(
3249 { 3263 {
3250 hr = S_OK; 3264 hr = S_OK;
3251 } 3265 }
3252 ExitOnFailure(hr, "Failed when querying Text/@Condition attribute."); 3266 ThmExitOnFailure(hr, "Failed when querying Text/@Condition attribute.");
3253 3267
3254 hr = XmlGetText(pixnChild, &bstrText); 3268 hr = XmlGetText(pixnChild, &bstrText);
3255 ExitOnFailure(hr, "Failed to get inner text of Text element."); 3269 ThmExitOnFailure(hr, "Failed to get inner text of Text element.");
3256 3270
3257 if (S_OK == hr) 3271 if (S_OK == hr)
3258 { 3272 {
3259 if (pConditionalText->sczCondition) 3273 if (pConditionalText->sczCondition)
3260 { 3274 {
3261 hr = StrAllocString(&pConditionalText->sczText, bstrText, 0); 3275 hr = StrAllocString(&pConditionalText->sczText, bstrText, 0);
3262 ExitOnFailure(hr, "Failed to copy text to conditional text."); 3276 ThmExitOnFailure(hr, "Failed to copy text to conditional text.");
3263 3277
3264 ++i; 3278 ++i;
3265 } 3279 }
@@ -3268,11 +3282,11 @@ static HRESULT ParseText(
3268 if (pControl->sczText) 3282 if (pControl->sczText)
3269 { 3283 {
3270 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); 3284 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
3271 ExitOnFailure(hr, "Unconditional text for the '%ls' control is specified multiple times.", pControl->sczName); 3285 ThmExitOnFailure(hr, "Unconditional text for the '%ls' control is specified multiple times.", pControl->sczName);
3272 } 3286 }
3273 3287
3274 hr = StrAllocString(&pControl->sczText, bstrText, 0); 3288 hr = StrAllocString(&pControl->sczText, bstrText, 0);
3275 ExitOnFailure(hr, "Failed to copy text to control."); 3289 ThmExitOnFailure(hr, "Failed to copy text to control.");
3276 3290
3277 // Unconditional text entries aren't stored in the conditional text list. 3291 // Unconditional text entries aren't stored in the conditional text list.
3278 --pControl->cConditionalText; 3292 --pControl->cConditionalText;
@@ -3303,19 +3317,19 @@ static HRESULT ParseTooltips(
3303 BSTR bstrText = NULL; 3317 BSTR bstrText = NULL;
3304 3318
3305 hr = XmlSelectSingleNode(pixn, L"Tooltip", &pixnChild); 3319 hr = XmlSelectSingleNode(pixn, L"Tooltip", &pixnChild);
3306 ExitOnFailure(hr, "Failed to select child Tooltip node."); 3320 ThmExitOnFailure(hr, "Failed to select child Tooltip node.");
3307 3321
3308 if (S_OK == hr) 3322 if (S_OK == hr)
3309 { 3323 {
3310 *pfAnyChildren |= TRUE; 3324 *pfAnyChildren |= TRUE;
3311 3325
3312 hr = XmlGetText(pixnChild, &bstrText); 3326 hr = XmlGetText(pixnChild, &bstrText);
3313 ExitOnFailure(hr, "Failed to get inner text of Tooltip element."); 3327 ThmExitOnFailure(hr, "Failed to get inner text of Tooltip element.");
3314 3328
3315 if (S_OK == hr) 3329 if (S_OK == hr)
3316 { 3330 {
3317 hr = StrAllocString(&pControl->sczTooltip, bstrText, 0); 3331 hr = StrAllocString(&pControl->sczTooltip, bstrText, 0);
3318 ExitOnFailure(hr, "Failed to copy tooltip text to control."); 3332 ThmExitOnFailure(hr, "Failed to copy tooltip text to control.");
3319 } 3333 }
3320 } 3334 }
3321 3335
@@ -3340,10 +3354,10 @@ static HRESULT ParseNotes(
3340 BSTR bstrText = NULL; 3354 BSTR bstrText = NULL;
3341 3355
3342 hr = XmlSelectNodes(pixn, L"Note", &pixnl); 3356 hr = XmlSelectNodes(pixn, L"Note", &pixnl);
3343 ExitOnFailure(hr, "Failed to select child Note nodes."); 3357 ThmExitOnFailure(hr, "Failed to select child Note nodes.");
3344 3358
3345 hr = pixnl->get_length(reinterpret_cast<long*>(&pControl->cConditionalNotes)); 3359 hr = pixnl->get_length(reinterpret_cast<long*>(&pControl->cConditionalNotes));
3346 ExitOnFailure(hr, "Failed to count the number of Note nodes."); 3360 ThmExitOnFailure(hr, "Failed to count the number of Note nodes.");
3347 3361
3348 if (pfAnyChildren) 3362 if (pfAnyChildren)
3349 { 3363 {
@@ -3353,7 +3367,7 @@ static HRESULT ParseNotes(
3353 if (0 < pControl->cConditionalNotes) 3367 if (0 < pControl->cConditionalNotes)
3354 { 3368 {
3355 MemAllocArray(reinterpret_cast<LPVOID*>(&pControl->rgConditionalNotes), sizeof(THEME_CONDITIONAL_TEXT), pControl->cConditionalNotes); 3369 MemAllocArray(reinterpret_cast<LPVOID*>(&pControl->rgConditionalNotes), sizeof(THEME_CONDITIONAL_TEXT), pControl->cConditionalNotes);
3356 ExitOnNull(pControl->rgConditionalNotes, hr, E_OUTOFMEMORY, "Failed to allocate note THEME_CONDITIONAL_TEXT structs."); 3370 ThmExitOnNull(pControl->rgConditionalNotes, hr, E_OUTOFMEMORY, "Failed to allocate note THEME_CONDITIONAL_TEXT structs.");
3357 3371
3358 i = 0; 3372 i = 0;
3359 while (S_OK == (hr = XmlNextElement(pixnl, &pixnChild, NULL))) 3373 while (S_OK == (hr = XmlNextElement(pixnl, &pixnChild, NULL)))
@@ -3365,17 +3379,17 @@ static HRESULT ParseNotes(
3365 { 3379 {
3366 hr = S_OK; 3380 hr = S_OK;
3367 } 3381 }
3368 ExitOnFailure(hr, "Failed when querying Note/@Condition attribute."); 3382 ThmExitOnFailure(hr, "Failed when querying Note/@Condition attribute.");
3369 3383
3370 hr = XmlGetText(pixnChild, &bstrText); 3384 hr = XmlGetText(pixnChild, &bstrText);
3371 ExitOnFailure(hr, "Failed to get inner text of Note element."); 3385 ThmExitOnFailure(hr, "Failed to get inner text of Note element.");
3372 3386
3373 if (S_OK == hr) 3387 if (S_OK == hr)
3374 { 3388 {
3375 if (pConditionalNote->sczCondition) 3389 if (pConditionalNote->sczCondition)
3376 { 3390 {
3377 hr = StrAllocString(&pConditionalNote->sczText, bstrText, 0); 3391 hr = StrAllocString(&pConditionalNote->sczText, bstrText, 0);
3378 ExitOnFailure(hr, "Failed to copy text to conditional note text."); 3392 ThmExitOnFailure(hr, "Failed to copy text to conditional note text.");
3379 3393
3380 ++i; 3394 ++i;
3381 } 3395 }
@@ -3384,11 +3398,11 @@ static HRESULT ParseNotes(
3384 if (pControl->sczNote) 3398 if (pControl->sczNote)
3385 { 3399 {
3386 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); 3400 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
3387 ExitOnFailure(hr, "Unconditional note text for the '%ls' control is specified multiple times.", pControl->sczName); 3401 ThmExitOnFailure(hr, "Unconditional note text for the '%ls' control is specified multiple times.", pControl->sczName);
3388 } 3402 }
3389 3403
3390 hr = StrAllocString(&pControl->sczNote, bstrText, 0); 3404 hr = StrAllocString(&pControl->sczNote, bstrText, 0);
3391 ExitOnFailure(hr, "Failed to copy text to command link control."); 3405 ThmExitOnFailure(hr, "Failed to copy text to command link control.");
3392 3406
3393 // Unconditional note entries aren't stored in the conditional notes list. 3407 // Unconditional note entries aren't stored in the conditional notes list.
3394 --pControl->cConditionalNotes; 3408 --pControl->cConditionalNotes;
@@ -3427,7 +3441,7 @@ static HRESULT StartBillboard(
3427 3441
3428 if (!::SetTimer(pTheme->hwndParent, pControl->wId, pControl->wBillboardInterval, NULL)) 3442 if (!::SetTimer(pTheme->hwndParent, pControl->wId, pControl->wBillboardInterval, NULL))
3429 { 3443 {
3430 ExitWithLastError(hr, "Failed to start billboard."); 3444 ThmExitWithLastError(hr, "Failed to start billboard.");
3431 } 3445 }
3432 3446
3433 hr = S_OK; 3447 hr = S_OK;
@@ -3865,7 +3879,7 @@ static DWORD CALLBACK RichEditStreamFromFileHandleCallback(
3865 3879
3866 if (!::ReadFile(hFile, pbBuff, cb, reinterpret_cast<DWORD*>(pcb), NULL)) 3880 if (!::ReadFile(hFile, pbBuff, cb, reinterpret_cast<DWORD*>(pcb), NULL))
3867 { 3881 {
3868 ExitWithLastError(hr, "Failed to read file"); 3882 ThmExitWithLastError(hr, "Failed to read file");
3869 } 3883 }
3870 3884
3871LExit: 3885LExit:
@@ -3967,17 +3981,17 @@ static void OnBrowseDirectory(
3967 if (pTargetControl && THEME_CONTROL_TYPE_EDITBOX == pTargetControl->type && !pTargetControl->fDisableVariableFunctionality) 3981 if (pTargetControl && THEME_CONTROL_TYPE_EDITBOX == pTargetControl->type && !pTargetControl->fDisableVariableFunctionality)
3968 { 3982 {
3969 hr = ThemeSetTextControl(pTheme, pTargetControl->wId, wzPath); 3983 hr = ThemeSetTextControl(pTheme, pTargetControl->wId, wzPath);
3970 ExitOnFailure(hr, "Failed to set text on editbox: %ls", pTargetControl->sczName); 3984 ThmExitOnFailure(hr, "Failed to set text on editbox: %ls", pTargetControl->sczName);
3971 } 3985 }
3972 else if (pTheme->pfnSetStringVariable) 3986 else if (pTheme->pfnSetStringVariable)
3973 { 3987 {
3974 hr = pTheme->pfnSetStringVariable(pAction->BrowseDirectory.sczVariableName, wzPath, pTheme->pvVariableContext); 3988 hr = pTheme->pfnSetStringVariable(pAction->BrowseDirectory.sczVariableName, wzPath, pTheme->pvVariableContext);
3975 ExitOnFailure(hr, "Failed to set variable: %ls", pAction->BrowseDirectory.sczVariableName); 3989 ThmExitOnFailure(hr, "Failed to set variable: %ls", pAction->BrowseDirectory.sczVariableName);
3976 } 3990 }
3977 else if (pTargetControl) 3991 else if (pTargetControl)
3978 { 3992 {
3979 hr = ThemeSetTextControl(pTheme, pTargetControl->wId, wzPath); 3993 hr = ThemeSetTextControl(pTheme, pTargetControl->wId, wzPath);
3980 ExitOnFailure(hr, "Failed to set text on control: %ls", pTargetControl->sczName); 3994 ThmExitOnFailure(hr, "Failed to set text on control: %ls", pTargetControl->sczName);
3981 } 3995 }
3982 3996
3983 ThemeShowPageEx(pTheme, pTheme->dwCurrentPageId, SW_SHOW, THEME_SHOW_PAGE_REASON_REFRESH); 3997 ThemeShowPageEx(pTheme, pTheme->dwCurrentPageId, SW_SHOW, THEME_SHOW_PAGE_REASON_REFRESH);
@@ -4019,7 +4033,7 @@ static BOOL OnButtonClicked(
4019 BOOL fCondition = FALSE; 4033 BOOL fCondition = FALSE;
4020 4034
4021 hr = pTheme->pfnEvaluateCondition(pAction->sczCondition, &fCondition, pTheme->pvVariableContext); 4035 hr = pTheme->pfnEvaluateCondition(pAction->sczCondition, &fCondition, pTheme->pvVariableContext);
4022 ExitOnFailure(hr, "Failed to evaluate condition: %ls", pAction->sczCondition); 4036 ThmExitOnFailure(hr, "Failed to evaluate condition: %ls", pAction->sczCondition);
4023 4037
4024 if (fCondition) 4038 if (fCondition)
4025 { 4039 {
@@ -4049,7 +4063,7 @@ static BOOL OnButtonClicked(
4049 4063
4050 if (!dwPageId) 4064 if (!dwPageId)
4051 { 4065 {
4052 ExitOnFailure(E_INVALIDDATA, "Unknown page: %ls", pChosenAction->ChangePage.sczPageName); 4066 ThmExitOnFailure(E_INVALIDDATA, "Unknown page: %ls", pChosenAction->ChangePage.sczPageName);
4053 } 4067 }
4054 4068
4055 ThemeShowPageEx(pTheme, pTheme->dwCurrentPageId, SW_HIDE, pChosenAction->ChangePage.fCancel ? THEME_SHOW_PAGE_REASON_CANCEL : THEME_SHOW_PAGE_REASON_DEFAULT); 4069 ThemeShowPageEx(pTheme, pTheme->dwCurrentPageId, SW_HIDE, pChosenAction->ChangePage.fCancel ? THEME_SHOW_PAGE_REASON_CANCEL : THEME_SHOW_PAGE_REASON_DEFAULT);
@@ -4108,7 +4122,7 @@ static HRESULT OnRichEditEnLink(
4108 case WM_LBUTTONDOWN: 4122 case WM_LBUTTONDOWN:
4109 { 4123 {
4110 hr = StrAlloc(&sczLink, link->chrg.cpMax - link->chrg.cpMin + 2); 4124 hr = StrAlloc(&sczLink, link->chrg.cpMax - link->chrg.cpMin + 2);
4111 ExitOnFailure(hr, "Failed to allocate string for link."); 4125 ThmExitOnFailure(hr, "Failed to allocate string for link.");
4112 4126
4113 TEXTRANGEW tr; 4127 TEXTRANGEW tr;
4114 tr.chrg.cpMin = link->chrg.cpMin; 4128 tr.chrg.cpMin = link->chrg.cpMin;
@@ -4118,7 +4132,7 @@ static HRESULT OnRichEditEnLink(
4118 if (0 < ::SendMessageW(hWndRichEdit, EM_GETTEXTRANGE, 0, reinterpret_cast<LPARAM>(&tr))) 4132 if (0 < ::SendMessageW(hWndRichEdit, EM_GETTEXTRANGE, 0, reinterpret_cast<LPARAM>(&tr)))
4119 { 4133 {
4120 hr = ShelExec(sczLink, NULL, L"open", NULL, SW_SHOWDEFAULT, hWnd, NULL); 4134 hr = ShelExec(sczLink, NULL, L"open", NULL, SW_SHOWDEFAULT, hWnd, NULL);
4121 ExitOnFailure(hr, "Failed to launch link: %ls", sczLink); 4135 ThmExitOnFailure(hr, "Failed to launch link: %ls", sczLink);
4122 } 4136 }
4123 4137
4124 break; 4138 break;
@@ -4209,7 +4223,7 @@ static HRESULT SizeListViewColumns(
4209 4223
4210 if (!::GetWindowRect(pControl->hWnd, &rcParent)) 4224 if (!::GetWindowRect(pControl->hWnd, &rcParent))
4211 { 4225 {
4212 ExitWithLastError(hr, "Failed to get window rect of listview control."); 4226 ThmExitWithLastError(hr, "Failed to get window rect of listview control.");
4213 } 4227 }
4214 4228
4215 iExtraAvailableSize = rcParent.right - rcParent.left; 4229 iExtraAvailableSize = rcParent.right - rcParent.left;
@@ -4270,10 +4284,10 @@ static HRESULT ShowControl(
4270 fSaveEditboxes && THEME_CONTROL_TYPE_EDITBOX == pControl->type && pControl->sczName && *pControl->sczName) 4284 fSaveEditboxes && THEME_CONTROL_TYPE_EDITBOX == pControl->type && pControl->sczName && *pControl->sczName)
4271 { 4285 {
4272 hr = ThemeGetTextControl(pTheme, pControl->wId, &sczText); 4286 hr = ThemeGetTextControl(pTheme, pControl->wId, &sczText);
4273 ExitOnFailure(hr, "Failed to get the text for control: %ls", pControl->sczName); 4287 ThmExitOnFailure(hr, "Failed to get the text for control: %ls", pControl->sczName);
4274 4288
4275 hr = pTheme->pfnSetStringVariable(pControl->sczName, sczText, pTheme->pvVariableContext); 4289 hr = pTheme->pfnSetStringVariable(pControl->sczName, sczText, pTheme->pvVariableContext);
4276 ExitOnFailure(hr, "Failed to set the variable '%ls' to '%ls'", pControl->sczName, sczText); 4290 ThmExitOnFailure(hr, "Failed to set the variable '%ls' to '%ls'", pControl->sczName, sczText);
4277 } 4291 }
4278 4292
4279 HWND hWnd = pControl->hWnd; 4293 HWND hWnd = pControl->hWnd;
@@ -4301,14 +4315,14 @@ static HRESULT ShowControl(
4301 if (pControl->sczVisibleCondition) 4315 if (pControl->sczVisibleCondition)
4302 { 4316 {
4303 hr = pTheme->pfnEvaluateCondition(pControl->sczVisibleCondition, &fVisible, pTheme->pvVariableContext); 4317 hr = pTheme->pfnEvaluateCondition(pControl->sczVisibleCondition, &fVisible, pTheme->pvVariableContext);
4304 ExitOnFailure(hr, "Failed to evaluate VisibleCondition: %ls", pControl->sczVisibleCondition); 4318 ThmExitOnFailure(hr, "Failed to evaluate VisibleCondition: %ls", pControl->sczVisibleCondition);
4305 } 4319 }
4306 4320
4307 // If the control has an EnableCondition, check if it's true. 4321 // If the control has an EnableCondition, check if it's true.
4308 if (pControl->sczEnableCondition) 4322 if (pControl->sczEnableCondition)
4309 { 4323 {
4310 hr = pTheme->pfnEvaluateCondition(pControl->sczEnableCondition, &fEnabled, pTheme->pvVariableContext); 4324 hr = pTheme->pfnEvaluateCondition(pControl->sczEnableCondition, &fEnabled, pTheme->pvVariableContext);
4311 ExitOnFailure(hr, "Failed to evaluate EnableCondition: %ls", pControl->sczEnableCondition); 4325 ThmExitOnFailure(hr, "Failed to evaluate EnableCondition: %ls", pControl->sczEnableCondition);
4312 } 4326 }
4313 } 4327 }
4314 4328
@@ -4332,7 +4346,7 @@ static HRESULT ShowControl(
4332 BOOL fCondition = FALSE; 4346 BOOL fCondition = FALSE;
4333 4347
4334 hr = pTheme->pfnEvaluateCondition(pConditionalText->sczCondition, &fCondition, pTheme->pvVariableContext); 4348 hr = pTheme->pfnEvaluateCondition(pConditionalText->sczCondition, &fCondition, pTheme->pvVariableContext);
4335 ExitOnFailure(hr, "Failed to evaluate condition: %ls", pConditionalText->sczCondition); 4349 ThmExitOnFailure(hr, "Failed to evaluate condition: %ls", pConditionalText->sczCondition);
4336 4350
4337 if (fCondition) 4351 if (fCondition)
4338 { 4352 {
@@ -4352,7 +4366,7 @@ static HRESULT ShowControl(
4352 BOOL fCondition = FALSE; 4366 BOOL fCondition = FALSE;
4353 4367
4354 hr = pTheme->pfnEvaluateCondition(pConditionalNote->sczCondition, &fCondition, pTheme->pvVariableContext); 4368 hr = pTheme->pfnEvaluateCondition(pConditionalNote->sczCondition, &fCondition, pTheme->pvVariableContext);
4355 ExitOnFailure(hr, "Failed to evaluate note condition: %ls", pConditionalNote->sczCondition); 4369 ThmExitOnFailure(hr, "Failed to evaluate note condition: %ls", pConditionalNote->sczCondition);
4356 4370
4357 if (fCondition) 4371 if (fCondition)
4358 { 4372 {
@@ -4366,7 +4380,7 @@ static HRESULT ShowControl(
4366 if (wzText && *wzText) 4380 if (wzText && *wzText)
4367 { 4381 {
4368 hr = pTheme->pfnFormatString(wzText, &sczText, pTheme->pvVariableContext); 4382 hr = pTheme->pfnFormatString(wzText, &sczText, pTheme->pvVariableContext);
4369 ExitOnFailure(hr, "Failed to format string: %ls", wzText); 4383 ThmExitOnFailure(hr, "Failed to format string: %ls", wzText);
4370 } 4384 }
4371 else 4385 else
4372 { 4386 {
@@ -4378,7 +4392,7 @@ static HRESULT ShowControl(
4378 if (wzNote && *wzNote) 4392 if (wzNote && *wzNote)
4379 { 4393 {
4380 hr = pTheme->pfnFormatString(wzNote, &sczText, pTheme->pvVariableContext); 4394 hr = pTheme->pfnFormatString(wzNote, &sczText, pTheme->pvVariableContext);
4381 ExitOnFailure(hr, "Failed to format note: %ls", wzNote); 4395 ThmExitOnFailure(hr, "Failed to format note: %ls", wzNote);
4382 } 4396 }
4383 else 4397 else
4384 { 4398 {
@@ -4401,7 +4415,7 @@ static HRESULT ShowControl(
4401 { 4415 {
4402 hr = S_OK; 4416 hr = S_OK;
4403 } 4417 }
4404 ExitOnFailure(hr, "Failed to get numeric variable: %ls", pControl->sczName); 4418 ThmExitOnFailure(hr, "Failed to get numeric variable: %ls", pControl->sczName);
4405 4419
4406 if (THEME_SHOW_PAGE_REASON_REFRESH != reason && pPage && pControl->wPageId) 4420 if (THEME_SHOW_PAGE_REASON_REFRESH != reason && pPage && pControl->wPageId)
4407 { 4421 {
@@ -4411,7 +4425,7 @@ static HRESULT ShowControl(
4411 if (SUCCEEDED(hr)) 4425 if (SUCCEEDED(hr))
4412 { 4426 {
4413 hr = StrAllocFormattedSecure(&pSavedVariable->sczValue, L"%lld", llValue); 4427 hr = StrAllocFormattedSecure(&pSavedVariable->sczValue, L"%lld", llValue);
4414 ExitOnFailure(hr, "Failed to save variable: %ls", pControl->sczName); 4428 ThmExitOnFailure(hr, "Failed to save variable: %ls", pControl->sczName);
4415 } 4429 }
4416 4430
4417 ++iPageControl; 4431 ++iPageControl;
@@ -4431,7 +4445,7 @@ static HRESULT ShowControl(
4431 } 4445 }
4432 else 4446 else
4433 { 4447 {
4434 ExitOnFailure(hr, "Failed to get string variable: %ls", pControl->sczName); 4448 ThmExitOnFailure(hr, "Failed to get string variable: %ls", pControl->sczName);
4435 } 4449 }
4436 4450
4437 if (THEME_SHOW_PAGE_REASON_REFRESH != reason && pPage && pControl->wPageId) 4451 if (THEME_SHOW_PAGE_REASON_REFRESH != reason && pPage && pControl->wPageId)
@@ -4442,7 +4456,7 @@ static HRESULT ShowControl(
4442 if (SUCCEEDED(hr)) 4456 if (SUCCEEDED(hr))
4443 { 4457 {
4444 hr = StrAllocStringSecure(&pSavedVariable->sczValue, sczText, 0); 4458 hr = StrAllocStringSecure(&pSavedVariable->sczValue, sczText, 0);
4445 ExitOnFailure(hr, "Failed to save variable: %ls", pControl->sczName); 4459 ThmExitOnFailure(hr, "Failed to save variable: %ls", pControl->sczName);
4446 } 4460 }
4447 4461
4448 ++iPageControl; 4462 ++iPageControl;
@@ -4463,7 +4477,7 @@ static HRESULT ShowControl(
4463 } 4477 }
4464 else 4478 else
4465 { 4479 {
4466 ExitOnFailure(hr, "Failed to get string variable: %ls", pControl->sczVariable); 4480 ThmExitOnFailure(hr, "Failed to get string variable: %ls", pControl->sczVariable);
4467 } 4481 }
4468 4482
4469 if (THEME_SHOW_PAGE_REASON_REFRESH != reason && pPage && pControl->wPageId && pControl->fLastRadioButton) 4483 if (THEME_SHOW_PAGE_REASON_REFRESH != reason && pPage && pControl->wPageId && pControl->fLastRadioButton)
@@ -4474,7 +4488,7 @@ static HRESULT ShowControl(
4474 if (SUCCEEDED(hr)) 4488 if (SUCCEEDED(hr))
4475 { 4489 {
4476 hr = StrAllocStringSecure(&pSavedVariable->sczValue, sczText, 0); 4490 hr = StrAllocStringSecure(&pSavedVariable->sczValue, sczText, 0);
4477 ExitOnFailure(hr, "Failed to save variable: %ls", pControl->sczVariable); 4491 ThmExitOnFailure(hr, "Failed to save variable: %ls", pControl->sczVariable);
4478 } 4492 }
4479 4493
4480 ++iPageControl; 4494 ++iPageControl;
@@ -4552,7 +4566,7 @@ static HRESULT ShowControls(
4552 if (!pControl->wPageId || pControl->wPageId == dwPageId) 4566 if (!pControl->wPageId || pControl->wPageId == dwPageId)
4553 { 4567 {
4554 hr = ShowControl(pTheme, pControl, nCmdShow, fSaveEditboxes, reason, dwPageId, &hwndFocus); 4568 hr = ShowControl(pTheme, pControl, nCmdShow, fSaveEditboxes, reason, dwPageId, &hwndFocus);
4555 ExitOnFailure(hr, "Failed to show control '%ls' at index %d.", pControl->sczName, i); 4569 ThmExitOnFailure(hr, "Failed to show control '%ls' at index %d.", pControl->sczName, i);
4556 } 4570 }
4557 } 4571 }
4558 4572
@@ -4702,7 +4716,7 @@ static HRESULT LoadControls(
4702 else 4716 else
4703 { 4717 {
4704 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); 4718 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
4705 ExitOnRootFailure(hr, "Invalid image or image list coordinates."); 4719 ThmExitOnRootFailure(hr, "Invalid image or image list coordinates.");
4706 } 4720 }
4707 break; 4721 break;
4708 4722
@@ -4746,7 +4760,7 @@ static HRESULT LoadControls(
4746 if (!vhModuleRichEd) 4760 if (!vhModuleRichEd)
4747 { 4761 {
4748 hr = LoadSystemLibrary(L"Riched20.dll", &vhModuleRichEd); 4762 hr = LoadSystemLibrary(L"Riched20.dll", &vhModuleRichEd);
4749 ExitOnFailure(hr, "Failed to load Rich Edit control library."); 4763 ThmExitOnFailure(hr, "Failed to load Rich Edit control library.");
4750 } 4764 }
4751 wzWindowClass = RICHEDIT_CLASSW; 4765 wzWindowClass = RICHEDIT_CLASSW;
4752 dwWindowBits |= ES_AUTOVSCROLL | ES_MULTILINE | WS_VSCROLL | ES_READONLY; 4766 dwWindowBits |= ES_AUTOVSCROLL | ES_MULTILINE | WS_VSCROLL | ES_READONLY;
@@ -4765,7 +4779,7 @@ static HRESULT LoadControls(
4765 wzWindowClass = WC_TREEVIEWW; 4779 wzWindowClass = WC_TREEVIEWW;
4766 break; 4780 break;
4767 } 4781 }
4768 ExitOnNull(wzWindowClass, hr, E_INVALIDDATA, "Failed to configure control %u because of unknown type: %u", i, pControl->type); 4782 ThmExitOnNull(wzWindowClass, hr, E_INVALIDDATA, "Failed to configure control %u because of unknown type: %u", i, pControl->type);
4769 4783
4770 // Default control ids to the theme id and its index in the control array, unless there 4784 // Default control ids to the theme id and its index in the control array, unless there
4771 // is a specific id to assign to a named control. 4785 // is a specific id to assign to a named control.
@@ -4791,7 +4805,7 @@ static HRESULT LoadControls(
4791 if (fVisible && pControl->sczVisibleCondition && pTheme->pfnEvaluateCondition && !pControl->fDisableVariableFunctionality) 4805 if (fVisible && pControl->sczVisibleCondition && pTheme->pfnEvaluateCondition && !pControl->fDisableVariableFunctionality)
4792 { 4806 {
4793 hr = pTheme->pfnEvaluateCondition(pControl->sczVisibleCondition, &fVisible, pTheme->pvVariableContext); 4807 hr = pTheme->pfnEvaluateCondition(pControl->sczVisibleCondition, &fVisible, pTheme->pvVariableContext);
4794 ExitOnFailure(hr, "Failed to evaluate VisibleCondition: %ls", pControl->sczVisibleCondition); 4808 ThmExitOnFailure(hr, "Failed to evaluate VisibleCondition: %ls", pControl->sczVisibleCondition);
4795 4809
4796 if (!fVisible) 4810 if (!fVisible)
4797 { 4811 {
@@ -4812,7 +4826,7 @@ static HRESULT LoadControls(
4812 BOOL fEnable = TRUE; 4826 BOOL fEnable = TRUE;
4813 4827
4814 hr = pTheme->pfnEvaluateCondition(pControl->sczEnableCondition, &fEnable, pTheme->pvVariableContext); 4828 hr = pTheme->pfnEvaluateCondition(pControl->sczEnableCondition, &fEnable, pTheme->pvVariableContext);
4815 ExitOnFailure(hr, "Failed to evaluate EnableCondition: %ls", pControl->sczEnableCondition); 4829 ThmExitOnFailure(hr, "Failed to evaluate EnableCondition: %ls", pControl->sczEnableCondition);
4816 4830
4817 fDisabled = !fEnable; 4831 fDisabled = !fEnable;
4818 dwWindowBits |= fDisabled ? WS_DISABLED : 0; 4832 dwWindowBits |= fDisabled ? WS_DISABLED : 0;
@@ -4826,7 +4840,7 @@ static HRESULT LoadControls(
4826 } 4840 }
4827 4841
4828 pControl->hWnd = ::CreateWindowExW(dwWindowExBits, wzWindowClass, pControl->sczText, pControl->dwStyle | dwWindowBits, x, y, w, h, hwndParent, reinterpret_cast<HMENU>(wControlId), NULL, pTheme); 4842 pControl->hWnd = ::CreateWindowExW(dwWindowExBits, wzWindowClass, pControl->sczText, pControl->dwStyle | dwWindowBits, x, y, w, h, hwndParent, reinterpret_cast<HMENU>(wControlId), NULL, pTheme);
4829 ExitOnNullWithLastError(pControl->hWnd, hr, "Failed to create window."); 4843 ThmExitOnNullWithLastError(pControl->hWnd, hr, "Failed to create window.");
4830 4844
4831 if (pControl->sczTooltip) 4845 if (pControl->sczTooltip)
4832 { 4846 {
@@ -4875,7 +4889,7 @@ static HRESULT LoadControls(
4875 ::SendMessageW(pControl->hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, pControl->dwExtendedStyle); 4889 ::SendMessageW(pControl->hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, pControl->dwExtendedStyle);
4876 4890
4877 hr = SizeListViewColumns(pControl); 4891 hr = SizeListViewColumns(pControl);
4878 ExitOnFailure(hr, "Failed to get size of list view columns."); 4892 ThmExitOnFailure(hr, "Failed to get size of list view columns.");
4879 4893
4880 for (DWORD j = 0; j < pControl->cColumns; ++j) 4894 for (DWORD j = 0; j < pControl->cColumns; ++j)
4881 { 4895 {
@@ -4889,7 +4903,7 @@ static HRESULT LoadControls(
4889 4903
4890 if (-1 == ::SendMessageW(pControl->hWnd, LVM_INSERTCOLUMNW, (WPARAM) (int) (j), (LPARAM) (const LV_COLUMNW *) (&lvc))) 4904 if (-1 == ::SendMessageW(pControl->hWnd, LVM_INSERTCOLUMNW, (WPARAM) (int) (j), (LPARAM) (const LV_COLUMNW *) (&lvc)))
4891 { 4905 {
4892 ExitWithLastError(hr, "Failed to insert listview column %u into tab control.", j); 4906 ThmExitWithLastError(hr, "Failed to insert listview column %u into tab control.", j);
4893 } 4907 }
4894 4908
4895 // Return value tells us the old image list, we don't care. 4909 // Return value tells us the old image list, we don't care.
@@ -4938,7 +4952,7 @@ static HRESULT LoadControls(
4938 4952
4939 if (-1 == ::SendMessageW(pControl->hWnd, TCM_INSERTITEMW, (WPARAM) (int) (j), (LPARAM) (const TC_ITEMW *) (&tci))) 4953 if (-1 == ::SendMessageW(pControl->hWnd, TCM_INSERTITEMW, (WPARAM) (int) (j), (LPARAM) (const TC_ITEMW *) (&tci)))
4940 { 4954 {
4941 ExitWithLastError(hr, "Failed to insert tab %u into tab control.", j); 4955 ThmExitWithLastError(hr, "Failed to insert tab %u into tab control.", j);
4942 } 4956 }
4943 } 4957 }
4944 } 4958 }
@@ -4961,7 +4975,7 @@ static HRESULT LoadControls(
4961 if (pControl->cControls) 4975 if (pControl->cControls)
4962 { 4976 {
4963 hr = LoadControls(pTheme, pControl, pControl->hWnd, rgAssignControlIds, cAssignControlIds); 4977 hr = LoadControls(pTheme, pControl, pControl->hWnd, rgAssignControlIds, cAssignControlIds);
4964 ExitOnFailure(hr, "Failed to load child controls."); 4978 ThmExitOnFailure(hr, "Failed to load child controls.");
4965 } 4979 }
4966 } 4980 }
4967 4981
@@ -4983,7 +4997,7 @@ static HRESULT LocalizeControls(
4983 { 4997 {
4984 THEME_CONTROL* pControl = rgControls + i; 4998 THEME_CONTROL* pControl = rgControls + i;
4985 hr = LocalizeControl(pControl, pWixLoc); 4999 hr = LocalizeControl(pControl, pWixLoc);
4986 ExitOnFailure(hr, "Failed to localize control: %ls", pControl->sczName); 5000 ThmExitOnFailure(hr, "Failed to localize control: %ls", pControl->sczName);
4987 } 5001 }
4988 5002
4989LExit: 5003LExit:
@@ -5002,59 +5016,59 @@ static HRESULT LocalizeControl(
5002 if (pControl->sczText && *pControl->sczText) 5016 if (pControl->sczText && *pControl->sczText)
5003 { 5017 {
5004 hr = LocLocalizeString(pWixLoc, &pControl->sczText); 5018 hr = LocLocalizeString(pWixLoc, &pControl->sczText);
5005 ExitOnFailure(hr, "Failed to localize control text."); 5019 ThmExitOnFailure(hr, "Failed to localize control text.");
5006 } 5020 }
5007 else if (pControl->sczName) 5021 else if (pControl->sczName)
5008 { 5022 {
5009 LOC_STRING* plocString = NULL; 5023 LOC_STRING* plocString = NULL;
5010 5024
5011 hr = StrAllocFormatted(&sczLocStringId, L"#(loc.%ls)", pControl->sczName); 5025 hr = StrAllocFormatted(&sczLocStringId, L"#(loc.%ls)", pControl->sczName);
5012 ExitOnFailure(hr, "Failed to format loc string id: %ls", pControl->sczName); 5026 ThmExitOnFailure(hr, "Failed to format loc string id: %ls", pControl->sczName);
5013 5027
5014 hr = LocGetString(pWixLoc, sczLocStringId, &plocString); 5028 hr = LocGetString(pWixLoc, sczLocStringId, &plocString);
5015 if (E_NOTFOUND != hr) 5029 if (E_NOTFOUND != hr)
5016 { 5030 {
5017 ExitOnFailure(hr, "Failed to get loc string: %ls", pControl->sczName); 5031 ThmExitOnFailure(hr, "Failed to get loc string: %ls", pControl->sczName);
5018 5032
5019 hr = StrAllocString(&pControl->sczText, plocString->wzText, 0); 5033 hr = StrAllocString(&pControl->sczText, plocString->wzText, 0);
5020 ExitOnFailure(hr, "Failed to copy loc string to control: %ls", plocString->wzText); 5034 ThmExitOnFailure(hr, "Failed to copy loc string to control: %ls", plocString->wzText);
5021 } 5035 }
5022 } 5036 }
5023 5037
5024 if (pControl->sczTooltip && *pControl->sczTooltip) 5038 if (pControl->sczTooltip && *pControl->sczTooltip)
5025 { 5039 {
5026 hr = LocLocalizeString(pWixLoc, &pControl->sczTooltip); 5040 hr = LocLocalizeString(pWixLoc, &pControl->sczTooltip);
5027 ExitOnFailure(hr, "Failed to localize control tooltip text."); 5041 ThmExitOnFailure(hr, "Failed to localize control tooltip text.");
5028 } 5042 }
5029 5043
5030 if (pControl->sczNote && *pControl->sczNote) 5044 if (pControl->sczNote && *pControl->sczNote)
5031 { 5045 {
5032 hr = LocLocalizeString(pWixLoc, &pControl->sczNote); 5046 hr = LocLocalizeString(pWixLoc, &pControl->sczNote);
5033 ExitOnFailure(hr, "Failed to localize control note text."); 5047 ThmExitOnFailure(hr, "Failed to localize control note text.");
5034 } 5048 }
5035 5049
5036 for (DWORD j = 0; j < pControl->cConditionalText; ++j) 5050 for (DWORD j = 0; j < pControl->cConditionalText; ++j)
5037 { 5051 {
5038 hr = LocLocalizeString(pWixLoc, &pControl->rgConditionalText[j].sczText); 5052 hr = LocLocalizeString(pWixLoc, &pControl->rgConditionalText[j].sczText);
5039 ExitOnFailure(hr, "Failed to localize conditional text."); 5053 ThmExitOnFailure(hr, "Failed to localize conditional text.");
5040 } 5054 }
5041 5055
5042 for (DWORD j = 0; j < pControl->cConditionalNotes; ++j) 5056 for (DWORD j = 0; j < pControl->cConditionalNotes; ++j)
5043 { 5057 {
5044 hr = LocLocalizeString(pWixLoc, &pControl->rgConditionalNotes[j].sczText); 5058 hr = LocLocalizeString(pWixLoc, &pControl->rgConditionalNotes[j].sczText);
5045 ExitOnFailure(hr, "Failed to localize conditional note."); 5059 ThmExitOnFailure(hr, "Failed to localize conditional note.");
5046 } 5060 }
5047 5061
5048 for (DWORD j = 0; j < pControl->cColumns; ++j) 5062 for (DWORD j = 0; j < pControl->cColumns; ++j)
5049 { 5063 {
5050 hr = LocLocalizeString(pWixLoc, &pControl->ptcColumns[j].pszName); 5064 hr = LocLocalizeString(pWixLoc, &pControl->ptcColumns[j].pszName);
5051 ExitOnFailure(hr, "Failed to localize column text."); 5065 ThmExitOnFailure(hr, "Failed to localize column text.");
5052 } 5066 }
5053 5067
5054 for (DWORD j = 0; j < pControl->cTabs; ++j) 5068 for (DWORD j = 0; j < pControl->cTabs; ++j)
5055 { 5069 {
5056 hr = LocLocalizeString(pWixLoc, &pControl->pttTabs[j].pszName); 5070 hr = LocLocalizeString(pWixLoc, &pControl->pttTabs[j].pszName);
5057 ExitOnFailure(hr, "Failed to localize tab text."); 5071 ThmExitOnFailure(hr, "Failed to localize tab text.");
5058 } 5072 }
5059 5073
5060 // Localize control's size, location, and text. 5074 // Localize control's size, location, and text.
@@ -5065,7 +5079,7 @@ static HRESULT LocalizeControl(
5065 { 5079 {
5066 ExitFunction1(hr = S_OK); 5080 ExitFunction1(hr = S_OK);
5067 } 5081 }
5068 ExitOnFailure(hr, "Failed to localize control."); 5082 ThmExitOnFailure(hr, "Failed to localize control.");
5069 5083
5070 if (LOC_CONTROL_NOT_SET != pLocControl->nX) 5084 if (LOC_CONTROL_NOT_SET != pLocControl->nX)
5071 { 5085 {
@@ -5090,7 +5104,7 @@ static HRESULT LocalizeControl(
5090 if (pLocControl->wzText && *pLocControl->wzText) 5104 if (pLocControl->wzText && *pLocControl->wzText)
5091 { 5105 {
5092 hr = StrAllocString(&pControl->sczText, pLocControl->wzText, 0); 5106 hr = StrAllocString(&pControl->sczText, pLocControl->wzText, 0);
5093 ExitOnFailure(hr, "Failed to localize control text."); 5107 ThmExitOnFailure(hr, "Failed to localize control text.");
5094 } 5108 }
5095 } 5109 }
5096 5110
@@ -5114,7 +5128,7 @@ static HRESULT LoadControlsString(
5114 { 5128 {
5115 THEME_CONTROL* pControl = rgControls + i; 5129 THEME_CONTROL* pControl = rgControls + i;
5116 hr = LoadControlString(pControl, hResModule); 5130 hr = LoadControlString(pControl, hResModule);
5117 ExitOnFailure(hr, "Failed to load string for control: %ls", pControl->sczName); 5131 ThmExitOnFailure(hr, "Failed to load string for control: %ls", pControl->sczName);
5118 } 5132 }
5119 5133
5120LExit: 5134LExit:
@@ -5130,14 +5144,14 @@ static HRESULT LoadControlString(
5130 if (UINT_MAX != pControl->uStringId) 5144 if (UINT_MAX != pControl->uStringId)
5131 { 5145 {
5132 hr = ResReadString(hResModule, pControl->uStringId, &pControl->sczText); 5146 hr = ResReadString(hResModule, pControl->uStringId, &pControl->sczText);
5133 ExitOnFailure(hr, "Failed to load control text."); 5147 ThmExitOnFailure(hr, "Failed to load control text.");
5134 5148
5135 for (DWORD j = 0; j < pControl->cColumns; ++j) 5149 for (DWORD j = 0; j < pControl->cColumns; ++j)
5136 { 5150 {
5137 if (UINT_MAX != pControl->ptcColumns[j].uStringId) 5151 if (UINT_MAX != pControl->ptcColumns[j].uStringId)
5138 { 5152 {
5139 hr = ResReadString(hResModule, pControl->ptcColumns[j].uStringId, &pControl->ptcColumns[j].pszName); 5153 hr = ResReadString(hResModule, pControl->ptcColumns[j].uStringId, &pControl->ptcColumns[j].pszName);
5140 ExitOnFailure(hr, "Failed to load column text."); 5154 ThmExitOnFailure(hr, "Failed to load column text.");
5141 } 5155 }
5142 } 5156 }
5143 5157
@@ -5146,7 +5160,7 @@ static HRESULT LoadControlString(
5146 if (UINT_MAX != pControl->pttTabs[j].uStringId) 5160 if (UINT_MAX != pControl->pttTabs[j].uStringId)
5147 { 5161 {
5148 hr = ResReadString(hResModule, pControl->pttTabs[j].uStringId, &pControl->pttTabs[j].pszName); 5162 hr = ResReadString(hResModule, pControl->pttTabs[j].uStringId, &pControl->pttTabs[j].pszName);
5149 ExitOnFailure(hr, "Failed to load tab text."); 5163 ThmExitOnFailure(hr, "Failed to load tab text.");
5150 } 5164 }
5151 } 5165 }
5152 } 5166 }