c++ - Owner Draw Button Force Refresh -
i have 4 owner draw buttons work tab system program. issue have that, when click on 1 of buttons, need change images of other buttons. whenever try reset images, changes image on button i've clicked. there someway of changing images on other buttons without being clicked ?
int_ptr callback springboard::dlgproc(hwnd hdlg, uint msg, wparam wparam, lparam lparam){ static drawitemstruct* pdis; switch (msg) { case wm_drawitem: pdis = (drawitemstruct*) lparam; // (winuser.h) maybe want account pdis->ctltype (odt_menu, odt_listbox, odt_combobox, odt_button, odt_static) switch(pdis->ctlid) { case idc_tab1: thespringboard.mymanageownerdrawiconbutton(pdis, hinstance); break; case idc_tab2: thespringboard.mymanageownerdrawiconbutton(pdis, hinstance); break; case idc_tab3: thespringboard.mymanageownerdrawiconbutton(pdis, hinstance); break; case idc_tab4: thespringboard.mymanageownerdrawiconbutton(pdis, hinstance); break; case idc_tab5: thespringboard.mymanageownerdrawiconbutton(pdis, hinstance); break; default: break; } int springboard::mymanageownerdrawiconbutton(drawitemstruct* pdis, hinstance hinstance) { static rect rect; static hbitmap hcurricon, hstdc, hstdoff, hstdon, hvfxc, hvfxoff, hvfxon, hcityc, hcityoff, hcityon, hmaxc, hmaxoff, hmaxon, hsetc, hsetoff, hseton; rect = pdis->rcitem; hstdoff = (hbitmap) loadbitmap(hinstance, makeintresource(idb_stdoff)); hstdon = (hbitmap) loadbitmap(hinstance, makeintresource(idb_stdon)); hstdc = (hbitmap) loadbitmap(hinstance, makeintresource(idb_stdclick)); hvfxoff = (hbitmap) loadbitmap(hinstance, makeintresource(idb_vfxoff)); hvfxon = (hbitmap) loadbitmap(hinstance, makeintresource(idb_vfxon)); hvfxc = (hbitmap) loadbitmap(hinstance, makeintresource(idb_vfxclick)); hcityoff = (hbitmap) loadbitmap(hinstance, makeintresource(idb_cityoff)); hcityon = (hbitmap) loadbitmap(hinstance, makeintresource(idb_cityon)); hcityc = (hbitmap) loadbitmap(hinstance, makeintresource(idb_cityclick)); hmaxoff = (hbitmap) loadbitmap(hinstance, makeintresource(idb_maxoff)); hmaxon = (hbitmap) loadbitmap(hinstance, makeintresource(idb_maxon)); hmaxc = (hbitmap) loadbitmap(hinstance, makeintresource(idb_maxclick)); hsetoff = (hbitmap) loadbitmap(hinstance, makeintresource(idb_settingoff)); hseton = (hbitmap) loadbitmap(hinstance, makeintresource(idb_settingon)); hsetc = (hbitmap) loadbitmap(hinstance, makeintresource(idb_settingclick)); if (idc_tab1 == pdis->ctlid) { // if button selected, display // "active" icon, else "inactive" icon: if (pdis->itemstate & ods_selected) hcurricon = hstdc; else hcurricon = hstdoff; if(tabroll == 1) hcurricon = hstdon; } if (idc_tab2 == pdis->ctlid) { // if button selected, display // "active" icon, else "inactive" icon: if (pdis->itemstate & ods_selected) hcurricon = hvfxc; else hcurricon = hvfxoff; //if(tabroll == 2) hcurricon = hvfxon; } if (idc_tab3 == pdis->ctlid) { // if button selected, display // "active" icon, else "inactive" icon: if (pdis->itemstate & ods_selected) hcurricon = hcityc; else hcurricon = hcityoff; //if(tabroll == 3) hcurricon = hcityon; } if (idc_tab4 == pdis->ctlid) { // if button selected, display // "active" icon, else "inactive" icon: if (pdis->itemstate & ods_selected) hcurricon = hmaxc; else hcurricon = hmaxoff; //if(tabroll == 4) hcurricon = hmaxon; } if (idc_tab5 == pdis->ctlid) { // if button selected, display // "active" icon, else "inactive" icon: if (pdis->itemstate & ods_selected){ hcurricon = hsetc;} else{ hcurricon = hsetoff;} //if(tabroll == 5) hcurricon = hseton; } hdc hdc = createcompatibledc(pdis->hdc); selectobject(hdc, hcurricon); bitblt(pdis->hdc,0, 0,icon_width, icon_height, hdc, 0, 0, srccopy); deletedc(hdc); return(ret_ok); }
you can simplify dlgproc
:
int_ptr callback springboard::dlgproc(hwnd hdlg, uint msg, wparam wparam, lparam lparam) { switch (msg) { case wm_drawitem: thespringboard.mymanageownerdrawiconbutton((drawitemstruct*)lp, hinstance); break; //... return false; }
in mymanageownerdrawiconbutton
, need these changes:
from hdc hdc = createcompatibledc(pdis->hdc);
to:
hdc hdc = pdis->hdc;
, not need call deletedc(hdc);
change declaration of rect
, doesn't have static.
rect rect = pdis->rcitem;
other static variables need initialized once, that's whole point of static:
static hbitmap hcurricon = (hbitmap) loadbitmap(hinstance, makeintresource(idb_something)); //...
ods_selected
means button pressed down. may want use own global variables manually keep track of buttons, set selection , remove selection other buttons...
ps, added winapi
tag question.
Comments
Post a Comment