c++ - Painted image is always black -
i'm trying draw image within popup windows. bitmap infos stream. part should ok, because if create file , save bitmap looks fine.
the byte array stored follows:
static byte* _bitampcontent;
here how create window:
static wchar name[] = l"bitmap display"; hinstance _instance = ::getmodulehandle(null); hwnd hwnd; msg msg; wndclass wndclass; wndclass.style = 0; wndclass.lpfnwndproc = class::_windowproc; wndclass.cbclsextra = 0; wndclass.cbwndextra = 0; wndclass.hbrbackground = (hbrush)getstockobject(gray_brush); wndclass.hicon = loadicon(null, idi_application); wndclass.hcursor = loadcursor(null, idc_arrow); wndclass.hinstance = _instance; wndclass.lpszmenuname = null; wndclass.lpszclassname = name; if (registerclass(&wndclass) == 0) { messagebox(0, l"the window not registered", l"message", mb_ok); return 0; } rect rc; getwindowrect(hwndowner, &rc); int xpos = (getsystemmetrics(sm_cxscreen) - rc.right) / 2; int ypos = (getsystemmetrics(sm_cyscreen) - rc.bottom) / 2; hwnd = createwindowex(ws_ex_topmost, name, name, ws_overlappedwindow, cw_usedefault, cw_usedefault, 200, 200, null, null, _instance, null); if (hwnd == 0) { messagebox(0, l"hwnd = 0", l"message", mb_ok); return 0; } showwindow(hwnd, sw_shownormal); updatewindow(hwnd); while (getmessage(&msg, null, 0, 0)) { translatemessage(&msg); dispatchmessage(&msg); } msg.wparam;
and in wndproc
function paint bitmap.
lresult callback class::_windowproc(hwnd hwnd, uint umsgid, wparam wparam, lparam lparam) { hbitmap hbitmap; bitmap bitmap; hdc hdc, hmemdc; switch (umsgid) { case wm_paint: bitmapinfoheader bmpinfoheader; bmpinfoheader = { 0 }; bmpinfoheader.bisize = sizeof(bitmapinfoheader); bmpinfoheader.bibitcount = 24; bmpinfoheader.biclrimportant = 0; bmpinfoheader.biclrused = 0; bmpinfoheader.bicompression = bi_rgb; bmpinfoheader.biheight = 200; bmpinfoheader.biwidth = 200; bmpinfoheader.biplanes = 1; unsigned long pixel_data_size; pixel_data_size = 200 * ((200 * (24 / 8))); bmpinfoheader.bisizeimage = pixel_data_size; bitmapinfo dbmi; zeromemory(&dbmi, sizeof(dbmi)); dbmi.bmiheader = bmpinfoheader; dbmi.bmicolors->rgbblue = 0; dbmi.bmicolors->rgbgreen = 0; dbmi.bmicolors->rgbred = 0; dbmi.bmicolors->rgbreserved = 0; void* bits; bits = null; hbitmap = createdibsection(null, &dbmi, dib_rgb_colors, &bits, null, 0); if (hbitmap == null) { messagebox(null, l"bitmap not loaded", l"error", mb_ok); return 0; } gdiflush(); // copy pixels dib. memcpy(bits, _bitampcontent, sizeof(_bitampcontent)); getobject(hbitmap, sizeof(bitmap), &bitmap); paintstruct paintstruct; hdc = beginpaint(hwnd, &paintstruct); hmemdc = createcompatibledc(hdc); selectobject(hmemdc, hbitmap); bitblt(hdc, 0, 0, bitmap.bmwidth, bitmap.bmheight, hmemdc, 0, 0, srccopy); deleteobject(hbitmap); endpaint(hwnd, &paintstruct); return 0;
my problem now, painted image black. assume behavior has dc's don't know what.
what need change?
Comments
Post a Comment