Solved

using a CTabCtrl in a Cwnd

Posted on 2002-03-07
12
579 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

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…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 clear a vector as well as how to detect empty vectors in C++.

803 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