Advertisement

i'm sorry... another blitting post

Started by January 25, 2002 07:08 PM
5 comments, last by graeme 22 years, 10 months ago
I feel a bit bit posting so many questions in the last 48hrs, but honestly I have been running into brick wall after brick wall, and searching online archives is proving to be only partially helpful. This is the deal, I am trying to create a bitmap with the display image in it, and then blit this into a moving window with no borders, and then blit an animated figure into that. I have the animation sorted out, it''s just the display that is not working at all. I''m not getting compiler errors, just no visible results. I have two functions, one that is called at the initialisation of the program, grabDisplay, which is supposed to fill bmDisplay, a global variable. Then, at the beginning of a function rePaint, before the animated bitmaps are displayed I want to blit the relevant portion of the bmDisplay onto my window. Eventually I want to update the bmDisplay bitmap, but for now just success with the original static one would be good enough. this is the grabDisplay function: BOOL grabDisplay (){ HDC hdcScreen = CreateDC("DISPLAY", NULL, NULL, NULL); //get hdc for the display HDC hdcDisplay= CreateCompatibleDC(hdcScreen); //dwScreenDC = GetDC(NULL); hbmDisplay = CreateCompatibleBitmap(hdcScreen, screenX, screenY); HDC hdcDst = CreateCompatibleDC(NULL); SelectObject(hdcDisplay, hbmDisplay); if (!BitBlt(hdcDisplay, 0,0, screenX, screenY, hdcScreen, 0, 0, SRCCOPY)) PostQuitMessage(0); DeleteObject(hdcDisplay); DeleteObject(hdcScreen); return TRUE; } and the beginning of the painting function: void rePaint(HWND hwnd){ // ShowWindow(hwnd,SW_HIDE); HDC hdc; hdc = GetDC(hwnd); //Copy from the Display Bitmap prepeared during grabDisplay HDC hdcDisplay = CreateCompatibleDC(NULL); HBITMAP hbmT2 = SelectBitmap(hdcDisplay,hbmDisplay); if (!BitBlt(hdc, 0,0, WINDOW_WIDTH, WINDOW_HEIGHT, hdcDisplay, myX, myY, SRCCOPY)) PostQuitMessage(0); SelectBitmap(hdcDisplay,hbmDisplay); DeleteDC(hdcDisplay); ... and so on My confusion is over the SelectBitmap command, I assume that this then binds the bitmap to the hdc associated with it in this operation so that, in the next line, where the blitting to that hdc the bitmap is changed? Or am I wrong? Very confused because this format appeared to work in earlier attempts at this. Again, sorry for a question which may seem like I''m not taking the time to work this out on my own, but believe me I am (I have only been learning c++ for a couple of weeks now) thanks, graeme
oops, that last post was ought to have read ''bit bad'' not ''bit bit''
Advertisement
OK, it''s been a few days since I made the original post, and I have read up on the topic and I made some changes to the code but it still doesn''t work!!

I am trying to copy the screen at the beginning of the program.

The window moves across the desktop and each frame i am trying to copy the windows area from the desktop bitmap that I made at the beginning, and blit it into the window. I then blit a frame from an animation into the window.

The background is not being blitted correctly, the animation is copying over itself without the old picture being erased by the process of blitting in from the bitmap which holds the display.

This is the function which is called once at the beginning of the program to initialise the display bitmap: (hbmDisplay, a global variable)

HDC hdcScreen = CreateDC("DISPLAY", NULL, NULL, NULL); //get hdc for the display
HDC hdcMem= CreateCompatibleDC(hdcScreen);


SelectBitmap(hdcMem, hbmDisplay);

if (!BitBlt(hdcMem,
0,0,
screenX, screenY,
hdcScreen,
0,
0,
SRCCOPY))
PostQuitMessage(0);

DeleteObject(hdcScreen);
DeleteObject(hdcMem);

return TRUE; etc

............................

this is the code which is executed every frame, it copies from the bitmap stored in hbmDisplay:


void rePaint(HWND hwnd){

HDC hdc;


//Copy from the Display Bitmap prepeared during grabDisplay
hdc = GetDC(hwnd);

HDC hdcDisplay = CreateCompatibleDC(NULL);

HBITMAP hbmT2 = SelectBitmap(hdcDisplay,hbmDisplay);
if (!BitBlt(hdc,
0,0,
WINDOW_WIDTH, WINDOW_HEIGHT,
hdcDisplay,
myX,
myY,
SRCCOPY))
PostQuitMessage(0);


DeleteDC(hdcDisplay);
DeleteObject(hbmT2);///???


Can any of you good people please tell me what you think may be wrong?

I cannot wait to wake up in the morning and see all your helpful posts!!! It feels like the eve of my birthday!! This problem has made my life miserable for the last 3 days!









Hey Graeme, wassup?

I took a quick glance over your code, but didn''t examine it as thouroughly as I should have - I''m about three winks from nodding off. It looks like you''re not grabbing the desktop properly. I think your question came up a few months back in one of the microsoft newsgroups pertaining to gdi. A google news search might be warranted. A good reference site for gdi is www.fengyuan.com. His GDIObj.exe is a must if your running W2K or XP. In the meantime, here''s the function that I use to capture the desktop to a bitmap.

Cheers,

  // ----------------------------------------------------------------------------//	Function captures current desktop storing the image in the bitmap parameter//BOOL __stdcall CaptureDesktop(HBITMAP *hBmpScr){	*hBmpScr = NULL;	HWND hwndDeskTop = GetDesktopWindow();	UpdateWindow(hwndDeskTop);	Sleep(500); // give the desktop time to repaint itself	HDC hdc = GetWindowDC(hwndDeskTop);	int iWidth = GetDeviceCaps(hdc, HORZRES);	int iHeight = GetDeviceCaps(hdc, VERTRES);	HDC memdc = CreateCompatibleDC(hdc);	*hBmpScr = CreateCompatibleBitmap(hdc, iWidth, iHeight);	HBITMAP hBmpPre = (HBITMAP)SelectObject(memdc, *hBmpScr);	BitBlt(memdc, 0, 0, iWidth, iHeight, hdc, 0, 0, SRCCOPY);	*hBmpScr = (HBITMAP)SelectObject(memdc, hBmpPre); //  ??	DeleteDC(memdc);	DeleteObject(hBmpPre);	ReleaseDC(hwndDeskTop, hdc);	return ( *hBmpScr != NULL );}  


‘But truth's a menace, science a public danger.’ Brave New World, Aldous Huxley
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
PS. This might be helpful too.

http://www.john.findlay1.btinternet.co.uk/gengfx/dog.zip



‘But truth's a menace, science a public danger.’ Brave New World, Aldous Huxley
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
That stuff is really helpful, thanks alot for that. I am trying to dissect the dog cpp, and a vague conception of czech is coming in handy here (I know Russian and it''s pretty similar,) in order to stop the flickering (I think I need to do a few searches on double-buffering, no?)
ArunVB replied in an earlier post of mine, suggesting I use ''REGION or CRgn (MFC Class) to create transparent regions.''
I have downloaded some source code, and one exe does this to great effect but it only uses one bitmap and I think to transfer this to multi bitmapped animation would be way beyond me.
Thanks again!
Advertisement
Sorry, I didn''t realize the notes to the dog program were written in czech! But I thought it was pretty cool how the dog ran outside of the window and that sounded sort of like what you were wanting to do.

‘But truth's a menace, science a public danger.’ Brave New World, Aldous Huxley
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man

This topic is closed to new replies.

Advertisement