C++ - WINAPI - Object-oriented approach to closing a window -


while trying create nice wrapper around win32 specific gui components, ran problem. problem i'm unable close application after windows created no longer exist.

my api works this:

/// ---------------------------- /// @author     god /// @project    helixirr widgets /// ---------------------------- #include <helixirrwidgets/helixirrwidgets.hpp>  int main(void){     helixirrwidgets::window __windows[2] = {helixirrwidgets::window("big window"), helixirrwidgets::window()};      __windows[0].position(200, 200);     __windows[0].size(800, 600);     __windows[0].visible(true);     __windows[0].save_changes();      __windows[1].name("tiny window");     __windows[1].position(10, 100);     __windows[1].size(400, 200);     __windows[1].visible(true);     __windows[1].save_changes();      while(__windows[0].active() || __windows[1].active()){         if(__windows[0].visible()){             __windows[0].show();         }         if(__windows[1].visible()){             __windows[1].show();         }     }     return 0; } 

in method of helixirrwidgets::window called "active", declared this

inline bool active(void) const noexcept; 

i can check, whether window active or not.

this method return const reference boolean member variable of instance. member variable modified in "show"-method of same class. here's definition:

void window::show(void){     if(getmessage(&_m_ophelper->message, _m_ophelper->handle_window, 0, 0)){         if(_m_ophelper->message.message == wm_close){             _m_bactive = false;             return;         }          translatemessage(&_m_ophelper->message);         dispatchmessage(&_m_ophelper->message);          showwindow(_m_ophelper->handle_window, sw_showdefault);         updatewindow(_m_ophelper->handle_window);          _m_bactive = true;         return;     }     _m_bactive = false; } 

do note use pimpl-idiom hide platform-specific structures ("_m_ophelper" pointer implementation).

it may works, doesn't , can't understand why. comes down simple question: how can close window implemented using winapi specific functions , structures closed appropriately user of application?

i guess cause of issue related fact wm_close not last message hwnd gets. messages wm_destroy, wm_ncdestroy , possibly more (depending on particlar window , state) come after wm_close, leading assignment _m_bactive = true.

i.e. window becomes inactive short time, , (likely) never inactive @ same time, causing endless loop in main().


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -