Solved

AnimateWindow and Onpaint

Posted on 2006-06-28
7
1,752 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 44

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 44

Accepted Solution

by:
AndyAinscow earned 150 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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

740 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