Setting item height of a list view? (using custom draw) - c++

How can I set the row height of a custom drawn list view? Or does it require an owner drawn list view?

It depends on the mode you are using it in. In some modes, you can use the LVM_SETITEMHEIGHT message. In others some modes, the item height is dictated by the height of an associated ImageList, if any, followed by the height of the assigned Font.
Update: turns out that LVM_SETITEMHEIGHT is part of the MiniGUI library, not part of the Win32 API. In that case, you would have to use the LVS_OWNERDRAWFIXED window style and then subclass the ListView to handle the WM_MEASUREITEM message.

Related

How to let user vertically resize window

I want the user to be able to vertically resize the Window but I'm unsure how I would do this. I have selected my root object (View of type QWidget) in Qt Creator but I do not see an option to allow users to vertically resize the object. Does this have to be done through code?
By default, if a QWidget is the top-level window you are able to resize it given that the minimumSize and maximumSize are different since they indicate the range of resizing.
If you want to let the user to resize vertically only, then you just have to set both minimumWidth and maximumWidth to the same value (probably to the current width of your QWidget). Qt will take care of indicating the underlying windows manager the rest.
You can do it in the Designer or programmatically using the setMinimumWidth and setMaximumWidth methods. Edit: As mentioned in a comment, there is a setFixedWidth method that simplifies this operation (and make it more explicit in your code).
Of course, you can play with the combinations such as setting a minimum width (or height, or both -minimum size-) to avoid your top-level window to collapse and become unusable, setting a maximum size... One common setting is making minimumSize = maximumSize, so you make the window fixed size (you can use the convenience method setFixedSize).
PS: see that this has nothing to do with the sizePolicy, which simply indicates parent layout which actions can be taken -regarding size- when placing the widget. As a top-level window has no parent layout this policy is simply not used.

Making UWP ComboBox exceeding parent windows

My app needs to be small in nature so I make it 500 x 100 px in size.
The problem is the ComboBox selection items are also squeezed into that small window size. Of course, I can scroll it, but it doesn't feel right this way.
Here is the picture:
Is it possible to expand the ComboBox selection list so that it exceeds the parent window? Preferably in XAML if possible
Is it possible to expand the ComboBox selection list so that it exceeds the parent window?
No, this is impossible in UWP apps. While using ComboBox class, it displays the drop-down list in PopupRoot, which is a layer has the same view port as its parent window. Anything outside this view port will be clipped, users can't see them. For example, following is a normal ComboBox:
After I give a Margin="-20,-30,0,0" to the drop-down list, it looks like
The part outside the window is clipped.
Besides, The implementation of ComboBox will also make sure the ComboBox's selection list won't exceeds the parent window. The selection list's max height is calculated at runtime, it will be always less than the parent window's height and we can't change its value manually, so it is not possible to expand the ComboBox's selection list.
It's not possible, but you can extend your page to the title bar to have at least some additional space using CoreApplicationViewTitleBar.ExtendViewIntoTitleBar property.
Take a look here and here. (I know the examples are written in C# but it should be similar in C++)

Button in MFC CtreeCtrl column

I have a CTreeListCtrl in my MFC application.What I need to do is add a button in a particular column of a node when a particular condition is satisfied(type is changed to reference).
In the image I have edited and added a blue rounded oval to mark the place of desired button.What I want to do is to invoke a dialog on clicking it.But I don't have any clue whether it is possible or not.If yes then pls give me some suggesions.
This is no normal tree control. It is already customized to use multiple columns and I am sure it uses some kid of owner draw. For me it seams more like a list control with tree Features... I know some similar code from Codepproject..
Creating a "real" button (window) isn't wise/good. because it is another window inside the list control...
Change your code to "Draw a button. You can use DrawFrameControl.
Just intercept the left mouse click. Check the range if this area is cliecked. Fire a user defined message to the parent window.

How can I add multiple icons to an individual TreeView item?

I am trying to display multiple icons to the Treeview item but it is not displaying all the icons, it displays only one.
I am using the following code:
CImageList m_imageState;
m_cTree.m_imageState.Create(16, 16, ILC_MASK, 0, 4);
m_cTree.m_imageState.Add(&bm, RGB(255,255,0));
m_cTree.m_imageState.Add(&bm2, RGB(255,0,255));
m_cTree.m_imageState.Add(&bm, RGB(255,255,0));
m_cTree.m_imageState.Add(&bm1, RGB(0,255,255));
m_cTree.SetImageList( &(m_cTree.m_imageState), TVSIL_NORMAL );
But when I see Treeview, item displays only one icon.
Is it possible to display multiple icons with Treeview item?
Please suggest how can I do this.
Correct, only one icon will be displayed per item in a TreeView control. This is by design, a hard limitation of the native control that the MFC library wraps.
The only way you're going to be able to display multiple icons per item is owner drawing. It's a pretty difficult task for a TreeView control, not nearly as easy as owner drawing a button or a label control. Make sure that you really this need this functionality, and consider whether there's a better way of displaying the relevant information to your users.
Alternatively, you could create custom bitmaps that combine multiple images next to one another, and add those to your ImageList. The resulting images will be wider than they are tall, but the control doesn't care: it will display whatever size images you specify, as long as all the images in the image list have the same dimensions. This is definitely a hack, but it might work, depending on your needs.

Get relative X/Y of a mouse-click on a MFC CListBox item

I have a CListBox with custom drawing being used, and need to detect mouse-clicks within each item to perform actions.
I can listen for mouse-clicks on the main control and mess about translating coords into the local space of the RECT for the item under the mouse. But is it possible to register message handlers for clicks on individual list items... are there messages for that?
You can use the LVM_HITTEST message to find out which item was clicked.
Well you could just listen for the LBN_SELCHANGE notification. This will fire every time the user clicks a new item. It won't activate if the already selected item is selected though. This may, or may not, be a problem.
Beyond that I'm pretty sure you'll need to intercept WM_LBUTTONUP messages and transform them to the list box's client space ...
OR You could just use a single columned CListCtrl (ListView) class with headers turned off (LVS_NOCOLUMNHEADER). You can then trap the NM_CLICK message. Personally, I massively prefer CListCtrl to CListBox. It IS a little more complex but way more powerful :)
Edit: Or you could try using http://msdn.microsoft.com/en-us/library/bb761323(VS.85).aspx
I'm not certain I understand why you need to have the XY coordinate inside each item of a Clistbox ?
anyway,
AFAIK, Individual items are not CWnd derived objects.
You could get the mouse position inside the control with OnLButtonDown (or up), it returns a CPoint.
After that, use CListBox::GetItemRect to get the rect of the currently selected item, do a bit of pixel computation and you should be able to get the XY inside the rect of the selected item.
Max.
Use the DPtoLP function to convert device coordinates into logical coordinates.
http://msdn.microsoft.com/en-us/library/dd162474(v=vs.85).aspx