This is a mirror of official site: http://jasper-net.blogspot.com/

Using the DrawAnimatedRects() function

| Friday, March 4, 2011
Introduction

If you look at MS Word and invoke the find dialog, you can see a neat animation. I wished to mimic this and came across the DrawAnimatedRects() function. The DrawAnimatedRects() function draws a wire-frame rectangle and animates it to indicate the opening of an icon, or the minimizing or maximizing of a window. The syntax is as follows:

BOOL WINAPI DrawAnimatedRects(
 HWND hwnd,            // handle to clipping window
 int idAni,            // type of animation
 CONST RECT *lprcFrom, // rectangle coordinates (minimized)
 CONST RECT *lprcTo    // rectangle coordinates (restored)
);

The lprcFrom parameter sets where the animation will start, and the lprcTo value where the animation will end. For instance, if you wish to make a window appear to expand from a button to a window, you would set lprcFrom as the dimensions of the button, and lprcTo as the dimensions of the final window position. The effect is not as good as MS Word, but if any GUI experts can provide a MS Word Sample, it will be of great help.

Using the function

The sample application demonstrates a nice use of the function. In the demo, the About Box is animated so it appears to expand and collapse from a button inside a dialog.

To achieve this, you simply override the OnCreate and OnDestroy functions in your About Box dialog class, and add calls to DrawAnimatedRects() at the appropriate places.

To make things simple, we first store the dimensions of the button where the About Box will expand from. We add a member variable m_rectFrom to the About Box class and to make the About Box appear, we use the following.

   CAboutDlg about;
   m_ctlButton.GetWindowRect(about.m_rectFrom);
   about.DoModal();

where m_ctlButton is the button control the About Box is appearing to expand from.

Next, you need to add overrides to OnCreate and OnDestroy inside your About Box class:

int CAboutDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
   if (CDialog::OnCreate(lpCreateStruct) == -1)
       return -1;

   if (!m_rectFrom.IsRectEmpty())
   {
       CRect rectTo(lpCreateStruct->x,lpCreateStruct->y,
           lpCreateStruct->x + lpCreateStruct->cx,
           lpCreateStruct->y + lpCreateStruct->cy);

       DrawAnimatedRects(m_hWnd, IDANI_CAPTION, m_rectFrom, rectTo);
   }

   return 0;
}

void CAboutDlg::OnDestroy()


Read more: Codeproject

Posted via email from Jasper-net

0 comments: