O.K. my latest dilemma...

i'm mucking around with MOBs CWS source because,.. essentially putting pretty bitmaps on the screen is one of the two things that sucked me into this whole asm thing in the first place (the other is the reasonn i keep trying).

so, heres my problem, i want to be able to change the bitmap at my leisure to any i so desire and most of this is working for me EXCEPT i need to know how to change the PatternBrush mob makes with this code:

invoke CreatePatternBrush, hBitmap01

and puts in the WNDCLASSEX structure before calling CreateWindowEx so i can process WM_ERASEBKND correctly.

so... anyone know how to change a brush on the fly, i'm sure i've read this somewhere but i'm a hoarder and i'm dissorganised and i can no longer find anything anymore.
time for some spring cleaning :)
Posted on 2002-12-22 22:49:10 by Crunchi
I dont know of Mob's tutorial/example. But the hBrush should be stored in the windows' HDC (why its given on creation). So when processing WM_PAINT events, and the hDC is recieved fromt the event:

1 Create and save a new brush
2 SelectObject in the new brush into the Window's HDC
3 Save the returned brush for cleanup
4 Go about your hDC business
5. Select back the old brush before finishing your painting

On ending your program destroy all brushes.

:alright:
NaN
Posted on 2002-12-22 23:37:59 by NaN
Thanks Nan, i'll give it a go,... (if i ever find the time)

i'll let you know how this goes,... (if i ever find the time)

Crunchi
Posted on 2002-12-25 02:18:55 by Crunchi
Thanks but, still a bit stumped here, though I think I am ALOT closer than the other day.
I think my problem is how I use the pattern brush,.. or which uMsg routine needs the pattern brush to work correctly.

I'm guessing it's WM_PAINT or WM_ERASEBKGND or both but past there I'm clueless, I wonder if I'm selecting the brush into the wrong HDC? I wonder if I should use patblt instead of bitblt? I wonder if I should get some sleep? probably yes.

After much toil and much use of the API (thanks NaN) I can make my window change its region at my will but it continually draws the same bitmap... ...very frustrating. I'm sure I'm selecting the bitmaps correctly as the regions turn out ok... hmmmm, still thinking about sleep.

This messsage cold be very cryptic without some code to accompany it so I'll include some for your viewing pleasure, if you can help I would really appreciate it. I've almost got my head around alot of gdi stuff but brushes are driving me batty.

I hope someone can help.


....and sleep.
Posted on 2002-12-25 17:15:42 by Crunchi
HMMMM.....

Still nothing eh? maybe its too obvious, nowell. if there is some simple way to do this i guess i'll find it eventually. maybe you have some WAY FAR OUT idea that you don't have the time to test. i don't know.

still, any hints would be great. i promise any fruits i gain from this will return the message board ten fold in time.

;) Crunchi
Posted on 2002-12-28 07:36:19 by Crunchi
Hi Crunchi,

I don't know if this is what you're looking for. Just try it
Posted on 2002-12-29 23:02:15 by HermanT
I didnt test this, but it 99% sure it will work:
.elseif( uMsg == WM_COMMAND )


.if ( ... == CHANGE_BITMAP_BRUSH )

mov eax, hNewBitmap (( Leave it to you to get handle somehow ))
mov BitmapHasChanged, eax
invoke InvalidateRect, hWnd, NULL, TRUE

.endif




.elseif( uMsg == WM_ERASEBACKGROUND )


.if( BitmapHasChanged != NULL )

push ebx
invoke CreatePatternBrush, BitmapHasChanged
mov ebx, eax
xor eax, eax
mov BitmapHasChanged, eax
invoke SelectObject, wParam, ebx
invoke DeleteObject, eax
pop ebx

.endif

... [do stuf with hDC to handle EraseBackground ]


It uses 'BitmapHasChanged' as both a flag, and a container for hNewBitmap. On a WM_ERASEBACKGROUND message, if the container is NULL it acts as a flag, indicating there is no new bitmap to change to. If not, it makes a new brush, loads it into the hDC, destroys the old brush, and sets the container to NULL again, to flag that things are normal again.

I leave it to you to process when the container (BitmapHasChanged:DWORD) is set to a new bitmap. I only gave a sample (uncompleted) WM_COMMAND handler to give you the rough idea...


:alright:
:nAn:
Posted on 2002-12-30 11:42:11 by NaN
Hi NaN :)

The program I attached before is already working.
I just made a little changed from Crunchi's program. I'm just not quite sure whether it is what his looking for.

BTW, the changed also invoking InvalidateRect which he did not :)

Regards
Posted on 2002-12-30 21:36:56 by HermanT
Thanx HermanT,

Im not trying to out-do you or anything.. I actually mis-read the contents of the above.... :rolleyes:

:alright:
NaN
Posted on 2002-12-30 22:27:24 by NaN
No, no... it is not your fault. It is my fault to reply something like that :o
I was not trying to do something about your reply. I have to admit that it was not clear what I meant :grin: So it was simply clearing up my first reply, that's it!
And even you out-do me, I don't mind at all (honest!). I'm a newbie compare to you.

Sorry about that. I will be more careful next time :)
Regards
Posted on 2002-12-31 09:50:13 by HermanT
yes, that IS what i'm looking for. I'll give NaNs a go too but i just got in from tokyo (for new years) and i wanted to see if there were any replies. looks like i was so close and yet so far. hmmmm... Invalidate rectangle, don't think i'll forget that one again.

thankyou very much for your help, happy new year!!!!!!

:cool:
Posted on 2003-01-01 06:14:14 by Crunchi