Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have created a CFormView based MFC SDI application. It has a CEdit control.

I wish to get the left and right position of the CEdit control and use those in GD+ shapes placement.

When I search I get solution for dialog based application, but not for CFormView based MFC SDI application

Please advise how to achieve this.

What I have tried:

I tried below code. It compiles but while running getting ucrtbased.pdb not loaded. When I comment out these lines this error goes away.
CRect programEditCntrlRect;
m_editCtrl.GetWindowRect(&programEditCntrlRect);
 // m_editCtrl is control variable for CEDit control.
this->ScreenToClient(&programEditCntrlRect);
int programEditCntrlX = programEditCntrlRect.left;
int programEditCntrlY = programEditCntrlRect.top;
Posted
Updated 25-Mar-21 6:26am
Comments
Richard MacCutchan 25-Mar-21 10:04am    
You should use GetClientRect which will give you the actual dimensions of the client area of the Edit window. The left and top will both be zero, which you can then use as the starting point for your drawing.
Member 15011436 25-Mar-21 10:06am    
Thanks,
Below code worked.

CRect programEditCntrlRect;
CWnd* prgEdit = GetDlgItem(IDC_EDIT_PrgTxt);
prgEdit->GetWindowRect(&programEditCntrlRect);
this->ScreenToClient(&programEditCntrlRect);
Rick York 25-Mar-21 13:19pm    
That is not an error. It just means it couldn't load a symbol file.

1 solution

CRect programEditCntrlRect;
CWnd* prgEdit = GetDlgItem(IDC_EDIT_PrgTxt);
prgEdit->GetWindowRect(&programEditCntrlRect);
this->ScreenToClient(&programEditCntrlRect);
 
Share this answer
 
Comments
Richard MacCutchan 25-Mar-21 12:46pm    
Use GetClientRect as I suggested as it will give you the exact dimensions without the need to call ScreenToClient

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900