News:

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

Main Menu

how to change background color of static control, and add text - resolved

Started by quarantined, August 14, 2022, 05:44:08 AM

Previous topic - Next topic

quarantined

Quote from: hutch-- on August 14, 2022, 06:22:05 PM
The WM_CTLCOLORBTN only works on the button border, not the face of the button.

Buttons... buttons? We don't need no stinkin' buttons...   :undecided:
Static control + WS_NOTIFY = nearly a button, but without simulated movement. I had been talking about static controls myself.

hutch--

You can get that functionality with a direct CreateWindowEx and you can do anything with it.

quarantined

Quote from: NoCforMe on August 14, 2022, 04:15:01 PM
So what issues have you had? That's one of the easier message classes to implement responses to. Maybe we can help you through this.

Okay, I found one of the few times that I have used WM_CTLCOLORSTATIC. (took me some time to find it...)
When you first asked, I had forgotten exactly the issue I had in the past. Then I found the source that this dialog came from.

The problem there is while the background color change works, there is a white border around the black text.

Source for succesful demonstration of static control with colored background and (black) text in my last post in this thread

quarantined

My last post gave me an idea. Suppose I put a transparent static control over the colored static control (when text is desired)?
I'm going to try that later when I have a little spare time, have to do some work in the yard...


Edit to add: Would have been a lot easier if there was such a thing as SS_SETTEXTCOLOR and SS_SETBKCOLOR.  :biggrin:
If I get this straightened out, I should make a self contained static control where both the text and background colors can be chaged without much hassle.  :cool:

quarantined

Quote from: TimoVJL on August 14, 2022, 06:00:42 PM
How about just making a bitmap and update it as grid ?
I'm not sure exactly what you mean...

TimoVJL

Quote from: swordfish on August 15, 2022, 01:26:59 AM
Quote from: TimoVJL on August 14, 2022, 06:00:42 PM
How about just making a bitmap and update it as grid ?
I'm not sure exactly what you mean...
In memory bitmap used for painting window is normal technique for games if window size is fixed.

In an old PC Magazine was an example of it ?

Use SetBkMode(hDC, TRANSPARENT); for transparent text. It should work with STATIC windows too.

EDIT:
Under WM_CTLCOLORSTATIC is place for SetBkMode and wparam gives hDC for it.

May the source be with you

quarantined

Quote from: TimoVJL on August 15, 2022, 01:45:48 AM
Use SetBkMode(hDC, TRANSPARENT); to transparent text.
Ok, thanks for the tips. Will look into that at some point...

       ***********  Here is the latest test piece  *********

Color static control with dynamic color change ability. (click on static control to 'highlight' it)
Shows the issue with white around the text when it is 'highlighted'

In the first couple of attempts, forgot about calling InvalidateRect <----- caused a bit of head scratching

Source for succesful demonstration of static control with colored background and (black) text in my last post in this thread

Source with awful white border around text below

quarantined

Quote from: TimoVJL on August 15, 2022, 01:45:48 AM
Under WM_CTLCOLORSTATIC is place for SetBkMode and wparam gives hDC for it.


:biggrin: I almost missed your edit. I will look into that later. Still doing some work in the yard. First day its not going to rain for at least two weeks, tomorrow as well. I should be able to try that after a little while but right now I gotta go back to the chores

quarantined

Just for kicks, I added "invoke SetBkMode, wParam, TRANSPARENT"
voila! You're a genius. Well a few more notches up the genius ladder than me that is.  :tongue:

And I thought I would have to use DrawText, and other GDI functions

As this has been resolved, I will no longer post any replies here


NoCforMe

Quote from: swordfish on August 15, 2022, 04:33:22 AM
As this has been resolved, I will no longer post any replies here
Don't make promises you can't keep.

Seriously, I figured this would be the problem you had: trying (unsuccessfully) to match the background color of the text. Which you nicely resolved.

Thing to keep in mind here is that you are setting two different background colors: one is the background color of the text, the other is the background color of the control itself (via the returned brush). If the two don't match, you get the ugliness you observed.
Assembly language programming should be fun. That's why I do it.

jj2007

Partial success: It works, but it does not behave like a normal pushbutton.

For your inspiration, here is a multi-button program I am currently working on. Warning, it's not Campus stuff. Button background colour is actually a bit too complicated for the Campus IMHO.

zedd151

If you create a static control as mentioned here and or the window style with SS_BITMAP, then SS_NOTIFY has NO effect meaning WndProc does not receive any WM_COMMAND message when left clicking on the static control. Else if SS_BITMAP is not or'ed with the static control window style, then WM_COMMAND messages will be received by WndProc as long as an ID is specified when creating the static control or is assigned through another method.


Also, SS_BITMAP does not play well with SetWindowText for the control. It could be that the bitmap is drawn after the text is written to the static control thereby covering the text but I have no way of knowing that for certain.


Just a little FYI for anyone interested.

NoCforMe

Quote from: zedd151 on August 22, 2022, 11:32:53 PM
If you create a static control as mentioned here and or the window style with SS_BITMAP, then SS_NOTIFY has NO effect meaning WndProc does not receive any WM_COMMAND message when left clicking on the static control.

Are you sure about that? MSDN says nothing about that in their documentation of the STN_CLICKED notification (which of course doesn't necessarily mean anything, since they're famous for omitting stuff).

Not challenging you, just curious. If you know this from experience then that's good enough for us. I haven't played with this enough to know for sure, but it wouldn't be hard to set up a testbed to check this out.
Assembly language programming should be fun. That's why I do it.

zedd151

STN_CLICKED I have never used. Frankly never new it exist. I usually used WM_COMMAND.  :toothy:
I'll try STN_CLICKED later.

NoCforMe

It is sent through WM_COMMAND:

QuoteParameters:
wParam
     The LOWORD contains the identifier of the static control. The HIWORD specifies the notification code.
lParam
     Handle to the static control.

(the notification code is STN_CLICKED)
Assembly language programming should be fun. That's why I do it.