diff options
author | Sean Hall <r.sean.hall@gmail.com> | 2021-10-27 15:29:19 -0500 |
---|---|---|
committer | Sean Hall <r.sean.hall@gmail.com> | 2021-11-01 16:34:09 -0500 |
commit | dce1c97c7d3e76c18e4f80d4ffe288d2933a74bc (patch) | |
tree | 68dc0653ee1a6fe962d82dac2159c8ab00a95808 /src/samples | |
parent | bad2e93524f376cfeb76d5231d4b08510bdad033 (diff) | |
download | wix-dce1c97c7d3e76c18e4f80d4ffe288d2933a74bc.tar.gz wix-dce1c97c7d3e76c18e4f80d4ffe288d2933a74bc.tar.bz2 wix-dce1c97c7d3e76c18e4f80d4ffe288d2933a74bc.zip |
Make thmutil automatically load controls during window creation.
Add control loaded event.
Diffstat (limited to 'src/samples')
-rw-r--r-- | src/samples/thmviewer/display.cpp | 58 | ||||
-rw-r--r-- | src/samples/thmviewer/thmviewer.cpp | 15 |
2 files changed, 26 insertions, 47 deletions
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( | |||
21 | __in WPARAM wParam, | 21 | __in WPARAM wParam, |
22 | __in LPARAM lParam | 22 | __in LPARAM lParam |
23 | ); | 23 | ); |
24 | static BOOL DisplayOnCreate( | 24 | static BOOL DisplayOnThmLoadedControl( |
25 | __in THEME* pTheme, | 25 | __in THEME* pTheme, |
26 | __in HWND hWnd | 26 | __in const THEME_LOADEDCONTROL_ARGS* args, |
27 | __in THEME_LOADEDCONTROL_RESULTS* results | ||
27 | ); | 28 | ); |
28 | 29 | ||
29 | 30 | ||
@@ -270,13 +271,6 @@ static LRESULT CALLBACK DisplayWndProc( | |||
270 | } | 271 | } |
271 | break; | 272 | break; |
272 | 273 | ||
273 | case WM_CREATE: | ||
274 | if (!DisplayOnCreate(pHandleTheme->pTheme, hWnd)) | ||
275 | { | ||
276 | return -1; | ||
277 | } | ||
278 | break; | ||
279 | |||
280 | case WM_TIMER: | 274 | case WM_TIMER: |
281 | if (!lParam && SUCCEEDED(ThemeSetProgressControl(pHandleTheme->pTheme, wParam, dwProgress))) | 275 | if (!lParam && SUCCEEDED(ThemeSetProgressControl(pHandleTheme->pTheme, wParam, dwProgress))) |
282 | { | 276 | { |
@@ -308,47 +302,45 @@ static LRESULT CALLBACK DisplayWndProc( | |||
308 | } | 302 | } |
309 | break; | 303 | break; |
310 | 304 | ||
311 | case WM_DESTROY: | ||
312 | ThemeUnloadControls(pHandleTheme->pTheme); | ||
313 | ::PostQuitMessage(0); | ||
314 | break; | ||
315 | |||
316 | case WM_NCDESTROY: | 305 | case WM_NCDESTROY: |
317 | DecrementHandleTheme(pHandleTheme); | 306 | DecrementHandleTheme(pHandleTheme); |
318 | ::SetWindowLongPtrW(hWnd, GWLP_USERDATA, 0); | 307 | ::SetWindowLongPtrW(hWnd, GWLP_USERDATA, 0); |
308 | ::PostQuitMessage(0); | ||
319 | break; | 309 | break; |
310 | |||
311 | case WM_THMUTIL_LOADED_CONTROL: | ||
312 | if (pHandleTheme) | ||
313 | { | ||
314 | return DisplayOnThmLoadedControl(pHandleTheme->pTheme, reinterpret_cast<THEME_LOADEDCONTROL_ARGS*>(wParam), reinterpret_cast<THEME_LOADEDCONTROL_RESULTS*>(lParam)); | ||
315 | } | ||
320 | } | 316 | } |
321 | 317 | ||
322 | return ThemeDefWindowProc(pHandleTheme ? pHandleTheme->pTheme : NULL, hWnd, uMsg, wParam, lParam); | 318 | return ThemeDefWindowProc(pHandleTheme ? pHandleTheme->pTheme : NULL, hWnd, uMsg, wParam, lParam); |
323 | } | 319 | } |
324 | 320 | ||
325 | static BOOL DisplayOnCreate( | 321 | static BOOL DisplayOnThmLoadedControl( |
326 | __in THEME* pTheme, | 322 | __in THEME* pTheme, |
327 | __in HWND hWnd | 323 | __in const THEME_LOADEDCONTROL_ARGS* args, |
324 | __in THEME_LOADEDCONTROL_RESULTS* results | ||
328 | ) | 325 | ) |
329 | { | 326 | { |
330 | HRESULT hr = S_OK; | 327 | HRESULT hr = S_OK; |
331 | 328 | const THEME_CONTROL* pControl = args->pThemeControl; | |
332 | hr = ThemeLoadControls(pTheme); | ||
333 | ExitOnFailure(hr, "Failed to load theme controls"); | ||
334 | 329 | ||
335 | // Pre-populate some control types with data. | 330 | // Pre-populate some control types with data. |
336 | for (DWORD i = 0; i < pTheme->cControls; ++i) | 331 | if (THEME_CONTROL_TYPE_RICHEDIT == pControl->type) |
337 | { | 332 | { |
338 | THEME_CONTROL* pControl = pTheme->rgControls + i; | 333 | hr = ThemeLoadRichEditFromResource(pTheme, pControl->wId, MAKEINTRESOURCEA(THMVWR_RES_RICHEDIT_FILE), ::GetModuleHandleW(NULL)); |
339 | if (THEME_CONTROL_TYPE_RICHEDIT == pControl->type) | 334 | ExitOnFailure(hr, "Failed to load richedit text."); |
340 | { | 335 | } |
341 | hr = ThemeLoadRichEditFromResource(pTheme, pControl->wId, MAKEINTRESOURCEA(THMVWR_RES_RICHEDIT_FILE), ::GetModuleHandleW(NULL)); | 336 | else if (THEME_CONTROL_TYPE_PROGRESSBAR == pControl->type) |
342 | ExitOnFailure(hr, "Failed to load richedit text."); | 337 | { |
343 | } | 338 | DWORD dwId = ::SetTimer(pTheme->hwndParent, pControl->wId, 500, NULL); |
344 | else if (THEME_CONTROL_TYPE_PROGRESSBAR == pControl->type) | 339 | dwId = dwId; // prevents warning in "ship" build. |
345 | { | 340 | Assert(dwId == pControl->wId); |
346 | DWORD dwId = ::SetTimer(hWnd, pControl->wId, 500, NULL); | ||
347 | dwId = dwId; // prevents warning in "ship" build. | ||
348 | Assert(dwId == pControl->wId); | ||
349 | } | ||
350 | } | 341 | } |
351 | 342 | ||
352 | LExit: | 343 | LExit: |
353 | return SUCCEEDED(hr); | 344 | results->hr = hr; |
345 | return TRUE; | ||
354 | } | 346 | } |
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( | |||
353 | case WM_NCDESTROY: | 353 | case WM_NCDESTROY: |
354 | DecrementHandleTheme(pHandleTheme); | 354 | DecrementHandleTheme(pHandleTheme); |
355 | ::SetWindowLongPtrW(hWnd, GWLP_USERDATA, 0); | 355 | ::SetWindowLongPtrW(hWnd, GWLP_USERDATA, 0); |
356 | break; | 356 | ::PostQuitMessage(0); |
357 | |||
358 | case WM_CREATE: | ||
359 | { | ||
360 | HRESULT hr = ThemeLoadControls(vpTheme); | ||
361 | if (FAILED(hr)) | ||
362 | { | ||
363 | return -1; | ||
364 | } | ||
365 | } | ||
366 | break; | 357 | break; |
367 | 358 | ||
368 | case WM_THMVWR_THEME_LOAD_BEGIN: | 359 | case WM_THMVWR_THEME_LOAD_BEGIN: |
@@ -377,10 +368,6 @@ static LRESULT CALLBACK MainWndProc( | |||
377 | OnNewTheme(vpTheme, hWnd, reinterpret_cast<HANDLE_THEME*>(lParam)); | 368 | OnNewTheme(vpTheme, hWnd, reinterpret_cast<HANDLE_THEME*>(lParam)); |
378 | return 0; | 369 | return 0; |
379 | 370 | ||
380 | case WM_DESTROY: | ||
381 | ::PostQuitMessage(0); | ||
382 | break; | ||
383 | |||
384 | case WM_THMUTIL_LOADING_CONTROL: | 371 | case WM_THMUTIL_LOADING_CONTROL: |
385 | return OnThemeLoadingControl(reinterpret_cast<THEME_LOADINGCONTROL_ARGS*>(wParam), reinterpret_cast<THEME_LOADINGCONTROL_RESULTS*>(lParam)); | 372 | return OnThemeLoadingControl(reinterpret_cast<THEME_LOADINGCONTROL_ARGS*>(wParam), reinterpret_cast<THEME_LOADINGCONTROL_RESULTS*>(lParam)); |
386 | 373 | ||