Urgent! InvalidateRect() doesn't work as expected. 
Author Message
 Urgent! InvalidateRect() doesn't work as expected.

Hi,All
I do all the drawing in function OnDraw(). And there are
many objects to be drawn. So the drawing efficiency is
crucial for me. In another function, I use InvalidateRect
(), expecting to refresh the selected region. But it turns
out that the whole client area along with the region is
refreshed. Why? This function works fine in VC6.0,why it
doesn't work as expected in Pocket PC?

And any advice on how to improve the drawing efficiency is
welcome.

Harry,

//////////////////
void CPocketMapView::OnDraw(CDC* pDC)
{
....
m_pGeoBmp->Draw(pDC);
m_pGeoBackground->OnDrawVector(pDC);
m_pGeoInfo->Draw(pDC);
m_pMapGrid->DrawGrid(pDC);
....

Quote:
}

void CPocketMapView::SelectObject()
{
  ...
  CRect rect;
  ...
  InvalidateRect(&rect,FALSE);
  ...
Quote:
}



Fri, 27 May 2005 20:53:04 GMT  
 Urgent! InvalidateRect() doesn't work as expected.


Quote:
> Hi,All
> I do all the drawing in function OnDraw(). And there are
> many objects to be drawn. So the drawing efficiency is
> crucial for me. In another function, I use InvalidateRect
> (), expecting to refresh the selected region. But it turns
> out that the whole client area along with the region is
> refreshed. Why? This function works fine in VC6.0,why it
> doesn't work as expected in Pocket PC?

> And any advice on how to improve the drawing efficiency is
> welcome.

I already responded to this in the thread you started before, December 4th.
Please see that.

--
--
Jason Teagle

-----------------------------------------------------------
A list of programming resources I use:
ML: www.windev.org, www.codecipher.com, www.beginthread.com
MB: www.codeguru.com, www.codeproject.com
NG: comp.lang.java.*
OI: www.php.net
-----------------------------------------------------------



Fri, 27 May 2005 21:05:02 GMT  
 Urgent! InvalidateRect() doesn't work as expected.
Thank you for your reply.

I finally found out the reason but I can't find the
solution. In my program, a thread is created to draw, and
that's where the problem arise. If I do all the drawing
directly in OnDraw(), InvalidateRect() will work as
expected. But if all drawing is put in the controlling
function for the thread , it won't.

How can I use the thread ,and still get the expected
result?

Thank you!
///////////////////////////////////////////////////////////
//////////////////
void CPocketMapView::OnDraw(CDC* pDC)
{
        if(m_pDrawThread!=NULL)
        {
                m_bDraw=FALSE;
                m_pDrawThread->ResumeThread();
                ::WaitForSingleObject(m_pDrawThread-

Quote:
>m_hThread,INFINITE);

                delete m_pDrawThread;
        }
        m_bDraw=TRUE;

        //Create thread to draw
        m_pDrawThread=AfxBeginThread((AFX_THREADPROC)
DrawBackMap,&m_hWnd,THREAD_PRIORITY_NORMAL,0,0,NULL);
        m_pDrawThread->m_bAutoDelete=FALSE;
        m_pDrawThread->ResumeThread();

Quote:
}

UINT DrawBackMap(LPVOID PHWndView)
{
        CWnd *temp_pWnd=CWnd::FromHandle(*(HWND*)
PHWndView);
        CDC  *ht=temp_pWnd->GetDC();

        if(m_bDraw)
        {
         m_pGeoBackground->Draw(ht);
         m_pMapGrid->Draw(ht);
         ......
        }

Quote:
}
>-----Original Message-----



>> Hi,All
>> I do all the drawing in function OnDraw(). And there are
>> many objects to be drawn. So the drawing efficiency is
>> crucial for me. In another function, I use
InvalidateRect
>> (), expecting to refresh the selected region. But it
turns
>> out that the whole client area along with the region is
>> refreshed. Why? This function works fine in VC6.0,why it
>> doesn't work as expected in Pocket PC?

>> And any advice on how to improve the drawing efficiency
is
>> welcome.

>I already responded to this in the thread you started

before, December 4th.

- Show quoted text -

Quote:
>Please see that.

>--
>--
>Jason Teagle

>----------------------------------------------------------
-
>A list of programming resources I use:
>ML: www.windev.org, www.codecipher.com,
www.beginthread.com
>MB: www.codeguru.com, www.codeproject.com
>NG: comp.lang.java.*
>OI: www.php.net
>----------------------------------------------------------
-

>.



Sun, 29 May 2005 17:10:47 GMT  
 Urgent! InvalidateRect() doesn't work as expected.


Quote:
> I finally found out the reason but I can't find the
> solution. In my program, a thread is created to draw, and
> that's where the problem arise. If I do all the drawing
> directly in OnDraw(), InvalidateRect() will work as
> expected. But if all drawing is put in the controlling
> function for the thread , it won't.

> How can I use the thread ,and still get the expected
> result?
> UINT DrawBackMap(LPVOID PHWndView)
> {
> CWnd *temp_pWnd=CWnd::FromHandle(*(HWND*)
> PHWndView);
> CDC  *ht=temp_pWnd->GetDC();

I believe this is the problem. When you use GetDC(), you're grabbing an
"uninitialised" DC. Instead, try passing in the pDC you're given in
OnDraw(). If your thread had a method to accept the current DC, this can
then be updated each time OnDraw() is called.

Also, shouldn't the "// Create thread to draw" bit be in an else clause?
Otherwise, it will create a new thread every time it paints even if the
thread already existed, would it not?

May I ask why you're using a thread to do the drawing anyway? Threads are
generally used to accomplish non-GUI tasks so that the GUI can remain
responsive - there seems to be no advantage in using a thread to do the
drawing when you're waiting for it to finish drawing anyway?

--
--
Jason Teagle

-----------------------------------------------------------
A list of programming resources I use:
ML: www.windev.org, www.codecipher.com, www.beginthread.com
MB: www.codeguru.com, www.codeproject.com
NG: comp.lang.java.*
OI: www.php.net
-----------------------------------------------------------



Sun, 29 May 2005 17:57:55 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. __unhook doesn't work as expected

2. explicit declaration doesn't work as expected

3. Update command UI doesn't work as I expect

4. ValidateRect() doesn't work, Urgent

5. vc++ 6.0 stl doesn't behave as expected

6. GetCurrentDirectory doesn't return what I expect on Windows98

7. CEdit.SetSel don't work as expected

8. Why isn't GetMenuItemRect working as expected.

9. SaveBarState (WORKS) LoadBarState(Doesn't Work)?

10. GetPrivateProfileSectionNames works in 2000, doesn't work in 98 or ME

11. Tooltip works and then doesn't work

12. Q147740 CWnd work-around doesn't work with control that uses lic file

 

 
Powered by phpBB® Forum Software