c++ - ellipse as checked icon in a menu -
i'm creating context menu window , i'd have in submenu filled ellipses, each in different colour, instead of texts - submenu responsible choosing colour. don't know how it... know concrete example? i've read on msdn pages owner-drawn menu items, there no example concerning specific task - so, don't know how it. later tried change checked icon menu item - turned out dev-c++ (under windows 7) knows neither setdcbrushcolor nor dc_brush, , still don't know how change checked icon without loading image file. added @ beginning of program following lines:
#define _win32_ie 0x0600 #define winver 0x0700 #define _win32_winnt 0x0700
then compiler doesn't protest, however, icon black, when i'm trying following code , whatever colour i'm choosing:
hwnd hwnd = getdesktopwindow(); hdc hdc = getdc( hwnd ); hdc hdcmem = createcompatibledc( hdc ); size size = { getsystemmetrics( sm_cxmenucheck ), getsystemmetrics( sm_cymenucheck ) }; hbitmap bitmap = createcompatiblebitmap( hdcmem, size.cx, size.cy ); hbitmap bitmapold = (hbitmap) selectobject( hdcmem, bitmap ); patblt( hdcmem, 0, 0, size.cx, size.cy, whiteness ); hbrush brushold = (hbrush) selectobject( hdcmem, getstockobject( null_brush ) ); ellipse( hdcmem, 0, 0, size.cx, size.cy); setdcbrushcolor( hdcmem, rgb(0,0,255) ); selectobject( hdcmem, getstockobject( dc_brush ) ); ellipse( hdcmem, 2, 2, size.cx-2, size.cy-2 ); selectobject( hdcmem, brushold ); selectobject( hdcmem, bitmapold ); deletedc( hdcmem ); releasedc( hwnd, hdc ); setmenuitembitmaps( mnu_t, (30*m_menu_t+25), mf_bycommand, bitmap, bitmap);// mnu_t , m_menu_t variables
can me?
the problem here:
hbitmap bitmap = createcompatiblebitmap( hdcmem, size.cx, size.cy );
this natural , rational statement write, doesn't people expect do. it's common mistake , can take forever figure out source of problem here. know making mistake more once myself.
createcompatiblebitmap
not create bitmap that's compatible specified device context (dc). well, does--sort of--but it's more nuanced that: creates new bitmap that's compatible bitmap that's selected specified dc.
when creating memory dc createcompatibledc
, new dc gets default bitmap 1 pixel wide 1 pixel high , color depth of 1 bit. not intuitive @ all, since asked dc compatible screen dc, , screen (almost certainly) has more 1 bit of color depth.
so when call createcompatiblebitmap
new bitmap of specified size uses 1 bit per pixel. can draw it, and, if stars align, you'll see crude outline of drew. if stars aren't aligned, you'll end pixels being single color.
when blit 1-bit per pixel bitmap dc, current text foreground , background colors used. since foreground text color black, end black rectangle , virtually no clue went wrong.
the solution specify screen or window dc instead of memory dc in call createcompatiblebitmap
. create new bitmap has same color depth bitmap used screen, far more useful.
Comments
Post a Comment