Solved

using a CTabCtrl in a Cwnd

Posted on 2002-03-07
12
587 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
  • 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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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…
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.

828 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