Jump to content

Detect Tab Change In GUIOnEventMode


Sunaj
 Share

Recommended Posts

How to detect tab change in OnEventMode? Code below should show a msgbox when TabSheet2 is activated, really hope someone can help with this :)

#include <GuiConstants.au3>

Opt("GUIOnEventMode", 1)

$dlgTabbed = GUICreate("Tabs", 412, 280, 302, 218)
$PageControl1 = GUICtrlCreateTab(8, 8, 396, 256)

$TabSheet1 = GUICtrlCreateTabItem("3")
GUICtrlCreateLabel("Tab 1", 168, 104, 61, 17)

$TabSheet2 = GUICtrlCreateTabItem("different")
GUICtrlSetOnEvent($TabSheet2, "tabchangedetected") ; I know this doesn't work.. what does though?

GUICtrlCreateLabel("Tab 2", 176, 136, 61, 17)
$TabSheet3 = GUICtrlCreateTabItem("Tabs")

GUICtrlCreateLabel("Tab 3", 184, 128, 61, 17)
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW,$dlgTabbed)
GUISetOnEvent($GUI_EVENT_CLOSE, "closeclicked")

While 1
Sleep(100)
Wend

Func closeclicked()
    Exit
EndFunc

Func tabchangedetected()
    MsgBox(4096, "Result", "Tab active")
EndFunc
Link to comment
Share on other sites

  • Moderators

This is a quick and VERY dirty way of doing it... I would seriously say look at GUIRegisterMsg()

#include <guitab.au3>
#include <GuiConstants.au3>

Opt("GUIOnEventMode", 1)

$dlgTabbed = GUICreate("Tabs", 412, 280, 302, 218)
$PageControl1 = GUICtrlCreateTab(8, 8, 396, 256)

$TabSheet1 = GUICtrlCreateTabItem("3")
GUICtrlCreateLabel("Tab 1", 168, 104, 61, 17)

$TabSheet2 = GUICtrlCreateTabItem("different")
GUICtrlSetOnEvent($TabSheet2, "tabchangedetected") ; I know this doesn't work.. what does though?

GUICtrlCreateLabel("Tab 2", 176, 136, 61, 17)
$TabSheet3 = GUICtrlCreateTabItem("Tabs")

GUICtrlCreateLabel("Tab 3", 184, 128, 61, 17)
GUICtrlCreateTabItem("")
GUISetOnEvent($GUI_EVENT_CLOSE, "closeclicked")
GUISetState(@SW_SHOW,$dlgTabbed)

Global $iCurrentTab = _GUICtrlTabGetCurFocus($PageControl1)
AdlibEnable('tabchangedetected', 10)
While 1
    Sleep(1000)
Wend

Func closeclicked()
    Exit
EndFunc

Func tabchangedetected()
    If _GUICtrlTabGetCurFocus($PageControl1) <> $iCurrentTab Then
        $iCurrentTab = _GUICtrlTabGetCurFocus($PageControl1)
        MsgBox(4096, "Result", "Tab active")
    EndIf
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

This is a quick and VERY dirty way of doing it... I would seriously say look at GUIRegisterMsg()

It may be dirty but it is completely functional from my perspective - I'll have a look at GUIRegisterMsg() later when my app is at a stage where it feels more right to polish the details! Thanks a lot for your quick reply SmOke_N. Since I've searched the forum thin without finding reference to this particular issue I'm sure it'll be of help to many other AutoItters :)

Link to comment
Share on other sites

Hmm, looked a bit at the code and got around to thinking that it might be better to do the following (this way AdlibEnable is avoided and I still avoid going into GUIRegisterMsg, which, after I looked at it, scare me quite a bit), I don't know whether it is better or worse from a technical standpoint.. but it works! :)

#include <guitab.au3>
#include <GuiConstants.au3>

Opt("GUIOnEventMode", 1)

$dlgTabbed = GUICreate("Tabs", 412, 280, 302, 218)
$PageControl1 = GUICtrlCreateTab(8, 8, 396, 256)

$TabSheet1 = GUICtrlCreateTabItem("3")
GUICtrlCreateLabel("Tab 1", 168, 104, 61, 17)

$TabSheet2 = GUICtrlCreateTabItem("different")
GUICtrlCreateLabel("Tab 2", 176, 136, 61, 17)

$TabSheet3 = GUICtrlCreateTabItem("Tabs")

GUICtrlCreateLabel("Tab 3", 184, 128, 61, 17)
GUICtrlCreateTabItem("")
GUISetOnEvent($GUI_EVENT_CLOSE, "closeclicked")
GUISetState(@SW_SHOW,$dlgTabbed)

Global $iCurrentTab = _GUICtrlTabGetCurFocus($PageControl1)

While 1
    Sleep(100)
    If _GUICtrlTabGetCurFocus($PageControl1) <> $iCurrentTab Then
        $iCurrentTab = _GUICtrlTabGetCurFocus($PageControl1)
        MsgBox(4096, "Result", "New Tab active")
    EndIf
Wend

Func closeclicked()
    Exit
EndFunc
Link to comment
Share on other sites

  • Moderators

Whatever floats your boat... Typically people use OnEventMode to save on CPU usage so I'm told, so I didn't think you wanted to play with the While/WEnd loop.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

You don't need adlib and you don't need it in the while loop, just put the event on the tab itself:

#include <guitab.au3>
#include <GuiConstants.au3>

Opt("GUIOnEventMode", 1)

$dlgTabbed = GUICreate("Tabs", 412, 280, 302, 218)
$PageControl1 = GUICtrlCreateTab(8, 8, 396, 256)
GUICtrlSetOnEvent($PageControl1, "tabchangedetected")

$TabSheet1 = GUICtrlCreateTabItem("3")
GUICtrlCreateLabel("Tab 1", 168, 104, 61, 17)

$TabSheet2 = GUICtrlCreateTabItem("different")

GUICtrlCreateLabel("Tab 2", 176, 136, 61, 17)
$TabSheet3 = GUICtrlCreateTabItem("Tabs")

GUICtrlCreateLabel("Tab 3", 184, 128, 61, 17)
GUICtrlCreateTabItem("")
GUISetOnEvent($GUI_EVENT_CLOSE, "closeclicked")
GUISetState(@SW_SHOW, $dlgTabbed)

Global $iCurrentTab = _GUICtrlTabGetCurFocus($PageControl1)

While 1
 Sleep(200
WEnd

Func closeclicked()
 Exit
EndFunc   ;==>closeclicked

Func tabchangedetected()
 If _GUICtrlTabGetCurFocus($PageControl1) <> $iCurrentTab Then
  $iCurrentTab = _GUICtrlTabGetCurFocus($PageControl1)
  MsgBox(4096, "Result", "Tab active:" & $iCurrentTab)
 EndIf
EndFunc   ;==>tabchangedetected

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...