MFC ListView Cntrl error - mfc

I am displaying a ListView cntrl in a modal Dialog box, with ListView properties as "Owner Draw" and "Owner Draw fixed" and using LVN_GETDISPINFO. The dialog along with the list view is getting displayed when there is no data. But strangely, when I am trying to insert data into the list view (by putting data in the array (vector) attached with the list view), my dialog is crashing.
On debugging, the error seems to be coming from the following MFC Library function :
void CListCtrl::DrawItem(LPDRAWITEMSTRUCT)
{
ASSERT(FALSE);
}
In my other applications I have successfully displayed a list control (with Owner draw and Owner data), without subclassing CListCtrl, and overidding DrawItem(). But in my present dialog, I am unable to understand why the list view is failing when I am inserting data into it?
Appreciate your time and help.
Thanks

when you define Owner Draw property, you must implement your own DrawItem function witch draw one item.
You can look for this article

Related

How insert multiple FormView in View of an SDI application

I searched on the forum and I don't find a solution for my issue. So I hope you can help me :)
I work on a personal project for SFC designing (Sequential functional chart) and I'm working with visual studio in SDI(I'm using MFC library). If you see the "design" of an SFC you can see the different elements needed to compose this. So you can find Step, Transition, and more. If I take a step for explaining my issue, after double click on the step a popup dialog is opened with the elements to define this step (actions on this step, and more). The issue is here, I can't see two or more step elements at the same time. I want to reuse the existing concept on other software, see this.
Step close
Step open
Dialog to add
My question is, how I can implement a dialog with my graphic element in mainframe (In this case, a step)? I don't know how I can insert a dialog with my element, I think I need to use CFormView, but I don't know.
This dialog needs to be resizable and reduce directly by the step graphic.
any idea?
Thank you in advance! Sorry for my English ..
Sorry, I think my request is not clear .. (Thank you for your answer)
The context, it's an SDI application with the Document/View architecture. Actually the view is derived from CScrollView.
So, in the document class, you have the different lists of components for make SFC (Steps, transitions and symbols ..). I'm working today on Step element.
The user inserts a new step, the step is draw on the view like this :
enter image description here
And now the user want change the events on this Step, for this after double click on the step the events editor is opened at right of step draw, like this :
enter image description here
For this, I've created a new dialog resource and create the class by wizard in CForwView derived class. In step attribute, you can find one instance of this derived class (The derived class of dialog).
But this doesn't work correctly, I think my method is bad. At the first try, I have sent the pointer of the current document to the "CFormView::Create" function for having the "Save" button active with the focus on the FormView. But after destroying the step, the instance of FormView is destroyed and the document with the instance of formview ...
No problem, you can use "Create" within CCreateContext a null pointer. But with the document or without I have a lot of problems (graphic design not correct in FormView, regularly (not systematic I have assert fail on Proc exchange (for differents reason)). But the "concept" is good, the editor follows the draw if I scroll, I can open or close the editor at any time and on any elements.
For the old capture, it's my SFC designer "model". My application is a complement to this application, so I want a similar design. I don't know how work my model application ..
On my application all is draw by MFC GDI, I don't use ActiveX or other tools.
So what is the correct way to implement one instance of editor by instance of step ?
For the implementation on this FormView I have :
- Make new dialog in ressource
- Create a derived class of CFormView with the created dialog
- Add one instance in attributes of Step element
- "OnDbClickOnStep" -> Call "Create" with the good position / size, pointer of mainview (in my case the CSrollView derived class)
- Done, FormView inserted in a mainview, I can edit my step events.
? Not done, I lost save button and other function linked to the document with the focus on a control in FormView. The app want a document with this view, how to override this ?
? Error in Proc exchange, for different reason...
You have an idea ?
You normally don't draw anything in the "main frame" (or the "MDI clild frames", in the case of a MDI application), this is done by the library, and imo sufficiently so. You display your data in a CView-derived class.
CView is the base class of all other MFC view classes. It's a simple graphical class - you need to paint it yourself in the OnDraw() member.
CScrollView is a descendant of CView, adding scrolling functionality (scroll-bars are automatically displayed if the scrollable area is bigger than the visible window area).
CFormView is a descendant of CScrollView, displaying a dialog resource-script, containing "controls" (edit-boxes, check-boxes, images, ActiveX etc).
As in your case the "controls" won't be initially known (except maybe for some few special cases) and rather programatically created, the resource script will most likely be empty, so using either CFormView or CScrollView will basically be the same. I would suggest starting with CFormView, and "downgrade" it to CScrollView if CFormView is not necessary or causes you troubles.
What are those "Step" items shown in the pics? ActiveX controls, child dialogs maybe? These work best as child controls on a dialog window. Are they already implemented, or they are just pics of some other software? Btw ActiveX is a way to define controls that can be used in other projects too, without having to include them in the project source.

Virtual Combo Box in MFC

I have 10 CComboBox in a tab page and I want to load 10k data to each combobox?
It is taking more time for the tab page to get loaded.
In MFC how to implement virtual combobox like virtual list control?
I need to set default selection in the combobox on loading tab.
Can you please someone give me some ideas?
Thanks
There is no such virtual Combobox in the WinApi, but you have serveral optimizations.
Only load the complete data to the box, if needed. So only when you get the CBN_DROPDOWN event you populate the box with all items. Otherwise you just insert the one selected item.
This method has a drawback that cursor up down in a closed combo doesn't work.
Also you can populate the box only when it receives the focus. Also in this case you just populate the box with the current selected item.
The best result you get is using a owner draw combobox, without using CBS_HASSTRING. CB_ADDSTRING receives a pointer to your data. In DrawItem you use this pointer for drawing.
You still need to add 10k items to each box, but there is no string management and the box is real fast without this memory allocations.

CListCtrl (MFC) selection click passes through to control UNDERNEATH the list

My CListCtrl (Report View, single column) ignores item selection when there's another control behind the CListCtrl. It's as if the click passes through to the control BEHIND the CListCtrl.
Selection is fine if the list item isn't on top of another dialog-box item.
It's baffling because the CListCtrl's z order is ABOVE these other controls. Can anyone suggest something I could try to make the CListCtrl accept a click even when there's another overlapped control? Thanks!
User Spy++ to check the message flow. And to check if another control is above your control! Maybe there is something wrong with you´r z-order even if you think that the control is above. Also check if you overwrote WM_NCHITTEST

Syslink in ListView

If I have a listview control in report mode, how could I stick a syslink control into one of the columns?
I want to have a link the user can click in one of the columns.
The listview control doesn't support this itself.
You could create a real Syslink control that's a child of the listview. You would need to sub-class the listview and reposition the Syslink control whenever the list scrolls (watch for WM_HSCROLL / WM_VSCROLL messages) or when items are added or removed, or when it's sorted. You can use LVM_GETSUBITEMRECT to find out where to position it.
Alternatively, you could handle it yourself by using NM_CUSTOMDRAW to display the "link" in a different color, and handle NM_CLICK to catch when the user clicks on the link. This would be the simplest method in my opinion. Note that if you want a hand cursor to be displayed over the link you would still need to sub-class the list and handle WM_SETCURSOR yourself.

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