News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

GDI question

Started by RedXVII, April 16, 2006, 12:18:03 AM

Previous topic - Next topic

RedXVII

I have a bitmap that i need to display. 2 questions.

1) The bitmap is not square, does anyone know how to set the "backround" color of the bitmap so it is not rendered. ie. it leaves the pizels behind it as they were and doesnt draw the outside of the bitmap im drawing. It looks like an ugly square and i should really fix it.

2) When i do make the bitmap it would be nice to have a windows message when the mouse moves over it. Whats tthe best way of going about this.

Im not looking for people to do it for me (alhough if you will thats ace =) ). Just point me to the right functions/in the right direction.

Cheers

jojo

Have you thought of creating a region in the shape of your bitmap? Try searching for
CreatePolygonRgn
SelectClipRgn
PtInRegion

Tedd

You want to create a mask for the bitmap and use that to 'filter' the pixels which should be drawn (see example.)
The example uses only BitBlt, you could also use MaskBlt which may be easier/quicker; though it's doesn't work on Win98.

For checking if the mouse is over the image, you can use a similar technique - when the mouse is in the image's square, check if that location is a black or white pixel on the mask, which will tell you if it's on the image parts you want :cheekygreen:


[attachment deleted by admin]
No snowflake in an avalanche feels responsible.

Mincho Georgiev

2 of my old ones using GDI & masks , not so simmilar to the subject as Tedd's one but can be usefull:

with 1 ball:
http://www.masmforum.com/simple/index.php?action=dlattach;topic=2339.0;id=1222

and with 2 balls (without collision):





[attachment deleted by admin]

zcoder

No matter what code you need I have written it, as long as it can be made a function of course.

This will do the trick.


.code
TransBitblt proc hDC:DWORD,Xpos:DWORD,Ypos:DWORD,hBitMap:DWORD

            LOCAL hdcOffScr    :DWORD
            LOCAL hbmOffScr    :DWORD
            LOCAL hObject      :DWORD
            LOCAL hdcImage     :DWORD
            LOCAL hdcMask      :DWORD
            LOCAL hbmMask      :DWORD
            LOCAL OldObject    :DWORD
            LOCAL OldbmOffScr  :DWORD
            LOCAL OldbmMask    :DWORD
           
            LOCAL bm           :BITMAP
            LOCAL rect         :RECT

            invoke GetObject,hBitMap,sizeof bm,addr bm
            invoke CreateCompatibleDC,hDC
            mov [hdcOffScr],eax
            invoke CreateCompatibleBitmap,hDC,bm.bmWidth,bm.bmHeight
            mov [hbmOffScr],eax
            invoke SelectObject,hdcOffScr,hbmOffScr
            mov [OldbmOffScr],eax
            invoke BitBlt,hdcOffScr,0,0,bm.bmWidth,bm.bmHeight,hDC,Xpos,Ypos,SRCCOPY
            invoke CreateCompatibleDC,hDC
            mov [hdcMask],eax
            invoke CreateCompatibleDC,hDC
            mov [hdcImage],eax
            invoke CreateBitmap,bm.bmWidth,bm.bmHeight,1,1,NULL
            mov [hbmMask],eax
            invoke SelectObject,hdcMask,hbmMask
            mov [OldbmMask],eax
            invoke SelectObject,hdcImage,hBitMap
            mov [OldObject],eax

            invoke GetPixel,hdcImage,0,0
            invoke SetBkColor,hdcImage,eax   
            invoke BitBlt,hdcMask,0,0,bm.bmWidth,bm.bmHeight,hdcImage,0,0,SRCCOPY

            invoke SelectObject,hdcImage,OldObject
            mov [hBitMap],eax
            invoke SelectObject,hdcMask,OldbmMask
            mov [hbmMask],eax

            invoke DeleteDC,hdcMask
            invoke DeleteDC,hdcImage

            invoke CreateCompatibleDC,hDC
            mov [hdcImage],eax
            invoke SelectObject,hdcImage,hBitMap
            mov [OldObject],eax
            invoke CreateCompatibleDC,hDC
            mov [hdcMask],eax
            invoke SelectObject,hdcMask,hbmMask
            mov [OldbmMask],eax
            invoke SetBkColor,hdcOffScr,0FFFFFFh
            invoke BitBlt,hdcOffScr,0,0,bm.bmWidth,bm.bmHeight,hdcImage,0,0,SRCINVERT
            invoke BitBlt,hdcOffScr,0,0,bm.bmWidth,bm.bmHeight,hdcMask,0,0,SRCAND
            invoke BitBlt,hdcOffScr,0,0,bm.bmWidth,bm.bmHeight,hdcImage,0,0,SRCINVERT
            invoke BitBlt,hDC,Xpos,Ypos,bm.bmWidth,bm.bmHeight,hdcOffScr,0,0,SRCCOPY
;Clean up.(do some house cleaning)
           
            invoke SelectObject,hdcImage,OldObject
            mov [hBitMap],eax
            invoke SelectObject,hdcMask,OldbmMask
            mov [hbmMask],eax
            invoke SelectObject,hdcOffScr,OldbmOffScr
            mov [hbmOffScr],eax
            invoke DeleteObject,hbmMask
            invoke DeleteObject,hbmOffScr
            invoke DeleteDC,hdcOffScr
            invoke DeleteDC,hdcImage
            invoke DeleteDC,hdcMask
            ret
TransBitblt endp



Zcoder....
Back in 1979, My computer ran so fine.
And there was no such thing,
As a Microsoft Crashed Machine.
http://zcoder.110mb.com
http://www.dietzel.com/partner/idevaffiliate.php?id=345_6  Free Domain Names