Link to home
Start Free TrialLog in
Avatar of PTRUSCOTT
PTRUSCOTT

asked on

Cannot Close a CDialog Box immediately when focus is on an inner CEdit control

I have the following dialog box -

1.  My outer dialog box is standard and is derived from CDialog
2.  It contains a CListBox control
3.  There is a CEdit control that appears over each row of the CListbox as the user is editing a series of numbers (the user has to enter a series of numbers in order down a column)

If the user clicks the Cancel button to get out he or she has to click it twice.  The first time takes the focus away from the CEdit control.  The second time the cancel is actually processed and the dialog box closes.

How do I get around this so that the first click on the cancel button closes the dialog?

-Philip T
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Is the CEdit control a standard CEdit or one you have customised?
Do you have any code that responds to the cancel button?
Avatar of KurtVon
KurtVon

You could catch the loss of focus to the edit/list control using the WM_SETFOCUS message, then, if the mouse was clicked over your dialog (or a control in the dialog) resend the mouse click with the SendInput function.

Hope this helps.
Avatar of PTRUSCOTT

ASKER

This is a standard CEdit control.  I have not added any code that responds to the Cancel button or any other button.  To the best of my knowledge the CEdit control is therefore responding in the normal way to mouseclicks.
Could you go into a little more detail about how to use the WM_SETFOCUS message?  I tried going into ClassWizard to generate a funcion that uses it but it did not come up in the list of WM_ messages.  My list goes straight from WM_SETCURSOR to WM_SHOWWINDOW.

-Philip T.
ASKER CERTIFIED SOLUTION
Avatar of KurtVon
KurtVon

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