Solved

using a CTabCtrl in a Cwnd

Posted on 2002-03-07
12
568 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
 

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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 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.

708 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

19 Experts available now in Live!

Get 1:1 Help Now