Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
CPoint point;
::GetCursorPos(&point);

CEdit* pt = (CEdit*)GetDlgItem(IDC_SOMEID);
DWORD dEditcontrol = SendMessage(EM_CHARFROMPOS,(WPARAM)0,(LPARAM)&point);
int CharPostrion = HIWORD(dEditcontrol);
int CharPo = LOWORD(dEditcontrol);

What I have tried:

Can Some Body suggest why i am getting Result as (65535, 65535)
in CharPostrion and CharPro.
Posted
Updated 30-Jun-20 14:56pm

EM_CHARFROMPOS message lParam should 4 Byte, CPoint is 8 Byte

MAKELPARAM(x, y);    //use this to replace CPoint
 
Share this answer
 
Most likely because the co-ordinates in the point structure are outside of the client Window. You need to convert them from screen to client co-ordinates. See the references: GetCursorPos function (winuser.h) - Win32 apps | Microsoft Docs[^] and EM_CHARFROMPOS message (Winuser.h) - Win32 apps | Microsoft Docs[^].
 
Share this answer
 
Comments
Cool Dude-P 17-Jun-20 23:38pm    
CRect rc;
CPoint point;
::GetCursorPos(&point);

CEdit* pt = (CEdit*)GetDlgItem(IDC_SOMEID);
pt->GetWindowRect(&rc);
pt->ScreenToClient(rc);

DWORD dEditcontrol = pt->SendMessage(EM_CHARFROMPOS,(WPARAM)0,(LPARAM)&point);
int CharPostrion = HIWORD(dEditcontrol);
int CharPo = LOWORD(dEditcontrol);

Still getting same Result as (65535, 65535)
Richard MacCutchan 18-Jun-20 5:02am    
You are calling ScreenToClient on the wrong values, it needs to be passed the point structure from GetCursorPos. See CWnd Class | Microsoft Docs[^].

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