diff options
author | Sean Hall <r.sean.hall@gmail.com> | 2021-10-31 14:20:44 -0500 |
---|---|---|
committer | Sean Hall <r.sean.hall@gmail.com> | 2021-11-01 16:34:09 -0500 |
commit | 7e60078d4a7fe748a39c135def9e84a2421ab474 (patch) | |
tree | 51dbe5067ca9596f99107719734c4946e4c080b4 /src/samples | |
parent | c092722a147940532b08f62403e182ef279f2c74 (diff) | |
download | wix-7e60078d4a7fe748a39c135def9e84a2421ab474.tar.gz wix-7e60078d4a7fe748a39c135def9e84a2421ab474.tar.bz2 wix-7e60078d4a7fe748a39c135def9e84a2421ab474.zip |
Avoid using control ids inside of thmutil.
Diffstat (limited to 'src/samples')
-rw-r--r-- | src/samples/thmviewer/display.cpp | 8 | ||||
-rw-r--r-- | src/samples/thmviewer/precomp.h | 1 | ||||
-rw-r--r-- | src/samples/thmviewer/thmviewer.cpp | 37 |
3 files changed, 30 insertions, 16 deletions
diff --git a/src/samples/thmviewer/display.cpp b/src/samples/thmviewer/display.cpp index 9ef88018..f40b50b5 100644 --- a/src/samples/thmviewer/display.cpp +++ b/src/samples/thmviewer/display.cpp | |||
@@ -188,7 +188,7 @@ static DWORD WINAPI DisplayThreadProc( | |||
188 | THEME_CONTROL* pControl = pCurrentHandle->pTheme->rgControls + i; | 188 | THEME_CONTROL* pControl = pCurrentHandle->pTheme->rgControls + i; |
189 | if (!pControl->wPageId) | 189 | if (!pControl->wPageId) |
190 | { | 190 | { |
191 | ThemeShowControl(pCurrentHandle->pTheme, pControl->wId, nCmdShow); | 191 | ThemeShowControl(pControl, nCmdShow); |
192 | } | 192 | } |
193 | } | 193 | } |
194 | 194 | ||
@@ -264,7 +264,7 @@ static LRESULT CALLBACK DisplayWndProc( | |||
264 | break; | 264 | break; |
265 | 265 | ||
266 | case WM_TIMER: | 266 | case WM_TIMER: |
267 | if (!lParam && SUCCEEDED(ThemeSetProgressControl(pHandleTheme->pTheme, wParam, dwProgress))) | 267 | if (!lParam && SUCCEEDED(ThemeSetProgressControl(reinterpret_cast<THEME_CONTROL*>(wParam), dwProgress))) |
268 | { | 268 | { |
269 | dwProgress += rand() % 10 + 1; | 269 | dwProgress += rand() % 10 + 1; |
270 | if (dwProgress > 100) | 270 | if (dwProgress > 100) |
@@ -322,12 +322,12 @@ static BOOL DisplayOnThmLoadedControl( | |||
322 | // Pre-populate some control types with data. | 322 | // Pre-populate some control types with data. |
323 | if (THEME_CONTROL_TYPE_RICHEDIT == pControl->type) | 323 | if (THEME_CONTROL_TYPE_RICHEDIT == pControl->type) |
324 | { | 324 | { |
325 | hr = ThemeLoadRichEditFromResource(pTheme, pControl->wId, MAKEINTRESOURCEA(THMVWR_RES_RICHEDIT_FILE), ::GetModuleHandleW(NULL)); | 325 | hr = WnduLoadRichEditFromResource(pControl->hWnd, MAKEINTRESOURCEA(THMVWR_RES_RICHEDIT_FILE), ::GetModuleHandleW(NULL)); |
326 | ExitOnFailure(hr, "Failed to load richedit text."); | 326 | ExitOnFailure(hr, "Failed to load richedit text."); |
327 | } | 327 | } |
328 | else if (THEME_CONTROL_TYPE_PROGRESSBAR == pControl->type) | 328 | else if (THEME_CONTROL_TYPE_PROGRESSBAR == pControl->type) |
329 | { | 329 | { |
330 | DWORD dwId = ::SetTimer(pTheme->hwndParent, pControl->wId, 500, NULL); | 330 | DWORD dwId = ::SetTimer(pTheme->hwndParent, reinterpret_cast<UINT_PTR>(pControl), 500, NULL); |
331 | dwId = dwId; // prevents warning in "ship" build. | 331 | dwId = dwId; // prevents warning in "ship" build. |
332 | Assert(dwId == pControl->wId); | 332 | Assert(dwId == pControl->wId); |
333 | } | 333 | } |
diff --git a/src/samples/thmviewer/precomp.h b/src/samples/thmviewer/precomp.h index f11d3534..762a0623 100644 --- a/src/samples/thmviewer/precomp.h +++ b/src/samples/thmviewer/precomp.h | |||
@@ -28,6 +28,7 @@ | |||
28 | #include "shelutil.h" | 28 | #include "shelutil.h" |
29 | #include "strutil.h" | 29 | #include "strutil.h" |
30 | #include "thmutil.h" | 30 | #include "thmutil.h" |
31 | #include "wndutil.h" | ||
31 | 32 | ||
32 | #include "resource.h" | 33 | #include "resource.h" |
33 | 34 | ||
diff --git a/src/samples/thmviewer/thmviewer.cpp b/src/samples/thmviewer/thmviewer.cpp index 94b1ef55..38f3c4dc 100644 --- a/src/samples/thmviewer/thmviewer.cpp +++ b/src/samples/thmviewer/thmviewer.cpp | |||
@@ -390,6 +390,12 @@ static void OnThemeLoadError( | |||
390 | LPWSTR* psczErrors = NULL; | 390 | LPWSTR* psczErrors = NULL; |
391 | UINT cErrors = 0; | 391 | UINT cErrors = 0; |
392 | TVINSERTSTRUCTW tvi = { }; | 392 | TVINSERTSTRUCTW tvi = { }; |
393 | const THEME_CONTROL* pTreeControl = NULL; | ||
394 | |||
395 | if (!ThemeControlExistsById(pTheme, THMVWR_CONTROL_TREE, &pTreeControl)) | ||
396 | { | ||
397 | ExitWithRootFailure(hr, E_INVALIDSTATE, "THMVWR_CONTROL_TREE control doesn't exist."); | ||
398 | } | ||
393 | 399 | ||
394 | // Add the application node. | 400 | // Add the application node. |
395 | tvi.hParent = NULL; | 401 | tvi.hParent = NULL; |
@@ -397,7 +403,7 @@ static void OnThemeLoadError( | |||
397 | tvi.item.mask = TVIF_TEXT | TVIF_PARAM; | 403 | tvi.item.mask = TVIF_TEXT | TVIF_PARAM; |
398 | tvi.item.lParam = 0; | 404 | tvi.item.lParam = 0; |
399 | tvi.item.pszText = L"Failed to load theme."; | 405 | tvi.item.pszText = L"Failed to load theme."; |
400 | tvi.hParent = reinterpret_cast<HTREEITEM>(ThemeSendControlMessage(pTheme, THMVWR_CONTROL_TREE, TVM_INSERTITEMW, 0, reinterpret_cast<LPARAM>(&tvi))); | 406 | tvi.hParent = reinterpret_cast<HTREEITEM>(::SendMessage(pTreeControl->hWnd, TVM_INSERTITEMW, 0, reinterpret_cast<LPARAM>(&tvi))); |
401 | 407 | ||
402 | if (!vsczThemeLoadErrors) | 408 | if (!vsczThemeLoadErrors) |
403 | { | 409 | { |
@@ -405,13 +411,13 @@ static void OnThemeLoadError( | |||
405 | ExitOnFailure(hr, "Failed to format error message."); | 411 | ExitOnFailure(hr, "Failed to format error message."); |
406 | 412 | ||
407 | tvi.item.pszText = sczMessage; | 413 | tvi.item.pszText = sczMessage; |
408 | ThemeSendControlMessage(pTheme, THMVWR_CONTROL_TREE, TVM_INSERTITEMW, 0, reinterpret_cast<LPARAM>(&tvi)); | 414 | ::SendMessage(pTreeControl->hWnd, TVM_INSERTITEMW, 0, reinterpret_cast<LPARAM>(&tvi)); |
409 | 415 | ||
410 | hr = StrAllocFromError(&sczMessage, hrFailure, NULL); | 416 | hr = StrAllocFromError(&sczMessage, hrFailure, NULL); |
411 | ExitOnFailure(hr, "Failed to format error message text."); | 417 | ExitOnFailure(hr, "Failed to format error message text."); |
412 | 418 | ||
413 | tvi.item.pszText = sczMessage; | 419 | tvi.item.pszText = sczMessage; |
414 | ThemeSendControlMessage(pTheme, THMVWR_CONTROL_TREE, TVM_INSERTITEMW, 0, reinterpret_cast<LPARAM>(&tvi)); | 420 | ::SendMessage(pTreeControl->hWnd, TVM_INSERTITEMW, 0, reinterpret_cast<LPARAM>(&tvi)); |
415 | } | 421 | } |
416 | else | 422 | else |
417 | { | 423 | { |
@@ -421,11 +427,11 @@ static void OnThemeLoadError( | |||
421 | for (DWORD i = 0; i < cErrors; ++i) | 427 | for (DWORD i = 0; i < cErrors; ++i) |
422 | { | 428 | { |
423 | tvi.item.pszText = psczErrors[i]; | 429 | tvi.item.pszText = psczErrors[i]; |
424 | ThemeSendControlMessage(pTheme, THMVWR_CONTROL_TREE, TVM_INSERTITEMW, 0, reinterpret_cast<LPARAM>(&tvi)); | 430 | ::SendMessage(pTreeControl->hWnd, TVM_INSERTITEMW, 0, reinterpret_cast<LPARAM>(&tvi)); |
425 | } | 431 | } |
426 | } | 432 | } |
427 | 433 | ||
428 | ThemeSendControlMessage(pTheme, THMVWR_CONTROL_TREE, TVM_EXPAND, TVE_EXPAND, reinterpret_cast<LPARAM>(tvi.hParent)); | 434 | ::SendMessage(pTreeControl->hWnd, TVM_EXPAND, TVE_EXPAND, reinterpret_cast<LPARAM>(tvi.hParent)); |
429 | 435 | ||
430 | LExit: | 436 | LExit: |
431 | ReleaseStr(sczMessage); | 437 | ReleaseStr(sczMessage); |
@@ -439,6 +445,7 @@ static void OnNewTheme( | |||
439 | __in HANDLE_THEME* pHandle | 445 | __in HANDLE_THEME* pHandle |
440 | ) | 446 | ) |
441 | { | 447 | { |
448 | const THEME_CONTROL* pTreeControl = NULL; | ||
442 | HANDLE_THEME* pOldHandle = reinterpret_cast<HANDLE_THEME*>(::GetWindowLongPtrW(hWnd, GWLP_USERDATA)); | 449 | HANDLE_THEME* pOldHandle = reinterpret_cast<HANDLE_THEME*>(::GetWindowLongPtrW(hWnd, GWLP_USERDATA)); |
443 | THEME* pNewTheme = pHandle->pTheme; | 450 | THEME* pNewTheme = pHandle->pTheme; |
444 | 451 | ||
@@ -460,17 +467,23 @@ static void OnNewTheme( | |||
460 | 467 | ||
461 | ::SetWindowLongPtrW(hWnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(pHandle)); | 468 | ::SetWindowLongPtrW(hWnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(pHandle)); |
462 | 469 | ||
470 | if (!ThemeControlExistsById(pTheme, THMVWR_CONTROL_TREE, &pTreeControl)) | ||
471 | { | ||
472 | TraceError(E_INVALIDSTATE, "Tree control doesn't exist."); | ||
473 | return; | ||
474 | } | ||
475 | |||
463 | // Remember the currently selected item by name so we can try to automatically select it later. | 476 | // Remember the currently selected item by name so we can try to automatically select it later. |
464 | // Otherwise, the user would see their window destroyed after every save of their theme file and | 477 | // Otherwise, the user would see their window destroyed after every save of their theme file and |
465 | // have to click to get the window back. | 478 | // have to click to get the window back. |
466 | item.mask = TVIF_TEXT; | 479 | item.mask = TVIF_TEXT; |
467 | item.pszText = wzSelectedPage; | 480 | item.pszText = wzSelectedPage; |
468 | item.cchTextMax = countof(wzSelectedPage); | 481 | item.cchTextMax = countof(wzSelectedPage); |
469 | item.hItem = reinterpret_cast<HTREEITEM>(ThemeSendControlMessage(pTheme, THMVWR_CONTROL_TREE, TVM_GETNEXTITEM, TVGN_CARET, NULL)); | 482 | item.hItem = reinterpret_cast<HTREEITEM>(::SendMessage(pTreeControl->hWnd, TVM_GETNEXTITEM, TVGN_CARET, NULL)); |
470 | ThemeSendControlMessage(pTheme, THMVWR_CONTROL_TREE, TVM_GETITEM, 0, reinterpret_cast<LPARAM>(&item)); | 483 | ::SendMessage(pTreeControl->hWnd, TVM_GETITEM, 0, reinterpret_cast<LPARAM>(&item)); |
471 | 484 | ||
472 | // Remove the previous items in the tree. | 485 | // Remove the previous items in the tree. |
473 | ThemeSendControlMessage(pTheme, THMVWR_CONTROL_TREE, TVM_DELETEITEM, 0, reinterpret_cast<LPARAM>(TVI_ROOT)); | 486 | ::SendMessage(pTreeControl->hWnd, TVM_DELETEITEM, 0, reinterpret_cast<LPARAM>(TVI_ROOT)); |
474 | 487 | ||
475 | // Add the application node. | 488 | // Add the application node. |
476 | tvi.hParent = NULL; | 489 | tvi.hParent = NULL; |
@@ -480,7 +493,7 @@ static void OnNewTheme( | |||
480 | tvi.item.pszText = pHandle && pHandle->pTheme && pHandle->pTheme->sczCaption ? pHandle->pTheme->sczCaption : L"Window"; | 493 | tvi.item.pszText = pHandle && pHandle->pTheme && pHandle->pTheme->sczCaption ? pHandle->pTheme->sczCaption : L"Window"; |
481 | 494 | ||
482 | // Add the pages. | 495 | // Add the pages. |
483 | tvi.hParent = reinterpret_cast<HTREEITEM>(ThemeSendControlMessage(pTheme, THMVWR_CONTROL_TREE, TVM_INSERTITEMW, 0, reinterpret_cast<LPARAM>(&tvi))); | 496 | tvi.hParent = reinterpret_cast<HTREEITEM>(::SendMessage(pTreeControl->hWnd, TVM_INSERTITEMW, 0, reinterpret_cast<LPARAM>(&tvi))); |
484 | tvi.hInsertAfter = TVI_SORT; | 497 | tvi.hInsertAfter = TVI_SORT; |
485 | for (DWORD i = 0; i < pNewTheme->cPages; ++i) | 498 | for (DWORD i = 0; i < pNewTheme->cPages; ++i) |
486 | { | 499 | { |
@@ -490,7 +503,7 @@ static void OnNewTheme( | |||
490 | tvi.item.pszText = pPage->sczName; | 503 | tvi.item.pszText = pPage->sczName; |
491 | tvi.item.lParam = i + 1; //prgdwPageIds[i]; - TODO: do the right thing here by calling ThemeGetPageIds(), should not assume we know how the page ids will be calculated. | 504 | tvi.item.lParam = i + 1; //prgdwPageIds[i]; - TODO: do the right thing here by calling ThemeGetPageIds(), should not assume we know how the page ids will be calculated. |
492 | 505 | ||
493 | HTREEITEM hti = reinterpret_cast<HTREEITEM>(ThemeSendControlMessage(pTheme, THMVWR_CONTROL_TREE, TVM_INSERTITEMW, 0, reinterpret_cast<LPARAM>(&tvi))); | 506 | HTREEITEM hti = reinterpret_cast<HTREEITEM>(::SendMessage(pTreeControl->hWnd, TVM_INSERTITEMW, 0, reinterpret_cast<LPARAM>(&tvi))); |
494 | if (*wzSelectedPage && CSTR_EQUAL == ::CompareStringW(LOCALE_NEUTRAL, 0, pPage->sczName, -1, wzSelectedPage, -1)) | 507 | if (*wzSelectedPage && CSTR_EQUAL == ::CompareStringW(LOCALE_NEUTRAL, 0, pPage->sczName, -1, wzSelectedPage, -1)) |
495 | { | 508 | { |
496 | htiSelected = hti; | 509 | htiSelected = hti; |
@@ -503,10 +516,10 @@ static void OnNewTheme( | |||
503 | htiSelected = tvi.hParent; | 516 | htiSelected = tvi.hParent; |
504 | } | 517 | } |
505 | 518 | ||
506 | ThemeSendControlMessage(pTheme, THMVWR_CONTROL_TREE, TVM_EXPAND, TVE_EXPAND, reinterpret_cast<LPARAM>(tvi.hParent)); | 519 | ::SendMessage(pTreeControl->hWnd, TVM_EXPAND, TVE_EXPAND, reinterpret_cast<LPARAM>(tvi.hParent)); |
507 | if (htiSelected) | 520 | if (htiSelected) |
508 | { | 521 | { |
509 | ThemeSendControlMessage(pTheme, THMVWR_CONTROL_TREE, TVM_SELECTITEM, TVGN_CARET, reinterpret_cast<LPARAM>(htiSelected)); | 522 | ::SendMessage(pTreeControl->hWnd, TVM_SELECTITEM, TVGN_CARET, reinterpret_cast<LPARAM>(htiSelected)); |
510 | } | 523 | } |
511 | } | 524 | } |
512 | 525 | ||