|
-
August 20th, 2001, 04:35 PM
#1
getting animation using doc redraw
This is similar to a post that I put on the beginner thread but I haven't yet been able to get a solution.
I have a simple SDI program and I am trying to handle a message from the menu in two different ways. One way, I handle the message in CFlashView and the other way, I handle the message in CFlashDoc. What I am trying to do is make the client area of a window flash through a bunch of colors - the real point is that I want to refresh a view that uses document information from the document. I think that there are three important parts of code from the two different methods:
1) CFlashView::OnFileRun()
2) CFlashDoc::OnFileRun()
3) CFlashView::OnDraw <--- not really that important
When I do this by putting the command handler in the CFlashView, it flashes the way that I want it to. When I put the command handler in CFlashDoc, it seems to run through the entire loop and then at the end, it refreshes the screen with the same picture that you get from the view but it doesn't show the intermediate colors and thus "flash".
What do I have to modify to make the screen flash if I put the command handler in the documnet?
void CFlashView::OnFileRun()
{
CFlashDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CClientDC* pDC = new CClientDC(this);
for(int x=0;x<1000;x++)
{
pDoc->m_colorPoint++;
OnDraw(pDC);
}
}
=====================
void CFlashDoc::OnFileRun()
{
for(int x=0;x<100000;x++)
{
m_colorPoint++;
UpdateAllViews(NULL);
}
}
=====================
void CFlashView::OnDraw(CDC* pDC)
{
CFlashDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CRect aRect;
pDC->GetWindow()->GetClientRect(aRect);
pDC->FillSolidRect(aRect,RGB((pDoc->m_colorPoint)%255,
(pDoc->m_colorPoint*2)%255,
(pDoc->m_colorPoint*3)%255
)
);
}
-
August 21st, 2001, 12:30 AM
#2
Re: getting animation using doc redraw
void CFlashDoc::OnFileRun()
{
for(int x=0;x<100000;x++)
{
m_colorPoint++;
UpdateAllViews(NULL);
MSG msg;
while( ::PeekMessage(&msg,NULL, 0, 0, PM_REMOVE)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
Rating isn't important...But gurus respect it and keep high
-
August 21st, 2001, 11:28 AM
#3
Re: getting animation using doc redraw
GREAT!!! That solves the problem though I still haven't figured out exactly what it's doing. A thing that I've noticed is that there is alot more screen flicker when I do this. I think that it redraws the entire screen instead of just the modified areas. Is there any way to just do the modified regions? If not, I can just put this back in each view or the mainframe where I can do an OnDraw.
Thank you very much
-
August 21st, 2001, 11:42 AM
#4
Re: getting animation using doc redraw
hi there, is it possible to let me have a look at that program you are writing? A sample
will do too!
thanks
-
August 22nd, 2001, 02:29 AM
#5
Re: getting animation using doc redraw
Typically you should not perform any drawing directly from OnUpdate. Instead, determine the rectangle describing, in device coordinates, the area that requires updating; pass this rectangle to CWnd::InvalidateRect. You could pass the rectangle via second parameter of UpdateAllViews:
RECT rect;
UpdateAllViews(NULL, (LPARAM)&Rect);
Rating isn't important...But gurus respect it and keep high
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|