Use Sendmessage API to simulate click  on Tab Control (SSTabCtlWndClass  class)

peispud
peispud used Ask the Experts™
on
HI
Using VB.net 2005

I am hoping for a reply that is VB.Net  specific, but would  be appreciate any help that I can get.  I haven't been getting any replies to this question and have been quite frustrated in my searches.  There are brilliant minds here so I refuse to believe that it can't be done!

To restate...
I have the handle for a SSTabCtlWndClass control that has several tabs.
I need to use api sendmessage to the control so that I can change the tab in focus (effectively clicking on the tab).

Thank you!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Actually, you don't need to us an API to select a specific Tab.  You can use the SelectTab method to make a specific Tab Page the active one:

http://msdn.microsoft.com/en-us/library/c881zk4f.aspx


TechSinger has the solution as long as SSTabCtlWndClass is based on TabControl, but I honestly don't know what SSTabCtlWndClass is. If TechSinger didn't solve your problem, please explain what SSTabCtlWndClass is.
peispudTech

Author

Commented:
Good try guys,   but I don't think that this will help me because all I have is the handle of the control that SPY++ reports as class "SSTabCtlWndClass ".  

When I enumerate the form window, I can drill down only as far as the tab control.  SPY++ won't drill down any further either so I presume that I must use the handle of the tabcontrol and sendmessage to select the tab page (like clicking on the tab).

Does anyone know this solution?

C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

That bit about SPY++ and only having a handle was an important little tidbit. Perhaps you could get the control from the handle? That would make life easier, right?
        Dim tabctrl As System.Windows.Forms.TabControl
 
        tabctrl = System.Windows.Forms.Control.FromHandle(hWnd)
        tabctrl.SelectTab(tabnum)

Open in new window

peispudTech

Author

Commented:
That is much closer but id did not work.   I tested it by bringing up System Properties in the control panel.  Then I used SPY++ to get the handle of the tabcontrol.  ( I am aware that the handle will change next time I open that window).   I plugged in the handle into the code (see code snippit).  
When I run the code,  I get a null reference exception.


Public Class Form1
 
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim tabctrl As System.Windows.Forms.TabControl
        Dim x As Integer = 2
        tabctrl = System.Windows.Forms.Control.FromHandle(&H0003107C)
        tabctrl.SelectTab(x)
    End Sub
End Class

Open in new window

Now I get where you are going (sort of). I did some digging and found many Web sites say that SSTabCtlWndClass is a standard VB6 control. Which leads me to believe it might be an MFC control, but I'm not totally sure. Maybe the following link will get you going in the right direction.

http://www.codeproject.com/KB/threads/InterprocessCommunicator.aspx
peispudTech

Author

Commented:
Thanks for your direction.    I will be studying that page,  but I already know that it will be difficult.

I will award you full points with thanks.  Could you  tell me why my code (that you gave me) wouldn't switch tabs on the control panel /systems properties tab.

The FromHandle method will return a non-null reference only if the handle points to an object of type TabControl or an object that derives from type TabControl. It appears that the SSTabCtlWndClass does not derive from TabControl because FromHandle returns null. Sorry about that. I didn't realize it.
Whereas TabControl is a .NET object, it looks from the Web sites I saw that SSTabCtlWndClass might be an MFC object. You should try to verify that and, if it is true, learn how to interop an MFC object. I've not done that so I don't want to try giving you advice on that, but the article might help.
Good luck!
Most Valuable Expert 2012
Top Expert 2014

Commented:
@dericstone
The solution you suggested would work if the TabControl is within the .NET application where the code is being executed correct? My understanding is that peispud is trying to change tabs of some other application (hence he is using the spy++ to get the window handle).

Here are some examples of sending Windows messages

http://www.geocities.com/practicalvb/vb/windows/messages.html

http://www.vbdotnetheaven.com/UploadFile/jscofield/MessageLoop04212005022256AM/MessageLoop.aspx

http://www.codeproject.com/KB/dialog/messagehandling.aspx?msg=2950698
peispudTech

Author

Commented:
Thanks for the help!!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial