Solved

CDialogBar and Listbox

Posted on 2000-04-04
1
296 Views
Last Modified: 2013-11-20
I created my own class derived from CDialogBar.  I added a listbox to the dialog bar and I was successful in docking my dialog bar with the list box and it displays fine.  (Most of this was done by the wizard - I just added the listbox and created a member variable for it).  My problem is that I cannot load any items into the list box.  So far, I was able to create a function in my CMainFrame class (MDI application) and used the ON_COMMAND_UPDATE_UI macro - using this, I was able to put items in the list box by calling AddString.  The only problem with this is that this routine continually runs while the program is idle and this doesn't seem to be the best way to load items into the listbox.  I can stop it by putting in a counter and preventing it from loading additional strings once it reaches a certain point, but then it is always checking it.  Is there any way I can do this that will be more efficient?  How can I interact with the listbox on the toolbar as if it was a regular dialog?  

FYI: I want to be able to have a listbox on the toolbar with a list of items that can be dragged and dropped onto different windows within the MDI.  I need to be able to change the items in the listbox at will, and I need to be able to drag them out from the list and drop them on other controls in other windows/views.  I was thinking of changing the CListBox to a CDragListBox, but I'm not sure if this would work.  Any insight you can provide on how to accomplish this ultimate goal will be helpful.

P.S. I already looked at the examples on the VC++ CD that put combo boxes on a dialog toolbar - this doesn't help me because the items in the combo box are static and set in the resource editor.
0
Comment
Question by:ardolino
1 Comment
 
LVL 31

Accepted Solution

by:
Zoppo earned 150 total points
ID: 2686760
Hi ardolino,

Don't use the ON_COMMAND_UPDATE_UI handler for such functionality, it's called very, very often and should only handle visibilty/state of the controls.

You can give your derived CDialogBar class the functionality to add the strings or add them directly from mainframe.

1.
CMyDialogBar::AddText( LPCTSTR pText )
{
 CListBox* pListBox = (CListBox*)GetDlgItem( IDC_LISTBOX );
 pListBox->AddString( text );
}

// in CMainFrame class you should have a member m_wndDlgBar of your derived class which is used in CMainFrame::OnCreate() to create the dialog
CMainFrame::AnyFunction()
{
 ...
 m_wndDlgBar.AddString( "A String..." );
 // or with direct access through main frame (without any error checking)
 ((CListBox*)m_wndDlgBar.GetDlgItem( IDC_LISTBOX ))->AddString( "Another String..." );
 ...
}


I don't see why there should be a problem using a CDragListBox.

For drag/drop samples (and even other samples) I suggest you to take a look at both www.codeguru.com and www.codeproject.com.

hope that helps,

ZOPPO
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Expand data scrubbing tool 13 32
only14 challenge 19 69
Problem to event 3 79
how to split multiple lines delimiter : 8 80
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now