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

zedd151


I have been looking at it, wondering why overcomplicate it if what you want to do can be done easier?


From the link you posted jj:

> P.S.: If I add a BS_COMMANDLINK style to the pXpButton3 button in Josep Roca's example, it doesn't change at all.



and in the code you attached:

invoke CreateWindowExW, 0, uc$("button"), uc$("Button"),
  WS_CHILD or WS_VISIBLE or WS_BORDER or BS_COMMANDLINK or BS_TEXT or BS_MULTILINE,
  9, 9, 96, 32, hWnd, 110, wcx.hInstance, NULL ; we have added an edit control



so, have you tried removing 'BS_COMMANDLINK' ? (not sure what does or is for, btw)

jj2007

Quote from: Swordfish on August 24, 2022, 07:27:18 AM
I have been looking at it, wondering why overcomplicate it if what you want to do can be done easier?

A pushbutton has a defined behaviour. Show me a static control that behaves exactly like a pushbutton.

NoCforMe

Quote from: Swordfish on August 24, 2022, 07:04:11 AM

        mov ws, WS_VISIBLE
         or ws, WS_CHILD
         or ws, SS_CENTER
         or ws, SS_NOTIFY


Hate to carp here (it doesn't have anything to do w/the question at hand), but this is so clunky. Why not just


        mov ws, WS_VISIBLE or WS_CHILD or SS_CENTER or SS_NOTIFY


KISS.
Assembly language programming should be fun. That's why I do it.

NoCforMe

Quote from: jj2007 on August 24, 2022, 06:51:40 AM
STN_CLICKED is interesting, too. I have been fighting for some days now with the NM_CUSTOMDRAW notification, and would appreciate help on this. The attached code is pure Masm32 SDK (and confused - apologies :rolleyes:)

JJ, I feel your pain here. I spent literally a whole day battling with NM_CUSTOMDRAW (for a listview), and finally just gave up in disgust.

First of all, the interface is just plain horrible. All those draw stages and states, and their ill-defined behaviors. (MSDN is only of limited help here, just enough to get you started and then very frustrated!) I did find a lot of stuff online, some of which was helpful in explaining how to actually use this stuff, but in the end I was never able to get it to work. (In fairness, some of the trouble was with the listview control itself, which is another can o'worms.)

I'll go back over what I did get to work and post it here later.

One thing: I glanced at the code you posted and noticed that you're mostly dealing with the "post-paint" stages. I never tried using these, only the "pre-paint" ones. Are you sure these are what you want? What exactly are you trying to do with your control? Can you clearly map out the sequence of events that should happen to render them the way you want?

I'm asking because I was never really able to figure that out for my code, so I was pretty much just floundering, trying this, trying that.
Assembly language programming should be fun. That's why I do it.

zedd151


Quote from: NoCforMe on August 24, 2022, 07:52:38 AM

        mov ws, WS_VISIBLE
         or ws, WS_CHILD
         or ws, SS_CENTER
         or ws, SS_NOTIFY

KISS.
To quickly see the list   :tongue:  And you complain about coding police  :badgrin:

Reply #45 is for jj btw (I added to it while you guys were posting)

Then we have this:
Quote from: jj2007 on August 24, 2022, 07:44:01 AM
A pushbutton has a defined behaviour. Show me a static control that behaves exactly like a pushbutton.
AAnnnd, I never mentioned that YOU should use static in place of a button. Even though WE were discussing static controls here, but I digress on that point.

NoCforMe

Well then how about


mov ws, WS_VISIBLE or \
WS_CHILD or \
SS_CENTER or \
SS_NOTIFY


Hey, saves you 3 whole instructions! Woo hoo. (The line continuation character is your friend here.)
Assembly language programming should be fun. That's why I do it.

jj2007

Quote from: NoCforMe on August 24, 2022, 07:56:11 AMI glanced at the code you posted and noticed that you're mostly dealing with the "post-paint" stages. I never tried using these, only the "pre-paint" ones.

Here are the four interesting stages (others are ITEM-specific, for listviews etc):
CDDS_PREPAINT           equ 00000001h
CDDS_POSTPAINT          equ 00000002h
CDDS_PREERASE           equ 00000003h
CDDS_POSTERASE          equ 00000004h


Now it seems that the posterase stage is never triggered. I tried googling "CDDS_POSTERASE" and stumble over my own posts in the FreeBasic forum; which probably means that nobody uses this.

The sequence I see is
CDDS_PREERASE
CDDS_PREPAINT
... text happens here ...
CDDS_POSTPAINT - only if prepaint returns CDRF_NOTIFYPOSTPAINT

Note this:
QuoteWhen the dwDrawStage member equals CDDS_PREPAINT and CDDS_PREERASE, some controls send the CDDS_PREERASE message first and expect the return value to indicate which subsequent messages will be sent

zedd151

Quote
Hey, saves you 3 whole instructions! Woo hoo. (The line continuation character is your friend here.)


That code is old code from my little "Basic Window" template. If it ain't broke don't fix it. If it is broke, blame M$.  :tongue:


NoCforMe

Quote from: jj2007 on August 24, 2022, 08:42:04 AM
Here are the four interesting stages (others are ITEM-specific, for listviews etc):
CDDS_PREPAINT           equ 00000001h
CDDS_POSTPAINT          equ 00000002h
CDDS_PREERASE           equ 00000003h
CDDS_POSTERASE          equ 00000004h


Keep in mind that you have to return certain values at certain stages to trigger certain events. (It's all in the MSDN documentation.)
Assembly language programming should be fun. That's why I do it.

jj2007

Quote from: NoCforMe on August 24, 2022, 08:54:56 AM
Quote from: jj2007 on August 24, 2022, 08:42:04 AM
Here are the four interesting stages (others are ITEM-specific, for listviews etc):
CDDS_PREPAINT           equ 00000001h
CDDS_POSTPAINT          equ 00000002h
CDDS_PREERASE           equ 00000003h
CDDS_POSTERASE          equ 00000004h


Keep in mind that you have to return certain values at certain stages to trigger certain events. (It's all in the MSDN documentation.)

Apart from M$'s bad language ("the dwDrawStage member equals CDDS_PREPAINT and CDDS_PREERASE" - impossible), you must dig deep to find out how to get all four stages; and even then, no luck with setting the text colour :sad:

I attach a version showing the four stages in action.

NoCforMe

One small thing that might help: Look at the actual values for the draw stages (CDDS_xxx) in windows.inc. Some of them are combinations of others.

One thing I did was log all the various stages, etc., in the NM_CUSTOMDRAW notifications.
Assembly language programming should be fun. That's why I do it.

jj2007

Quote from: NoCforMe on August 24, 2022, 09:38:27 AM
One thing I did was log all the various stages, etc., in the NM_CUSTOMDRAW notifications.

Quote from: jj2007 on August 24, 2022, 09:27:14 AM
I attach a version showing the four stages in action.

zedd151

Jochen, I know we have had our disagreements but also I know that you know your stuff when it comes to writing code. (At least most of the time  :tongue: )
It seems that either the function(s) that you are trying to use are either buggy in their internals, or need to be used with exact parameters or you're missing a crucial step, or something of that nature.
Anyway I would like to know how this button your working on is supposed to work and what does it do. Have you considered any other methods to achieve the same goal? There is usually more than one way to skin a cat after all. Or is this just an exercise on how to implement custom drawn buttons?


I've been scouring the internet looking for additional info regarding custom drawn controls will post link(s) if I find anything that might be useful for your research. The only thing I found (searching custom drawn vs. owner drawn) other than MSDN is --> link , seems just basic stuff there no examples. Found some MFC stuff in another search quite sure you dont want that though.

hutch--

Guys, this is a system defined bitmap button example.

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

If you really want "science", you use this technique but create the two bitmaps dynamically using GDI. Create two bitmaps of the right size then write text to both bitmaps. Then you can have button change when clicked, you can have whatever change in appearance you require.

Its not exactly amateur hour to code this but if you needed it, it can be done. An alternative is to only set one bitmap to the button if you don't want and change on it being clicked.

Another option is to create a window with CreateWindowEx with a hollow brush then write text and perhaps a border to it in whatever colour you want. All it takes is the usual creative genius and knowing how to do it.

jj2007

Quote from: Swordfish on August 24, 2022, 04:59:45 PMAnyway I would like to know how this button your working on is supposed to work and what does it do.

As already shown in the example above: a coloured pushbutton. Everything works fine, even the rounded corners; the only missing bit is the text colour. And that's what's annoying me: SetTextColor should work, according to the documentation, but it doesn't. I've tried all stages, and it just refuses to function. SetBkMode works fine, for example :sad: