Solved

Set MFC dialog focus?

Posted on 2009-05-16
4
1,612 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

As the title indicates, I have done this before. It chills me everytime I update the OS on my phone, (http://www.experts-exchange.com/articles/18084/Upgrading-to-Android-5-0-Lollipop.html) because one time I did this and I essentially had a bricked …
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 concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

746 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now