Click here to Skip to main content
15,791,440 members
Articles / Desktop Programming / MFC

Sliding Dialog Windows

Rate me:
Please Sign up or sign in to vote.
4.83/5 (7 votes)
13 Feb 20012 min read 110.7K   3.9K   52   19
Simple version of sliding dialog windows like MS Media Player 7

Sample Image - SlidingDialog.jpg


This Source Code is for building a sliding dialog, one that slide's out from under another dialog. I have seen someone who already did it, but this code is easier to understand and I have implemented it in a different (and better) way. The OnTop class can be used with any Dialog. There can even be more than one sliding dialog associated with parent-dialog.

Steps To A Working Sliding Dialog

  1. Create a MFC dialog based application.
  2. Create a dialog resource using the resource editor, and then create the dialog class to associate with the dialog resource using class wizard.
  3. Add SlidingSon.h and SlidingSon.cpp to your Workspace
  4. Add a SlideSon.h include directive to your dialog class header.
  5. In your newlly created dialog class replace the base class in the associated header file to CSlideSon from CDialog.
  6. Do the same thing in the dialog's implementation file. Do not forget to replace class name in the BEGIN_MESSAGE_MAP declaration.
  7. In order to make this dialog modeless, add a create member function to your dialog header with no parameters.
  8. In the dialog's implementation file add the create function as follows:
    return CSlideSon::Create(<<Your dialog class name>>::IDD);
  9. Add a button to your main application dialog to open / close the sliding dialog, or use any other event to open the sliding dialog.
  10. I recommend adding a boolean value to your main application dialog class which will indicate the state of the SlidingSon. Because we create a modeless dialog, you will have to add a member variable that will point to your sliding dialog class object.
    <<Your sliding dialog class name>>* m_pModeless;
  11. When you wish to slide the dialog out, use the following code in your application dialog event handlers:
    m_pModeless = new <<Your sliding dialog class name>>(this);
    if (<<Your sliding dialog class name>> ->GetSafeHwnd()==0)
  12. Note that you can control the sliding speed with integer values and slide direction (RIGHT, LEFT)
  13. When you wish to close the dialog use the following code:
    delete m_pModelles;
  14. To slide the dialog back when you press the cancel\ok button of the sliding dialog, add the following line after
    ON_MESSAGE(WM_CLOSE_SLIDING,OnClose)  // OnClose or any event handling 
                                          // function
  15. You can change the ratio between the sliding dialog and its father in the SlidingSon.cpp
  16. Catch the OnMove() event for the main application dialog, and call m_pModelled->RePosition(), to update the sliding dialog’s position.


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
Israel Israel
C++ Developer

Comments and Discussions

GeneralCould you please tell me how to slide multiple dialog in mfc. Pin
narmada Padhy10-Feb-11 1:01
narmada Padhy10-Feb-11 1:01 
Could you please tell me how to slide multiple dialog in mfc. i-e let us suppose we have two dialog dialog1 and dialo2. i want when i click on left dialog1 will move to left and dialog2 will come in place on dialog1. Cry | :((
Generalbug Pin
guyuewuhua14-Aug-09 0:18
guyuewuhua14-Aug-09 0:18 
QuestionRestore Dialog doesnt work Pin
SiHot3-Jul-07 4:42
SiHot3-Jul-07 4:42 
GeneralVery Nice Application.... Pin
RajeevSahu23-May-07 18:45
RajeevSahu23-May-07 18:45 
Generaltop and bottom Pin
pekto28-Nov-06 22:47
pekto28-Nov-06 22:47 
GeneralNeat codes! Pin
GrabBot3-Oct-06 18:32
GrabBot3-Oct-06 18:32 
GeneralGood Work... Pin
sony_synco12-Aug-06 5:15
sony_synco12-Aug-06 5:15 
GeneralNice, but little bug Pin
sheny11-Jul-06 22:12
sheny11-Jul-06 22:12 
GeneralRe: Nice, but little bug Pin
GrabBot3-Oct-06 18:36
GrabBot3-Oct-06 18:36 
GeneralAlso see AnimateWindow() - Win2K only Pin
Ravi Bhavnani9-Oct-01 4:46
professionalRavi Bhavnani9-Oct-01 4:46 
GeneralGreat Job! Pin
RobJones25-Sep-01 11:31
RobJones25-Sep-01 11:31 
GeneralRe: Great Job! Pin
narmada Padhy9-Feb-11 23:04
narmada Padhy9-Feb-11 23:04 
GeneralRe: Great Job! Pin
narmada Padhy9-Feb-11 23:05
narmada Padhy9-Feb-11 23:05 
GeneralSize of the sliding window Pin
1-Aug-01 5:23
suss1-Aug-01 5:23 
GeneralSize of the sliding window Pin
1-Aug-01 5:21
suss1-Aug-01 5:21 
28-Feb-01 17:14
suss28-Feb-01 17:14 
Newton111-May-01 11:10
Newton111-May-01 11:10 
GeneralMemory leak detected Pin
Newton114-Feb-01 19:39
Newton114-Feb-01 19:39 
GeneralRe: Memory leak detected Pin
6-May-01 18:36
suss6-May-01 18:36 

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.