TAB control background in ATL App, XP styles - c++

I have an ATL application with a dialog containing a TAB control. The App uses a common controls manifest.
Under XP with visual styles, the tab control background is a different color than the dialog and the controls (mostly checkboxes), so it looks quite ugly.
Screenshot
How can I fix that?

There is - apparently - one thing to do to get tab control pages colored correctly using XP visual styles.
In the WM_INITDIALOG handler for each page, call the uxtheme API EnableThemeDialogTexture
With the ETDT_ENABLETAB flag this automatically changes the background color of the dialog and all its child controls to paint appropriately on a tab.
The dialog pages do not need any kind of transparent flag, or indeed any style bit set differently from previously. If you have overridden WM_ERASEBKGND or WM_CTLCOLORDLG in your pages DialogProc you will need to revert to default handling (return FALSE).

Here you could find answer to your question.

The check boxes will post WM_CTLCOLORBTN notifications to their parent. If, for the checkbox control IDs, the parent window's message handler returns the result of
GetStockObject(HOLLOW_BRUSH)
then the check boxes should be drawn with a transparent background, which should give you the look you want.

Related

can't change mfc controls order

I have a dialog box with a list box,slider and a button.
I tried to change the background color but I couldn't managed to change that, so i thought that if I add a "picture control" as a bitmap and put it in the background i will succed, but now the problem is that the "picture control" is on top of all the controls.
I tried to change the the tab control with Ctrl+d but it didn't change anything.
I also tried to use SetWindowPos to top or buttom but also it didn't change anything.
I noticed that if I click in the location of the button it's brought to the front as I want.
Is there any way to "click" all the controls at the begining? do i miss something in order to bring the control to the top?
If you need to change the background colour of the dialog box, you need to handle the WM_CTLCOLORDLG message and return the handle to a brush (if the brush is not a stock object, make sure you delete the brush after the dialog box is closed) -- or, you can process the WM_ERASEBKGND message and erase the background yourself.
I tried to change the the tab control with Ctrl+D but it didn't change anything. I also tried to use SetWindowPos to top or buttom but also it didn't change anything.
Ctrl+D does get you in reordering mode, however there is a more reliable way of checking. The dialog template is in text form in .RC file, where you can review the order of control with text editor and sort lines manually the way you wish. This will be the order of control creation and tab order as well. Sometimes it's even easier to reorder controls this way.
More to that, when your application is running, Spy++ SDK tool can enumerate windows and again it will give you window order for checking.
SetWindowPos with proper arguments changes Z-order of controls on runtime as well.

C++ WinAPI - How to make button appear pressed?

I have in my editor few editing modes. I can choose specific mode using buttons that are placed on a toolbar. I want to indicate which mode is currently on. When I press appropriate button - I want to make the clicked button remain pushed. How do I do that in WinAPI? My toolbar uses bitmaps for icons if that's relevant.
There used to be a way to get something like the look and feel of a toolbar by using a normal check box with the BS_PUSHLIKE style set. But that got broken a bit with Windows XP because of mouse hover effects, so it's not widely used any more.
If you want to create your own toolbar, without the help of MFC, there is an MSDN article that covers the creation and management of a toolbar window (actually a dedicated window class as part of the Common Controls Library).

Needed: A popup window without a taskbar icon

I am designing a UI engine that needs to render into popup (WS_POPUP) windows. As these windows cannot be children of other windows, each instance is given its own taskbar icon.
I need a way to prevent the taskbar icons from appearing for certain windows that are created as "dialogs". I cannot use an OS-provided dialog because they all have frames (and I can't figure out how to render into them) or a tool-created custom dialog (which seem to require the CLR).
I am not an expert with the windows API and I feel that I have missed something obvious...
Also: Anything involving CLI/CLR is not an option.
EDIT:
The WS_EX_NOACTIVATE style can be used for this purpose as well, though the activation behavior would need to be emulated by the program.
If you set the WS_EX_TOOLWINDOW extended style for your window, it won't be shown in the task bar or Alt+Tab list. This does cause the window to be rendered slightly differently, however (thinking floating tool palette).

flicker free tab control with WS_EX_COMPOSITED

I have a VS2008 C++ application for Windows XP SP3 developed using WTL 8.1. My application contains a tab control that flickers when the application border is resized.
My window hierarchy looks like this:
CFrameWindowImpl CMainFrm
|-CSplitterWindow Splitter
|-CTabView Configuration Tabs
| |-CDialogImpl Configuration View 1
| |-CDialogImpl Configuration View 2
| |-CDialogImpl Configuration View 3
|-CDialogImpl Control View
The solution I'm trying is to make the CFrameWindowImpl derived class use the WS_EX_COMPOSITED style and all windows beneath it use the WS_EX_TRANSPARENT style. Unfortunately, this makes the tab control buttons show as an empty black bar and the controls of any Configuration View to not show at all.
If I remove the WS_EX_COMPOSITED and WS_EX_TRANSPARENT styles, the form displays properly, but the CTabView and everything beneath it flickers horribly when resized.
What do I need to change to eliminate the flicker and draw the controls properly?
Thanks,
PaulH
Edit:
Got it working. I removed all the WS_EX_TRANSPARENT styles per Mark Ransom's suggestion. I put the WS_EX_COMPOSITED style on only the CTabCtrl (contained within the CTabView). Other controls get double-buffering as needed through WTL::CDoubleBufferImpl<>.
A window flickers because it gets erased before it's drawn. To eliminate this you need to disable erasing of the window entirely and use double buffering - draw the window contents into a bitmap, then copy the bitmap to the window. Because the bitmap contains the entire contents including the background, there's no need to erase anymore.
It looks like WS_EX_COMPOSITED will handle the double buffering automatically, but you still probably need to use a NULL background brush and/or handle the WM_ERASEBKGND message.
Whats not mentioned in MSDN is that the Desktop Window Manager - the component that hooks window painting on Windows Vista and 7 to perform the desktop composition necessary to get the aero glass effect - does NOT implement WS_EX_COMPOSITED.
Which means all the work you put into getting this style to work on XP, is doomed to become irrelevent on Vista or later.
The other problem with WS_EX_COMPOSITED - and why it was an optional style and not a default on XP: The double buffering only picks up painting performed during the BeginPaint / EndPaint block of the parent window. Lots of, even standard controls, perform painting outside of their WM_PAINT handlers, and as a result the backbuffer gets only partially painted.
Sadly, the result is, the only way to "eliminate" flicker in native API apps is to try to minimize it: WS_CLIPCHILDREN and WS_CLIPSIBLINGS can help if you dont have overlapping controls - to ensure that each control's area is painted only once. And ensure that the main dialog does not perform any flood filling in WM_ERASEBKGND
It is not, in my experience, possible to use double-buffering for anything that contains child controls (unless they all fully support WM_PRINT, which most do not).

Styles of buttons on win32 C++

i know there are some styles you can put on a button in C++ win32 exa. like BS_DEFPUSHBUTTON BS_RADIOBUTTON but i do not know all of them and also how would i go about making a user drawn button
You can find the reference of all button styles on MSDN (as usual). And an overview of the Button control in general.
To create an owner drawn button, you need to specify the BS_OWNERDRAW flag and pocess the WM_DRAWITEM notification in the button parent window.
And if you only want to tweak the button drawing algorithm, you should look at the DrawThemeBackground API - that allows you to draw the button using the same visuals that the standard Windows Theme engine uses.
You do need to be careful to handle the case when theming is disabled (when OpenTheme fails) however - in that case you're on your own unfortunately.