Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Getting and killing focus in edit control?

Posted on 1999-01-25
10
Medium Priority
?
464 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
  • 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
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 
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 300 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

783 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