From dce1c97c7d3e76c18e4f80d4ffe288d2933a74bc Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Wed, 27 Oct 2021 15:29:19 -0500 Subject: Make thmutil automatically load controls during window creation. Add control loaded event. --- src/samples/thmviewer/display.cpp | 58 ++++++++++++++++--------------------- src/samples/thmviewer/thmviewer.cpp | 15 +--------- 2 files changed, 26 insertions(+), 47 deletions(-) (limited to 'src/samples') diff --git a/src/samples/thmviewer/display.cpp b/src/samples/thmviewer/display.cpp index c0e6c7e1..e64f79c6 100644 --- a/src/samples/thmviewer/display.cpp +++ b/src/samples/thmviewer/display.cpp @@ -21,9 +21,10 @@ static LRESULT CALLBACK DisplayWndProc( __in WPARAM wParam, __in LPARAM lParam ); -static BOOL DisplayOnCreate( +static BOOL DisplayOnThmLoadedControl( __in THEME* pTheme, - __in HWND hWnd + __in const THEME_LOADEDCONTROL_ARGS* args, + __in THEME_LOADEDCONTROL_RESULTS* results ); @@ -270,13 +271,6 @@ static LRESULT CALLBACK DisplayWndProc( } break; - case WM_CREATE: - if (!DisplayOnCreate(pHandleTheme->pTheme, hWnd)) - { - return -1; - } - break; - case WM_TIMER: if (!lParam && SUCCEEDED(ThemeSetProgressControl(pHandleTheme->pTheme, wParam, dwProgress))) { @@ -308,47 +302,45 @@ static LRESULT CALLBACK DisplayWndProc( } break; - case WM_DESTROY: - ThemeUnloadControls(pHandleTheme->pTheme); - ::PostQuitMessage(0); - break; - case WM_NCDESTROY: DecrementHandleTheme(pHandleTheme); ::SetWindowLongPtrW(hWnd, GWLP_USERDATA, 0); + ::PostQuitMessage(0); break; + + case WM_THMUTIL_LOADED_CONTROL: + if (pHandleTheme) + { + return DisplayOnThmLoadedControl(pHandleTheme->pTheme, reinterpret_cast(wParam), reinterpret_cast(lParam)); + } } return ThemeDefWindowProc(pHandleTheme ? pHandleTheme->pTheme : NULL, hWnd, uMsg, wParam, lParam); } -static BOOL DisplayOnCreate( +static BOOL DisplayOnThmLoadedControl( __in THEME* pTheme, - __in HWND hWnd + __in const THEME_LOADEDCONTROL_ARGS* args, + __in THEME_LOADEDCONTROL_RESULTS* results ) { HRESULT hr = S_OK; - - hr = ThemeLoadControls(pTheme); - ExitOnFailure(hr, "Failed to load theme controls"); + const THEME_CONTROL* pControl = args->pThemeControl; // Pre-populate some control types with data. - for (DWORD i = 0; i < pTheme->cControls; ++i) + if (THEME_CONTROL_TYPE_RICHEDIT == pControl->type) { - THEME_CONTROL* pControl = pTheme->rgControls + i; - if (THEME_CONTROL_TYPE_RICHEDIT == pControl->type) - { - hr = ThemeLoadRichEditFromResource(pTheme, pControl->wId, MAKEINTRESOURCEA(THMVWR_RES_RICHEDIT_FILE), ::GetModuleHandleW(NULL)); - ExitOnFailure(hr, "Failed to load richedit text."); - } - else if (THEME_CONTROL_TYPE_PROGRESSBAR == pControl->type) - { - DWORD dwId = ::SetTimer(hWnd, pControl->wId, 500, NULL); - dwId = dwId; // prevents warning in "ship" build. - Assert(dwId == pControl->wId); - } + hr = ThemeLoadRichEditFromResource(pTheme, pControl->wId, MAKEINTRESOURCEA(THMVWR_RES_RICHEDIT_FILE), ::GetModuleHandleW(NULL)); + ExitOnFailure(hr, "Failed to load richedit text."); + } + else if (THEME_CONTROL_TYPE_PROGRESSBAR == pControl->type) + { + DWORD dwId = ::SetTimer(pTheme->hwndParent, pControl->wId, 500, NULL); + dwId = dwId; // prevents warning in "ship" build. + Assert(dwId == pControl->wId); } LExit: - return SUCCEEDED(hr); + results->hr = hr; + return TRUE; } diff --git a/src/samples/thmviewer/thmviewer.cpp b/src/samples/thmviewer/thmviewer.cpp index e593d6ad..1d941323 100644 --- a/src/samples/thmviewer/thmviewer.cpp +++ b/src/samples/thmviewer/thmviewer.cpp @@ -353,16 +353,7 @@ static LRESULT CALLBACK MainWndProc( case WM_NCDESTROY: DecrementHandleTheme(pHandleTheme); ::SetWindowLongPtrW(hWnd, GWLP_USERDATA, 0); - break; - - case WM_CREATE: - { - HRESULT hr = ThemeLoadControls(vpTheme); - if (FAILED(hr)) - { - return -1; - } - } + ::PostQuitMessage(0); break; case WM_THMVWR_THEME_LOAD_BEGIN: @@ -377,10 +368,6 @@ static LRESULT CALLBACK MainWndProc( OnNewTheme(vpTheme, hWnd, reinterpret_cast(lParam)); return 0; - case WM_DESTROY: - ::PostQuitMessage(0); - break; - case WM_THMUTIL_LOADING_CONTROL: return OnThemeLoadingControl(reinterpret_cast(wParam), reinterpret_cast(lParam)); -- cgit v1.2.3-55-g6feb