Advertisement

What's wrong with this GDI blitting code?

Started by January 07, 2001 03:13 PM
3 comments, last by Burning_Ice 24 years ago
Hi I got a really simple piece of code here but it just won''t work If anyone knows what I''m doing wrong please tell me here''s the code:
  
	HDC dc  = GetDC(hwnd);                 // Get DC from main HWND

	HDC dc2 = CreateCompatibleDC ( dc );   // Create memory DC

	if ( (dc==NULL) || (dc2==NULL) )
		MessageBox (NULL,"Error","Error",0);
	LineTo ( dc, 200, 200 );               // Do something on DC

	// blit from dc to dc2

	if (BitBlt ( dc2, 0, 0, 200, 200, dc, 0, 0, SRCCOPY )==0)
		MessageBox (NULL,"Error","Error",0);
	// blit from dc2 to dc on coord 

	if (BitBlt ( dc, 100, 100, 200, 200, dc2, 0, 0, SRCCOPY )==0)
		MessageBox (NULL,"Error","Error",0);
	
	ReleaseDC ( hwnd, dc );
	ReleaseDC ( hwnd, dc2 );
  
None of the MessageBoxes come up, so all functions are successfull...but it just doesnt do anything It only draws the first line to dc but the blitting just does nothing at all
I think just creating a memorydc isn't enough, you need to select a memory bitmap into it...
try:

              HBITMAP bmp, bmpold;	HDC dc  = GetDC(hwnd);                 // Get DC from main HWND	HDC dc2 = CreateCompatibleDC ( dc );   // Create memory DCbmp=CreateCompatibleBitmap(dc,200,200);	bmpOld = (HBITMAP)  SelectObject(dc2, bmp);	if ( (dc==NULL) || (dc2==NULL) )		MessageBox (NULL,"Error","Error",0);	LineTo ( dc, 200, 200 );               // Do something on DC	// blit from dc to dc2	if (BitBlt ( dc2, 0, 0, 200, 200, dc, 0, 0, SRCCOPY )==0)		MessageBox (NULL,"Error","Error",0);	// blit from dc2 to dc on coord 	if (BitBlt ( dc, 100, 100, 200, 200, dc2, 0, 0, SRCCOPY )==0)		MessageBox (NULL,"Error","Error",0);		SelectObject(dc2, bmpOld);        DeleteObject(bmp)	ReleaseDC ( hwnd, dc );	ReleaseDC ( hwnd, dc2 );      






Edited by - harrys on January 7, 2001 5:49:19 PM
Advertisement
Yes that works!
Thanks alot!
quote: Original post by Burning_Ice

Yes that works!
Thanks alot!


No problem...

btw: I just looked over your page and found something interessting - that noise generator you wrote seems to be perfect for terrain generation and plant placement for my iso engine. Whats its current status? Is it functional?
Yep it''s already finished, but crosswinds is updating servers and don''t let me upload anything on the page since yesterday, but I hope they''re done by tomorrow and I can put it on the page then




---------------

MindFly Games

---------------

This topic is closed to new replies.

Advertisement