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

x
?
Solved

Set MFC dialog focus?

Posted on 2009-05-16
4
Medium Priority
?
1,903 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 1500 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Once again I push the limits of my phone.  An introduction to the Android Google Now Launcher.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Suggested Courses

885 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