The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: zemtex on January 27, 2011, 01:08:59 AM

Title: GDI Brushes, Pens, Bitmaps
Post by: zemtex on January 27, 2011, 01:08:59 AM
Hi.

I have created a GDI object of type HBITMAP. I paint some graphics into it and then I create a pattern brush from it by calling CreatePatternBrush. I store the brush in a global variable to avvoid losing it when I need it in WM_PAINT. I create the bitmap and the brush in the WM_INITDIALOG

My question is, can I delete the bitmap after creating the brush or is the brush dependant on the bitmap, is the brush just a pointer to the bitmap or is the brush standing on its own after its created?
The hopeless windows docs says nothing about this.
Title: Re: GDI Brushes, Pens, Bitmaps
Post by: hutch-- on January 27, 2011, 02:45:36 AM
Have a look at the API functions SelectObject() and DeleteObject(). An allocated brush is a different animal but remember when you use SelectObject() that you save the old object and when you are finished you reselect the old object and delete your new one.
Title: Re: GDI Brushes, Pens, Bitmaps
Post by: zemtex on January 27, 2011, 04:21:07 AM
When I draw a bitmap at the bottom of my screen, about 60% of the bottom of the bitmap ends up in the upper region and the other 40% gets wrapped beneath that again. Why does this not happen when i print the same bitmap at the very top of the DC bitmap?

I have checked coordinates, they should be alright, and not crossing any borders.

Here is an illustration of what I mean:

(http://i56.tinypic.com/m7t3wh.png)
Title: Re: GDI Brushes, Pens, Bitmaps
Post by: zemtex on January 27, 2011, 05:38:36 AM
I Solved it. SetBrushOrgEx should be used to properly align.
Title: Re: GDI Brushes, Pens, Bitmaps
Post by: zemtex on January 27, 2011, 06:26:41 AM
Btw, why doesnt my StretchBlt mirror my image, I want it mirrored on the vertical axis.

This doesnt work, it produces blackness and the bitmap disappears.

      invoke StretchBlt, memDC2, 0, 0, rect.right, 82, memDC, 0, 0, rect.right, -82, SRCCOPY


Fixed it:

      invoke StretchBlt, memDC2, 0, 0, rect.right, 82, memDC, 0, 82, rect.right, -82, SRCCOPY


Btw (again): The bitmap above looks untasteful and waste of bytes, but trust me its not what it looks like, its a very humble and resource friendly thing. Just so that people dont think im one of those kiddies who put all kinds of bitmaps in their window just-to-look-cool-sort of thing. Its a totally different thing.