Solved

Getting and killing focus in edit control?

Posted on 1999-01-25
10
461 Views
Last Modified: 2013-12-03
I'm trying to show a dialog box when user clicks on the edit control.
I process EN_SETFOCUS so that when application receives an EN_SETFOCUS, it
makes a dialog box by DialogBox.
The problem with this method is that when I close the dialog box by EndDialog, it
dispaly dialog again and again. I think it's because that the edit control still has input
focus. So I fall into a kind of infinite loop to display dialog box.
Could someone tell me a better way to implement this?
0
Comment
Question by:slumber
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +4
10 Comments
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1419216
First of all your conclusion is right. After the dialog is destroyed, you receive focus again and therefor you are in an infinite loop.
The best solution is to test where the focus came from. If it comes from an other window then do not show the dialog.
Please let me know if this helped.
0
 
LVL 10

Expert Comment

by:Lischke
ID: 1419217
Hi slumber,

wouldn't it be better to process the mouse down message rather than set focus? You want the dialog to appear when a click occurs, not by a focus change, doesn't you?
0
 
LVL 1

Expert Comment

by:Seeker092397
ID: 1419218
You can do the following trick:

In the handler for EN_SETFOCUS after you return from DialogBox you can remove additional EN_SETFOCUS messages sent to your window right after dialog box got closed(i suppose they will be sent right away, but may be i'm wrong and all this won't work). You can do it by following code:

MSG msg;
while (PeekMessage(&msg, hWnd/*or NULL*/, EN_SETFOCUS, EN_SETFOCUS, PM_REMOVE));

I think it would work, but again...

Best regards.
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 3

Expert Comment

by:luisr
ID: 1419219
You don't say what are you trying to achieve, but I suppose is some kind of data entry (that is, the dialog allows you to select some data to put in the edit control). Maybe you could delay the display of the dialog until a key is pressed (WM_KEYDOWN or WM_CHAR).
0
 
LVL 3

Expert Comment

by:PinTail
ID: 1419220
If the mouse click option is no good, why not just call NextDlgItem() before launching the Dialog, this way when the dialog closes, the focus is on another control
0
 

Author Comment

by:slumber
ID: 1419221
Dear PinTail:

Even though I change the focus to other control just before calling a dialog box, the original edit control gain again when I destroy dialog box. So infinite loop still continues.
Isn't there any other way?

Dear Lischke:
How can I interpret a mouse event as selecting edit control?
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 1419222
slumber, it seems that you doing something wrong. May be, the best way is to do not use this strange behavior of edit box?
0
 
LVL 1

Expert Comment

by:Seeker092397
ID: 1419223
Hi Slumber.
Have you tried my approach?
0
 
LVL 10

Expert Comment

by:Lischke
ID: 1419224
slumber,

process the WM_LBUTTONDOWN or WM_LBUTTONDBLCLK message to get notified when the user clicks in the edit control window.

Ciao, Mike
0
 
LVL 3

Accepted Solution

by:
PinTail earned 100 total points
ID: 1419225
I beg your pardon, I said NextDlgItem(), I should have said NextDlgCtrl().  I have tested this and it works for me, It definitely does not get called more than once just because the CDummy Dlg object gets destroyed.  Are you changing the value in the edit box via the child dialog ??

void CTestDlg::OnSetfocusEdit1()
{
NextDlgCtrl();      
CDummy oDlg;
oDlg.DoModal();
}
0

Featured Post

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question