C ++ Win32, the easiest way to show a window with a bitmap

This is for debugging purposes only, so I don’t want to spend a lot of time on it, and it’s not very important. The program exports data in the form of png, jpg, svg, etc. - so this is not very important, although it would be nice to see the image during its creation. In addition, the program will be used on a Linux server; but I will limit this "function" to Win version.

I also do not want to use the library, except that it is very, very light (I used CImg for a while, but I was not very happy with my speed, so I wrote important functions myself and just using libjpeg and libpng directly).

I have an image in ARGB format (32bpp), although format conversion will not be a problem at all. I would like to use Win32, creating a window from a function inside the code (unknown hInstance, etc.), and writing a bitmap. Quick and easy, I hope.

But I do not know win32api. I saw that the only option for drawing (GDI) is an HBITMAP object ... Any piece of code or example that I can rely on? Any thoughts I might not notice? Or maybe, given my time limits - should I just forget about it?

Thank!

+3
source share
2 answers

- . , . ( ).

HBITMAP, BitBlt StretchBlt, , HBITMAP, StretchDIBits, , , . , BITMAPINFOHEADER . -

SIZE sBmp = { 100, 200 };
LPBITMAPINFOHEADER pbi;    // the bitmap header from the file, etc.
LPVOID             pvBits; // the raw bitmap bits

StretchDIBits (hdc, 0, 0, sBmp.cx, sBmp.cy, 
               0, 0, sBmp.cx, sBmp.cy,
               pvBits, pbi, 
               DIB_RGB_COLORS, 
               SRCCOPY);

, : HDC? , . HDC hdc = GetDC(NULL) DC, , , Aero Windows Vista, . , , HDC hdc = GetDC (hwnd) .

, , . , , .

WM_PAINT WM_ERASEBKGND . , . , . , , -, , , .

HINSTANCE, , . .

+4

, , (HDC). :

  • CreateDibSection DIBSection.
  • , CreateDibSection.
  • DC, DC.
  • DIBSection DC.
  • BitBlt ( StretchBlt) DC DC.
+1

Source: https://habr.com/ru/post/1732937/


All Articles