comparison foosdk/sdk/libPPUI/windowLifetime.h @ 1:20d02a178406 default tip

*: check in everything else yay
author Paper <paper@tflc.us>
date Mon, 05 Jan 2026 02:15:46 -0500
parents
children
comparison
equal deleted inserted replaced
0:e9bb126753e7 1:20d02a178406
1 #pragma once
2 #include "ImplementOnFinalMessage.h"
3 #include "win32_op.h"
4 #include <functional>
5
6 namespace PP {
7 //! Create a new window object - obj_t derived from CWindowImpl<> etc, with automatic lifetime management, \n
8 //! OnFinalMessage() is automatically overridden to delete the window object. \n
9 //! Does NOT create the window itself, it's up to you to call Create() or SubclassWindow() with the returned object.
10 template<typename obj_t, typename ... arg_t>
11 obj_t* newWindowObj(arg_t && ... arg) {
12 return new ImplementOnFinalMessage<obj_t>(std::forward<arg_t>(arg) ...);
13 }
14
15 //! Subclass HWND with window class object obj_t deriving from CWindowImpl<> etc, with automatic lifetime management of the object, \n
16 //! OnFinalMessage() is automatically overridden to delete the window subclass object.
17 template<typename obj_t, typename ... arg_t>
18 obj_t* subclassThisWindow(HWND wnd, arg_t && ... arg) {
19 PFC_ASSERT( wnd != NULL );
20 auto ret = newWindowObj<obj_t>(std::forward<arg_t>(arg) ...);
21 WIN32_OP_D(ret->SubclassWindow(wnd));
22 return ret;
23 }
24
25 //! Creates a new window object, of ctrl_t typem with automatic lifetime management,
26 //! and replaces an existing control in a dialog.
27 template<typename ctrl_t>
28 ctrl_t * replaceDialogCtrl(CWindow wndDialog, UINT replaceControlID) {
29 CWindow wndReplace = wndDialog.GetDlgItem(replaceControlID);
30 ATLASSERT(wndReplace != NULL);
31 CRect rc;
32 CWindow wndPrev = wndDialog.GetNextDlgTabItem(wndReplace, TRUE);
33 WIN32_OP_D(wndReplace.GetWindowRect(&rc));
34 WIN32_OP_D(wndDialog.ScreenToClient(rc));
35 CString text;
36 wndReplace.GetWindowText(text);
37 WIN32_OP_D(wndReplace.DestroyWindow());
38 auto ctrl = newWindowObj<ctrl_t>();
39 WIN32_OP_D(ctrl->Create(wndDialog, &rc, text, 0, 0, replaceControlID));
40 if (wndPrev != NULL) ctrl->SetWindowPos(wndPrev, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
41 ctrl->SetFont(wndDialog.GetFont());
42 return ctrl;
43 }
44 }