flat assembler
Message board for the users of flat assembler.

Index > Windows > Tab control background color

Author
Thread Post new topic Reply to topic
fasm14



Joined: 23 Jan 2021
Posts: 14
Location: Russia
fasm14 14 Aug 2021, 11:35
Hello! I've been trying to figure out how to change a tab control's background color; it doesn't have any messages that can be sent to it to change it and so the background with the required color needs to be drawn manually; I found some solutions on the Internet (like this one: http://web.archive.org/web/20190119111408/http://www.glennslayden.com/code/win32/tab-control-background-brush) but they seem complicated and I'm not good enough with C to translate them into asm; I was wondering if there's an easier way to do this, by changing the default background color or something similar? I tried SetSysColors with COLOR_BTNFACE (and some other ones) but it changed the color for the entire system and the tab control wasn't even affected...
Post 14 Aug 2021, 11:35
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1043
Location: Russia
macomics 14 Aug 2021, 18:32
The example you found uses subclassing.
Quote:
hwnd = CreateWindow(...);
oldProc=SetWindowLong(hwnd, GWL_WNDPROC, SubClassingProc);

They replace the standard function of the created window with their own. In your function, you process only those messages that you need, and call the old function to process the rest.
Quote:
... SubClassingProc(..., UINT umsg, ...)
{
switch (umsg)
{
case WM_PAINT: //draw element
break;
default: // Any other messages
CallWindowProc(..., oldProc);
}
}

In the found example, only the WM_PAINT message is processed, drawing elements with an arbitrary background, and all other messages go to the old function for processing.
Post 14 Aug 2021, 18:32
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4078
Location: vpcmpistri
bitRAKE 14 Aug 2021, 18:44
This looks like a good answer:
http://www.equestionanswers.com/vcpp/background-color-edit-static.php
...but no tab control.

https://social.msdn.microsoft.com/Forums/en-US/44bf30c8-ca7b-483f-9c8f-8aafcffd389e/picking-up-the-background-of-a-tab-control-in-a-dialog?forum=vcgeneral

Owner-drawn tabs seem overkill just to change the color. (AHK example)

Looking at Notepad++ source code it looks like subclassing and painting the background by handling WM_ERASEBKGND might be sufficient.
Post 14 Aug 2021, 18:44
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4078
Location: vpcmpistri
bitRAKE 16 Aug 2021, 08:40
Handling WM_ERASEBKGND definitely doesn't work - in fact the WM_PAINT for the tab control completely covers the client area, so anything done in WM_ERASEBKGND is over-written.

I did log the messages for the tab control and there is no WM_CTLCOLOR* type message or internal "hacky-way" to set the color that I could see.

Looks like owner-drawn control is the only way.


Description: The wrong way. Just because there are so few tab control examples.
Download
Filename: badhack.zip
Filesize: 4.35 KB
Downloaded: 402 Time(s)


_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 16 Aug 2021, 08:40
View user's profile Send private message Visit poster's website Reply with quote
fasm14



Joined: 23 Jan 2021
Posts: 14
Location: Russia
fasm14 17 Aug 2021, 16:07
I tried replacing just WM_ERASEBKGND at first, but then the new background only occasionally appeared after I dragged the window off screen (also the tabs themselves stopped working); I tried to do something similar to the posted example by first calling the original WM_PAINT then recolouring the background, but it didn't work either... Originally I was trying to make the background have the default form color, and apparently just setting the TCS_OWNERDRAWFIXED style makes the background have that exact color; now all I need to do is put static text controls where the tabs are supposed to be (their layout and boundaries are still drawn). Thanks a lot, bitRAKE and macomics!
Post 17 Aug 2021, 16:07
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.