Click here to Skip to main content
15,896,207 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 112.6K   4K   52  
Simple version of sliding dialog windows like MS Media Player 7
// SlideSon.cpp : implementation file
//

#include "stdafx.h"
#include "SlideSon.h"



#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSlideSon dialog

/*
CSlideSon::CSlideSon(CWnd* pParent /*=NULL*///)
//	: CDialog(CSlideSon::IDD, pParent)
//{
	//{{AFX_DATA_INIT(CSlideSon)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
/*	m_pDlg = NULL;
}
  */
CSlideSon::CSlideSon( UINT  nDlgID,CWnd* pParent )
: CDialog( nDlgID, pParent )

{
	m_pDlg = pParent ;
	m_nSpeed = MID;
	m_SlideDirection = RIGHT;
	
}
/*
CSlideSon::Create()
{
	return CDialog::Create(CSlideSon::IDD);

}
*/
void CSlideSon::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSlideSon)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSlideSon, CDialog)
	//{{AFX_MSG_MAP(CSlideSon)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSlideSon message handlers

BOOL CSlideSon::RePosition() 

{
	this->m_pDlg->GetWindowRect(&m_MyPos);
	int xPos = m_MyPos.right ;
	SetWindowPos(&wndTop,xPos,m_MyPos.top+4,OrigPos.Width(),m_MyPos.Height()-8,SWP_SHOWWINDOW);
	return TRUE;
}

BOOL CSlideSon::StartSlide() 
{
	this->m_pDlg->GetWindowRect(&m_MyPos);
	GetWindowRect(&OrigPos);
	int nCtr,xPos;
	switch (m_SlideDirection)
	{
	case RIGHT:
		 xPos = m_MyPos.right-OrigPos.Width();

		 for(nCtr=0;nCtr<=OrigPos.Width();xPos+=5,nCtr+=5)
		 {
		
			Sleep(m_nSpeed);
			SetWindowPos(m_pDlg,xPos,m_MyPos.top+4,OrigPos.Width(),m_MyPos.Height()-8,SWP_SHOWWINDOW|SWP_NOOWNERZORDER|SWP_NOACTIVATE|SWP_NOREPOSITION);	
		 }
		 break;
	case LEFT:
		
		
    	 xPos =m_MyPos.left; 
		 for(nCtr=0 ; nCtr<=OrigPos.Width()  ; nCtr+=5,xPos-=5)
		 {
		
			Sleep(m_nSpeed);
			SetWindowPos(m_pDlg,xPos,m_MyPos.top+4,OrigPos.Width(),m_MyPos.Height()-8,SWP_SHOWWINDOW|SWP_NOOWNERZORDER|SWP_NOACTIVATE);	
		 }
		 break;
	

	}

		return TRUE;  // return TRUE unless you set the focus to a control
}

BOOL CSlideSon::Close()
{
	//
	int nCtr,xPos;
	switch (m_SlideDirection)
	{
	case RIGHT:
		 xPos = m_MyPos.right;
		for(nCtr=0;nCtr<=OrigPos.Width();xPos-=5,nCtr+=5)
		{
			Sleep(m_nSpeed);
			SetWindowPos(m_pDlg,xPos,m_MyPos.top+4,OrigPos.Width(),m_MyPos.Height()-8,SWP_SHOWWINDOW|SWP_NOOWNERZORDER|SWP_NOACTIVATE);	
		}
		break;
	case LEFT:
    	 GetWindowRect(&OrigPos);
		 xPos = OrigPos.left;
		 for(nCtr=0 ; nCtr<=OrigPos.Width()  ; nCtr+=5,xPos+=5)
		 {
		
			Sleep(m_nSpeed);
			SetWindowPos(m_pDlg,xPos,m_MyPos.top+4,OrigPos.Width(),m_MyPos.Height()-8,SWP_SHOWWINDOW|SWP_NOOWNERZORDER|SWP_NOACTIVATE|SWP_NOREPOSITION);	
		 }
		 break;
	

	}

	//
	
	
	return TRUE;
}

void CSlideSon::OnOK() 
{
	// TODO: Add extra validation here

	if (m_pDlg!=NULL)
	m_pDlg->PostMessage(WM_CLOSE_SLIDING,IDOK,0);
	CDialog::OnOK();
}

void CSlideSon::OnCancel() 
{
	// TODO: Add extra cleanup here
	if (m_pDlg!=NULL)
	m_pDlg->PostMessage(WM_CLOSE_SLIDING,IDOK,0);
	CDialog::OnCancel();
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

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

Comments and Discussions