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/episodelistview.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'c/episodelistview.cpp') diff --git a/c/episodelistview.cpp b/c/episodelistview.cpp index 88fb7ac..e34fb34 100644 --- a/c/episodelistview.cpp +++ b/c/episodelistview.cpp @@ -6,16 +6,13 @@ #include "resource.h" #include "defs.h" -extern DataListView g_dlv; +extern DataListView *g_lpDlv; static int CALLBACK ElvSort(LPARAM, LPARAM, LPARAM); -void -EpisodeListView::Create() +EpisodeListView::EpisodeListView() : ListView((HMENU)IDC_EPISODELISTVIEW, 0) { LVCOLUMN lvc; - ListView::Create((HMENU)IDC_EPISODELISTVIEW, 0); - lvc.mask = LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM; lvc.iSubItem = ELVSIEPISODE; lvc.pszText = TEXT("#"); @@ -62,7 +59,7 @@ EpisodeListView::HandleNotify(LPARAM lParam) m_lviFocus.iItem = lpNmLv->iItem; m_lviFocus.lParam = lpNmLv->lParam; UpdateItem(&m_lviFocus); - g_dlv.ShowEpisode(lpNmLv->lParam); + g_lpDlv->ShowEpisode(lpNmLv->lParam); } break; case LVN_COLUMNCLICK: /* Sort by column. */ @@ -207,7 +204,7 @@ s: ListView_SetItemState(m_hWnd, -1, LVIF_STATE, LVIS_SELECTED); m_lviFocus.iItem = iItem; m_lviFocus.lParam = iEpisode; UpdateItem(&m_lviFocus); - g_dlv.ShowEpisode(iEpisode); + g_lpDlv->ShowEpisode(iEpisode); } /* Select next/previous unwatched episode. */ -- cgit v1.2.3