Sliding Dialogs


I was fascinated by the motion of dialog box in the Microsoft Windows Media Player 7. When in compact mode, the act of selecting the playlist results in a dialog literally sliding out from behind the main dialog! Therefore, with this code, I present a means for you to include this user interface element in your applications.

Implementing the Code

The key to making this work is the SetTimer and SetWindowPos functions. The following step-by-step demo will illustrate how you can implement this functionality in your own dialog-based applications.
  1. Using the ClassWizard, create a dialog-based application named SlidngDoor
  2. Create a second dialog template resource (the ID is unimportant for this demo)
  3. Using the ClassWizard, create a CDialog-derived class for your new dialog called CChild
  4. Add the following two member variables to your dialog application's class (CSlidingDoorApp)
  5. RECT RectMainWndPos;
    BOOL b_child_hide;
  6. Add the following line of code to the application's object's constructor (CSlidingDoorApp::CSlidingDoorApp)
  7. b_child_hide=TRUE;
  8. Add the following lines to the main dialog's declaration
  9. CChild Cdlg_child;
    RECT RectMainWndPos;
  10. Add an include directive to the top of the dialog's header file (SlidingDoorDlg.h)
  11. Add the following two declarations to the main dialog class (CSlidingDoorDlg)
  12. CChild Cdlg_child;
    RECT RectMainWndPos;
  13. Add the following to the CSlidingDoorDlg::OnInitDialog member function
  14. SetWindowPos( NULL,300,300,270,270,SWP_NOZORDER);
  15. Using the ClassWizard, add a handler to the CSlidingDoorDlg for the WM_MOVE message and modify it so that when finished the CSlidingDoorDlg::OnMove member function looks like the following. This will take care of repositioning the child dialog in case the user moves the parent dialog.
    void CSlidingDoorDlg::OnMove(int x, int y) 
     CDialog::OnMove(x, y);
     // TODO: Add your message handler code here
  16. Now add the actual repositiong code to the CSlidingDoorDlg class by adding the followingmember function.
  17. void CSlidingDoorDlg::ChildWndReposition()
     CSlidingDoorApp *pApp=(CSlidingDoorApp *)AfxGetApp();
      Cdlg_child.SetWindowPos(GetParent(), RectMainWndPos.right,,
  18. Next, in the CSlidingDoorDlg class add the following call whereever you want the child dialog to slide out from behind the main dialog
  19. Cdlg_child.StartSliding();
  20. Add the following member variables to the CChild dialog class
  21. RECT RectMainWndPos;
    int m_sizey;
    int m_childwidth;
    int m_childdepth;
    CSlidingDoorApp *pApp;
  22. Add the following initialization code to the CChild::CChild constructor
  23. m_childdepth=248;
  24. Now, you need to implement the Child::StartSliding member function as follows. Note that this function will take care of toggling whether or not it needs to display or hide the child dialog.
    void CChild::StartSliding()
  25. As you saw in the previous CChild member function, a timer is used to "slide" the child dialog out from behind the parent dialog. Using the ClassWizard, add a handler to the CChild dialog class and modify it so that when finished, it looks like the following.
    void CChild::OnTimer(UINT nIDEvent) 
     int nWidth=m_childwidth/25;
       SetWindowPos(GetParent() ,RectMainWndPos.left+m_sizey*nWidth,,
     if(pApp->b_child_hide && m_sizey*nWidth>=m_childwidth)

At this point, you should now be enjoying the UI benefits of the sliding dialog! Enjoy!


Download demo project - 12 Kb


Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds