How do i create i Windows TreeView with multiple selection (C++) - c++

I am trying to implement a custom draw tree view in my WinAPI application. I found samples to manage the custom draw etc. However i do not find a solution to enable multiple selections. I found a attribute TVS_EX_MULTISELECT, but this seems not to be supported, although there is a article about using that flag in c# and there is even a article from MSDN Magazine explaining this flag. But setting
TreeView_SetExtendedStyle(hWndTreeView, TVS_EX_MULTISELECT, TVS_EX_MULTISELECT);
seems to have no effect.
Finally i found a code project implementing a custom draw tree control with multiple selections, but this seems quite complicated and its based on MFC.
How can i create a plain tree view (using custom draw) and enable multiple selections on it? WPF/MFC etc or even Qt are not an option. We use a large custom build C++ Framework based on WinAPI.

Related

Table/Grid using MFC

I just started developing an MFC application for the first time and I'm hoping to get more familiar with the whole "controls" concept. I am using the dialog editor in visual studio and so far I was not able to find functionality to add a simple table/grid. It seems quite basic to me, but I can't even find reliable information on how to do it on the internet.
I am looking for something similar to Qt's QTableWidget, something that I can later program with variable amount of rows and columns tailored to my application's use cases.
Do you have any ideas how to do it?
I use CGridCtrl which is very powerful and does a lot of the legwork for you.
Sounds like you're after a List View Control, which is wrapped by MFC's CListCtrl class. The dialog editor will enable you to add one and set its properties.

GUI Composition in Qt

I have experience building GUIs in Java, C#, and C++ using the WinAPI. I'm attempting my first GUI in C++ using Qt and I have a bit of a transition problem. In any of the other three GUI paradigms, I could create my own GUI components, extend existing JPanels, etc. and end up with a custom-made GUI element that I could add to other GUI windows. C# is particularly good at this as anything I create automatically shows up in the Toolbox after it compiles.
From what I can see there are only two options in Qt and I'm hoping there is something I'm missing. The options are:
Create a custom Widget which may then be imported using a widget container promoted to the right widget.
Build what I like and drag it to scratchpad, from where I can replicate it to my heart's content.
The problem is that I want dynamically add/remove GUI elements at run time. For example, I have a Model-View-Control pattern. The view and control are two different panels in the GUI. When I switch to a different view in one panel, I want to remove the control from the other panel and replace it with the right control for the new view.
From what I can tell, I could do this using custom widgets, but it seems extremely heavy handed to do this for tons of minor widgets in composition to a greater capability. And although I can do the kind of composition I want in scratchpad, I can't figure out how to dynamically add something I have saved in scratchpad.
It is also possible that there is a Qt way of doing things which I have not found. For instance, I have some friends that have successfully created the effects above using different tabs. That seems like a cheap answer, which I could use, but I'd like to believe that Qt has sufficient flexibility to let me build any kind of GUI.
Any suggestions would be helpful
---------------------Improved example--------------------
Let me use the example code that #m7913d gave. (http://doc.qt.io/qt-5/qtwidgets-layouts-basiclayouts-example.html) Suppose that I want to make this portion of the gui into a reusable component which i can add to any GUI I want. How do I do that?
If this was C# I would create a new user control, add the GUI elements, set up the code that makes the unit work as a whole and possibly set up event listeners or properties of the user control as a whole. then I can instantiate, add, and remove them at will from the rest of the GUI. That is what I want.

How to use an autocomplete edit control in an MFC Ribbon Application

I need to develop a search module for an mfc ribbon application using C++. I have used auto complete feature in C#.NET but never worked on any mfc ribbon application. I want auto complete search with an icon image as prefix of each suggestion, just like Facebook search. I have also consulted this article, but that uses CComboBox, I need to use CMFCRibbonCombobox in my program because I tried with CCombobox but that was causing problems. Any help will be appreciated.
you need to create your own CMFCRibbonComboBox derived class, that will be pretty much a copy of the CMFCRibbonFontCombBox without the fonts.to check how you draw the images you can check the CMFCRibbonFontComboBox::OnDrawDropListItem implementation.
Then I think that you will have to dynamicaly add it to the ribbon.

Can I use the search box control seen in Windows Explorer in my own application?

Can I use this search box control seen in Windows Explorer in my own Qt/C++ application? Or is it a custom control I'd have to implement manually?
I haven't seen this kind of control, however in Qt it's easy to implement it manually. You may follow this tutorial: http://labs.qt.nokia.com/2007/06/06/lineedit-with-a-clear-button/ and just replace a clear icon with a search one (and change slot from clear() to something which performs desired search, of course).
You can use the Windows Search Service to access the search functionality; I'm not sure you can embed the actual control that Explorer uses in your own app, but you could certainly create your own that works the same way.

Custom styles for custom widgets in Qt

Does anybody have experience with custom styled, custom widgets in Qt?
(I am using Qt 4.5)
The problems looks like this:
I want to develop some custom controls that are not based entirely on existing drawing primitives and sub-controls. Since the entire application should be skinnable, I want to rely on custom styles, possible on style sheets as well.
What I need to configure for those new controls are the following:
additional metrics
additional palette entries
additional style options
Digging on internet and documentation, I found out that I need to derive a new style class from one the QStyle sub-classes, and override polish method for adding new palette entries, and drawControl (and the other draw methods) for painting logic for custom control and custom parts.
I have two issues that bother me:
Currently, there are different style classes for different styles, already implemented in Qt. (e.g. QMotifStyle, QWindowsStyle), each with different settings. Through inheritance, I would need to re-implement the painting and additional setup logic for each style, in order to properly integrate in all these styles. Do I have another alternative?
I am still confused about how can style sheets be used with these custom styles. Can anybody point to a place where I can find more information than the one provided by Qt documentation? (The samples in Qt don't help me too much).
The style sheet problem will not be solved, as it will not on custom classes.
The extra goodies added to a custom style will not be understood and taken care by already existing classes. This is because C++ is a static language and there is no (clean and sane) way to monkey-patch the run-time classes. A potential solution is to use a proxy style which wraps a certain instance of standard QStyle subclasses. Depending on how much you want to achieve with it, you can refer to two articles: Cross-platform code and styles and Look 'n' Feel Q & A.
If I were you, I would not go with the QStyle approach. Afterall, you create custom widgets (e.g. FooSomething) so you can as well add create completely different custom styles (e.g. FooStyle), it does not even need to mimic QStyle. Of course then you still need to replicate similar functionalities, e.g. to support style sheet.
An alternative could be to use QPalette to get the correct colours and QStyle to get the correct spacing.
QStyle's documentation for Qt 4.5:
Warning: Qt style sheets are currently
not supported for custom QStyle subclasses.
We plan to address this in some future release.