3D Studio Max like Slidable DialogBar






4.93/5 (27 votes)
Feb 18, 2002
1 min read

271630

8146
Ever seen 3D Studio 2.5 Slidable DialogBar? Want to know how they did it?
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
- Create any kind of
CWnd
derived class . That will be your TOP level Window (could be aCDialog
/CDialogBar
/CButton
anything...)Lets say
CDialogBarExt
....derived fromCDialogBar
. - Create a
CWnd
derived Class that will contain the actual sliding dialog.Lets say
CDlgContainer
....derived fromCWnd
- Create a member variable for
CDialogBarExt
of typeCDlgContainer
.
- Create a
CDialog
derived class .Lets say
CInnerDlg
(this is the actual sliding dialog !!!) - Create a member variable of type
CInnerDlg
forCDlgContainer
....
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); }