Click here to Skip to main content
15,895,746 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
// SlidingDemoDlg.cpp : implementation file
//

#include "stdafx.h"
#include "SlidingDemo.h"
#include "SlidingDemoDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CSlidingDemoDlg dialog

CSlidingDemoDlg::CSlidingDemoDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSlidingDemoDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSlidingDemoDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	m_bOpen = FALSE;
}

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

BEGIN_MESSAGE_MAP(CSlidingDemoDlg, CDialog)
	//{{AFX_MSG_MAP(CSlidingDemoDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(ID_OPEN, OnOpen)
	ON_BN_CLICKED(ID_CLOSE, OnClose)
	ON_WM_MOVE()
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_CLOSE_SLIDING,OnClose)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSlidingDemoDlg message handlers

BOOL CSlidingDemoDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CSlidingDemoDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CSlidingDemoDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CSlidingDemoDlg::OnOpen() 
{
	// TODO: Add your control notification handler code here
	if (!m_bOpen)
	{
	this->m_pModelles = new CSlide(this);
		if (this->m_pModelles->GetSafeHwnd()==0)
		{
			m_pModelles->Create();
			m_pModelles->SetSlideSpeed(MID);
			
			m_pModelles->SetSlideDirection(RIGHT);


			m_pModelles->StartSlide();
			m_bOpen = TRUE;
			
		}
	}
	
}


void CSlidingDemoDlg::OnClose() 
{

	// TODO: Add your control notification handler code here
	if (m_bOpen)
	{
		m_pModelles->Close();
		delete 	m_pModelles;
		m_bOpen = FALSE;

	}
	
}

void CSlidingDemoDlg::OnMove(int x, int y) 
{
	CDialog::OnMove(x, y);
	
	// TODO: Add your message handler code here

	if (m_bOpen)
	{

		m_pModelles->RePosition();
		

	}

	
}

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