diff options
Diffstat (limited to 'src/samples/thmviewer/thmviewer.cpp')
-rw-r--r-- | src/samples/thmviewer/thmviewer.cpp | 37 |
1 files changed, 25 insertions, 12 deletions
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 | ||