Solved

AnimateWindow and Onpaint

Posted on 2006-06-28
7
1,721 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

757 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now