c++ - Given just a HBITMAP, how to draw to it? -


i'm absolute beginner @ have managed blunder way 93% of want be. need final 7%.

i've manually created bitmap so:

bitmapinfo bmpinfo = { 0 }; bitmapinfoheader bmpinfoheader = { 0 }; bitmap imagebitmap; void *bits;  bmpinfoheader.bisize = sizeof(bitmapinfoheader); bmpinfoheader.bibitcount = 32; bmpinfoheader.biclrimportant = 0; bmpinfoheader.biclrused = 0; bmpinfoheader.bicompression = bi_rgb; bmpinfoheader.biheight = -image_display_height; bmpinfoheader.biwidth = image_display_width; bmpinfoheader.biplanes = 1; bmpinfoheader.bisizeimage = image_display_width * image_display_height * 4;  zeromemory(&bmpinfo, sizeof(bmpinfo)); bmpinfo.bmiheader = bmpinfoheader; bmpinfo.bmicolors->rgbblue = 0; bmpinfo.bmicolors->rgbgreen = 0; bmpinfo.bmicolors->rgbred = 0; bmpinfo.bmicolors->rgbreserved = 0;  g_himagebitmap = createdibsection(hdc, &bmpinfo, dib_rgb_colors, &bits, null, 0); getobject(g_himagebitmap, sizeof(bitmap), &imagebitmap);  (i = 0; < image_display_width; i++) {     (j = 0; j < image_display_height; j++) {         ((unsigned char *)bits)[j*image_display_width * 4 + * 4] = 255;         // blue         ((unsigned char *)bits)[j*image_display_width * 4 + * 4 + 1] = 255;     // green         ((unsigned char *)bits)[j*image_display_width * 4 + * 4 + 2] = 255;     // red         ((unsigned char *)bits)[j*image_display_width * 4 + * 4 + 3] = 0;     } }  g_imagebitmappixels = bits; 

and elsewhere wm_paint handles drawing so

hdc = beginpaint(hwnd, &ps);  if (g_himagebitmap != null) {     getobject(g_himagebitmap, sizeof(bitmap), &bm);     holdbitmap = (hbitmap)selectobject(hmemorydc, g_himagebitmap);     bitblt(hdc, upper_left_image_x, upper_left_image_y,         bm.bmwidth, bm.bmheight, hmemorydc, 0, 0, srccopy);     selectobject(hmemorydc, holdbitmap); } 

given global variable g_imagebitmappixels other parts of program can change , manipulate individual pixels in bitmap, , when happens, use

invalidaterect(hwnd, &rect_imageupdate_window, true); updatewindow(hwnd); 

to update little portion of screen. works great. hooray me.

to point, question is, if function has hbitmap (g_himagebitmap) ... there way call windows library functions draw lines, text, circles, filled circles, hbitmap? these functions

movetoex(hdc, x1, y1, null); lineto(hdc, x2, y2 );  hbrush hredbrush = createsolidbrush(rgb(255, 0, 0)); fillrect(hdc, &somerectangle, hredbrush); 

except instead of needing device context, take hbitmap?

i have pointer actual pixels (g_imagebitmappixels) could write own line drawing, circle drawing, rectangle filling functions. indeed have done that, seems shame not use functions microsoft kindly provides. also, i'm not smart enough make own text-drawing functions.

thank help.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -