Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MDI question 1

Status
Not open for further replies.

smoothcoder

Programmer
Sep 24, 2002
19
RO
I want to create a MDI application with HTMLView derived views. I also want a child dialog on the left side of the main wnd. That dialog should contain a list of links and when I click one item in the list a new htmlview should appear. Is there any way so that I could attach that dialog to the left side of the MDI frame? Something like in VC++ 6.0 IDE...
 
For the dialog you can go under the 'Project->Add To Project->Components and Controls' menu and add a dialog bar control to your project. You can implement this so that it can dock and/or float. You can stick whatever you want on the dialog using the resource editor.

As for the HTML view: when you first create your project and you're using the wizard to determine what your project will be like, you click on the Document/View architecture box and there will be a choice of which base class you want your view to be derived from (if I recall this may under the 'Advanced' button). Choose CHTMLView from the combo box.

Hope this helps.
 
Thank you so much, qednick!
One more question, please:
am I supposed to attach a class for that dialog bar? I would need a class to manage all the events ant controls on that dialog bar, wouldn't I?
 
When you insert the component a class is not normally created. Instead, your MainFrame class will have a member of type CDialogBar.

What I normally do is declare a new class manually just above the CMainFrame class declaration which is derived from CDialogBar and then change the CDialogBar member in CMainFrame to be of my new new class type, for example:

// in mainfram.h file

// declare a new class derived from CDialogBar

class MyDialogBar : public CDialogBar
{

};

// now change the CDialogBar member in
// CMainFrame to type MyDialogBar


class CMainFrame : public CMDIFrameWnd
{
... exisiting class members here ...

MyDialogBar m_wndDlgBar;
// change from type CDialogBar to new class

... exisiting class members here ...
};


The reason you are declaring a new class which is derived from CDialogBar is to give you some control over the bar. Remember, a DialogBar is NOT a dialog!! However, you can implement a lot of functionality that you would normally have in a dialog because CDialogBar is a decendant of CWnd.
Only problem is, you have to manually implement the functionality that Class Wizard would otherwise insert for you such as message maps, etc.

In the simplest form, you can manipulate items in your dialog bar by using the GetDlgItem() function. For example, say you have inserted a list box control to your dialog bar resource with an ID of IDD_MYLIST. You can manipulate the list box like this:

// first get a pointer to the control
CListBox* myList = (CListBox*)m_wndDlgBar.GetDlgItem(IDD_MYLIST);

// now do something to the list
myList->AddString("Hello World!");


If you need any more help on this just let me know. :)
 
OK, and WHERE am I supposed to write the code for adding those strings?
I've tried to do it in the MainFrame's OnCreate() but the "myList" pointer is NULL and an error comes up everytime my app loads...
 
OK, first make sure you are not trying to access dialog items before the dialog bar is created in your CMainFrame::OnCreate() function. VC++ should have automatically inserted a load of comments and some creation code for your dialog bar in the OnCreate() function. You should ensure your are not trying to access dialog members BEFORE this creation code!

Secondly, ensure that you have the ID of your list box correct and the name of the dialog bar member:

CListBox* myList = (CListBox*)m_wndDlgBar.GetDlgItem(IDD_MYLIST);

There's no reason why this code shouldn't work - I've even tried it for you!

:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top