Toolbar on a Dialog - help with sample 
Author Message
 Toolbar on a Dialog - help with sample

Hi

After questing as to how to put a toolbar on a dialog, I was directed to see
the MFC Sample. I did that, but even after almost-completely reproducing the
code in my program, I can't seem to get the toolbar. The following code does
shift all the controls down after correctly calculating the space that will
be taken up by the toolbar, in order to make room for the same. But the
toolbar? Can't find it!

Please study the following code and help me out. I spent the last two nights
over this. It's placed in the TODO section of the OnInitDialog of the
dialog-based application.

Regards,

Michelle Stone

 // TODO: Add extra initialization here
 // Create toolbar at the top of the dialog window

 CToolBar m_toolBar;

 if (m_toolBar.Create(this))
 {
  m_toolBar.LoadToolBar (IDR_MAIN);
 }

 m_toolBar.SetBarStyle(m_toolBar.GetBarStyle() |
  CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);

 // We need to resize the dialog to make room for control bars.
 // First, figure out how big the control bars are.
 CRect rcClientStart;
 CRect rcClientNow;
 GetClientRect(rcClientStart);
 RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST,
       0, reposQuery, rcClientNow);

 // Now move all the controls so they are in the same relative
 // position within the remaining client area as they would be
 // with no control bars.
 CPoint ptOffset(rcClientNow.left - rcClientStart.left,
     rcClientNow.top - rcClientStart.top);

 CRect  rcChild;
 CWnd* pwndChild = GetWindow(GW_CHILD);
 while (pwndChild)
 {
  pwndChild->GetWindowRect(rcChild);
  ScreenToClient(rcChild);
  rcChild.OffsetRect(ptOffset);
  pwndChild->MoveWindow(rcChild, FALSE);
  pwndChild = pwndChild->GetNextWindow();
 }

 // Adjust the dialog window dimensions
 CRect rcWindow;
 GetWindowRect(rcWindow);
 rcWindow.right += rcClientStart.Width() - rcClientNow.Width();
 rcWindow.bottom += rcClientStart.Height() - rcClientNow.Height();
 MoveWindow(rcWindow, FALSE);

 // And position the control bars
 RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
 m_toolBar.MoveWindow (0, 0, 260, 30);
 // Set the icon for this dialog.  The framework does this automatically
 //  when the application's main window is not a dialog
 SetIcon(m_hIcon, TRUE);         // Set big icon
 SetIcon(m_hIcon, FALSE);        // Set small icon

 // Finally, center the dialog on the screen
 CenterWindow();



Wed, 13 Aug 2003 17:58:48 GMT  
 Toolbar on a Dialog - help with sample
Try using CReBar -- it simplifies things dramatically ...

Regards
Naren


Quote:
> Hi

> After questing as to how to put a toolbar on a dialog, I was directed to
see
> the MFC Sample. I did that, but even after almost-completely reproducing
the
> code in my program, I can't seem to get the toolbar. The following code
does
> shift all the controls down after correctly calculating the space that
will
> be taken up by the toolbar, in order to make room for the same. But the
> toolbar? Can't find it!

> Please study the following code and help me out. I spent the last two
nights
> over this. It's placed in the TODO section of the OnInitDialog of the
> dialog-based application.

> Regards,

> Michelle Stone

>  // TODO: Add extra initialization here
>  // Create toolbar at the top of the dialog window

>  CToolBar m_toolBar;

>  if (m_toolBar.Create(this))
>  {
>   m_toolBar.LoadToolBar (IDR_MAIN);
>  }

>  m_toolBar.SetBarStyle(m_toolBar.GetBarStyle() |
>   CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);

>  // We need to resize the dialog to make room for control bars.
>  // First, figure out how big the control bars are.
>  CRect rcClientStart;
>  CRect rcClientNow;
>  GetClientRect(rcClientStart);
>  RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST,
>        0, reposQuery, rcClientNow);

>  // Now move all the controls so they are in the same relative
>  // position within the remaining client area as they would be
>  // with no control bars.
>  CPoint ptOffset(rcClientNow.left - rcClientStart.left,
>      rcClientNow.top - rcClientStart.top);

>  CRect  rcChild;
>  CWnd* pwndChild = GetWindow(GW_CHILD);
>  while (pwndChild)
>  {
>   pwndChild->GetWindowRect(rcChild);
>   ScreenToClient(rcChild);
>   rcChild.OffsetRect(ptOffset);
>   pwndChild->MoveWindow(rcChild, FALSE);
>   pwndChild = pwndChild->GetNextWindow();
>  }

>  // Adjust the dialog window dimensions
>  CRect rcWindow;
>  GetWindowRect(rcWindow);
>  rcWindow.right += rcClientStart.Width() - rcClientNow.Width();
>  rcWindow.bottom += rcClientStart.Height() - rcClientNow.Height();
>  MoveWindow(rcWindow, FALSE);

>  // And position the control bars
>  RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
>  m_toolBar.MoveWindow (0, 0, 260, 30);
>  // Set the icon for this dialog.  The framework does this automatically
>  //  when the application's main window is not a dialog
>  SetIcon(m_hIcon, TRUE);         // Set big icon
>  SetIcon(m_hIcon, FALSE);        // Set small icon

>  // Finally, center the dialog on the screen
>  CenterWindow();

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.204 / Virus Database: 96 - Release Date: 10/23/00


Thu, 14 Aug 2003 00:10:43 GMT  
 Toolbar on a Dialog - help with sample

Quote:

> Hi

> After questing as to how to put a toolbar on a dialog, I was directed to see
> the MFC Sample. I did that, but even after almost-completely reproducing the
> code in my program, I can't seem to get the toolbar. The following code does
> shift all the controls down after correctly calculating the space that will
> be taken up by the toolbar, in order to make room for the same. But the
> toolbar? Can't find it!

> Please study the following code and help me out. I spent the last two nights
> over this. It's placed in the TODO section of the OnInitDialog of the
> dialog-based application.

> Regards,

> Michelle Stone

>  // TODO: Add extra initialization here
>  // Create toolbar at the top of the dialog window

>  CToolBar m_toolBar;

>  if (m_toolBar.Create(this))

That very first line appears to be a major problem involving basic C++ memory
allocation.  It creates the CToolBar object on the stack.  Objects created on
the stack are destroyed when the enclosing function returns!  m_ToolBar should
be a member variable so it will stay allocated for the life of the parent dialog
object.  I.e. move that line into the class definition in the h file.

--
Scott McPhillips [VC++ MVP]



Thu, 14 Aug 2003 01:51:23 GMT  
 Toolbar on a Dialog - help with sample
Its not the same at all. The problem was not due to use of a toolbar, as
explained by Scott. Use of ToolBar is not difficult at all. Equivalent of
toolbar would NOT be a CRebar but rather a CDialogBar as it gives you the
opportunity to float and dock like a toolbar.

--
Ajay Kalra [MVP - VC++]

Note: Please post all replies to newsgroup only.


Quote:
> Try using CReBar -- it simplifies things dramatically ...

> Regards
> Naren



> > Hi

> > After questing as to how to put a toolbar on a dialog, I was directed to
> see
> > the MFC Sample. I did that, but even after almost-completely reproducing
> the
> > code in my program, I can't seem to get the toolbar. The following code
> does
> > shift all the controls down after correctly calculating the space that
> will
> > be taken up by the toolbar, in order to make room for the same. But the
> > toolbar? Can't find it!

> > Please study the following code and help me out. I spent the last two
> nights
> > over this. It's placed in the TODO section of the OnInitDialog of the
> > dialog-based application.

> > Regards,

> > Michelle Stone

> >  // TODO: Add extra initialization here
> >  // Create toolbar at the top of the dialog window

> >  CToolBar m_toolBar;

> >  if (m_toolBar.Create(this))
> >  {
> >   m_toolBar.LoadToolBar (IDR_MAIN);
> >  }

> >  m_toolBar.SetBarStyle(m_toolBar.GetBarStyle() |
> >   CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);

> >  // We need to resize the dialog to make room for control bars.
> >  // First, figure out how big the control bars are.
> >  CRect rcClientStart;
> >  CRect rcClientNow;
> >  GetClientRect(rcClientStart);
> >  RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST,
> >        0, reposQuery, rcClientNow);

> >  // Now move all the controls so they are in the same relative
> >  // position within the remaining client area as they would be
> >  // with no control bars.
> >  CPoint ptOffset(rcClientNow.left - rcClientStart.left,
> >      rcClientNow.top - rcClientStart.top);

> >  CRect  rcChild;
> >  CWnd* pwndChild = GetWindow(GW_CHILD);
> >  while (pwndChild)
> >  {
> >   pwndChild->GetWindowRect(rcChild);
> >   ScreenToClient(rcChild);
> >   rcChild.OffsetRect(ptOffset);
> >   pwndChild->MoveWindow(rcChild, FALSE);
> >   pwndChild = pwndChild->GetNextWindow();
> >  }

> >  // Adjust the dialog window dimensions
> >  CRect rcWindow;
> >  GetWindowRect(rcWindow);
> >  rcWindow.right += rcClientStart.Width() - rcClientNow.Width();
> >  rcWindow.bottom += rcClientStart.Height() - rcClientNow.Height();
> >  MoveWindow(rcWindow, FALSE);

> >  // And position the control bars
> >  RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
> >  m_toolBar.MoveWindow (0, 0, 260, 30);
> >  // Set the icon for this dialog.  The framework does this automatically
> >  //  when the application's main window is not a dialog
> >  SetIcon(m_hIcon, TRUE);         // Set big icon
> >  SetIcon(m_hIcon, FALSE);        // Set small icon

> >  // Finally, center the dialog on the screen
> >  CenterWindow();

> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.204 / Virus Database: 96 - Release Date: 10/23/00



Thu, 14 Aug 2003 02:18:20 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Toolbar on a Dialog - help with sample

2. Toolbar on a Dialog - help with sample

3. Toolbar on a Dialog - help with sample

4. Help: Tooltips for toolbar in modeless dialog

5. HELP: docking toolbar & single dialog application

6. MFC dialogs and toolbars help

7. Customizing Toolbars (at runtime) sample code

8. Toolbar sample bitmaps

9. Common Dialog sample problem

10. Problem with DLL containing modeless dialog - sample.zip (0/1)

11. I need a CRichEditCtrl sample for a Dialog app

12. Screen Saver Sample, add dialog

 

 
Powered by phpBB® Forum Software