c++ - BitBlt Memory leak -


i using bitblt display bitmaps on buttons. of it, fine, there memory leak causes program crash after while. doing wrong ?

int springboard::drawbasicbuttons(drawitemstruct* pdis, hinstance hinstance){     rect rect;     static hbitmap hcurricon, hiconoff, hiconon;     rect = pdis->rcitem;      hfont font = createfont(13, 0, 0, 0, 300, false, false, false, default_charset, out_default_precis, clip_default_precis, default_quality, default_pitch, l"arial");     tchar txtstr[max_path];     bool istext = false;     int textsize;      if (idc_hold == pdis->ctlid) {         hiconoff = (hbitmap) loadbitmap(hinstance, makeintresource(basic_holdoff));         hiconon = (hbitmap) loadbitmap(hinstance, makeintresource(basic_holdon));         _tcscpy( txtstr, _t("hold      "));         istext = true;         if (pdis->itemstate & ods_selected) hcurricon = hiconon;         else hcurricon = hiconoff;     }      hdc hdc = createcompatibledc(pdis->hdc);     selectobject(hdc, hcurricon);      bitblt(pdis->hdc,0, 0,icon_width,icon_height, hdc, 0, 0, srccopy);      if(istext == true){         textsize = _tcslen(txtstr);         settextcolor(pdis->hdc, rgb(230,230,230));         hfont hfontold = (hfont) selectobject(pdis->hdc, font);         drawtext(pdis->hdc, txtstr, textsize, &pdis->rcitem, dt_singleline | dt_vcenter | dt_right);         selectobject( pdis->hdc, hfontold );     }      deletedc(hdc);     deletebitmap(hcurricon);     deletebitmap(hiconoff);     deletebitmap(hiconon);     font = null;      return(ret_ok); } 

you need select old objects hdc before calling deletedc().

also, seems not cleaning hfont returned createfont().


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -