Use CreateWindow(Ex) to create a dummy parent control (like a panel) - c++

So basically, I have a Tab Control (WC_TABCONTROL) and I want to place all of the controls that go with a single tab page on a single window (control, if you will, or panel). I want to create something like the panel in wxWidgets, so that when I call ShowWindow(panel, SW_HIDE), I can hide the panel and all controls inside it. I hope you understand. Thanks, Grant.

I think what you want is a borderless, captionless dialogbox. I've used that very thing with tab-controls. Show and hide them on the tab control click events.
Actually some tab-controls will use the caption of the dialogbox in their own caption. YMMV.
Here's an old-school example. It shows all the basics.
http://msdn.microsoft.com/en-us/library/bb760551%28VS.85%29.aspx
HTH

Related

Disabling a ComboBox item in Win32 API

I would like to disable an item in a combobox in my Win32 application (C++). I'm not quite sure how to do this. I'm trying to achieve something that looks like this:
Notice how CollectionItem2 and 3 are greyed-out.
Any help would be very much appreciated!
If you truly need a combobox for this, then (as #IInspectable said) you'll need to do a custom drawn control. Basically, you'll have to store some information saying which items are disabled/grayed, and draw the items appropriately based on whether they're enabled or not.
There may be a somewhat easier way though. This is normally done with a Split Button. This is button with the BS_SPLITBUTTON style set. When the drop-down part of the button is clicked, it sends a BCN_DROPDOWN notification.
You normally respond to that by displaying a menu, typically using TrackPopupMenu to display it immediately below the button (or immediately to its right, if you prefer). This is a normal menu, so it can have items enabled, disabled, grayed, have check boxes, etc., as you see fit.
If you're using MFC, it has a CSplitButton class that wraps the Split Button, simplifying the code a little bit--you can pass an identifier of a menu and sub-menu when you create the CSplitButton object, and it handles things from there.
A sample result probably looks pretty familiar:
Note: MFC also has a CMfcMenuButton class. This has roughly similar functionality, but is somewhat clumsier to use. If memory serves, it is compatible with older versions of Windows (but the split button goes back to Vista, so it's fine unless you really need to support XP).

How to add or remove textboxes by changing the options in the combobox in Visual c++?

I want to know that whether I can add a textbox or label by changing the options in combo box. For example, I have 2 options in Combobox. If I choose the #1, it must show me 2 textboxes, but if I choose #2 it must show 3 textboxes.Can I do something like this in Visual Studio C++?
This can be done in two ways:
Dynamically create and destroy the edit controls using CreateWindowEx and DestroyWindow.
Statically create your GUI with 3 edit controls and set the visibility of the controls based on the selection using ShowWindow.
Have as many text-boxes you want. But hide them.
Handle CBN_SELCHANGE (ON_CBN_SEL_CHANGE in MFC).
In the handler, show (or hide) the text boxes depending on selection.
Showing/hiding text boxes aren't good from UI perspective. You better enable/disable them appropriately. You may put alternate text when they are disabled, and bring back original change when they have to be enabled.
Creating textboxes at runtime, and then deleting them isn't' good approach. You will need to keep track of Win32 UI handle and/or MFC object. This approach will also need more of UI resource creation/deletion, parent-child relationship handling et. al.

Prevent Up-Down control for Tab Control?

As documented:
"If not all tabs can be shown at once, the tab control displays an up-down control so that the user can scroll additional tabs into view."
http://msdn.microsoft.com/en-us/library/bb760550%28VS.85%29.aspx
I don't want this. I don't want an up down control to show if I have too many and I don't want multiline tabs. I want a single strip. I will handle the case of too many tabs with a control I create myself, but I don't want the up-down control. Thanks
There's no style for that, so i believe the only way is a bit of hacking. From what i can see with my Spy++, the updown control is a true child control of the tab control with id = 1. So, you can actually hide it with ShowWindow().

Binding a static text box to a checkbox

I need some help in MFC. The following is my problem:
I have two controls a static text and a checkbox
When using MFC Wizard, i place a '&' in front of one of the letters in the static text, while executing if i press Alt+, the checkbox either gets enabled or disabled.
Now my problem is i am adding these controls programaticaly, and even though i have the '&' placed in the static text, if i press the Alt+, it doesn't change the state of the checkbox control.
My queries are:
Can anyone kindly let me know if there is some binding which has to be done in case we are adding the controls programatically.
If someone can briefly explain how the binding is taken care by MFC it will be gr8 help
edit:
One more thing the checkbox won't have any text associated with it.
Since the static text is not associated with the checkbox control, how can the system know which checkbox it should link? I bet if you look at the TAB ordering and the group settings of the controls, you will arrive at your solution.

Adding drop down arrows to CMFCToolBar buttons

Can anyone explain how to add dropdown arrows to CMFCToolBar toolbar buttons - like for undo/redo buttons. We had this with CToolBar by using the TBSTYLE_EX_DRAWDDARROWS style and TBN_DROPDOWN notification. This doesn't seem to work with CMFCToolBar. These dropdown arrows i believe are added to the VisualStudioDemo MFC feature pack demo but i can not figure out how.
In the VisualStudioDemo sample, in CMainFrame::OnToolbarReset they replace the Undo button of the toolbar with a custom class called CUndoButton, like this:
m_wndToolBar.ReplaceButton(ID_EDIT_UNDO, CUndoButton(ID_EDIT_UNDO, _T("&Undo")));
CUndoButton is declared in file "UndoBar.h" of the sample project, so you can use it or change it however you like.