From 26f70ab37bee8ffd70b662ff999613c643215605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Thu, 14 Jul 2022 02:34:42 +0200 Subject: Initialize global variables in the right place. The rules for what messages are sent at window creation -- and in which order -- are neither intuitive or clear. WM_CREATE can NOT be relied upon to initialize global state required by handlers of other messages (such as WM_GETMINMAXINFO, which seems to be sent before WM_CREATE). Thus, the better solution is to initialize everything using a CBT hook before the window procedure is even run. Because CBTProc creates (child): windows of its own, though, one must be careful to only run the initialization once, which is done by checking g_hWnd. --- c/datalistview.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'c/datalistview.cpp') diff --git a/c/datalistview.cpp b/c/datalistview.cpp index 05d46a4..bd9b317 100644 --- a/c/datalistview.cpp +++ b/c/datalistview.cpp @@ -6,15 +6,12 @@ #include "resource.h" #include "defs.h" -extern EpisodeListView g_elv; +extern EpisodeListView *g_lpElv; -void -DataListView::Create() +DataListView::DataListView() : ListView((HMENU)IDC_DATALISTVIEW, LVS_NOCOLUMNHEADER) { LVCOLUMN lvc; - ListView::Create((HMENU)IDC_DATALISTVIEW, LVS_NOCOLUMNHEADER); - lvc.mask = LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM; lvc.iSubItem = DLVSIKEY; lvc.pszText = TEXT("Key"); @@ -75,7 +72,7 @@ DataListView::ShowEpisode(int iEpisode) LVFINDINFO lvfi; lvfi.flags = LVFI_PARAM; lvfi.lParam = iEpisode; - int iItem = ListView_FindItem(g_elv.HWnd(), -1, &lvfi); + int iItem = ListView_FindItem(g_lpElv->HWnd(), -1, &lvfi); if (iItem != -1) - ListView_EnsureVisible(g_elv.HWnd(), iItem, TRUE); + ListView_EnsureVisible(g_lpElv->HWnd(), iItem, TRUE); } -- cgit v1.2.3