Click here to Skip to main content
14,577,302 members
Rate this:
Please Sign up or sign in to vote.
See more:
CEdit* pEditControl = (CEdit*)GetDlgItem(IDC_ID);

POINT  CaretPos;

pEditControl->SetSel(CaretPos.x, CaretPos.y);

What I have tried:

Can some one help me with this
Updated 30-Jun-20 15:24pm
Rate this:
Please Sign up or sign in to vote.

Solution 1

Check the documentation : CEdit Class | Microsoft Docs[^]

Neither override takes an x-y position.

You can call call CharFromPos() to get a character position from a point. Then call SetSel().

These are in the docs.
G Kumar P 19-Jun-20 4:48am
Hi Rick
Thanks for reply i want to set position of cursor to current x,y position what are ways we can do that.
Rick York 19-Jun-20 15:57pm
call CharFromPos first.
Rate this:
Please Sign up or sign in to vote.

Solution 2

just set position of cursor in edit, Other way except CharFromPos 

you can use mouse_event(SendInput) to click edit
also you can sendmessage(mouse message) to edit


	POINT		pt;

	NSys::InputMouseClick(pt.x, pt.y, 0, TRUE);
	NSys::InputMouseClick(pt.x, pt.y, 0, FALSE);

BOOL	NSys::InputMouseClick(int x, int y, int nButton, BOOL bDown)
	INPUT		input;
	BOOL		bRetVal;
	int			nScrW, nScrH;

	nScrW = GetSystemMetrics(SM_CXSCREEN);
	nScrH = GetSystemMetrics(SM_CYSCREEN);
	x = (x)*(65536-1)/(nScrW-1);
	y = (y)*(65536-1)/(nScrH-1);
	input.type				= INPUT_MOUSE;
	input.mi.dwExtraInfo	= NULL;
	input.mi.dx				= x;
	input.mi.dy				= y;
	input.mi.mouseData		= 0;
	input.mi.time			= GetTickCount();
	input.mi.dwFlags		= MOUSEEVENTF_ABSOLUTE;
	case 0:	input.mi.dwFlags |= bDown ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_LEFTUP;		break;
	case 1:	input.mi.dwFlags |= bDown ? MOUSEEVENTF_RIGHTDOWN : MOUSEEVENTF_RIGHTUP;	break;
	case 2:	input.mi.dwFlags |= bDown ? MOUSEEVENTF_MIDDLEDOWN : MOUSEEVENTF_MIDDLEUP;	break;
	default:	assert(0);	return FALSE;
	bRetVal = SendInput(1, &input, sizeof(input));
	return bRetVal;

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