c++ - How can I "validate" CWnd* object? -
(there's tl;dr on last line)
i'm implementing handler close selected windows open in software application. here's rough code:
void cdlg_dummy_dialog::onclosewindows() { (int = 0; < m_windowsinfo.size(); i++) { window_node *pwn = &m_windowsinfo.at(i); if (pwn->checked && iswindow(pwn->pwnd->getsafehwnd())) { pwn->pwnd->getparentframe()->sendmessage(wm_close); } } }
here declarations of parameters shown above:
struct window_node { cstring name; cstring path; cwnd *pwnd; bool checked; hicon icon; .... }; class cdlg_dummy_dialog : public cdialog { ... protected: std::vector<struct window_node> m_windowsinfo; ... }
also, there can multiple instances of window_node
different pwnd
parameter, originating single cdocument
class (ie. different types of windows exist show different displays document).
for software, if first window of document (which "green" window type in diagram) closed, other windows associated document automatically closed them. problem happens.
if user selects multiple windows same document (with green window among them), closes windows time finishes first iteration, , pwnd
pointers pointing unassigned memory. therefore, when tries call getsafehwnd()
on next iteration, prompts memorry access violation error:
first-chance exception @ 0x00000000521b4ad0 (mfc100d.dll) in settle3d.exe: 0xc0000005: access violation reading location 0x00000000136943e0. unhandled exception @ 0x00000000521b4ad0 (mfc100d.dll) in settle3d.exe: 0xc000041d: unhandled exception encountered during user callback.
i'm aware easy fix iterate through vector in opposite direction. however, trying integrate method on several other software well, , don't organize windows in same manner.
so, after long question above, here's tl;dr:
is there way check if instance of cwnd* pointing valid window?
one possibility start main window, , recursively search through child windows if find hwnd in question.
get first child cwnd::getwindow(gw_child)
, next windows cwnd::getwindow(gw_hwndnext)
.
Comments
Post a Comment