Click here to Skip to main content
16,022,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to see cursor wheen I click in my edit, I use a derive class, I wrote:

void CEditMod::OnLButtonDown(UINT nFlags, CPoint point)
{
	
	SetFocus();
	SetSel(0,-1);

	CEdit::OnLButtonDown(nFlags, point);
}

I have 10 Edit
and when I click in an Edit cursor doesn't compare in the edit

In this way border of CEdit is selected, but if I select an other edit border of past edit isn't deselect..


void CEditMod::OnKillFocus(CWnd* pNewWnd)
{
	
	int n_gr;

	n_gr = m_nGruppo;

	CString str1;

	str1 = m_strDx_sx;

	CString text;

	GetWindowText(m_strTesto);

	

//	__super::OnKillFocus(pNewWnd);
	//ReleaseCapture();
}


What I have tried:

I tried to use the code that I wrote,
Posted
Updated 19-Jun-24 22:34pm
v3
Comments
Shao Voon Wong 20-Jun-24 1:17am    
Not sure what you meant by "cursor doesn't compare in my edit"? Your new code does not show any compare code. Perhaps, you want to explain what you are trying to achieve.
Member 14594285 20-Jun-24 4:35am    
I improved my question
Shao Voon Wong 21-Jun-24 1:01am    
I have not encountered this behaviour on CEdit. You do not need to fix this with your OnLButtonDown. This is probably a bug with your derived CEdit or code in your MFC dialog. Without access to your code, I cannot help you.

Maybe your 10 CEdit share the same ID. Open your resource file (*.rc) to check for duplicate ID. Maybe some of your CEdit IDs share same resource number: Open resource.h to check. Below is one example.

#define IDC_EDIT1 5263
#define IDC_EDIT2 5263
jeron1 20-Jun-24 10:25am    
Do you mean 'appear' instead of 'compare'?

1 solution

I would first call the base class method and then the desired functions:
C++
void CEditMod::OnLButtonDown(UINT nFlags, CPoint point)
{
    CEdit::OnLButtonDown(nFlags, point);
    SetFocus();
    int nCharIndex = CharFromPos(point);
    SetSel(nCharIndex, nCharIndex);
}


//edit:
I still have no idea why the OnLButtonDown() method should be changed. Reading the text of an edit control with GetWindowText() does not seem to me to be the right way. The use of GetWindowText() is not necessary if you manage the text of the edit controls automatically via the DDX (Dialog Data Exchange). To use DDX, you need a separate CString variable in the CMyMainFrame class for each CEdit control.
C++
class CMyMainFrame : public CFrameWnd
{
private:
    CEditMod m_EditControl1, m_EditControl2, m_EditControl3;
    CString m_strText1, m_strText2, m_strText3;
//...
}

You can then use DDX functions in the CMyMainFrame class to automatically keep the variables up to date.
C++
void CMyMainFrame::DoDataExchange(CDataExchange* pDX)
{
    CFrameWnd::DoDataExchange(pDX);
    DDX_Text(pDX, 1, m_strText1);
    DDX_Text(pDX, 2, m_strText2);
    DDX_Text(pDX, 3, m_strText3);
}

If a custom OnLButtonDown() method is used, at least the base class method must be called first.
C++
void CEditMod::OnLButtonDown(UINT nFlags, CPoint point)
{
    __super::OnLButtonDown(nFlags, point);
}
 
Share this answer
 
v3
Comments
Member 14594285 19-Jun-24 2:55am    
cursor doesn'compare with this code
merano99 19-Jun-24 11:15am    
Please use the improve link above to describe exactly which functionality is required. I can't do anything with the comment.

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