Click here to Skip to main content
15,890,579 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.3K   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

 
PraiseI don't konw what i should fill here Pin
Member 1334380822-Sep-17 16:22
Member 1334380822-Sep-17 16:22 
Generalyes but... legal issues Pin
stormydaniels13-Nov-08 4:53
stormydaniels13-Nov-08 4:53 
QuestionHow do I replace m_inner with a sheet Pin
akira3230-Oct-08 0:57
akira3230-Oct-08 0:57 
QuestionHelp to use the buttons on it Pin
master_pgl30-Oct-07 20:59
master_pgl30-Oct-07 20:59 
GeneralGreat effort indeed (to author) Pin
Ali Imran Khan Shirani30-Jul-06 1:34
Ali Imran Khan Shirani30-Jul-06 1:34 
GeneralProblem CInnerDlg is not "inside" my Container Pin
peca200610-Jun-06 23:35
peca200610-Jun-06 23:35 
Generalgreat job, can you helpl me to figure out this problem, thanks a lot Pin
Ray Guan25-Jul-05 22:47
Ray Guan25-Jul-05 22:47 
Mr. John,
firstly, thanks for your great job ,

BTW, can you help me figure out this problem , a dialogbar problem.
i just posted it on the message board, i copy them here ,thank you in advance

============================================================
hi, all
a problem trouble me for a long time. Dead | X|
and i have been looking for the answer for a long time.
but i still can't solve it,i hope somebody can give me a
little suggestion. thanks in advance.

my dev platform: MFC 7 & Windows Server 2003
my question:

i want to subclass my checkbox on a dialogbar, and load my bitmap
to the checkbox's face.

all of my checkbox were set to push like style here
owner-draw mode was set to true .

in headfile MyDialogBar.h
====================================================
CBitmapButton m_btnCheck;<br />
BOOL InitButtons();

====================================================

in cppfile MyDialogBar.cpp
====================================================
BOOL CMyDialogBar::InitButtons()<br />
{<br />
   <pre>m_btnCheck.SubclassDlgItem(IDC_TOOLBTN_SELECT, this);	<br />
	m_btnCheck.LoadBitmaps(IDB_BITMAP_ICON_SELECT);</pre><br />
}

====================================================

in headfile MainFrm.h
====================================================
CMyDialogBar m_myDlgbar;
====================================================

in cppfile MainFrm.cpp
====================================================
int CMainFrm::OnCreate(...)<br />
{<br />
<pre>	if(!m_myDlgbar.Create(...))<br />
        {<br />
           TRACE0("sorry >_< ");<br />
           return -1;<br />
        };	<br />
	m_myDlgbar.InitButtons();</pre><br />
}

====================================================

Notes:
IDB_BITMAP_ICON_SELECT is a ID of bitmap resource file created by resource editor , i want this bitmap loaded on the checkbox button.

IDC_TOOLBTN_SELECT is the ID of the CheckBox

the checkbox can works fine, but i just cannot put my bitmap on it. why??
Confused | :confused: Confused | :confused:
i used to subclass my checkbox and load a bitmap on its face for many times
in common dialog application , there is no problems. why i use it in dialogbar, it doesn't work, and no error occured , the checkbox button works
fine.Confused | :confused:

i found something seems to be useful on MS KB, i rewrite my code , and it still does not work, D'Oh! | :doh:
http://support.microsoft.com/kb/185672

anybody here met this problems before?
can you get me out of this swampCry | :(( ? can anybody post some related sample code or links here ? thank you very much Wink | ;)

any suggestion should be appreciated!Smile | :) Rose | [Rose]


sincerely,
nickong

Today is a gift, that's why we call it present
QuestionHow to make a Dockable "TabPan" with this DialogBar just like 3DS MAX ? Pin
sgy2321-Dec-03 23:22
sgy2321-Dec-03 23:22 
AnswerRe: How to make a Dockable &quot;TabPan&quot; with this DialogBar just like 3DS MAX ? Pin
imsniper15-Jan-04 3:36
imsniper15-Jan-04 3:36 
QuestionHow to map messages back to the main frame? Pin
Bubba214618-Jul-03 3:48
Bubba214618-Jul-03 3:48 
AnswerRe: How to map messages back to the main frame? Pin
Bubba214621-Jul-03 5:06
Bubba214621-Jul-03 5:06 
GeneralRe: How to map messages back to the main frame? Pin
WREY3-Jun-04 18:43
WREY3-Jun-04 18:43 
Generaldoesn't always work Pin
Stober1-Jul-03 10:07
Stober1-Jul-03 10:07 
GeneralAwesome, but I have problems Pin
Turok_4_2_023-May-03 7:33
Turok_4_2_023-May-03 7:33 
GeneralThanks a lot Pin
cwtung10-Apr-03 21:33
cwtung10-Apr-03 21:33 
GeneralRe: Thanks a lot Pin
imsniper18-Apr-03 0:19
imsniper18-Apr-03 0:19 
GeneralRe: Thanks a lot Pin
cwtung14-Aug-07 18:51
cwtung14-Aug-07 18:51 
QuestionHow to make it slide? Pin
Jinming Xu10-Apr-03 9:16
Jinming Xu10-Apr-03 9:16 
AnswerRe: How to make it slide? Pin
Anonymous22-Apr-03 1:39
Anonymous22-Apr-03 1:39 
Generalthere is a control better than this already in Code Project Pin
konqueror22-Jan-03 23:47
konqueror22-Jan-03 23:47 
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 

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.