News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Button colors

Started by peaslee, September 21, 2015, 01:48:07 PM

Previous topic - Next topic

peaslee

This is where I complain.

It is hard for me to imagine how programs can be developed without the ability to change the colors of buttons. I have coded in  a number of  "higher level" programs where syntax such as:

SetControlColor hControl, red, green
is commonplace. I do not understand why this is so difficult in assembler. I have searched this site, I have searched the net, and I even got the owner of one of those other languages to send me his code. I cannot get any of it to work. Put "change button color" into Google. It will drive you crazy.

I am attaching an example of a program written in Ionic Wind Basic where the above code is used. I have change the background color of the dialog and the button to go with it.

hutch--

#1
Its pretty simple stuff actually, the "BUTTON" class of Window does not respond to the WM_CTRCOLORxxx range of messages and it never has since the Win 3.0 days. When you have coloured button, they are a different control of custom origin. They are not all that hard to write by running your own CreateWindowEx() based code, you dump a rectangle in the middle, draw what border style you require and superimpose text if required on top of it. Its a reasonable amount of work but its not rocket science.

I had a look at the image you have posted and it is not a system button for either XP or Win7 64 so I imagine it can only be a custom button.

dedndave

yah - that's definately not a windows control, as Hutch says
it is evident because the border is a pure rectangle, as with many windows created using CreateWindowEx

let me start by saying that per the windows user experience guidelines, it's not kosher to change these colors
their reasoning is, the user has selected their theme colors, and a programmer should honor them
that having been said, many programs create windows that do not obey the UX guidelines - lol

it's very problematic to set a button color
one problem is, that buttons (since common controls v6) use gradient shades, not solid colors



it can probably be done by subclassing the window
but, that is also problematic
since windows 7, many windows controls are children of "worker" windows
so, you go to subclass a control, and you get the handle for the worker window
the whole thing doesn't fly
this can be overcome by using FindWindowEx or something to search for children of the worker window

there are 2 good alternatives:

1) write your own button control
this is probably the most work, especially if you want the button to behave like a windows button
i.e., send and handle button messages, change fonts, and so on
this is possibly the most rewarding method, though

2) use an owner-drawn button
this isn't so bad - essentially, you use an image as the background

with the later method, you can use a resource image (your favorite politician, if you like)
or, you can create a DIB section and "draw" the button with code
there are many such examples on the web
and, i believe there are some asm code examples in the masm32\examples folder   :t

dedndave

in truth, a button doesn't really need to be a window
it can just be a rectangle
you draw the button as desired, and react to mouse activity inside the rectangle

ragdog

Hello

You can draw a button in Wm_Paint (with subclass) or OwnerDraw (WM_DRAWITEM)

peaslee

Thanks for the help.

I will explore the custom button aspect. I suspect that is what the Basic developer is doing.

As to experience guidelines, when I first started programming, I let things be. Then many users would change the colors and complain the my work looked terrible or couldn't be read.


zedd151

Take a look in the examples folder where you have masm32 installed.

There are several examples of using 'Bitmap' buttons.

If done correctly, the button will seemlessly blend in with the background.




jj2007

Check BmpButton proc in \Masm32\examples\exampl01\bmbutton\bmbutton.asm

peaslee

I found that the button is owner drawn.

BTW: please excuse my crabbiness.

peaslee

The bitmap solution works perfectly. It is obvious once you think about it. After all, you can make a bitmap any color you want.

Thanks again to all for the help.

zedd151

Quote from: peaslee on September 22, 2015, 12:43:33 PM
The bitmap solution works perfectly.....

Thanks again to all for the help.

:t

If you don't have photoshop, try 'the gimp' (it's free) and make some really good looking buttons.

zedd151

peaslee, you might want to also look at this example:

http://masm32.com/board/index.php?topic=754.0

ragdog

Is a Toolbar buttons exmaple

peaslee

Here is what I have done so far with your kind help. I had to delete the images (the exe still runs) because of the size restraints. I kept the close button   ;)

dedndave

try using a 256-color BMP   :t
in fact, it will be smaller if you put all the buttons in one image, then split them up with code