The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: rodderswank on December 04, 2005, 09:58:17 PM

Title: bmp buttons
Post by: rodderswank on December 04, 2005, 09:58:17 PM
How can u draw bmp on to buttons using CreateWindowEx
Title: Re: bmp buttons
Post by: petezl on December 05, 2005, 12:20:53 AM
invoke CreateWindowEx,NULL, ADDR ButtonClassName,NULL,\
WS_CHILD or WS_VISIBLE or  BS_BITMAP or BS_DEFPUSHBUTTON,\
2,2,110,20,hWnd,ButtonID1,hInstance,NULL
mov hwndButton1,eax

invoke LoadBitmap,hInstance,IDB_MAIN
mov hBitmap,eax
invoke SendMessage,hwndButton1,BM_SETIMAGE,0,hBitmap

Don't forget to delete it before exiting
Peter
Title: Re: bmp buttons
Post by: rodderswank on December 05, 2005, 02:45:55 AM
tnx that works great what do u mean by deleting it? and also how can the button be borderless for you can stilll see some grey around the edge of the buttons how can i fill the whole button with the bmp?
Title: Re: bmp buttons
Post by: rodderswank on December 05, 2005, 07:21:35 AM
or how would u do this with a button in a rc file

CONTROL "", 0, BUTTON, BS_PUSHBUTTON | BS_BITMAP | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 126, 86, 60, 14
Title: Re: bmp buttons
Post by: sluggy on December 05, 2005, 09:43:29 AM
Quote from: rodderswank on December 05, 2005, 07:21:35 AM
or how would u do this with a button in a rc file

CONTROL "", 0, BUTTON, BS_PUSHBUTTON | BS_BITMAP | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 126, 86, 60, 14
See where you were ORing those other BS_* constants together? Have you tried doing it there?

It seems to me that with every tiny little thing that pops up with your project, you are asking the question on this board. There is nothing wrong with that - except for the fact that the stuff you are asking about is quite basic, and you could find the answers yourself with just a quick search, either through the board, with Google, or with MSDN online.
I'm not saying this to be mean, i'm just mentioning it because learning to follow your nose and solve your own problems is a valuable skill for a programmer to learn. And like i said, all of the stuff you have asked is pretty basic and a quick search of the forum would have answered most of it for you  :U

Title: Re: bmp buttons
Post by: rodderswank on December 05, 2005, 10:28:23 AM
i figured that mush but im getting readonly errors when using createwindowex. the button draws fine the bitmap doesnt
Title: Re: bmp buttons
Post by: hutch-- on December 05, 2005, 10:31:07 AM
rodderswank,

There is example code in the MASM32 project to do what you are after, either the simple bitmaps on normal buttons or a seperate costom control where you completely control the apprearance of the button.
Title: Re: bmp buttons
Post by: rodderswank on December 05, 2005, 10:36:03 AM
Ive done this sucessfully b4 im just having problems with it when using a dialog. those example r only for use with a window. I know how to define it in the rc file im just havng problems writing it to the screen of a dialog box also in the rc file

when i use

invoke LoadBitmap,hInstance,IDB_MAIN
mov hBitmap,eax
invoke SendMessage,hwndButton1,BM_SETIMAGE,0,hBitmap

in a window works perfect but for a dialog im getting read only errors.
Title: Re: bmp buttons
Post by: hutch-- on December 05, 2005, 11:04:56 AM
What styles have you set the button as a resource ? This may be a factor in whether it succeeds or not.

Attached is a working example of using the masm32 bitmap button that is in the masm32 library.

[attachment deleted by admin]
Title: Re: bmp buttons
Post by: petezl on December 05, 2005, 11:17:33 AM
As Sluggy and Hutch has said, you need to experiment...

BTW I answered because I happen to be teaching a local guy the basics of win32 asm and had the information to hand.
Learnt most of the basics by eavesdropping on the winasm community board a few years back (plus a shed load of experimenting). Also check out the excellent tutes on Hutches site.
Treat Dialogs as different entity from windows. Yes they are similar but have slight but significant coding differnces from each other.

To answer your question, in asm you have to do everything manually so as soon as you deviate from something like a standard button you have to code to allow for bmp size, screen res and other unexpected anomalies.. Also anything you create (bitmap in this case), it has to be deleted
ie.
.ELSEIF uMsg==WM_DESTROY
invoke DeleteObject,hBitmap
invoke PostQuitMessage,NULL

Peter.
Title: Re: bmp buttons
Post by: rodderswank on December 05, 2005, 11:30:28 AM
Quote from: hutch-- on December 05, 2005, 11:04:56 AM
What styles have you set the button as a resource ? This may be a factor in whether it succeeds or not.

Attached is a working example of using the masm32 bitmap button that is in the masm32 library.

CONTROL "Exit", 1003, BUTTON, BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | BS_BITMAP | WS_TABSTOP, 106, 125, 56, 11

iinvoke LoadBitmap,hInstance,1003
mov hBitmap,eax
iinvoke SendMessage,hwndButton,BM_SETIMAGE,0,hBitmap

also

invoke  CreateWindowEx,NULL, ADDR ButtonClassName,ADDR ButtonText,\
               WS_CHILD or WS_VISIBLE or BS_DEFPUSHBUTTON or BS_BITMAP,\
               268,14,60,25,hWin,ButtonID,hInstance,NULL
        mov    hwndButton,eax
        invoke LoadBitmap,hInstance,300
        mov hBitmap,eax
        invoke SendMessage,hwndButton,BM_SETIMAGE,0,hBitmap

when the second one compiles it get readonly errors

warnging a4000 cannot modify readonly segment
this is in the WM_INITDIALOG Section

Title: Re: bmp buttons
Post by: hutch-- on December 05, 2005, 11:32:40 AM
Here is both types, a custom button and a dialog button set with the BS_BITMAP style.

[attachment deleted by admin]
Title: Re: bmp buttons
Post by: rodderswank on December 05, 2005, 11:37:47 AM
well i dont know how i would incorporate that in to my code i guess ill have to leave it...

ive tried the new source i get a bmpbutton undefined symbol and all the includes r rite. I just dont see why the above way works for a window but not for a dialog procedure. although i think its a problem with getting the buttonhandle from the rc file unsure on that though.

Also i cant get that tut to even compile has about 5 errors.
Title: Re: bmp buttons
Post by: hutch-- on December 05, 2005, 11:59:07 AM
The obvious answer is you are not including the MASM32 library that has the bitmap button procedure. The example is a dialog not a CreateWindowEx() and it will build with any current version of MASM32. I don't know what you are using so you may need to explain when method you are using to build the code of your own.
Title: Re: bmp buttons
Post by: rodderswank on December 05, 2005, 12:01:31 PM
im  using masm 8.2

i managed to port some of the code over im getting the same errors readonly segments

with just this im still getting the readonly errors

               invoke GetDlgItem,hWin,1003
                mov hwndButton,eax
               invoke LoadBitmap,hInstance,666

is there anyway though i get it to work with createwindowex
Title: Re: bmp buttons
Post by: hutch-- on December 05, 2005, 12:52:11 PM
Get the latest beta version from the masm32 subforum. 8.2 is missing a fewq of the macros that have been developed later.
Title: Re: bmp buttons
Post by: rodderswank on December 05, 2005, 11:51:45 PM
Ok ive installed the service pack and im still getting the read only errors. this is the project could someone have a look and see if they can see any problems

the added code is commented out.

I have also tried moving things like hBitmap to the .data section this seems to have sorted the read only errors although the bitmap isnt setting. properly plz help me....

Could any1 take the time to show me how to correct it in the following file. either the buttons already displayed or with a button using CreateWindowEx
tnx.

[attachment deleted by admin]
Title: Re: bmp buttons
Post by: hutch-- on December 06, 2005, 07:37:21 AM
Ok, I have fixed most of it and it roughly works, the single black bitmap is placed on both the about button and a CreateWindowEx button.

I did tell you to get the BETA of masm32 as it has the later macros in it and if you DON'T have this installed it will not build. Example runs properly.

This example is basically too advanced for someone starting assembler programming.

[attachment deleted by admin]
Title: Re: bmp buttons
Post by: rodderswank on December 06, 2005, 08:19:22 AM
thanks hutch for taking the time to show me i just wanted to see whta i was doing wrong whcih was appaerently everything. I had the latest masm installed as well.

1 other question is there a away to get rid of the grey border around the button so the whole thing is black.
Title: Re: bmp buttons
Post by: hutch-- on December 06, 2005, 10:58:59 AM
Unfirtunately no, thats why I wrote the custom control in the masm32 library so that you can specify an up and down bitmap and completely control the appearance.
Title: Re: bmp buttons
Post by: rodderswank on December 07, 2005, 02:47:34 PM
ok tnx for your help hutch
Title: Re: bmp buttons
Post by: rodderswank on December 07, 2005, 08:33:21 PM
Is there any way by creating a different button?
Title: Re: bmp buttons
Post by: PBrennick on December 08, 2005, 02:50:30 AM
rodderswank,
I think Hutch already answerred your question...

Quote...custom control in the masm32 library so that you can specify an up and down bitmap and completely control the appearance.

Paul
Title: Re: bmp buttons
Post by: rodderswank on December 08, 2005, 04:06:40 AM
eh

there no way of getting rid of it? :(