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 …


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__;

// FlashDlg dialog

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


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



// FlashDlg message handlers

BOOL FlashDlg::OnInitDialog()

// TODO: Add extra initialization here


CRect dlgRect;

CRect desktopRect;

(desktopRect.Width() – dlgRect.Width()) / 2,
(desktopRect.Height() – dlgRect.Height()) / 2,
dlgRect.Width(), dlgRect.Height() );
(desktopRect.Width() – dlgRect.Width()) / 2,
(desktopRect.Height() – dlgRect.Height()) / 2,
0 );
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

CRect dlgRect;
CRect desktopRect;
if(nIDEvent == IDT_TIMER3)
(-dx+desktopRect.Width() – dlgRect.Width()) / 2,
(-dy+desktopRect.Height() – dlgRect.Height()) / 2,
+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);


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

#if !defined(
#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

#include // MFC support for Windows Common Controls

#define IDT_TIMER3 WM_USER +0x0100 //Saeed

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



Download demo project – 340 Kb

Download source – 6 Kb

More by Author

Previous articlePOP3 Wrapper Class 2001
Next articleSafe Win32 Timer

Must Read