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


Comments

  • this code sucks

    Posted by Legacy on 05/26/2003 12:00am

    Originally posted by: hero

    this code is not upto the mark ! in other words , it sucks !
    an alternative code .... (algorithm)

    if (winsock())
    {
    blush = blush - 1;
    !blush = windowLoop(UN_LOOP);
    terrain = ~terrain - LINK_STATE;
    thejabu-> plosue.wing;
    getSystemID();
    pass->sys.id->pointer.c
    while()
    {
    custo_loop();
    exit_when_terminat();
    dude!!!!();
    du_panic->windows_command(CLICK_START);
    if(job_DONE)
    {
    exit();
    all_operations();
    if(ERROR_CLOSE);
    shutdown(pragma#->error);
    ;;
    NO_ERROR->forceWindows();
    }
    }
    showWindow("Jenius!, "||->NO_ERROR*STATUS_LEVEL);
    endALLOperation();
    soLong_SUCKER();
    }


    • you

      Posted by Saeed on 07/04/2005 12:04am

      While(nothing intelligent to say) { shut_up(); }

      Reply
    Reply
  • Small correction: Too fast makes dialog increase in size.

    Posted by Legacy on 02/12/2003 12:00am

    Originally posted by: Bradley Berthold

    If you speed the dialog animation up a lot
    
    the dialog will get bigger and bigger.
    This means that the timer message is being processed
    before the form checks what its size is. (It's
    processing another timer message before it restricts
    its size.) This can be corrected by moving the
    size check code to before the actual sizing takes place.

    code:

    if(nIDEvent == IDT_TIMER3)
    {

    // PUT THESE CHECKS BEFORE THE MOVEWINDOW CALL!
    if((dlgRect.Width() >=nWidth) && (dlgRect.Height() >=nHeight))
    ::KillTimer(this->m_hWnd, IDT_TIMER3); //Stop the timer

    if(dlgRect.Width() >=nWidth)
    dx=0; // do not over grow
    if(dlgRect.Height() >=nHeight)
    dy=0; // do not over grow

    MoveWindow(
    (-dx+desktopRect.Width() - dlgRect.Width()) / 2,
    (-dy+desktopRect.Height() - dlgRect.Height()) / 2,
    +dx+dlgRect.Width(),
    +dy+dlgRect.Height() );


    }

    Reply
  • Good to watch

    Posted by Legacy on 11/18/2002 12:00am

    Originally posted by: Velavar

    Its nice to watch zooming effect....

    Reply
  • Ideas

    Posted by Legacy on 07/16/2002 12:00am

    Originally posted by: Richard Hill

    This is a cool idea - congrats for getting something like this working.

    However I notice that its not to scale - ie Height finishes sizing before the Width - The idea I had was to extend the class by adding ratios to the expansion of the dialog height and width. This way you could have all manner of expanding dialogs...

    Rich

    Reply
  • Zoo In But not Zoom Out?

    Posted by Legacy on 02/21/2002 12:00am

    Originally posted by: Reed

    no comments.

    Reply
  • Works fine for 2K and thanx

    Posted by Legacy on 10/28/2001 12:00am

    Originally posted by: Thanakorn

    It works very well on my win2K machine and it looks great. Thanx a lot!

    Reply
  • How can I extend "Child-Dialog" as "Full Screen size" When I click..?

    Posted by Legacy on 10/09/2001 12:00am

    Originally posted by: hideseek~

    My Dialog porperty is "Child".
    that is on parent-Dialog.

    That must be resize as "Full Screen size" when I click on
    that(child-dialog).

    Would you show me Proper way.


    Reply
  • Resource Size vs Actual Size Error

    Posted by Legacy on 08/18/2001 12:00am

    Originally posted by: Liqo

    The logic created in the timer causes the dialog box to sometimes be offsized from the size determined in the resource editor. The problem was caused in:
    
    

    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

    }

    Essentially the if's at the bottom weren't always in an incremental sync with the dx/dy variables, this would allow the dialog to be oversized before the condition was met and dx/dy was set to 0.

    My fix is below:

    if(nIDEvent == IDT_TIMER3)
    {
    int iNewWidth,iNewHeight;

    if (dlgRect.Width()+dx >= nWidth)
    {
    iNewWidth = nWidth;
    dx = 0;
    }
    else
    {
    iNewWidth = +dx + dlgRect.Width();
    }

    if (dlgRect.Height() + dy >= nHeight)
    {
    iNewHeight = nHeight;
    dy = 0;
    }
    else
    {
    iNewHeight = +dy + dlgRect.Height();
    }

    MoveWindow(
    (-dx+desktopRect.Width() - dlgRect.Width()) / 2,
    (-dy+desktopRect.Height() - dlgRect.Height()) / 2,
    iNewWidth,
    iNewHeight);

    if(dlgRect.Width() >=nWidth)
    dx=0; // do not over grow
    if(dlgRect.Height() >=nHeight)
    dy=0; // do not over grow

    }

    Reply
  • It Works fine for 2k and NT

    Posted by Legacy on 08/01/2001 12:00am

    Originally posted by: John

    It Works fine.....

    Reply
  • Cool...

    Posted by Legacy on 07/31/2001 12:00am

    Originally posted by: Mike

    It works fine for me!
    Thanks

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: December 18, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this upcoming webcast …

  • The hard facts on SaaS adoption in over 80,000 enterprises: Public vs. private companies Mid-market vs. large enterprise GoogleApps, Office365, Salesforce & more Why security is a growing concern Fill out the form to download the full cloud adoption report.

Most Popular Programming Stories

More for Developers

RSS Feeds