News:

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

bmp buttons

Started by rodderswank, December 04, 2005, 09:58:17 PM

Previous topic - Next topic

rodderswank

How can u draw bmp on to buttons using CreateWindowEx

petezl

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
Cats and women do as they please
Dogs and men should realise it.

rodderswank

#2
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?

rodderswank

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

sluggy

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


rodderswank

i figured that mush but im getting readonly errors when using createwindowex. the button draws fine the bitmap doesnt

hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

rodderswank

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.

hutch--

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]
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

petezl

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.
Cats and women do as they please
Dogs and men should realise it.

rodderswank

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


hutch--

Here is both types, a custom button and a dialog button set with the BS_BITMAP style.

[attachment deleted by admin]
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

rodderswank

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.

hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

rodderswank

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