Click here to Skip to main content
15,892,059 members
Articles / Desktop Programming / MFC
Article

3D Studio Max like Slidable DialogBar

Rate me:
Please Sign up or sign in to vote.
4.93/5 (30 votes)
17 Feb 20021 min read 268.6K   8.1K   98   50
Ever seen 3D Studio 2.5 Slidable DialogBar? Want to know how they did it?

Image 1

Introduction

Kinetix and Autodesk always impressed me with their great GUI. 3D Studio Max has a Slidable DialogBar that the user can slide up and down... Well here is how to do it yourself. It is probably one of the easiest code I ever had to show around and anybody with a little experience in VC++ / MFC will get it. (I actually posted it because I have never seen another programmer or company create a GUI similar to 3DS Max)

Here is the Magic Theory behind it

  1. Create any kind of CWnd derived class . That will be your TOP level Window (could be a CDialog / CDialogBar / CButton anything...)

    Lets say CDialogBarExt ....derived from CDialogBar.

  2. Create a CWnd derived Class that will contain the actual sliding dialog.

    Lets say CDlgContainer ....derived from CWnd

  3. Create a member variable for CDialogBarExt of type CDlgContainer.

  4. Create a CDialog derived class .

    Lets say CInnerDlg (this is the actual sliding dialog !!!)

  5. Create a member variable of type CInnerDlg for CDlgContainer....

So up till know we have CDialogBarExt--->CDlgContainer--->CInnerDlg ? ok? the Code for Sliding the dialog is below and should be entered in the

CInnerDlg

The easiest way to understand, is to look through the code it is very simple!!!

void CInnerDlg::OnLButtonUp(UINT nFlags, CPoint point) 
{
    /// IF WE WHERE DRAGGING THEN RELEASE THE MOUSE CAPTURE
    if(m_bDragging)
    {
        ReleaseCapture();
        m_bDragging = FALSE;
    }
    
    CDialog::OnLButtonUp(nFlags, point);
}

void CInnerDlg::OnMouseMove(UINT nFlags, CPoint point) 
{

 int ydiff;

    if(m_bDragging && nFlags & MK_LBUTTON)
    {
       // GET DIALOGS WINDOW SCREEN COORDINATES
       CRect rcWnd;
       GetWindowRect(&rcWnd);

       // GET PARENTS CLIENT RECTANGLE
       CRect prect;
       GetParent()->GetClientRect (prect);

       // IF WE HAVE TO GO DOWN OR UP // 
       if (m_ptDragFrom.y>point.y) {    
          ydiff = point.y - m_ptDragFrom.y;
          posY+=ydiff;
       }// IF WE HAVE TO GO DOWN OR UP // 
       if (m_ptDragFrom.y<point.y) {    
          ydiff = m_ptDragFrom.y -point.y;
          posY-=ydiff;
       }
       //////////////////////////////


       // CALCULATE IF WE ARE GOING TO EXCEED BOTTOM DIALOG BORDER
       int tmp=prect.Height ()-rcWnd.Height ();
       
       // CONSTRAINTS !
       if (posY<tmp+1) posY=tmp+1;
       if (posY>-1) posY=-1;

       // MOVE THE DIALOG 
        SetWindowPos(NULL, 3, 
                     posY, 
                     rcWnd.Width(), 
                     rcWnd.Height(), SWP_SHOWWINDOW|SWP_NOSIZE);


    }    
    
    CDialog::OnMouseMove(nFlags, point);
}

void CInnerDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
   // START DRAGGING 
   SetCapture();
   m_bDragging = TRUE;
   m_ptDragFrom = point;
   ::SetCursor(AfxGetApp()->LoadCursor (IDC_CURSOR_HAND));
   CDialog::OnLButtonDown(nFlags, point);
}

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Generaldocking CdialogBar like toolbal Pin
yaser8-Sep-02 21:16
yaser8-Sep-02 21:16 
GeneralRe: docking CdialogBar like toolbal Pin
mnansyah30-Jan-03 20:04
mnansyah30-Jan-03 20:04 
GeneralUsability... Pin
aaron.pedigo3-Sep-02 6:29
aaron.pedigo3-Sep-02 6:29 
GeneralRe: Usability... Pin
Anonymous8-Sep-02 1:26
Anonymous8-Sep-02 1:26 
GeneralThank you, thank you..oh, and thank you!! Pin
Anonymous16-Jul-02 22:33
Anonymous16-Jul-02 22:33 
GeneralIt has a problem.... Pin
18-Jun-02 3:04
suss18-Jun-02 3:04 
GeneralRe: It has a problem.... Pin
John Aspras19-Jun-02 20:59
John Aspras19-Jun-02 20:59 
GeneralSorry, not cool at all Pin
20-Mar-02 13:11
suss20-Mar-02 13:11 
IMO this is just terrible. It might have been interesting to program, but I hope nobody thinks of using this sort of thing in their application. I've never seen 3D Studio Max, but if that program has a similar dialog bar then they made a bad mistake in UI design.

If their isn't enough room for all those controls then as others have said think about tabs or put the less-often used controls in dialog boxes where they belong. At least with a tab the user has some indication that there is more there. As it is, you may have no idea there are more controls and even if you do clicking and dragging the dialog bar is something many people would never think of.

Oh, and why does the dialog bar have a gripper when it can't be undocked?

GeneralRe: Sorry, not cool at all Pin
John Aspras2-Apr-02 20:48
John Aspras2-Apr-02 20:48 
GeneralRe: Sorry, not cool at all Pin
ZHANG Yan8-May-02 21:21
ZHANG Yan8-May-02 21:21 
GeneralRe: Sorry, not cool at all Pin
Anonymous20-Aug-02 12:50
Anonymous20-Aug-02 12:50 
GeneralRe: Sorry, not cool at all - cool code, but stupid reader! Pin
Anonymous-219-Aug-02 0:09
sussAnonymous-219-Aug-02 0:09 
GeneralRe: Sorry, not cool at all - cool code, but stupid reader! Pin
Anonymous-219-Aug-02 0:09
sussAnonymous-219-Aug-02 0:09 
GeneralRe: Sorry, not cool at all Pin
cwtung10-Apr-03 21:43
cwtung10-Apr-03 21:43 
GeneralRe: Sorry, not cool at all Pin
aguest22-Apr-03 19:22
aguest22-Apr-03 19:22 
GeneralRe: Sorry, not cool at all Pin
doublej7-Nov-03 3:45
doublej7-Nov-03 3:45 
GeneralRe: Sorry, not cool at all Pin
Synetech29-Oct-04 9:43
Synetech29-Oct-04 9:43 
GeneralRe: Sorry, not cool at all Pin
cwtung14-Aug-07 19:43
cwtung14-Aug-07 19:43 
GeneralGood work. Just a problem! Pin
26-Feb-02 11:04
suss26-Feb-02 11:04 
GeneralRe: Good work. Just a problem! Pin
John Aspras6-Mar-02 1:59
John Aspras6-Mar-02 1:59 
QuestionUsability issue? Pin
18-Feb-02 20:29
suss18-Feb-02 20:29 
AnswerRe: Usability issue? Pin
Christian Graus18-Feb-02 23:34
protectorChristian Graus18-Feb-02 23:34 
GeneralRe: Usability issue? Pin
Thomas Freudenberg18-Feb-02 23:54
Thomas Freudenberg18-Feb-02 23:54 
AnswerRe: Usability issue? Pin
Mitchell19-Feb-02 4:42
Mitchell19-Feb-02 4:42 
AnswerRe: Usability issue? Pin
Bjoern Graf19-Feb-02 5:48
Bjoern Graf19-Feb-02 5:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.