Jump to content

Side ScrollRibon


ioa747
 Share

Recommended Posts

Sidescrolllribon is a side menu in a given window.

in this example in scite

modifying the Function:
 GUICtrlCreateRibon("[TITLE:SciTE; CLASS:SciTEWindow]", 66, 400, 10, 70, 255)

can follow any other.

:) Please, leave your comments and experiences here.

 

#NoTrayIcon
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Array.au3>
#include <ButtonConstants.au3>
#include <FontConstants.au3>

#Region === GUI ===
Opt("MouseCoordMode", 1) ;1=absolute, 0=relative, 2=client
Opt("MustDeclareVars", 1) ;0=no, 1=require pre-declaration
Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
Opt("GUIOnEventMode", 1) ;0=disabled, 1=OnEvent mode enabled

;Mouse hook ;------------------------------------------------------------------
Global $mX, $mY, $mEvent
Global $hDLL = DllOpen("user32.dll")
Global $hHook, $hStub_KeyProc, $hmod
$hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam")
$hmod = _WinAPI_GetModuleHandle(0)
$hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hStub_KeyProc), $hmod)
;------------------------------------------------------------------------------
Global $hRibonForm, $idButtonOpt, $RibonArray
Global $hWinPos, $tmpWPos, $MouseOver, $tmpTrack, $WheelTrack = 0
Global $thWnd, $FW, $FH, $idButton, $Trans0, $Trans1, $GuiVisible = False

;GUICtrlCreateRibon($FollowhWinTitle [, $RibonWith=70] [, $RibonHight=280] [, $RibonButtonCnt=7] [, $RTrans0=50] [, $RTrans1=255])
GUICtrlCreateRibon("[TITLE:SciTE; CLASS:SciTEWindow]", 66, 400, 10, 70, 255) ;<|<|<|<|<|<|<|<|<|<|<|<|<|<|<|<|<|<|<|<|<|<|<|<|<|<|

GUISetState(@SW_SHOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "GoToExit")
#EndRegion === GUI ===

While 1        ; Loop until the user exits.
    GetMouseMsg()
    RibonUpDate()
    RibonMouseOver()
    Sleep(40)
WEnd

;------------------------------------------------------------------------------
Func GoToExit()    ; exit & Cleanup
    Cleanup()
    Exit
EndFunc   ;==>GoToExit
;------------------------------------------------------------------------------
Func Cleanup()    ; Cleanup dll callback
    _WinAPI_UnhookWindowsHookEx($hHook)
    DllCallbackFree($hStub_KeyProc)
EndFunc   ;==>Cleanup
;------------------------------------------------------------------------------
Func _KeyProc($nCode, $wParam, $lParam)    ; callback function mouse hook
    Local $tKEYHOOKS, $X, $Y, $tmp, $Delta
    If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
    $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)

    $X = DllStructGetData($tKEYHOOKS, "vkCode")
    $Y = DllStructGetData($tKEYHOOKS, "scanCode")

    Switch $wParam
        Case $WM_MOUSEWHEEL
            $Delta = BitShift(DllStructGetData($tKEYHOOKS, "flags"), 16)

            If $Delta > 0 Then
                $tmp = 'WHEEL_UP'
            Else
                $tmp = 'WHEEL_DOWN'
            EndIf
            $tmp &= ' (' & $Delta & ')'

        Case Else
            $tmp = ""
            $mEvent = ""
            $mX = $X
            $mY = $Y
            Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)

    EndSwitch

    $mEvent = $tmp

EndFunc   ;==>_KeyProc
;------------------------------------------------------------------------------
Func GetMouseMsg()    ; Mouse Msg

    Local $mMsg

    If $mEvent = "" Then

    ElseIf $mEvent = "WHEEL_UP (120)" Then
        ;ConsoleWrite("$mEvent = " & $mEvent & @CRLF)
        $mEvent = ""
        $mMsg = "WHEEL_UP"
        $WheelTrack -= 1

    ElseIf $mEvent = "WHEEL_DOWN (-120)" Then
        ;ConsoleWrite("$mEvent = " & $mEvent & @CRLF)
        $mEvent = ""
        $mMsg = "WHEEL_DOWN"
        $WheelTrack += 1

    Else
        ;nothing
        ConsoleWrite("$mEvent = " & $mEvent & @CRLF)
        $mEvent = ""
        $mMsg = ""
    EndIf

    Return $mMsg
EndFunc   ;==>GetMouseMsg
;------------------------------------------------------------------------------
Func RibonNewTo()    ; Ribon make

    $hWinPos = WinGetPos($thWnd)
    Local Const $COLOR_WHITE = 0xFFFFFF, $COLOR_BLACK = 0x000000

    $hRibonForm = GUICreate("RibonForm", $FW, $FH, $hWinPos[0], ($hWinPos[1] - $FH) / 2, $WS_POPUPWINDOW, $WS_EX_TOOLWINDOW)

    Local $Ystep = ($FH - 4) / $idButton[0]
    Local $Ystart = ($Ystep * -1) + 2

    For $i = 1 To $idButton[0]

        $idButton[$i] = GUICtrlCreateButton("Button_" & $i, 2, $Ystart + ($i * $Ystep), $FW - 4, $Ystep, $BS_MULTILINE)

        GUICtrlSetData($idButton[$i], $RibonArray[$i])
        GUICtrlSetTip($idButton[$i], $RibonArray[$i])
        ;GUICtrlSetFont(-1, 9, $FW_NORMAL)
        ;GUICtrlSetColor(-1, $COLOR_BLACK)

        GUICtrlSetOnEvent($idButton[$i], "RibonCmd_" & $i + 100)
    Next

    $idButtonOpt = GUICtrlCreateButton("", 0, 0, 15, $FH)


EndFunc   ;==>RibonNewTo
;------------------------------------------------------------------------------
Func RibonUpDate()    ; Ribon move with win

    Local $iState

    If WinActive($thWnd) Then ; Check if win is currently active.
        $iState = WinGetState($hRibonForm)
        If BitAND($iState, $WIN_STATE_VISIBLE) Then
            ;ConsoleWrite("$hRibonForm is @SW_SHOW " & @CRLF)
        Else
            ;ConsoleWrite("$hRibonForm is @SW_HIDE " & @CRLF)
            WinSetState($hRibonForm, "", @SW_SHOW)
        EndIf

    ElseIf WinActive($hRibonForm) Then
        ;nothing
    Else
        ;ConsoleWrite("Win NOT Active" & @CRLF)
        WinSetState($hRibonForm, "", @SW_HIDE)
        WinWaitActive($thWnd)
        WinSetOnTop($hRibonForm, "", $WINDOWS_ONTOP)
    EndIf


    $hWinPos = WinGetPos($thWnd)

    If $tmpWPos = $hWinPos[0] & ", " & $hWinPos[1] Then
        ; nothing
    Else
        WinMove($hRibonForm, "", $hWinPos[0] + 3, $hWinPos[1] + ($hWinPos[3] - $FH) / 2)
        $tmpWPos = $hWinPos[0] & ", " & $hWinPos[1]
        ConsoleWrite("WinPos ==> " & $tmpWPos & @CRLF)

        ;WinActivate ( $thWnd )
        RibonSetState()

    EndIf

EndFunc   ;==>RibonUpDate
;------------------------------------------------------------------------------
Func RibonSetState()    ; Ribon update

    If $GuiVisible = True Then    ;hide form
        WinMove($hRibonForm, "", $hWinPos[0] + 10, $hWinPos[1] + ($hWinPos[3] - $FH) / 2, $FW, $FH)
        GUISetState(@SW_UNLOCK, $hRibonForm)
        GUICtrlSetState($idButtonOpt, $GUI_HIDE)
        WinSetOnTop($hRibonForm, "", 1)
        WinSetTrans($hRibonForm, "", $Trans1)
        ;ConsoleWrite("$GuiVisible = False" & @CRLF)
    Else    ;----------------   ;unhide form
        WinMove($hRibonForm, "", $hWinPos[0] + 3, $hWinPos[1] + ($hWinPos[3] - $FH) / 2, 15, $FH)
        GUICtrlSetState($idButtonOpt, $GUI_SHOW)
        WinSetOnTop($hRibonForm, "", 0)
        WinSetTrans($hRibonForm, "", $Trans0)
        GUISetState(@SW_LOCK, $hRibonForm)
        ;ConsoleWrite("$GuiVisible = True" & @CRLF)
    EndIf
EndFunc   ;==>RibonSetState
;------------------------------------------------------------------------------
Func RibonMouseOver()    ; Ribon tsek if mouse over

    Local $wPos = WinGetPos($hRibonForm)
    ; [0]=X position  [1]=Y position  $aArray[2]=Width  $aArray[3]=Height

    If $GuiVisible Then
        ;WinActivate($hRibonForm)
        If $mX > $wPos[0] - 5 And $mY > $wPos[1] - 25 _
                And $mX < ($wPos[0] + $FW) + 5 And $mY < ($wPos[1] + $FH) + 25 Then
            RibonAct()
        Else
            $GuiVisible = False
            RibonSetState()
        EndIf

    Else

        If $mX > $wPos[0] - 5 And $mY > $wPos[1] - 5 _
                And $mX < ($wPos[0] + $wPos[2]) + 5 And $mY < ($wPos[1] + $FH) + 5 Then
            $GuiVisible = True
            RibonSetState()
        EndIf

    EndIf

EndFunc   ;==>RibonMouseOver
;--------------------------------------------------------------------------------------------
Func RibonAct()        ; Ribon scroll

    Local $WheelOfset

    If $WheelTrack > $RibonArray[0] Then
        $WheelTrack = 0
    ElseIf $WheelTrack < 0 Then
        $WheelTrack = $RibonArray[0]
    EndIf

    If $tmpTrack = $WheelTrack Then
        ;noting
    Else
        ;ConsoleWrite("--- $WheelTrack=[" & $WheelTrack & "]" & @CRLF)
        For $i = 1 To $idButton[0]

            If $i + $WheelTrack > $RibonArray[0] Then
                $WheelOfset = $i + $WheelTrack - $RibonArray[0]
            ElseIf $i + $WheelTrack < 1 Then
                $WheelOfset = $i + $WheelTrack + $RibonArray[0]
            Else
                $WheelOfset = $i + $WheelTrack
            EndIf

            GUICtrlSetData($idButton[$i], $RibonArray[$WheelOfset])
            GUICtrlSetTip($idButton[$i], $RibonArray[$WheelOfset])
            GUICtrlSetOnEvent($idButton[$i], "RibonCmd_" & $WheelOfset + 100)
        Next

        $tmpTrack = $WheelTrack

    EndIf

EndFunc   ;==>RibonAct
;------------------------------------------------------------------------------
Func RibonLoad($RS_Name = "RibonCmd")    ; Ini Read
    ;ConsoleWrite("-->" & " " & $TM_Name & @CRLF)
    Local $MyIni = @ScriptDir & "\Ribon.ini"
    Local $iniFileExists = FileExists($MyIni)
    Local $index = 0
    Local $TMenuArray[1] = [$index]

    ; Checks if Ribon.ini not exists then make one.
    If Not $iniFileExists Then
        RibonMakeIni($MyIni)
    EndIf

    ; Read the INI section labelled '$RS_Name'. This will return a 2 dimensional array.
    Local $aArray = IniReadSection($MyIni, $RS_Name)

    ; Check if an error occurred.
    If Not @error Then
        ; Enumerate through the array displaying the keys and their respective values.
        For $i = 1 To $aArray[0][0]
            ReDim $TMenuArray[UBound($TMenuArray) + 1]
            $index += 1
            $TMenuArray[0] = $index     ; cnt
            $TMenuArray[$index] = $aArray[$i][1]
        Next
    EndIf

    ;_ArrayDisplay($TMenuArray, "$TMenu")
    Return $TMenuArray

EndFunc   ;==>RibonLoad
;------------------------------------------------------------------------------
Func RibonMakeIni($sFilePath)    ; Make new Ini file

    ; Open the file for writing (append to the end of a file) and store the handle to a variable.
    Local $hFileOpen = FileOpen($sFilePath, $FO_APPEND)
    If $hFileOpen = -1 Then
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred while writing the Ribon.ini file.")
        GoToExit()
    EndIf

    ; Write data to the file using the handle returned by FileOpen.
    FileWrite($hFileOpen, "[RibonCmd]" & @CRLF)
    FileWrite($hFileOpen, "101=Exit" & @CRLF)
    FileWrite($hFileOpen, "102=AutoIt Window Info" & @CRLF)
    FileWrite($hFileOpen, "103=Click" & @CRLF)

    For $i = 104 To 130
        FileWrite($hFileOpen, $i & "=Cmd_" & $i & @CRLF)
    Next

    ; Close the handle returned by FileOpen.
    FileClose($hFileOpen)

    Sleep(300)

EndFunc   ;==>RibonMakeIni

; #FUNCTION# ----------------------------------------------------------------------------------------------------------
; Name...........: GUICtrlCreateRibon()
; Description ...: Make Ribon GUICtrl
; Syntax.........: GUICtrlCreateRibon($FollowhWinTitle [, $RibonWith=70] [, $RibonHight=280] [, $RibonButtonCnt=7] [, $RTrans0=50] [, $RTrans1=255])
; Parameters ....: $FollowhWinTitle     - The Title of Win to folow e.g. "[TITLE:SciTE; CLASS:SciTEWindow]"
;                  $RibonWith           - Optional: Ribon With. (Default is 70)
;                  $RibonHight          - Optional: Ribon Hight. (Default is 280)
;                  $RibonButtonCnt      - Optional: Ribon Buttons count. (Default is 7)
;                  $RTrans0             - Optional: Ribon transparency when is Invisible. (Default is 50)
;                  $RTrans1             - Optional: Ribon transparency when is Visible. (Default is 255)
; Author ........: ioa747
;-------------------------------------------------------------------------------
Func GUICtrlCreateRibon($FollowhWinTitle, $RibonWith = 70, $RibonHight = 280, $RibonButtonCnt = 7, $RTrans0 = 50, $RTrans1 = 255)

    If WinExists($FollowhWinTitle) Then
        ;MsgBox($MB_SYSTEMMODAL, "", "Window exists")
        $thWnd = WinWait($FollowhWinTitle)
        $FW = $RibonWith
        $FH = $RibonHight
        $Trans0 = $RTrans0
        $Trans1 = $RTrans1
        Local $TmpArr[$RibonButtonCnt + 1]
        $TmpArr[0] = $RibonButtonCnt
        $idButton = $TmpArr
        $RibonArray = RibonLoad()
        RibonNewTo()

    Else
        MsgBox($MB_SYSTEMMODAL + $MB_ICONERROR, "Error", "Window does not exist")
    EndIf

EndFunc   ;==>GUICtrlCreateRibon
;----------------------------------------------------------------------------------------------------------------------

#Region === RibonCmd ===
Func RibonCmd_101()    ; Exit
    ConsoleWrite("Exit" & @CRLF)
    GoToExit()
EndFunc   ;==>RibonCmd_101
Func RibonCmd_102()    ; AutoIt Window Info
    ShellExecute(@ScriptDir & "\LNK\AutoIt Window Info (x64).lnk")
EndFunc   ;==>RibonCmd_102
Func RibonCmd_103()    ; Click
    ConsoleWrite("Click" & @CRLF)
EndFunc   ;==>RibonCmd_103
Func RibonCmd_104()
    ; cmd ..........
EndFunc   ;==>RibonCmd_104
Func RibonCmd_105()
    ; cmd ..........
EndFunc   ;==>RibonCmd_105
Func RibonCmd_106()
    ; cmd ..........
EndFunc   ;==>RibonCmd_106
Func RibonCmd_107()
    ; cmd ..........
EndFunc   ;==>RibonCmd_107
Func RibonCmd_108()
    ; cmd ..........
EndFunc   ;==>RibonCmd_108
Func RibonCmd_109()
    ; cmd ..........
EndFunc   ;==>RibonCmd_109
Func RibonCmd_110()
    ; cmd ..........
EndFunc   ;==>RibonCmd_110
Func RibonCmd_111()
    ; cmd ..........
EndFunc   ;==>RibonCmd_111
Func RibonCmd_112()
    ; cmd ..........
EndFunc   ;==>RibonCmd_112
Func RibonCmd_113()
    ; cmd ..........
EndFunc   ;==>RibonCmd_113
Func RibonCmd_114()
    ; cmd ..........
EndFunc   ;==>RibonCmd_114
Func RibonCmd_115()
    ; cmd ..........
EndFunc   ;==>RibonCmd_115
Func RibonCmd_116()
    ; cmd ..........
EndFunc   ;==>RibonCmd_116
Func RibonCmd_117()
    ; cmd ..........
EndFunc   ;==>RibonCmd_117
Func RibonCmd_118()
    ; cmd ..........
EndFunc   ;==>RibonCmd_118
Func RibonCmd_119()
    ; cmd ..........
EndFunc   ;==>RibonCmd_119
Func RibonCmd_120()
    ; cmd ..........
EndFunc   ;==>RibonCmd_120
Func RibonCmd_121()
    ; cmd ..........
EndFunc   ;==>RibonCmd_121
Func RibonCmd_122()
    ; cmd ..........
EndFunc   ;==>RibonCmd_122
Func RibonCmd_123()
    ; cmd ..........
EndFunc   ;==>RibonCmd_123
Func RibonCmd_124()
    ; cmd ..........
EndFunc   ;==>RibonCmd_124
Func RibonCmd_125()
    ; cmd ..........
EndFunc   ;==>RibonCmd_125
Func RibonCmd_126()
    ; cmd ..........
EndFunc   ;==>RibonCmd_126
Func RibonCmd_127()
    ; cmd ..........
EndFunc   ;==>RibonCmd_127
Func RibonCmd_128()
    ; cmd ..........
EndFunc   ;==>RibonCmd_128
Func RibonCmd_129()
    ; cmd ..........
EndFunc   ;==>RibonCmd_129
Func RibonCmd_130()
    ; cmd ..........
EndFunc   ;==>RibonCmd_130
#EndRegion === RibonCmd ===

 

Edited by ioa747

I know that I know nothing

Link to comment
Share on other sites

in the left side of scite window is a bar,  when mouse is over  then menu is Visible.

Maybe the bar is too transparent

make a higher value to $RTrans0 in the function in line 28 from

GUICtrlCreateRibon("[TITLE:SciTE; CLASS:SciTEWindow]", 66, 400, 10, 70, 255)

to

GUICtrlCreateRibon("[TITLE:SciTE; CLASS:SciTEWindow]", 66, 400, 10, 200, 255)

By doing the bar less transparent can help in its location

 

and let me know if is ok  :)

Edited by ioa747

I know that I know nothing

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...