CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2004
    Posts
    62

    Can somebody please help me with this ?

    I have a little problem with updating on a dialog. If I make a Dialog with onpaint:

    Code:
    void CTestDlg::OnPaint() 
    {
    	if (IsIconic())
    	{
    		CPaintDC dc(this); // device context for painting
    
    		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
    
    		// Center icon in client rectangle
    		int cxIcon = GetSystemMetrics(SM_CXICON);
    		int cyIcon = GetSystemMetrics(SM_CYICON);
    		CRect rect;
    		GetClientRect(&rect);
    		int x = (rect.Width() - cxIcon + 1) / 2;
    		int y = (rect.Height() - cyIcon + 1) / 2;
    
    		// Draw the icon
    		dc.DrawIcon(x, y, m_hIcon);
    	}
    	else
    	{
    		CPaintDC  dc(this);
    
    		CRect winpos = dc.m_ps.rcPaint;
    
    		dc.FillSolidRect(winpos.left, winpos.top, 
    			winpos.Width(), winpos.Height(), 0);
    
    	}
    }
    and OnEraseBkgn:

    Code:
    BOOL CTestDlg::OnEraseBkgnd(CDC* pDC) 
    {	return TRUE;	
    }
    and move a small window (i.e. notepad) fast over, then it sometimes it doesn't refresh the window correctly. Why ?

    It works if I always update the entire screen instead of the rectangle that "needs" to be updated. But I don't want to do that. I mean, I get the rectangle exactly for the reason that I don't have to update everything. That would make my program much slower.

    I appreciate any help on this...


    PS: The code fragments I posted are not my real code. I just used them to show the problem. My real code is far to complex to post but the problem is the same. So please do not get hung up on the code I posted, except of course there is something important that I didn't notice...

  2. #2
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815

    Re: Can somebody please help me with this ?

    Quote Originally Posted by Zaph-0
    and move a small window (i.e. notepad) fast over, then it sometimes it doesn't refresh the window correctly. Why ?
    Sorry, but I can't reproduce that behaviour. When I take your exact code (I assume you have created a "dialog-based app") and move any other Window as fast as I like in front of the dialog box, no lines are remaining - the entire screen area is always correctly repainted in black.

    Quote Originally Posted by Zaph-0
    It works if I always update the entire screen instead of the rectangle that "needs" to be updated. But I don't want to do that. I mean, I get the rectangle exactly for the reason that I don't have to update everything. That would make my program much slower.
    I don't understand why you are bothering with this - are you aware of the fact that Windows does its own clipping? So if you are correctly using a CPaintDC for drawing, anything you draw will be clipped to the intersection of the invalid region and the clipping region - there's no need to do that yourself. Also, note that when you move one or more windows in front of your window, or when your window is brought to the front, the invalid region is usually not a simple rectangle, but a more complexely shaped region. The rectangle you get in the PAINTSTRUCT is just the bounding area of that region, it is actually more than what needs to be redrawn.

    So have you tried to simply repaint the entire client area? Have you measured whether this is actually slower than using just the rect from the PAINTSTRUCT? Try it and you will see that it's the same (or even slightly faster), since Windows clips to the invalid region anyway.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured