Yes I have but it does not seem to have any effect. I tried using SetFocus on both the dialog window itself as well as one of the edit controls in the window.
Main Topics
Browse All TopicsI have an odd problem here, hoping someone can help.
I have a small dialog based app that is run (using a system()) call from another application which I can only tell to issue the system() call. That part is OK and my dialog does appear on the desktop and, as desired, it shows up on top of the calling app. The calling app hangs until my dialog closes, also as intended.
The problem is that once my dialog appears, it looks like it is the active window (i.e. the banner is shows in the active window color) and there is a CEdit box in it that has the cursor showing in it. But, the keyboard focus is NOT in this dialog. If I cancel the dialog any keystrokes are then caught by the original application. Of course if I click on or in the dialog with the mouse or use ALT-TAB and switch to it, it works properly.
Question: How can I have this application grab the keyboard input no matter what?
TIA
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Nick,
I mentioned that I tried that already without success.
I used the SendInput to send a mouse-down and a mouse-up to the window which seems to have remedied the problem But I still don't understand why this is needed in this case.
Will still award points to anyone who can explain what's going on and a (IMHO) better solution than sending mouse clicks...
Hi jhance,
>> I mentioned that I tried that already without success.
Sorry... I did not see any mention of you saying that you had set the OnInitDialog function to return FALSE. This is normally the issue with this type of problem.
Quoting from the MSDN:
======
CDialog::OnInitDialog
This member function is called in response to the WM_INITDIALOG message.
Return Value:
Specifies whether the application has set the input focus to one of the controls in the dialog box. If OnInitDialog returns nonzero, Windows sets the input focus to the first control in the dialog box. The application can return 0 only if it has explicitly set the input focus to one of the controls in the dialog box.
======
Btw...
In your OnInitDialog, do you call the base class OnInitDialog first?
Regds,
Nick
None of the suggestions were found to be a resolution to this issue. As I mentioned before, I ended up using SendInput to force key and/or mouse input into the dialog which had the effect of moving the focus to it.
You may want to PAQ this question anyway since someone else may find the problem and (messy) solution helpful.
Sorry to clutter up your question queue...
Business Accounts
Answer for Membership
by: jkrPosted on 2006-12-11 at 08:59:03ID: 18115925
Stupid question: Have you already tried to explicitly set the input focus suing 'SetFocus()'?