Solved

Set MFC dialog focus?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
zeroFront challenge 7 80
Can not remove SSL certificate on iPhone 6 - iOS10.2 12 259
Updating statistics with error notification email in SQL server 4 72
Droid 4 15 104
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…
In this article we will discuss all things related to StageFright bug, the most vulnerable bug of android devices.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

911 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

22 Experts available now in Live!

Get 1:1 Help Now