From 2f7b69d6d4cf18ca9ca04d9a44aaa6871ce51160 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Wed, 7 Sep 2022 00:40:26 +0200 Subject: Improve error handling. --- c/listview.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'c/listview.cpp') diff --git a/c/listview.cpp b/c/listview.cpp index b638f7b..0615ed0 100644 --- a/c/listview.cpp +++ b/c/listview.cpp @@ -2,6 +2,7 @@ #include #include "drag.h" +#include "err.h" #include "listview.h" #include "win32.h" #include "window.h" @@ -14,17 +15,19 @@ ListView::ListView(Window& parent, const HMENU hMenu, const DWORD dwStyle) : par { extern HFONT g_hfNormal; - hWnd = Require(CreateWindowExW( + if (!(hWnd = CreateWindowExW( WS_EX_CLIENTEDGE, WC_LISTVIEW, L"", dwStyle|WS_CHILD|WS_VISIBLE|WS_VSCROLL|WS_TABSTOP|LVS_REPORT|LVS_SHOWSELALWAYS, 0, 0, 0, 0, - parent.hWnd, hMenu, GetModuleHandle(nullptr), this)); + parent.hWnd, hMenu, GetModuleHandle(nullptr), this))) + throw Err(WINDOWS, L"List view could not be created: %s"); m_proc0 = reinterpret_cast(SetWindowLongPtr( - hWnd, GWLP_WNDPROC, reinterpret_cast(::WndProc))); + hWnd, GWLP_WNDPROC, reinterpret_cast(Except<::WndProc>))); - Require(SetPropW(hWnd, L"this", reinterpret_cast(this))); + if (!SetPropW(hWnd, L"this", reinterpret_cast(this))) + throw Err(WINDOWS, L"List view property could not be set: %s"); ListView_SetExtendedListViewStyle(hWnd, LVS_EX_FULLROWSELECT|LVS_EX_DOUBLEBUFFER); SendMessageW(hWnd, WM_SETFONT, reinterpret_cast(g_hfNormal), MAKELPARAM(FALSE, 0)); } -- cgit v1.2.3