-
February 13th, 2011, 12:45 AM
#1
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.
-
February 13th, 2011, 05:20 AM
#2
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
-
February 13th, 2011, 06:12 AM
#3
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.
-
February 13th, 2011, 07:47 AM
#4
Re: CRect.PtInRect(point) problem on scrolling.
Originally Posted by nitinmalapalli
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
-
February 13th, 2011, 11:51 AM
#5
Re: CRect.PtInRect(point) problem on scrolling.
Originally Posted by D_Drmmr
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.
-
February 13th, 2011, 11:54 AM
#6
Re: CRect.PtInRect(point) problem on scrolling.
Originally Posted by nitinmalapalli
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.
-
February 14th, 2011, 04:40 AM
#7
Re: CRect.PtInRect(point) problem on scrolling.
Originally Posted by nitinmalapalli
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
-
February 14th, 2011, 08:18 AM
#8
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?
-
February 14th, 2011, 08:59 AM
#9
Re: CRect.PtInRect(point) problem on scrolling.
Originally Posted by nitinmalapalli
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|