Click here to Skip to main content
14,577,302 members
Rate this:
Please Sign up or sign in to vote.
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
Rate this:
Please Sign up or sign in to vote.

Solution 1

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[^].
   
Comments
G Kumar 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[^].
Rate this:
Please Sign up or sign in to vote.

Solution 3

EM_CHARFROMPOS message lParam should 4 Byte, CPoint is 8 Byte

MAKELPARAM(x, y);    //use this to replace CPoint
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100