Solved

using a CTabCtrl in a Cwnd

Posted on 2002-03-07
12
609 Views
Last Modified: 2008-02-01
I created a CTabCtrl & put it in a CWnd. Is there a way to know when the user hits a new tab, therby causing the first tab window to be hidden & the new tab window is visible, like with a CPropertyPage in the DDX you can check to see if the user is switching pages by checking the m_bSaveAndValidate variable, is there such a thing with a tab controls pages?
0
Comment
Question by:borghard
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 2
12 Comments
 
LVL 30

Expert Comment

by:Axter
ID: 6847745
You can use GetCurFocus
0
 
LVL 30

Expert Comment

by:Axter
ID: 6847760
Here's some example code:

void CMyTabCtrl::OnLButtonDown(UINT nFlags, CPoint point)
{
     CTabCtrl::OnLButtonDown(nFlags, point);
     SetProperFocus();
}

void CMyTabCtrl::SetProperFocus()
{
     int nCurFocus = GetCurFocus();

.... act on new focus
0
 
LVL 30

Expert Comment

by:Axter
ID: 6847775
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:borghard
ID: 6847866
Thanks for your reply, I guess I didn't explain myself well.
I have a class CEditor that is a CWnd, & each tab is a separate class derived from CWnd.
CTab1 *m_tab1;
CTab2 *m_tab2;
CTab3 *m_tab3;
CEditor::OnCreate()
{
  m_tabCtrl.Create(.....);

  m_tab1 = new CTab1();
  m_tab1->Create(......)
  m_tabCtrl.AddTab(m_tab1,"tab1");

  m_tab2 = new CTab2();
  m_tab2->Create(......)
  m_tabCtrl.AddTab(m_tab2,"tab2");


  m_tab3 = new CTab3();
  m_tab3->Create(......)
  m_tabCtrl.AddTab(m_tab3,"tab3");
}
so what I was asking is: If I am in CTab1 how do I know that I just left that page, like with  a CPropertyPage the way to know if you left is by checking in the DDX the m_bSaveAndValidate variable?
I saw there is a TCN_SELCHANGED but when I try to use it, in the class of the window that holds the tabcontrol(CEditor) I get an error "undeclared identifier"
what I did was like this
ON_NOTIFY(TCN_SELCHANGED, IDNUM, OnSelChanged)
CEditor::OnSelChanged(...)
{
}
0
 
LVL 30

Expert Comment

by:Axter
ID: 6847944
CWnd::OnKillFocus should be called when you leave the page.

You can use the above function to find out when CTab1 change page.
0
 

Author Comment

by:borghard
ID: 6848066
Thanks, I tried it, it works but it's not perfect for example when I tab to the next page it will call OnKillFocus but when I go back to the CTab1 page & I click in one of the controls on the CTab1 page it will also call OnKillFocus eventho I am still on that page, & I really only have to know when it's leaving the page  so I can update the data accordingly.
0
 
LVL 30

Expert Comment

by:Axter
ID: 6848091
You could use IsWindowVisible() within OnKillFocus to see if you're tab is still visible.
If it's not still visible, then you know your tab lost focus.
0
 

Author Comment

by:borghard
ID: 6848157
Thanks, almost there, the only problem I encounter now is that when the window is first initialized & I put in my data then when I click the next tab it doesn't even get into the OnKillFocus method.
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 200 total points
ID: 6849839
Just a note: It sounds like you are using a CTabCtrl to simulate the functionality of a CPropertySheet.  

Do you know that it is possible to make a CPropertySheet as a child window?  If you do that, you can use normal propertysheet/propertypage logic.

-- Dan
0
 

Author Comment

by:borghard
ID: 6850831
Thanks alot for that information, it was a lot easier to implement.
0
 

Author Comment

by:borghard
ID: 6850836
Thanks alot for that information, it was a lot easier to implement.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6850936
Glad to help.  It often pays to look not at the actual question but at the underlying need.

-- Daan
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

624 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