Dialog Box Zoom In/Out Special Effect

You click on the Push Button

A dialog begins to grow to its original size in both directions

Grown full in height ,but still growing in width ...

Done.

Environment: Windows

In this article I discuss how you can add an extra touch to the way your dialog pop up on the screen . This gives your application that extra GUI special effect using Timer() & MoveWindow() functions .

Once you do a DoModal() on a dialog , quicker than a snap of your fingers, you will have the dialog on the screen. Wouldn't it be nice to add an extra touch to the way the dialog appears? How about giving the effect of zooming in or zooming out once you intend to put a new dialog on the screen, or smoothly removing out off the screen? A zooming in technique is shown here. I am sure you'll be able to implement zooming out by following the logic in the code presented here.

There are 2 parameters (int dx ,dy) that govern the speed of horizonatal stretch and vertical ones of a dialog. Both are modifiable as well as the timeslice that is hardcoded in

::SetTimer(this->m_hWnd, IDT_TIMER3,10 , NULL); 

These 3 parameters can control the way you want your dialoge box to be zoomied in or out.

Have a go at the sample demo. I am sure you will have a few ideas of your own to throw.

Feel free to contact me if you have ay question.

MAX( 10/1000 * Width/Dx ,  10/1000 * Height/Dy ) =
        Time for Dialog to appear

NOTE:There is a possible error in size by +/- (Dx-1) in width or +/- (Dy-1) in height from the origial size of the Dialog .

// FlashDlg.cpp : implementation file
//

#include "stdafx.h"
#include "FashDlg.h"
#include "FlashDlg.h"

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

///////////////////////////////////////////////////
// FlashDlg dialog

FlashDlg::FlashDlg(CWnd* pParent /*=NULL*/)
   : CDialog(FlashDlg::IDD, pParent)
{
   //{{AFX_DATA_INIT(FlashDlg)
      // NOTE: the ClassWizard will add member 
      //       initialization here
   //}}AFX_DATA_INIT
}


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


BEGIN_MESSAGE_MAP(FlashDlg, CDialog)
   //{{AFX_MSG_MAP(FlashDlg)
   ON_WM_TIMER()
   //}}AFX_MSG_MAP
END_MESSAGE_MAP()

////////////////////////////////////////////////////
// FlashDlg message handlers

BOOL FlashDlg::OnInitDialog() 
{
  CDialog::OnInitDialog();
  
  // TODO: Add extra initialization here

//==============================================Saeed
  CRect dlgRect;
  GetWindowRect(dlgRect);

  CRect desktopRect;
  GetDesktopWindow()->GetWindowRect(desktopRect);

  MoveWindow(
    (desktopRect.Width() - dlgRect.Width()) / 2,
    (desktopRect.Height() - dlgRect.Height()) / 2, 
    dlgRect.Width(), dlgRect.Height() );
      MoveWindow(
    (desktopRect.Width() - dlgRect.Width()) / 2,
    (desktopRect.Height() - dlgRect.Height()) / 2, 
    0,
    0 );
  nWidth=dlgRect.Width();
  nHeight=dlgRect.Height();
  dx=1; // you can modify this
  dy=4; // you can modify this
  ::SetTimer(this->m_hWnd, IDT_TIMER3,10 , NULL);
//====================================================

  

  return TRUE;  // return TRUE unless you set the 
                //       focus to a control
                // EXCEPTION: OCX Property Pages should
                //            return FALSE
}

void FlashDlg::OnTimer(UINT nIDEvent) 
{
  // TODO: Add your message handler code here and/or 
  //       call default

//=============================================Saeed
  CRect dlgRect;
  GetWindowRect(dlgRect);
  CRect desktopRect;
  GetDesktopWindow()->GetWindowRect(desktopRect);
  if(nIDEvent == IDT_TIMER3)
  {
    MoveWindow(
    (-dx+desktopRect.Width() - dlgRect.Width()) / 2,
    (-dy+desktopRect.Height() - dlgRect.Height()) / 2, 
     +dx+dlgRect.Width(),
     +dy+dlgRect.Height() );

    if(dlgRect.Width() >=nWidth) 
      dx=0; // do not over grow
    if(dlgRect.Height() >=nHeight)
      dy=0; // do not over grow
  }
  if((dlgRect.Width() >=nWidth) && 
              (dlgRect.Height() >=nHeight))
    // Stop the timer:
    ::KillTimer(this->m_hWnd, IDT_TIMER3);

//===============================================
  CDialog::OnTimer(nIDEvent);
}


// stdafx.h : include file for standard system
//  include files, or project specific include files that 
//  are used frequently, but are changed infrequently
//

#if !defined(
  AFX_STDAFX_H__11C9DE08_759C_11D5_9375_0006296FFBCA__INCLUDED_)
#define AFX_STDAFX_H__11C9DE08_759C_11D5_9375_0006296FFBCA__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#define VC_EXTRALEAN  // Exclude rarely-used stuff 
                      //     from Windows headers

#include       // MFC core and standard components
#include       // MFC extensions
#include      // MFC Automation classes
#include     // MFC support for Internet Explorer 4
                         //           Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include   // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT

#define IDT_TIMER3    WM_USER +0x0100 //Saeed

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations 
// immediately before the previous line.

#endif 

Downloads

Download demo project - 340 Kb
Download source - 6 Kb