Solved

AnimateWindow and Onpaint

Posted on 2006-06-28
7
1,760 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
Industry Leaders: 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Suggested Courses

734 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