CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Jun 2006
    Posts
    148

    CTabCtrl Enumeration Problem

    Hi All,

    I am trying to Enumerate all the child and sub child windows of a CTabCtrl window which is in external window. (Not my application)

    I can successfully enumerate all the childs of the CTabCtrl window but they dont come in the perfect order of the Tab Page (Tabpage index wise).

    Suppose there are Five Tab pages in CTabCtrl say A, B, C, D and E.
    For every tab page there are five Dialog controls (Having class "#32770")
    In each dialog controls there are some controls like Textbox, dropdownlist and ListBox etc.

    When i try to enumerate them, the order of the dialog control (inside each tabpage) changes in the EnumWindow procedure.

    Some times A-B-C-D-E and some times D-E-A-B-C and so on.

    One thing i have noticed is that as the focus of the Tabpage in CTabCtrl changes, the enum order also changes.

    Now my problem is that i want child controls of specific Tabpage, which i am not able to achieve.

    Following is the Tab Enumeration Code

    Code:
    HWND m_fDialogs[5];
    int DlgCounter=0;
    BOOL CALLBACK EnumAllDialogs(HWND hwndChild,LPARAM lp)
    {
    	char szClassName[256];
    	GetClassName(hwndChild,szClassName,strlen(szClassName)-1);
    	CString strClassName = CString(szClassName);
    	if(strClassName=="#32770")
    	{
    		m_fDialogs[DlgCounter] = hwndChild;
    		DlgCounter++;
    	}
    	return TRUE;
    
    }
    Here the order of the handles in the array changes as the focus of the Tabpage changes. I need to have the controls from the dialogs of the Tabpage 0 and 3.

    Thanx for any kind of help...

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: CTabCtrl Enumeration Problem

    You'd make your problem much easier using CPropertySheet/CPropertyPage classes
    Victor Nijegorodov

  3. #3
    Join Date
    Jun 2006
    Posts
    148

    Re: CTabCtrl Enumeration Problem

    Quote Originally Posted by VictorN View Post
    You'd make your problem much easier using CPropertySheet/CPropertyPage classes
    what i have done from your suggestion is

    Code:
    CPropertySheet *cps = (CPropertySheet*)CWnd::FromHandle(m_fSysTab);
    //m_fSysTab is the HWND of the CTabCtrl Control found in enumeration
    int pageCount = cps->GetPageCount()
    Here i got an unhandled exception...

    Am i on wrong path???

    Thanx for any kind of help...

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: CTabCtrl Enumeration Problem

    I never suggested you to cast tab control to CPropertySheet.
    Moreover, it is wrong!
    CPropertySheet uses tab control as a child window.
    Victor Nijegorodov

  5. #5
    Join Date
    Jun 2006
    Posts
    148

    Re: CTabCtrl Enumeration Problem

    Quote Originally Posted by VictorN View Post
    I never suggested you to cast tab control to CPropertySheet.
    Moreover, it is wrong!
    CPropertySheet uses tab control as a child window.
    How can i have CPropertySheet from the following windows hierarchy.

    Code:
    ---> Message Bar
    	|---> Message Bar
    		|---> SysTabControl32
    			|---> "32770" Dialog
    				|---> TextBox
    			|---> "32770" Dialog
    				|---> TextBox		
    			|---> "32770" Dialog
    				|---> TextBox
    			|---> "32770" Dialog
    				|---> TextBox
    			|---> "32770" Dialog
    				|---> TextBox
    This is the hierarchy as per SPY++.
    Now what i am doing is...
    1. Enumerating Wndows to get MessageBar
    2. Enumerating Windows to get MessageBar
    3. Enumerating Windows to get SysTabControl32
    4. Enumerating All Dialog Controls of SysTabControl32

    How can i do this with CPropertySheet/CPropertyPage...

    Please help...
    Last edited by shail2k4; October 5th, 2010 at 07:06 AM.

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: CTabCtrl Enumeration Problem

    Quote Originally Posted by shail2k4 View Post
    How can i have CPropertySheet from the following windows hierarchy.
    You cannot.
    But you could very simple solve your problem if you changed your design from using CTabCtrl+Dialogs to CPropertySheet+CPropertyPages.

    Note that
    there is no such a concept as a "Tabpage 0 and 3". There are tabs and you, of course, can open some "page" by new tab selection, and this "page" may be a dialog or some other window type like just a static control, or there may no "page" at all!
    Victor Nijegorodov

  7. #7
    Join Date
    Jun 2006
    Posts
    148

    Re: CTabCtrl Enumeration Problem

    Quote Originally Posted by VictorN View Post
    You cannot.
    But you could very simple solve your problem if you changed your design from using CTabCtrl+Dialogs to CPropertySheet+CPropertyPages.
    Oh, i think there is misunderstanding

    This is not my design... It is an external application and i want to get data from that application..

    Though i have got the desired data, but as the order in the enumeration changes, everything becomes kbooom!!!

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: CTabCtrl Enumeration Problem

    Quote Originally Posted by shail2k4 View Post
    Oh, i think there is misunderstanding

    This is not my design... It is an external application and i want to get data from that application..
    Then why didn't you mention it from the very begin in your OP?

    The order of child windows you get using EnumWindow (or using GetWindow/GetNextWindow depends on Z Order, so what you see ba enumeration is "by design" of Windows!

    Note also that in some cases the dialogs corresponding some tabs may have not been created in the moment you are trying to enumerate them (usually, such dialogs are created only after corresponding tab becomes active.
    Victor Nijegorodov

  9. #9
    Join Date
    Jun 2006
    Posts
    148

    Re: CTabCtrl Enumeration Problem

    Quote Originally Posted by VictorN View Post
    Then why didn't you mention it from the very begin in your OP?
    I have already mentioned that in my post at begining

    Hi All,

    I am trying to Enumerate all the child and sub child windows of a CTabCtrl window which is in external window. (Not my application)
    Note also that in some cases the dialogs corresponding some tabs may have not been created in the moment you are trying to enumerate them (usually, such dialogs are created only after corresponding tab becomes active.
    In every trial i am getting all five dialogs and the controls of that dialogs even if the application is not active...

    The problem is the order of the enumeration...

  10. #10
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: CTabCtrl Enumeration Problem

    Quote Originally Posted by shail2k4 View Post
    I have already mentioned that in my post at begining
    You are right. I missed it... Sorry!

    Quote Originally Posted by shail2k4 View Post
    In every trial i am getting all five dialogs and the controls of that dialogs even if the application is not active...
    ...
    Well, perhaps you were lucky in all your trials. But there is no any guarantee it will be always so "good"...

    Quote Originally Posted by shail2k4 View Post
    The problem is the order of the enumeration...
    Then try to activate the tab you need to get info from before enumerating...
    Victor Nijegorodov

  11. #11
    Join Date
    Jun 2006
    Posts
    148

    Re: CTabCtrl Enumeration Problem

    Quote Originally Posted by VictorN View Post
    You are right. I missed it... Sorry!
    No probs at all....

    Will try with all of your suggestions...

    Thanx a lot...

    Regards,
    Shail2k4

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured