MFC Dialog Combo Box in a List Control - c++

I'm trying to create a dialog window with a List Control (report view) that displays a column of text. I'm trying to add another column that displays a combo box that will hold a list of possible actions for the first column. Is there any easy way to do this in MFC?

You can't do that with something like CListCtrl (or not without a lot of owner drawn code). Instead have a look at a 3rd party control like CGridListCtrlEx which will do all the heavy lifting for you.

Related

MFC dynamic adding controls with scroll bar

I want to add controls, including buttons, edit box and custom controls, dynamically in a MFC MDI application. I am using from view and I want to create the following GUI.
What I want to do is:
I am able to create those row of controls(Button, Edit box and custom
control) dynamically.
I can have many rows of those controls.
When there are too many rows and the form view has no space to
display them, a scroll bar will appear.
I had read some resources talking about how to create controls dynamically. But I am still wondering how to insert them into something so that I can have a scroll bar when there are too many rows of controls I have to handle.

Win32 (C++) :- How to make a list item collapsible

I have a listbox in which multiple list items are there. I want to implement something like if we click on the list item, it will collapse and show the summary of the clicked item:
I have been searching this on the web for quite sometime but haven't got any good solution. I am very new to Win32. Any suggestions on how to approach this like which control should I use. Any help will be appreciated.
Standard ListBox and ListView controls do not natively support expanding/collapsing items, however it is possible to implement it in a ListBox with some extra work.
Give the ListBox the LBS_OWNERDRAWVARIABLE list box style to allow the list to contain items of different heights. When a new item is added to the list, the ListBox will send a WM_MEASUREITEM message to its parent window asking for the item's initial height. Return an appropriate height based on whether the item should be displayed as collapsed or expanded.
Once an item has been added to the list, you can send the ListBox a LB_SETITEMHEIGHT message to assign a new height for that item based on whether it should now be displayed collapsed or expanded. Then invalidate the ListBox to trigger a repaint of the items.
The LBS_OWNERDRAW... styles require you to manually draw each list item whenever the ListBox sends a WM_DRAWITEM message to its parent window. You can draw the requested item on the provided HDC however you want, such as with the DrawText() function, configuring its parameters based on whether the item's text is currently being displayed as collapsed or expanded. Also use the state information provided by the message itself to configure the HDC's font and background/foreground colors as desired (particularly important when rendering items in the selected and focused states).
With that in place, all you have left to do is make your click handler determine the index of the item being clicked on (via GetMessagePos(), ScreenToClient(), and LB_ITEMFROMPOINT), and then assign it a new height based on its new expanded/collapsed state, and let the resulting repaint draw the new text accordingly.

How to add QMenus or Qactions on a Widget like QlistWidget area as a list item?

Is there any way to add QActions as a list item on QListWidget?
I want to make a customization window which will show list of actions on a widget for move up, move down, Rename and other options. I'd like to display it on the widget same as it appears as a context menu.
I tried adding it as a list item with icon and text, but the look it not very good:
i) list items with blank icon are not aligning properly, even after adding a blank icon of size 16*16 is not taking up any space and text with icons & w/o icon are not aligning.
ii) I'm unable to add right-pointing black triangle at the right most, in-case of sub-menus cause somehow unicode character for this is not getting displayed on my Linux machine.
That's why I want to add QActions as it are getting popped at original place.
Any suggestions?
Yes I have a suggestion : do not try to make fancy widgets like this, users will not find it intuitive
You should find another way to implement this.
Imo, something like a QToolButton with a QToolButton::MenuButtonPopup popup mode will do the trick. This way, you can embed menu and sub-menus in a widget, using QToolButton::setMenu().

MFC tooltip for list control of dialog box

I have developed on application, which shows a dialog box with two list controls.
In this list control, I am showing images. Now I want is, when we move the mouse on images from the list control of dialog box, It will show tool tip for that.
How can I show tool tips for images in a list control in a dialog box?
The CToolTipCtrl control is the MFC wrapper class around the Win32 "tool tip". You can use this to display a small pop-up window to describe another control or provide additional information in your app.
If you're using a ListBox control, explore one of these sample projects to see how to display tooltips for individual items displayed within that ListBox control:
ListBox With ToolTip Support
List Box With ToolTips
And if you're using a ListView control (CListCtrl in MFC), then you should start by reading the documentation for the GetToolTips function and the corresponding SetToolTips function. You can also check out how this sample ListView control implements tooltips:
CListCtrl and Displaying a Tooltip

Custom dropdown for CComboBox

I'm trying to create a custom dropdown for a derivative of CComboBox. The dropdown will be a calendar control plus some 'hotspots', e.g.
So I figure the best way to achieve this is to have a simple CWnd-derived class which acts as the parent to the calendar control, and have it paint the hotspots itself.
The window needs to be a popup window - I think - rather than a child window so that it isn't clipped. But doing this causes the dialog (on which the combobox control is placed) to stop being the topmost (foreground?) window, leading to its frame being drawn differently:
alt text http://img693.imageshack.us/img693/3474/35148785.png
This spoils the illusion that the dropdown is part of the combobox since its acting more like a modal dialog at this point. Any suggestions on how I make the custom dropdown behave like the regular dropdown?
Are there any other pitfalls I need to watch out for, e.g. focus and mouse capture issues?
When you create your popup window, you need to specify its owner. Owned popup windows will activate their owner when you activate them. Not specifying an owner will cause your window to get activated, which causes the change in the owner you're seeing.
Yeah I had this problem once. A quick google makes me suspect I solved this by using CreateWindowEx() and specifying WS_EX_NOACTIVATE. I have some other code that achieves the same effect by making the window with WS_EX_TOOLWINDOW rather than as a popup window, but I'm not sure of why that was done that way, my intuition would say that making it a popup window would be the way to go.
You can find in the following links two sample project that put in the CComboBox dropdown window a CTreeCtrl or a CListCtrl controls ... similar, you can put whatever you need there. Here is the links:
Tree ComboBox Control
and
List ComboBox Control
I hope this help you.