Tab Fenster

  • bräuchte nochmals Hilfe,

    wenn ich hier im Fenster auf Tab4 drücke, soll ne Passwortabfrage kommen

    [autoit]

    #include <GUIConstants.au3>
    $Form1_1 = GUICreate("Testfenster", 297, 341, 210, 144)
    $Programme = GUICtrlCreateTab(8, 8, 280, 304)
    GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
    $tab1 = GUICtrlCreateTabItem("Tab1")
    $tab2 = GUICtrlCreateTabItem("Tab2")
    $tab3 = GUICtrlCreateTabItem("Tab3")
    $tab4 = GUICtrlCreateTabItem("Tab4")
    GUICtrlCreateTabItem("")
    GUISetState(@SW_SHOW)
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Programme
    EndSwitch
    WEnd

    [/autoit]


    weiss einer wie ich das machen könnte.

    • Offizieller Beitrag

    Das geht so (statt MsgBox dann dein Code):

    Spoiler anzeigen
    [autoit]

    #include <GUIConstants.au3>
    $Form1_1 = GUICreate("Testfenster", 297, 341, 210, 144)
    $Programme = GUICtrlCreateTab(8, 8, 280, 304)
    GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
    $tab1 = GUICtrlCreateTabItem("Tab1")
    $tab2 = GUICtrlCreateTabItem("Tab2")
    $tab3 = GUICtrlCreateTabItem("Tab3")
    $tab4 = GUICtrlCreateTabItem("Tab4")
    GUICtrlCreateTabItem("")
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Programme
    Switch GUICtrlRead($Programme)
    Case 0
    MsgBox(0, '', 'Tab1 aktiviert')
    Case 1
    MsgBox(0, '', 'Tab2 aktiviert')
    Case 2
    MsgBox(0, '', 'Tab3 aktiviert')
    Case 3
    MsgBox(0, '', 'Tab4 aktiviert')
    EndSwitch
    EndSwitch
    WEnd

    [/autoit]
    • Offizieller Beitrag

    Falls du willst, dass das angeklickte (oder per Tastatur angewählte) TabItem erst nach erfolgreicher Passwortabfrage gezeigt wird, muß man Maus- und Tastatur per Hook abfangen.
    Ich habe auch mal dieses Bsp. erstellt:

    Spoiler anzeigen
    [autoit]

    #include <GuiConstantsEx.au3>
    #include <GuiTab.au3>
    #include <WinAPI.au3>
    #include <WindowsConstants.au3>
    #include <StructureConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global Const $HC_ACTION = 0
    Global Const $WM_LBUTTONDOWN = 0x201

    [/autoit] [autoit][/autoit] [autoit]

    Global $hStub_MouseProc = DllCallbackRegister("_MouseProc", "long", "int;wparam;lparam")
    Global $hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam")
    Global $hmod = _WinAPI_GetModuleHandle(0)
    Global $hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hStub_MouseProc), $hmod)
    Global $hHook2 = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hStub_KeyProc), $hmod)
    Global $hTab, $lastTab = 0, $checkPass = 0
    Global $Passwort = 'pass', $passItem = 2 ; <== Index des PW-geschützten TabItems

    [/autoit] [autoit][/autoit] [autoit]

    $Form1_1 = GUICreate("Testfenster", 297, 341, 210, 144)
    $Programme = GUICtrlCreateTab(8, 8, 280, 304)
    $hTab = GUICtrlGetHandle($Programme)
    GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
    $tab1 = GUICtrlCreateTabItem("Tab1")
    $tab2 = GUICtrlCreateTabItem("Tab2")
    $tab3 = GUICtrlCreateTabItem("Tab3")
    $tab4 = GUICtrlCreateTabItem("Tab4")
    GUICtrlCreateTabItem("")
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit]

    Global $hookGUI = $Form1_1, $hookID = $Programme

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While 1
    If $checkPass Then _CheckPass()
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Programme
    Switch GUICtrlRead($Programme)
    Case 0
    ;~ MsgBox(0, '', 'Tab1 aktiviert')
    Case 1
    ;~ MsgBox(0, '', 'Tab2 aktiviert')
    Case 2
    ;~ MsgBox(0, '', 'Tab3 aktiviert')
    Case 3
    ;~ MsgBox(0, '', 'Tab4 aktiviert')
    EndSwitch
    EndSwitch
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _MouseProc($nCode, $wParam, $lParam)
    If $nCode < 0 Or (Not _MouseOverTabItem($hookGUI, $hTab, $passItem)) Then
    Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
    EndIf
    If $nCode = $HC_ACTION And $wParam = $WM_LBUTTONDOWN Then
    $checkPass = 1 ; Überprüfung aktivieren
    Return -1 ; Mausklick wird ignoriert ==> TabItem noch nicht aktiviert
    EndIf
    Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _CheckPass()
    If InputBox('Passwort', 'Bitte Passwort eingeben:') == $Passwort Then
    _GUICtrlTab_SetCurSel($hTab, $passItem)
    Else
    MsgBox(0, 'Fehler', 'Falsches Passwort!')
    EndIf
    $checkPass = 0
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _MouseOverTabItem($GUI, $hWnd, $iTabItem)
    If Not BitAND(WinGetState($GUI), 8) Then Return False
    Local $old = Opt('MouseCoordMode', 2)
    Local $posM = MouseGetPos()
    Opt('MouseCoordMode', $old)
    Local $posC = _GUICtrlTab_GetItemRect($hWnd, $iTabItem)
    If ($posM[0] >= $posC[0] And $posM[0] <= $posC[2]) And _
    ($posM[1] >= $posC[1] And $posM[1] <= $posC[3]) Then
    Return True
    Else
    Return False
    EndIf
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _KeyProc($nCode, $wParam, $lParam)
    Local $tKEYHOOKS, $vkCode, $ret, $curPos, $curItem
    $ret = DllCall("user32.dll","long","GetKeyState","long", 0x14)
    If $ret[0] Then $isCapsLock = 1
    $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
    $curPos = GUIGetCursorInfo($hookGUI) ; <== check, welche ID aktiv
    If $nCode < 0 Or $curPos[4] <> $hookID Then Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
    $vkCode = DllStructGetData($tKEYHOOKS, "vkCode")
    If $wParam = $WM_KEYDOWN Then
    Switch $vkCode
    Case 0x25 ; ==> Pfeil li.
    If GUICtrlRead($hookID) -1 = $passItem Then
    $checkPass = 1
    Return -1
    EndIf
    Case 0x27 ; ==> Pfeil re.
    If GUICtrlRead($hookID) +1 = $passItem Then
    $checkPass = 1
    Return -1
    EndIf
    EndSwitch
    EndIf
    Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func OnAutoItExit()
    _WinAPI_UnhookWindowsHookEx($hHook)
    DllCallbackFree($hStub_MouseProc)
    _WinAPI_UnhookWindowsHookEx($hHook2)
    DllCallbackFree($hStub_KeyProc)
    EndFunc ;==>OnAutoItExit

    [/autoit]

    Edit: Hatte grad noch einen Fehler beim Positionsvergleich der Maus entdeckt - nun passt es. ;)