How to mark multiple CButtons as clicked in MFC - c++

I have a set of normal CButtons in MFC when a user clickes on one button its appearence should be changed to reflex the idea that it has been clicked sth like in the picture
i tried to change the style of the clicked button using the following code
button->SetButtonStyle(BS_DEFPUSHBUTTON);
Invalidate();
but the problem with this approach is that just one button at time is allowed to be marked so any ideas ? is the only way is to use a bitmap ?

Use CButton::SetState
This page has an example of what you want to do:
http://msdn.microsoft.com/en-us/library/ebw1hfe8(v=vs.90).aspx

Related

Embedding dialogs in main dialog and switching them with button click in MFC

I have a design like below:
So basically, I want to embed three dialogs in the application main dialog and switch between them, for each button click i.e., button 1 will show dialog one , button 2 will hide dialog 1 and show dialog 2 .. and so on.
Each dialog will be having a different design and functions.
I tried using CPropertySheet class to Add pages but its GUI is different. It has either option for navigating the dialogs using next / back button , or from a tab control.
None of which is as per my requirement.
So I want to know is it possible to have a design like this in MFC ? If yes how? Which Class/ control should I use.
Any help will be appreciated.
What you can do is use a normal CDialog class, add your buttons to it and also create a frame/rect as a placeholder for where your embedded dialogs are to appear. The following piece of code will create and position your embedded dialog.
CRect rect;
CWnd *pHost = GetDlgItem(ID_OF_YOUR_FRAME_RECT);
pHost->GetWindowRect(&rect);
ScreenToClient(&rect);
pDialog->Create(ID_OF_YOUR_DIALOG, this);
pDialog->MoveWindow(&rect);
pDialog->ShowWindow(SW_SHOW);
On button clicks, you hide the previously shown dialog (SW_HIDE) and show your selected dialog(SW_SHOW) with ShowWindow(...).
If you create your embedded dialogs with IDD_FORMVIEW style in the add resource editor it'll have the proper styles for embedding.
Another option is probably to use an embedded PropertySheet and hide the tab row and programatically change the tabs on the button clicks. I just find it to be too much fuzz with borders, positioning, validation and such for my liking.
If you have the MFC Feature Pack, that first came with VS2008 SP1 and is in all later versions, you might like to consider CMFCPropertySheet. There are a number of examples on the linked page, that are very similar to your design.
For example, this:
What worked for me just using dialog based application is SetParent() method. Dont know why nobody mentioned it. It seems to work fine.
I am doing like below:
VERIFY(pDlg1.Create(PanelDlg::IDD, this));
VERIFY(pDlg2.Create(PanelDlg2::IDD, this));
VERIFY(pDlg3.Create(PanelDlg2::IDD, this));
::SetParent(pDlg1.GetSafeHwnd(), this->m_hWnd);
::SetParent(pDlg2.GetSafeHwnd(), this->m_hWnd);
::SetParent(pDlg3.GetSafeHwnd(), this->m_hWnd);
Now I can show or hide a child dialog at will (button clicks) as below:
pDlg1.ShowWindow(SW_SHOW);
pDlg2.ShowWindow(SW_HIDE);
pDlg3.ShowWindow(SW_HIDE);

MFC VSListBox change icons

Does anyone know if it is possible to change the icons on the MFC VSListBox Dialog Control?
Specifically I'm trying to change the folder icon to a '+' icon instead:
I haven't tried it myself, but CVSListBoxBase::AddButton() seems to be what you need.
CVSListBox derives from CVSListBoxBase, and when you call CVSListBoxBase::SetStandardButtons to set the buttons, it calls AddButton() for each button.
The documentation for CVSListBoxBase is unfinished, so you'll have to "play" with it, but you can read the code in afxvslistbox.cpp/.h

How do I add a Checkbox to a tool bar in MFC with a custom bitmap?

I have a C++ MFC MDI application. I have a tool bar with some buttons on it. I need to add some check boxes to this toolbar and i need them to have custom bitmaps just as my buttons do. Thanks
EDIT:
By bitmpas i refer to the pixel images that can be created using the tool bar editor in visual stuidos 2008. I would like a picture (of my creation) instead of the usual tick box.
You don't use checkboxes on toolbars.
You should rather use regular buttons in Check mode. That means that the button stays pressed when user releases it. Clicking it a second time releases the button. This is the same behaviour as a checkbox.
You can either set a toolbar button as checkable by code:
m_ToolBar.SetButtonStyle(nButtonId, TBBS_CHECKBOX);
Or by enabling the corresponding property in the resource editor.
If you want to modify the image displayed when the button is pressed, in your ON_UPDATE_COMMAND_UI handler, use m_ToolBar.GetButtonInfo() to check if the image matches the state. If not, change it using m_ToolBar.SetButtonInfo() and specify the index of an extra image added to the image list of the toolbar.
The following is a link which might help you
http://www.ucancode.net/Visual_C_Control/Place-Combo-Edit-Box-Progress-Control-On-ToolBar-CToolBar-VC-Example.htm

Win32 Window Menu is appearing along left side instead of across top of window

I think I may be using a wrong window style or something or maybe just adding the menu to the window incorrectly. I'll post a link to an image here so you can see what I mean about the menu not diplaying correctly:
http://img707.imageshack.us/img707/4828/wtfmenu.jpg
And here's a link to the code that creates the menu and the window:
http://pastebin.com/CBrSVXUD
I'm sure I'm missing something simple and dumb in the labyrinth of styles, settings and etc that are part and parcel for the Win32 API. Has anyone seen this before and know what I'm doing wrong? I just want a 'normal' menu bar along the top, snug against the title bar.
Thanks in advance for any advice.
The MF_MENUBREAK flag you use when adding the popups causes this—that flag is only required if you want the menu item to appear on a new line in the menu bar. Take out both of the MF_MENUBREAK flags and all will be well.

How to set colour in child Clistbox with owner CMFCTabCtrl Class

I using MFC AppWizard and created the SDI application
I need to set colour for the outputwnd debug tab in some sequence
for example
if any wrong value entered in the some control
i need to display text in RED stating that invalid value entered
if login done welcome message in GREEN and so on
I tried to use DrawItem
I am not able to set the listBox stye as LBS_OWNERDRAWFIXED|LBS_HASSTRING
on AddString i am getting error
How to set colour in child Clistbox with owner CMFCTabCtrl Class
I think you need to override CListBox::DrawItem. There's an example in this MSDN page.
few years ago i use this advanced mvc listbox from Ultimate Toolbox
http://www.codeproject.com/KB/MFC/UltimateToolbox_ListBoxEx.aspx
You can easy change items color, font etc with this
Thanks to all for quick and helpfull reply
The help resolved my problem and I am able to change the colour and font of the list box
One more thing i want to add
We need to override measureItem as well. No need to add any code but need to have defination and declaration
otherwise the application will throw execption for using LBS_OWNERDRAWFIXED|LBS_HASSTRING