GUI Creation Problem

Can someone tell me about how to do this :-

1.I created a window and a child button.Now I want to colour the button.
2.I created a window and a child button.When user presses the button, it should change its position to another desired coordinates.

I'm not using softwares like QT or another but instead I'm using wxDev C++.

Part 1.) I don't know about other programmers, but personally I avoid the default button-types that Windows supplies, making your own button type is often easier than modifying their buttons and it will give your program a unique feel.

Part 2.) Look up SetWindowPos() and MoveWindow() functions, I'm not sure if they will actually resize/move a button, but since a button is a window I don't know why it wouldn't.
Last edited on
I agree with the answer about MoveWindow() but what about colouring the button ? I'm not using the default button provided by the library.Please Assist.
You can change the color of most of the standard Win32 controls (Edit, Static, Scrollbar, etc) by handling the appropriate WM_CTLCOLORXXXX message (e.g. WM_CTLCOLOREDIT, WM_CTLCOLORSTATIC) by providing the background brush you want the control to be painted with, and setting the text and text background colors.

Unfortunately, while WM_CTLCOLORBTN exists, it does not support push buttons, only radio buttons and check boxes (which are types of button). So, push buttons, you will need to use the owner draw mechanism (you give the button the style BS_OWNERDRAW and then handle the WM_DRAWITEM message to draw it youself).

This article show how to do owner draw, but of a button with curved edges rather than a colored one.

Subclassing and Owner Drawing, the SDK Way
http://www.codeproject.com/Articles/1306/Subclassing-and-Owner-Drawing-the-SDK-Way

Andy

PS This article does show how to color a button, but it uses MFC. If you can read around the boiler plate, it might be of some use?

CColorBox
http://www.codeproject.com/Articles/7876/CColorBox
Last edited on
But I wanted to colour it the way it is done in minesweeper game.They are pushbutton and still have blue colour on them.Can anyone?
My last response explains how it must be done using the Win32 API. That is, you need to use the owner draw mechanism.

(Actually, it only mentions the easiest route. You could also code your own button window class ground up, but that would be overkill.)

You mentioned wxDev. Does this mean you are using wxWidgets as your GUI framework? If so, then wxButton already supports custom colours thorugh its SetForegroundColour and SetBackgroundColour methods.

If that's not enough, then this is the wxWidget way to create a custom button class:

Painting your custom control
http://wiki.wxwidgets.org/Painting_your_custom_control

Note that if you want the button to look 3D, and like it's pushed, you will have to modify the code so it draws the button edges.

Andy
Last edited on
Topic archived. No new replies allowed.