c++ - MFC button onclick handler -
i've 2 mfc buttons want hide when 3d stl file being loaded , show buttons again when stl loading complete. prevent user re-loading model when loading taking place.
the snippet of code below
{ // change control state when model loads ((cbutton *)this->getdlgitem(idc_reload_stock_button))->showwindow(sw_hide); ((cbutton *)this->getdlgitem(idok))->showwindow(sw_hide); updatewindow(); } // process takes few seconds load file in memory customstockmodel.loadfile(pathname.getbuffer(pathname.getlength())); { // change control state when model has loaded ((cbutton *)this->getdlgitem(idc_reload_stock_button))->showwindow(sw_show); ((cbutton *)this->getdlgitem(idok))->showwindow(sw_show); updatewindow(); }
the buttons hidden , reappear expect, when click button area while it's hidden, onclick handler gets called when button control reappears on screen. seems click message queued , mfc calls handler once buttons activated. doing wrong here?
ideally should read file in thread - allow application refresh , process messages. if unsure (multi-threading is hard), can call regularly following function in lenghty function clear message loops.
bool yourclass::doevents() { msg msg; while (::peekmessage(&msg, null, 0, 0, pm_remove)) { if (msg.message == wm_quit) { return false; } if (!afxgetapp()->pretranslatemessage(&msg)) { ::translatemessage(&msg); ::dispatchmessage(&msg); } } return true; }
it work "proper programmers" scream when see this! luck
Comments
Post a Comment