CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Feb 2011
    Posts
    39

    CRect.PtInRect(point) problem on scrolling.

    Hello all,

    I am developing this little app in which there's a table and the user may scroll sideways to view the full table and choose to make an entry in any of the cells by clicking on the respective cell.

    When the screen is not scrolled (m_nHScrollPos is zero) and when I click on a cell, the app creates a CEdit control in that particular cell and it's all good. However, when I scroll sideways (m_nHScrollPos > 0) to further reveal the table and then click on the cell which appears, the app creates a CEdit control which is offset greatly to the right (from it's actual required position).

    It appears to be a problem with the origin to my inexperienced programmer mind. Please note that to bring about the scroll effect, in the OnPaint handler, I have used pDC->SetwindowOrg(m_nHscrollPos, m_nVScrollPos).

    I'd be grateful if you could shed light on this problem. I've been working on this problem for quite a while already...

    Thanks a lot, cheers.

  2. #2
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: CRect.PtInRect(point) problem on scrolling.

    How do you create the CEdit control? How do you tell it where it's placed?
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

  3. #3
    Join Date
    Feb 2011
    Posts
    39

    Re: CRect.PtInRect(point) problem on scrolling.

    This is how I create the CEdit control:

    Code:
    void CMainChildWnd :: OnLButtonDown(UINT nFlags, CPoint point)
    {
    	GetClientRect(&cRectChildWnd);
    	if(cNewEntry.crEditorAdd.PtInRect(point))
    	{	
    		if(cNewEntry.bfSelected == FALSE)
    		{
    			//Create the field text control
    			cNewEntry.SetValues(&cRectChildWnd, TYPE_BANKACC, m_nHScrollPos);
    			cNewEntry.CreateField(this);
    			SelectNewEntry();
    			return;
    		}
    	}
    
        else if(cNewEntry.crEntries[0].PtInRect(point)) //input region (1st entry rect)
        {
    		if(cNewEntry.bfSelected == TRUE)
    		{
    			cNewEntry.DestroyTextIn();
    	        cNewEntry.nFieldNo = 0;
    
    	        GetClientRect(&cRectChildWnd);
    	        cNewEntry.SetValues(&cRectChildWnd, TYPE_BANKACC, m_nHScrollPos);
    	        cNewEntry.CreateField(this);
    
                cNewEntry.ceTextIn.SetFocus();
    		
    	        //Force repaint to ghost text
    	        Invalidate();
    	        SendMessage(WM_PAINT);
    		}
        }
    }
    The function CreateField:

    Code:
    void CEntry :: CreateField(CWnd* pHome)
    {
    	pParent = pHome;
    
    	ceTextIn.Create(ES_CENTER | WS_VISIBLE | ES_NOHIDESEL, crEntries[nFieldNo], pParent, ID_TEXTFIELD);
    
    	if(bAlreadyInputBefore)
    	SelectGhostTexts();
    }
    SelectGhostTexts() displays the old (destroyed) CEdit's data. cNewEntry.SetValues(..) sets the exact CRects for all the required CEdit cells which are crEntries[4]. Finally, cNewEntry.DestroyTextIn() destroys the window after retrieving the CEdit's information.

    Thanks for replying.

  4. #4
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: CRect.PtInRect(point) problem on scrolling.

    Quote Originally Posted by nitinmalapalli View Post
    cNewEntry.SetValues(..) sets the exact CRects for all the required CEdit cells which are crEntries[4].
    Then I guess that's where you have to adjust the position of the rectangle for the scrolling.
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

  5. #5
    Join Date
    Feb 2011
    Posts
    39

    Re: CRect.PtInRect(point) problem on scrolling.

    Quote Originally Posted by D_Drmmr View Post
    Then I guess that's where you have to adjust the position of the rectangle for the scrolling.
    I have been trying precisely that. Any suggestions as to how I can do that? What sort of adjustment would I have to do? I have tried many combinations but none of them work.

  6. #6
    Join Date
    Feb 2011
    Posts
    39

    Re: CRect.PtInRect(point) problem on scrolling.

    Quote Originally Posted by nitinmalapalli View Post
    I have been trying precisely that. Any suggestions as to how I can do that? What sort of adjustment would I have to do? I have tried many combinations but none of them work.
    I had hoped that perhaps this was a standard problem.

  7. #7
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: CRect.PtInRect(point) problem on scrolling.

    Quote Originally Posted by nitinmalapalli View Post
    I have been trying precisely that. Any suggestions as to how I can do that? What sort of adjustment would I have to do? I have tried many combinations but none of them work.
    It's just plain logic. Think what the values should be and adjust the way the actual values are calculated such that they match.
    You can also do this using trial-and-error by scrolling just a little bit and observing how the edit is misplaced. If it's too far to the right, you'll have to decrease the left and right values in the rectangle. If it's too low, you'll have to increase the top and bottom values.
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

  8. #8
    Join Date
    Feb 2011
    Posts
    39

    Re: CRect.PtInRect(point) problem on scrolling.

    I could do that. But wouldn't it be a problem when I run the app on a computer with different monitor specifications having different resolutions? Dabbling with pixels can cause such errors, right?

  9. #9
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: CRect.PtInRect(point) problem on scrolling.

    Quote Originally Posted by nitinmalapalli View Post
    I could do that. But wouldn't it be a problem when I run the app on a computer with different monitor specifications having different resolutions? Dabbling with pixels can cause such errors, right?
    Different resolution, different settings, different theme, even a different window placement could reveal a bug in your code. So you should test for all of these things to make sure your code works correctly in all situations. If your code uses magic numbers, it's likely to fail in a different situation. So make sure you call the proper Windows functions to get the size of scrollbars, etc.
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

Tags for this Thread

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