c++ - Converting ICON to BITMAP -- side-effect -
how make code strictly conversion windows icon cbitmap?
the code incorrectly displaying new bitmap on screen. :(
this code acquired 'someone' on web. , though achieves it's goal of converting icon, it displays icon on screen (upper left hand corner) should not doing.
d'oh!
void cuihelper::converticontobitmap2(cbitmap& bmpobj, hicon hicon) { cclientdc clientdc(null); cdc memdc; memdc.createcompatibledc(&clientdc); assert(hicon); iconinfo info; verify(geticoninfo(hicon, &info)); bitmap bmp; getobject(info.hbmcolor, sizeof(bmp), &bmp); hbitmap hbitmap = (hbitmap)copyimage(info.hbmcolor, image_bitmap, 0, 0, 0); assert(hbitmap); assert(memdc.getsafehdc()); hbitmap holdbmp = (hbitmap)memdc.selectobject(hbitmap); clientdc.bitblt(0, 0, bmp.bmwidth, bmp.bmheight, &memdc, 0, 0, srccopy); memdc.selectobject(holdbmp); verify( bmpobj.attach(hbitmap) ); deleteobject(info.hbmcolor); deleteobject(info.hbmmask); }
i dumb when comes gdi.
clientdc.bitblt(0, 0, bmp.bmwidth, bmp.bmheight, &memdc, 0, 0, srccopy);
should be
memdc.bitblt(0, 0, bmp.bmwidth, bmp.bmheight, &memdc, 0, 0, srccopy);
Comments
Post a Comment