Click here to Skip to main content
15,880,796 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
CEdit* pEditControl = (CEdit*)GetDlgItem(IDC_ID);

POINT  CaretPos;
::GetCaretPos(&CaretPos);

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


What I have tried:

Can some one help me with this
Posted
Updated 30-Jun-20 15:24pm
v2

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.
 
Share this answer
 
v2
Comments
Cool Dude-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.
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

example:

xxxxxx()
{
	POINT		pt;

	GetCursorPos(&pt);
	NSys::InputMouseClick(pt.x, pt.y, 0, TRUE);
	Sleep(10);
	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;
	switch(nButton)
	{
	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;
}
 
Share this answer
 

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