Click to See Complete Forum and Search --> : Loading a Bitmap and blitting it to a DC.
denniswrenn
Feb 16th, 2001, 05:36 AM
Hello,
How do I load a bitmap, and blit it to a DC? I also want to display it on the screen.
Thanks,
Dennis
PS: I will not be using any MFC. Just a plain Win32 App.
Technocrat
Feb 16th, 2001, 10:13 AM
Wow I get to help Dennis, this is a first :D
Note: I am writing this all from memory.
HDC hDC;
HBITMAP hBitmap;
hDC = CreateCompatibleDC(NULL);
hBitmap = (HBITMAP)SelectObject(hDC, LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP) );
//You could also use LoadImage instead of LoadBitmap
BitBlt(hDCOfDeviceToPaint, StartXofDevice, StartYofDevice, PaintToX, PaintToY, hDC, StartXofBitmap, StartYofBitmap, SRCCOPY);
//if you use case WM_PAINT do
//PAINTSTRUCT ps;
//BeginPaint(hWndofDeviceToPaintTo, &ps);
//BitBlt(ps.hdc, StartXofDevice, StartYofDevice, PaintToX, PaintToY, hDC, StartXofBitmap, StartYofBitmap, SRCCOPY);
//EndPaint(hWndofDeviceToPaintTo, &ps);
If you want the bitmap to have a transparent back ground see:
http://forums.vb-world.net/showthread.php?s=&threadid=54501
Technocrat
Feb 16th, 2001, 10:29 AM
Sorry at looking at your post I did not read BitBlt it to a DC. My mistake.
To do that just add:
HDC hDC2;
BITMAP bm;
//Size
GetObject(hBitmap, sizeof(BITMAP), &bm);
hDC2 = CreateCompatibleDC(NULL);
BitBlt(hDC2, 0, 0, bm.bmWidth, bm.bmHeight, hDC, 0, 0, SRCCOPY);
I also forgot you have to delete the objects and DCs when you are done with them
DeleteDC(hDC);
DeleteDC(hDC2);
DeleteObject(hBitmap);
Thanks :D
Another question, how do I blit the bitmap to the screen?
Technocrat
Feb 16th, 2001, 04:16 PM
You just need a device handle to BitBlt it to. You can use almost anything, but static devices are the best. I made a staitic device that filled my entire window.
hWnd_Static = CreateWidnowEx(WS_EX_NOPARENTNOTIFY, "Static", NULL, WS_CHILD | SS_REALSIZEIMAGE, 0, 0, WindowWidth, WindowHeight, hWnd, NULL, hInstance, NULL);
Then if you wanted to have it be there all the time you just catch the WM_PAINT when you are catching you messages and use this:
PAINTSTRUCT ps;
case WM_PAINT:
//This is really important, the window itself has to be painted. This had me messed up for days
BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
BeginPaint(hWnd_Static, &ps);
BitBlt(ps.hdc, 0, 0, (WindowWidth-5), WindowHeight, hDC, 0, 0, SRCCOPY);
EndPaint(hWnd_Static, &ps);
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.