just trying to draw a bitmap on a window.

when i use
BeginPaint,hWnd,addr ps
mov hDC,eax

and then create a compatilbe memory DC to flip on wm_paint,
it displays the bitmap correctly.

but if i use
GetDC,hWnd
mov hDC,eax

on wm_create and then flip the memory DC to hDC,
it doesn't display.

what do i have to do to draw to the memory DC on wm_create
and then flip it on wm_paint?
Posted on 2001-12-17 02:06:56 by grv575
I don't think theres any flipping in windows GDI, only Bltting.

In WM_CREATE use CreateCompatibleDC to create a memory DC. Then select your bitmap into it, or use CreateBitmap to create a blank one for it.

Once you have a bitmap selected into it you can prefrom all standard GDI operations on it. This means in WM_PAINT you can BitBlt it to the window DC
Posted on 2001-12-17 03:45:35 by Eóin
ok I don't think the problem was with GetDC after all.

i can blit the bitmap onto the main window DC and it will display.
but if i create a memory dc and blit to that and then blit the mDC to the window it doesn't...

so if i just change


invoke BitBlt,hWndDC,0,0,BMPWIDTH,BMPHEIGHT,hBitmapDC,0,0,SRCCOPY ;1

; invoke BitBlt,hMemoryDC,0,0,BMPWIDTH,BMPHEIGHT,hBitmapDC,0,0,SRCCOPY ;2
; invoke BitBlt,hWndDC,0,0,BMPWIDTH,BMPHEIGHT,hMemoryDC,0,0,SRCCOPY ;



;1 to ;2
nothing gets displayed

here's the source if anyone doesn't mind taking a look at it
Posted on 2001-12-17 15:17:38 by grv575
nm i figured it out. needed to create a compatible memory bitmap to select onto the memory dc.

here's the source to a really simple example if anyone else is having problems with "double-buffering".

left button draws the bitmap to the backbuffer & flips it
right button exits

no resizing on wm_paint/wm_size
Posted on 2001-12-17 17:01:48 by grv575
Creating a Compatible Bitmap and getting the DC of the Bitmap to
draw one on the other is a lot of typing. To ease all this work I
created two functions which I include usually in all my projects.
Called UsefulProcs.inc *g*

Here they are:


;==============================================
; GetCompatibleBitmap
;==============================================
; This is used to create DC's for BackBuffers, ImageDC etc...
; invoke GetCompatibleBitmap, ADDR ImageDC, ADDR hImageDC, hwnd, 500, 300
;==============================================
GetCompatibleBitmap proc uses ebx AnotherDC:DWORD, HandleOfDC:DWORD, hwnd:DWORD, xPos:DWORD, yPos:DWORD

invoke CreateCompatibleDC,NULL
mov ebx,AnotherDC
mov dword ptr [ebx],eax
invoke GetDC,hwnd
push eax
invoke CreateCompatibleBitmap,eax,xPos,yPos
mov ebx,HandleOfDC
mov dword ptr [ebx],eax
pop eax
invoke ReleaseDC,hwnd,eax
mov ebx,HandleOfDC
mov eax,[ebx]
mov ebx,AnotherDC
mov ecx,[ebx]
invoke SelectObject,ecx,eax
ret
GetCompatibleBitmap endp

;==============================================
; GetBitmapDC
;==============================================
; This is used to create DC's for Bitmaps
; invoke GetBitmapDC, ADDR BitmapDC, ADDR NameOfBitmap, ADDR hBitmap, hwnd
;==============================================
GetBitmapDC proc uses ebx AnotherDC:DWORD, BitmapADDR:DWORD,HandleOfBitmap:DWORD, hwnd:DWORD

invoke GetDC,hwnd
push eax ;1 push DC for release later

invoke CreateCompatibleDC,eax
mov ebx,AnotherDC
mov dword ptr [ebx],eax
push eax ;2 push DC for SelectObject
invoke LoadBitmap,hInstance,BitmapADDR
mov ebx,HandleOfBitmap
mov dword ptr [ebx],eax
pop ecx ;2 pop Created DC
invoke SelectObject,ecx,eax

pop eax ;1 pop DC to release
invoke ReleaseDC,hwnd,eax
ret
GetBitmapDC endp


It makes working with Bitmaps etc much more handy :-)
Don't forget ;-) : You still have to DeleteObjects and DeleteDCs

Hope this helps somebody out.

JimmyClif
Posted on 2001-12-17 19:12:12 by JimmyClif
Nice helper PROCs JimmyClif. :)
;==============================================

; GetCompatibleBitmap
;==============================================
; This is used to create DC's for BackBuffers, ImageDC etc...
; invoke GetCompatibleBitmap, ADDR ImageDC, ADDR hImageDC, hwnd, 500, 300
;==============================================
GetCompatibleBitmap proc AnotherDC:DWORD, HandleOfDC:DWORD, hwnd:DWORD, xPos:DWORD, yPos:DWORD
invoke CreateCompatibleDC,NULL
mov edx,AnotherDC
push eax
mov [edx],eax
invoke GetDC,hwnd
push eax
invoke CreateCompatibleBitmap,eax,xPos,yPos
mov edx,HandleOfDC
mov ecx,[esp] ; pop ecx
mov [esp],eax ; push eax
mov [edx],eax
invoke ReleaseDC,hwnd,ecx
pop eax ; HandleOfDC
pop ecx ; AnotherDC
invoke SelectObject,ecx,eax
ret
GetCompatibleBitmap endp

;==============================================
; GetBitmapDC
;==============================================
; This is used to create DC's for Bitmaps
; invoke GetBitmapDC, ADDR BitmapDC, ADDR NameOfBitmap, ADDR hBitmap, hwnd
;==============================================
GetBitmapDC proc AnotherDC:DWORD, BitmapADDR:DWORD,HandleOfBitmap:DWORD, hwnd:DWORD
invoke GetDC,hwnd
push eax ;1 push DC for release later
invoke CreateCompatibleDC,eax
mov edx,AnotherDC
push eax ;2 push DC for SelectObject
mov [edx],eax
invoke LoadBitmap,hInstance,BitmapADDR
mov edx,HandleOfBitmap
pop ecx ;2 pop Created DC
mov [edx],eax
invoke SelectObject,ecx,eax
pop eax ;1 pop DC to release
invoke ReleaseDC,hwnd,eax
ret
GetBitmapDC endp
Posted on 2001-12-17 21:18:16 by bitRAKE
Thanks for the compliment bitRAKE :) && for optimizing them a little...
Posted on 2001-12-18 16:31:06 by JimmyClif
I just figured if you were going to use them all the time...wouldn't hurt. :tongue:
Posted on 2001-12-18 18:20:10 by bitRAKE
This is not an attempt at one-up-manship but if you use CreateBitmap instead of CreateCompatibleBitmap you don't need to get the window DC.

invoke CreateCompatibleDC,0
mov bDc,eax
invoke CreateBitmap,gWd,gHt,1,32,0
mov bBm,eax
invoke SelectObject,bDc,eax

I've never had any problems using this method, however maybe you'd prefeer the bitmap created to have the same bitdepth as the window DC. I may have read somewhere that bitblt is fastest when there is no conversion to be preformed.
Posted on 2001-12-19 06:36:40 by Eóin