Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

AnimateWindow and Onpaint

Posted on 2006-06-28
7
Medium Priority
?
1,820 Views
Last Modified: 2013-11-20
Hi everybody,

I have a CDialog in which I display a colored rectangle using :
void CMyAppDlg::OnPaint()
{
      CPaintDC dc(this); // device context for painting
      CRect rDividerInfo;
      GetDlgItem(IDC_STATICRECT)->GetWindowRect(rDividerInfo);
      ScreenToClient(rDividerInfo);
      dc.FillSolidRect(rDividerInfo, RGB(251,207,111));
}

It works fine when I open this dialog using DoModal, or when I use Create(IDC_MYDIALOG) and ShowWindow(SW_SHOW)
But if I try :

HWND hwnd=myDialog->GetSafeHwnd();
BOOL bRis= AnimateWindow(hwnd, 3000, AW_SLIDE | AW_VER_POSITIVE);

the animateWindow sliding effect works, but my colored rectangle is no displayed  anymore...

Could anyone help me?

Thanks a lot!

Vincent
0
Comment
Question by:vinceTrace
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 16999925
To redraw rectangle after animation, add lines:
BOOL bRis= AnimateWindow(hwnd, 3000, AW_SLIDE | AW_VER_POSITIVE);
Invalidate();
UpdateWindow();

To redraw rectangle during animation, you ned to handle WM_PRINT message.

AnimateWindow function requirement:
The window procedures for the window and its child windows should handle any WM_PRINT or WM_PRINTCLIENT messages. Dialog boxes, controls, and common controls already handle WM_PRINTCLIENT. The default window procedure already handles WM_PRINT.

So, AnimateWindow function sends WM_PRINT message to dialog window procedure and it drawis itself using default implementation. But this default implementation doesn't include your drawing code. Try this way:
http://web2.codeproject.com/staticctrl/xhtmlstatic.asp?df=100&forumid=6192&exp=0&select=976390

See the post "needs supports for WM_PRINT".
0
 

Author Comment

by:vinceTrace
ID: 17000212
Hi,

Thanks, I still miss something... Now my dialog is only displayed when I put an other window over it, ( the sliding effect is not visible). I suppose I've not rightly dealed with OnPaint... Thanks a lot for your help

In my main dailog I call:

CMyDialogDlg* dlg=new CMyDialogDlg();
dlg->Create(IDD_MYDIALOG,this);
HWND hwnd=effec->GetSafeHwnd();
BOOL bRis = AnimateWindow(hwnd, 3000, AW_SLIDE | AW_VER_POSITIVE);

Then in MyDialogDlg.cpp I've added :

//}}AFX_MSG_MAP
      ON_MESSAGE(WM_PRINT, OnPrint)
END_MESSAGE_MAP()

and :

LRESULT CMyDialogDlg::OnPrint(WPARAM wParam, LPARAM lParam)
{
    Draw((HDC) wParam);
      DoEvents();
    return 0;
}

void CMyDialogDlg::Draw(HDC hdc)
{
    CDC    dc;
    dc.Attach(hdc);
    CRect rDividerInfo;
    GetDlgItem(IDC_STATICRECT)->GetWindowRect(rDividerInfo);
    ScreenToClient(rDividerInfo);
    dc.FillSolidRect(rDividerInfo, RGB(251,207,111));
}

void CMyDialogDlg::OnPaint()
{
      CPaintDC dc(this); // device context for painting
      Draw(dc.m_ps.hdc);
}

and in MyDialog.h

      afx_msg void OnPaint();
      //}}AFX_MSG
                                 LRESULT OnPrint(WPARAM wParam, LPARAM lParam);
      DECLARE_MESSAGE_MAP()
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 17000596
>>the sliding effect is not visible

what if you use Sleep() after AnimateWindow() something like :

AnimateWindow(hWnd, 500, AW_SLIDE or AW_VER_POSITIVE )
Sleep(1000);
AnimateWindow(hWnd, 500, AW_SLIDE or AW_VER_NEGATIVE);

-MAHESH

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 22

Expert Comment

by:mahesh1402
ID: 17000663
AnimateWindow(hWnd, 500, AW_SLIDE | AW_VER_POSITIVE )
Sleep(1000);
AnimateWindow(hWnd, 500, AW_SLIDE | AW_VER_NEGATIVE);
0
 

Author Comment

by:vinceTrace
ID: 17000798
No changes...
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 17017675
You have a problem in the following function
void CMyDialogDlg::Draw(HDC hdc)
{
    CDC    dc;
    dc.Attach(hdc);
    CRect rDividerInfo;
    GetDlgItem(IDC_STATICRECT)->GetWindowRect(rDividerInfo);
    ScreenToClient(rDividerInfo);
    dc.FillSolidRect(rDividerInfo, RGB(251,207,111));
dc.Detach();   //<<----------------------  VERY IMPORTANT TO RELEASE THE DC AFTER USE
}



I have tried this here with success  (Overrride the WindowProc of the dialog)


LRESULT CMyDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
      // TODO: Add your specialized code here and/or call the base class
      LRESULT lRes = CDialog::WindowProc(message, wParam, lParam);
      if(message == WM_PRINT)
      {
            CDC dc;
            dc.Attach((HDC)wParam);
            dc.FillSolidRect(10, 10, 100, 100, RGB(255, 0, 0));
            dc.Detach();
      }

      return lRes;
}

0
 
LVL 45

Accepted Solution

by:
AndyAinscow earned 600 total points
ID: 17017757
All you should require is

HWND hwnd=myDialog->GetSafeHwnd();
BOOL bRis= AnimateWindow(hwnd, 3000, AW_SLIDE | AW_VER_POSITIVE);

LRESULT CMyDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
     // TODO: Add your specialized code here and/or call the base class
     LRESULT lRes = CDialog::WindowProc(message, wParam, lParam);
     if(message == WM_PRINT)
     {
          CDC dc;
          dc.Attach((HDC)wParam);
      CRect rDividerInfo;
     GetDlgItem(IDC_STATICRECT)->GetWindowRect(rDividerInfo);
     ScreenToClient(rDividerInfo);
     dc.FillSolidRect(rDividerInfo, RGB(251,207,111));
          dc.Detach();
     }

     return lRes;
}
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question