15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


How to position a CDialogBar?

Luca ENEA-SPILIMBERGO -- luca_esl@pointest.com
Monday, October 28, 1996

Environment:  VC++ 4.0, NT3.51

I've created two floating and dockable DialogBar deriving each one from
CDialogBar. Each of them has some controls on it and looks like a vertical
rectangle.

All works fine but whem my MDI application starts, the two bars are side by
side docked on the right side of my app frame (my Frame and bars are allowed
to dock only on left and right side)

---------------------------------------
|My App title bar                     |
---------------------------------------
|                     |------- -------|
|                     |!  B  ! !  B  !|
|                     |!  A  ! !  A  !|
|                     |!  R  ! !  R  !|
|                     |!  1  ! !  2  !|
|                     |------- -------|
|                     |               |
|                     | unused space  |
|                     |               |
---------------------------------------

I can manually move Bar1 under the bottom of Bar2 but I wish I could make it
automatically at my application startup.

I've tried with MoveWindow, SetWindowPos and a version of DockControlBar
that take, as parameter, a RECT that is the destination rectangle for docking.

I create the two bars in OnCreate function of my MDIFrameWnd and I tried to
move them just after their creations.

Got some ideas???

Thanks



                           \\\|///
                         \\  - -  //
                          (  @ @  )
O-----------------------oOOo-(_)-oOOo--------------------O
| Luca ENEA-SPILIMBERGO                 Via P.Neruda 4/A |
|                                       20060 BUSSERO MI |
| luca_esl@pointest.com          Oooo   ITALY            |
O------------------------oooO---(   )--------------------O
                        (   )    ) /
                         \ (    (_/
                          \_)




Randy Taylor -- drt@ebt.com
Wednesday, October 30, 1996

[Mini-digest: 6 responses]

Derive a class from CDockBar (an MFC "private" class
documented in the source code only), and override it's
CalcFixedLayout function. Almost any problem or issue
you have with layout of control bars can be solved 
by your own custom version of that class.
In your frame window's OnCreate member function,
create your dockbar BEFORE you call CFrameWnd::EnableDocking().
Like this:

	// DOCKBAR
	m_wndDockBar = new SmDockBar;
	if (!m_wndDockBar->Create(this,
		WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_CHILD|WS_VISIBLE|CBRS_TOP,
		AFX_IDW_DOCKBAR_TOP))
		return -1;      // fail to create

	// ENABLE DOCKING ***AFTER*** CREATION OF CUSTOM DOCKBAR
	this->EnableDocking(CBRS_ALIGN_TOP);


randy_taylor@ebt.com



>Environment:  VC++ 4.0, NT3.51
>
>I've created two floating and dockable DialogBar deriving each one from
>CDialogBar. Each of them has some controls on it and looks like a vertical
>rectangle.
>
>All works fine but whem my MDI application starts, the two bars are side by
>side docked on the right side of my app frame (my Frame and bars are allowed
>to dock only on left and right side)
>
>---------------------------------------
>|My App title bar                     |
>---------------------------------------
>|                     |------- -------|
>|                     |!  B  ! !  B  !|
>|                     |!  A  ! !  A  !|
>|                     |!  R  ! !  R  !|
>|                     |!  1  ! !  2  !|
>|                     |------- -------|
>|                     |               |
>|                     | unused space  |
>|                     |               |
>---------------------------------------
>
>I can manually move Bar1 under the bottom of Bar2 but I wish I could make it
>automatically at my application startup.
>
>I've tried with MoveWindow, SetWindowPos and a version of DockControlBar
>that take, as parameter, a RECT that is the destination rectangle for docking.
>
>I create the two bars in OnCreate function of my MDIFrameWnd and I tried to
>move them just after their creations.
>
>Got some ideas???
>
>Thanks
>
>
>
>                           \\\|///
>                         \\  - -  //
>                          (  @ @  )
>O-----------------------oOOo-(_)-oOOo--------------------O
>| Luca ENEA-SPILIMBERGO                 Via P.Neruda 4/A |
>|                                       20060 BUSSERO MI |
>| luca_esl@pointest.com          Oooo   ITALY            |
>O------------------------oooO---(   )--------------------O
>                        (   )    ) /
>                         \ (    (_/
>                          \_)
>
>

-----From: "Thomas W. McAlees" 

We had a similar  problem with MFC positioning multiple toolbar's on top of
each other, rather than next to each other.  To solve this problem, we
added a method to the CMainFrame class class DockPosition().  This only
works with CToolBar's and is only meant to align CToolBars on the top or
bottom of the main frame window.  But you should be able to make it work
for CDialogBars.

void CMainFrame::DockPosition(CToolBar* LeftToolbar, CToolBar*
RightToolbar)
{
	CRect rect;			//Holds the rectangle area of the toolbar.
	DWORD dw;			//Holds the toolbar's attributes.
	UINT n;				//Used for operations on the position.
	
	// We need to force MFC to adjust the dimensions for all docked ToolBars
	// in order for us to have an accurate value from GetWindowRect.
	RecalcLayout();						//force a relook at the layout.
	LeftToolbar->GetWindowRect(&rect);		//pointer to the rect area of toolbar
we want to the left.
	rect.OffsetRect(1,0);				//move the toolbar to the desired position.
	dw=LeftToolbar->GetBarStyle();
	n = 0;
	n = (dw&CBRS_ALIGN_TOP) ? AFX_IDW_DOCKBAR_TOP : n;
	n = (dw&CBRS_ALIGN_BOTTOM && n==0) ? AFX_IDW_DOCKBAR_BOTTOM : n;
	n = (dw&CBRS_ALIGN_LEFT && n==0) ? AFX_IDW_DOCKBAR_LEFT : n;
	n = (dw&CBRS_ALIGN_RIGHT && n==0) ? AFX_IDW_DOCKBAR_RIGHT : n;
	DockControlBar(RightToolbar,n,&rect);
}

Tom McAlees
tmcalees@csci.csc.com
-----From: "Doug Brubacher" 

     Review the documentation for
     
     CFrameWnd::DockControlBar
     
     void DockControlBar( CControlBar * pBar, UINT nDockBarID = 0, LPCRECT 
     lpRect = NULL );
     
     The lpRect parameter should allow you to position the second Toolbar 
     below the first
     
     Regards,
     
     Doug Brubacher
     DouglasB@msn.com

-----From: browkl@inel.gov (Kenneth L Brown)

I did something similar with the DockControlBar member of CFrameWnd to
position a toolbar.  I have not done this with a dialog bar but it is
worth a try.

Kenneth Brown
browkl@inel.gov

-----From: ppbillc@srv2.sj.ablecom.net

IF you call BringWindowToTop for one of the DialogBars it should 
place it above the other.

B


 
 /    \
 *    *
\ _,-._/
-----From: "Andrea Bioli" 

Ciao Luca.
Scusa se ti invio un messaggio non richiesto, e spero di non
disturbarti.
Mi chiamo Andrea Bioli e sono direttore di Professional Developer's
Journal, una nuova rivista per programmatori arrivata al secondo
numero in questi giorni.
Ti invito quindi a visitare la nostra home page (http://www.gen.com/pdj),
e ti chiedo se sei interessato a scrivere articoli per la nostra rivista,
visto che dovresti essere un tecnico del settore (ho visto un tuo
messaggio nella mfc-l).
Spero di avere tue notizie, e se ti ho disturbato ti chiedo scusa ancora.

Grazie e ciao
Andrea Bioli
Professional Developer's Journal




Kenneth L Brown -- browkl@inel.gov
Thursday, October 31, 1996

After I replied to your message yesterday I did some checking on the
problem you describe and found something that might be useful to you.  I
am writing an application where I have a tool bar and a dialog bar at
the top of the window.  I noticed the same problem with positioning them
side by side or in your case over and under.

I found a sample app on the CD under \msdev\samples\mfc\general\docktool
that has examples of docking toolbars side by side.  In the
mainframe.cpp file I modified the DockControlBarLeftOf routine to look
like this:

void CEditFrame::DockControlBarLeftOf(CControlBar* Bar,CControlBar*
LeftOf)
{
	CRect rect;
	DWORD dw;
	UINT n;

	// get MFC to adjust the dimensions of all docked ToolBars
	// so that GetWindowRect will be accurate
	RecalcLayout();
	LeftOf->GetWindowRect(&rect);
	rect.OffsetRect(1,0);
	dw=LeftOf->GetBarStyle();
	n = 0;
	n = (dw&CBRS_ALIGN_TOP) ? AFX_IDW_DOCKBAR_TOP : n;
	n = (dw&CBRS_ALIGN_BOTTOM && n==0) ? AFX_IDW_DOCKBAR_BOTTOM : n;
	n = (dw&CBRS_ALIGN_LEFT && n==0) ? AFX_IDW_DOCKBAR_LEFT : n;
	n = (dw&CBRS_ALIGN_RIGHT && n==0) ? AFX_IDW_DOCKBAR_RIGHT : n;

	// When we take the default parameters on rect, DockControlBar will
dock
	// each Toolbar on a seperate line.  By calculating a rectangle, we in
effect
	// are simulating a Toolbar being dragged to that location and docked.
	DockControlBar(Bar,n,&rect);
}

The only difference is I changed the signature to use CControlBar
arguments instead of CToolBar and it works fine for both.

To position the toolbars just use DockControlBar to place the first
control bar and DockControlBarLeftOf to position the second control bar.

	DockControlBar(&m_wndToolBar);
	DockControlBarLeftOf(&m_wndDialogBar,&m_wndToolBar);

Hopefully this will help.

Kenneth Brown
browkl@inel.gov

Luca ENEA-SPILIMBERGO wrote:
> 
> Environment:  VC++ 4.0, NT3.51
> 
> I've created two floating and dockable DialogBar deriving each one from
> CDialogBar. Each of them has some controls on it and looks like a vertical
> rectangle.
> 
> All works fine but whem my MDI application starts, the two bars are side by
> side docked on the right side of my app frame (my Frame and bars are allowed
> to dock only on left and right side)
> 
> ---------------------------------------
> |My App title bar                     |
> ---------------------------------------
> |                     |------- -------|
> |                     |!  B  ! !  B  !|
> |                     |!  A  ! !  A  !|
> |                     |!  R  ! !  R  !|
> |                     |!  1  ! !  2  !|
> |                     |------- -------|
> |                     |               |
> |                     | unused space  |
> |                     |               |
> ---------------------------------------
> 
> I can manually move Bar1 under the bottom of Bar2 but I wish I could make it
> automatically at my application startup.
> 
> I've tried with MoveWindow, SetWindowPos and a version of DockControlBar
> that take, as parameter, a RECT that is the destination rectangle for docking.
> 
> I create the two bars in OnCreate function of my MDIFrameWnd and I tried to
> move them just after their creations.
> 
> Got some ideas???
> 
> Thanks
> 
>                            \\\|///
>                          \\  - -  //
>                           (  @ @  )
> O-----------------------oOOo-(_)-oOOo--------------------O
> | Luca ENEA-SPILIMBERGO                 Via P.Neruda 4/A |
> |                                       20060 BUSSERO MI |
> | luca_esl@pointest.com          Oooo   ITALY            |
> O------------------------oooO---(   )--------------------O
>                         (   )    ) /
>                          \ (    (_/
>                           \_)




| Вернуться в корень Архива |