First post, not quite as epic as I'd hoped for, and first off sorry to whoever the guy/girl who registered "clone", 'tis a shame it was already taken, for my login has always been clone elsewhere, nevermind that, onto my problem.

I'm using MASM32 as my assembler here, and I quickly written out this function to make usable device contexts of a specific size Here is my code:

;Function to make a HDC, returns a handle to it.
;Input is X and Y widths in PX
;bmpH is used so I have a handle to the bmp... needed for me to delete it on cleanup.
invoke CreateCompatibleDC,0
mov DCTMP,eax ;store our DC
invoke CreateCompatibleBitmap,DCTMP,eX,eY ;makes a BMP  of given width, on our given DC object.
mov bmpH,eax
invoke SelectObject,DCTMP,bmpH ;applies BMP to DC. 'tis now ready for drawing etc.
mov eax,DCTMP ;copy handle to register.
.if eax == 0
invoke MessageBox,0,SADD("Could not make DC"),SADD("Dbg"),MB_OK ;display error if NULL, for debugging
ret  ;we are done.
MakeDC endp

Alright, but I'm having some problems using this in my code, everything seems to work okay, apart from the fact the resulting DC only supports monochrome. I have no idea why this is, that code is basically a re-make of a function I used to use in Visual Basic for the purpose of making DCs, and I never had a monochrome one before

So then, I swapped the line
	invoke CreateCompatibleDC,0

invoke CreateDC,SADD("DISPLAY"),0,0,0

this produced a coloured DC! Of course, the problem is with that... a copy of it is also displayed at the top left of the screen, but at least I know where the problem is now.
Do any of you know what I should do about all this? Do you know of some way I can fix CreateCompatibleDC? Or is there a way of using CreateDC without it getting flicked over to the screen?

It's not so important but in-case you're wondering what I'm using this for -- I am making a very basic game [300 lines and counting] and I'm using this code to create me a back buffer of the same size of my dialogue window.

I have some more lesser issues that I'd also appreciate any advice on, my game works by setting a timer function when the window is initiated, this timer basically works at 30 calls per seconds -- give or take a few -- I'm noticing that my blitted backbuffer flickers once or twice every 10 seconds , this is not such a big issue as this is my first project to get a feel for the language, but I'd like to get rid of this, am I right in thinking my gripe is with WM_PAINT or whatever it is? But I guess I can leave this minor issue 'till later, I think sorting out the backbuffer should be my priority.
My second minor issue is I need to remove the little X in the top right of my small dialogue, although my backbuffer blits directly over the caption and the X, I guess it'd be an issue if the user accidentally clicks his/her mouse there, heh. I'm guessing I'll be able to find more on this one by reading the MASM32 realtime dialogue help.

Thanks for any advice you can provide on this one, I'm grateful.

Posted on 2005-07-23 19:44:28 by //clone
Those two functions are old and error proofed ;)

;? 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 ,eax
invoke GetDC,hwnd
push eax
invoke CreateCompatibleBitmap,eax,xPos,yPos
mov edx,HandleOfDC
mov ecx,;pop ecx
mov ,eax;push eax
mov ,eax
invoke ReleaseDC,hwnd,ecx
pop eax;HandleOfDC
pop ecx;AnotherDC
invoke SelectObject,ecx,eax
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 ,eax
invoke LoadBitmap,hInstance,BitmapADDR
mov edx,HandleOfBitmap
pop ecx ;2 pop Created DC
mov ,eax
invoke SelectObject,ecx,eax
pop eax ;1 pop DC to release
invoke ReleaseDC,hwnd,eax
GetBitmapDC endp

To eliminate the flicker do ALL your painting on the backbufferDC, and only in the last line of Wm_Paint blit the backbufferDC to the DisplayDC.
If you need to redraw use InvalidateRect,0,FALSE to make it redraw.

For the Dialog blitting over the why not make a Dialog without a Caption? Use WS_POPUPWINDOW as style.

A good tut for any kind of game (Tile based) is available on and it's called Mosaic Game. This tut explains in great detail a lot of things you will be needing along the way.
Posted on 2005-07-23 20:01:17 by JimmyClif
I really was not expecting such a detailed repply so soon! Thanks for taking the time and helping me out.... I guess you can tell I'm new to all this -- I'll definitely check out that website for more info.

Posted on 2005-07-23 20:20:45 by //clone