Link to home
Start Free TrialLog in
Avatar of AniBala
AniBala

asked on

How to get a Double Click Event for CEdit box?

In Visual basic(VB) we have double click event for Text box (Edit box). But in Visual C++ MFC we don't have a double click event for edit box. All we have for this are SetFocus, KillFocus, Change etc. Is there any way we could get this double click event for Edit box like VB?
ASKER CERTIFIED SOLUTION
Avatar of fl0yd
fl0yd

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Vinayak Kumbar
Vinayak Kumbar

Hi,

Follow the steps to get the Double click event for the edit box.

1. Go to class wizard and add a new class say CTestEdit and derive it form CEdit class.

2. Using class wizard, go to member variables tab and add a member variable of type "control" and "CTestEdit" to the edit box id, say IDC_TEST_EDIT

3. As soon as u add a control type of CTestEdit, the classwizard will ask u to add the TestEdit.h to the zzzDlg.h file, where zzzDlg.h is ur dialog class header file on which u have placed the edit control.

4. Open the zzzDlg.h file and include "TestEdit.h" file to it.

5. Now go to class wizard and select the CTestEdit class. Then select WM_LBUTTONDBCLK message from "messages" list. Add the function to that message.

6. Now open the TestEdit.cpp file and u will find the OnLButtonDbClk(...) function. U add ur code here. say just AfxMessageBox("Edit double Clicked"); Now run and double click, u will see the message box pop up.

Now u can change the behaviour to whatever u want. This process is known as "Subclassing" and using this method u can subclass the controls and get the behaviour of ur desire.

Try it out.
VinExpert