Solved

AnimateWindow and Onpaint

Posted on 2006-06-28
7
1,776 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
Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

 
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

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!

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

624 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