Solved

Set MFC dialog focus?

Posted on 2009-05-16
4
1,697 Views
Last Modified: 2013-12-21
If I have an MFC dialog and dynamically create controls on it e.g a tab control.  How do I set focus on the main parent dialog afterwards?
0
Comment
Question by:Wanting2LearnMan
  • 3
4 Comments
 
LVL 7

Accepted Solution

by:
lucky_james earned 500 total points
ID: 24401888
you can use WM_NEXTDLGCTL message

check out:
http://blogs.msdn.com/oldnewthing/archive/2004/08/02/205624.aspx


James
0
 
LVL 7

Expert Comment

by:lucky_james
ID: 24401890
alternatively, you can use CWnd::SetForegroundWindow() to move the dialog up in z-order

James
0
 

Author Comment

by:Wanting2LearnMan
ID: 24401902
OK Thanks,

Can you tell me how to use this in my OnInitFunction??  InMy Oninit I create a tab control like so:
dlgTab1Dlg = new CTab1(this);
     dlgTab1Dlg->Create(IDD_TAB1_DIALOG, this);
     dlgTab1Dlg->SetParent(&m_tabOptions);
     dlgTab1Dlg->ShowWindow(SW_SHOW);
     dlgTab1Dlg->SetWindowPos(NULL, rTab.left, rTab.top, rTab.Width(), rTab.Height(), SWP_NOZORDER);

     dlgTab2Dlg = new CTab2(this);
     dlgTab2Dlg->Create(IDD_TAB2_DIALOG, this);
     dlgTab2Dlg->SetParent(&m_tabOptions);
     dlgTab2Dlg->ShowWindow(SW_SHOW);
     dlgTab2Dlg->SetWindowPos(NULL, rTab.left, rTab.top, rTab.Width(), rTab.Height(), SWP_NOZORDER);

anf after this I want focus to go to my main dialog.
0
 
LVL 7

Expert Comment

by:lucky_james
ID: 24401958
is the tab control the part of your main dialog.
if not, fetch the handle to the main dialog window.
then use
PostMessage with required LParam and WParam:

for example, check out:
http://www.softwareobjectives.com.au/VoConversion/Lists/VOTips/DispForm.aspx?ID=106

for details of message, check out:
http://msdn.microsoft.com/en-us/library/ms645432(VS.85).aspx

Do let me know if you have any queries.

James
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
computer science syllabus 3 89
wordappend challenge 8 201
Beginner to Unreal Engine 4 5 94
How to Implement Two Event Listeners in Android 2 45
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Once again I push the limits of my phone.  An introduction to the Android Google Now Launcher.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

832 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