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

x
?
Solved

using a CTabCtrl in a Cwnd

Posted on 2002-03-07
12
Medium Priority
?
618 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 800 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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.
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.

782 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