Sign in to follow this  
Followers 0
picea892

Show accelerator tooltips

1 post in this topic

#1 ·  Posted (edited)

Hi everyone

I believe I have a really neat script here. It can be used to enhance anyones existing script which use guisetaccelerators.

it is extremely self contained and easy to add to your script. Set up your accelerator array like normal and then add a 3rd column for controlhandle.

you then call _guisetaccelerators($aAccelerator,$main_Gui) instead of guisetaccelerators

Next insert the following line in your while loop

_modifierpressed($aAccelerator,$main_Gui)

copy the appropriate functions >_< and your done.

What does it do?

hold down your modifier (shift, ctrl or alt) and it will hover a control tip over all buttons with accelerators. Tooltip shows next letter or number to press.

It looks very slick. I got the idea from nomad.net

anyways, here is the example.

#include <ButtonConstants.au3>
#include <GDIPlus.au3>
#include <Array.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <Winapi.au3>
#include<Misc.au3>
#include <Process.au3>
#include <StaticConstants.au3>
#include <GuiConstants.au3>
#include <ListboxConstants.au3>
#Include <GuiListBox.au3>
#include <Constants.au3>
Opt("GUIOnEventMode", 1)

dim $but[9]
dim $label[4]
dim $aAccelerator[11][3]
;create the dummy gui, buttons disabled, radio buttons checked etc.
Global $main_Gui = GUICreate("test",300,300,200,200,$WS_POPUP, $WS_EX_TOOLWINDOW)
$but[0] = GUICtrlCreateButton("But 1", 5, 5,55,35)
GUICtrlSetOnEvent(-1,"actions")
$but[1] = GUICtrlCreateButton("But 2", 65, 5,55,35)
GUICtrlSetOnEvent(-1,"actions")
$but[2] = GUICtrlCreateButton("But 3", 125, 5,55,35)
GUICtrlSetOnEvent(-1,"actions")
GUICtrlSetState(-1,$GUI_DISABLE)
$numdown=60
for $i=3 to 8
$but[$i] = GUICtrlCreateButton("But"&$i+1, 5, $numdown,55,35,$BS_ICON)
GUICtrlSetOnEvent(-1,"actions")
GUICtrlSetImage(-1, "shell32.dll", 22+$i)
$numdown=$numdown+40
Next
$numdown=180
for $i= 1 to 3
    $label[$i]=GUICtrlCreateLabel("Label"&$i, 140, $numdown, 100, 20)
    GUICtrlSetOnEvent($label[$i],"actions")
    GUICtrlSetBkColor(-1,"0xBABABA")
    $numdown=$numdown+40
Next
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Set up the accelerators
for $i=0 to 3
    $aAccelerator[$i][0] = "^"&$i+1
    $aAccelerator[$i][1] = $but[$i]
    $aAccelerator[$i][2] = GUICtrlGetHandle($but[$i])

Next
    $aAccelerator[4][0] = "!z"
    $aAccelerator[4][1] = $but[4]
    $aAccelerator[4][2] = GUICtrlGetHandle($but[4])
    $aAccelerator[5][0] = "!x"
    $aAccelerator[5][1] = $but[5]
    $aAccelerator[5][2] = GUICtrlGetHandle($but[5])
    $aAccelerator[6][0] = "!c"
    $aAccelerator[6][1] = $but[6]
    $aAccelerator[6][2] = GUICtrlGetHandle($but[6])
    $aAccelerator[7][0] = "!v"
    $aAccelerator[7][1] = $but[7]
    $aAccelerator[7][2] = GUICtrlGetHandle($but[7])
    $aAccelerator[8][0] = "+a"
    $aAccelerator[8][1] = $but[8]
    $aAccelerator[8][2] = GUICtrlGetHandle($but[8])
    $aAccelerator[9][0] = "+s"
    $aAccelerator[9][1] = $label[1]
    $aAccelerator[9][2] = GUICtrlGetHandle($label[1])
    $aAccelerator[10][0] = "+d"
    $aAccelerator[10][1] = $label[2]
    $aAccelerator[10][2] = GUICtrlGetHandle($label[2])

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

_guisetaccelerators($aAccelerator,$main_Gui)

GUISetState(@SW_SHOW,$main_Gui)
            
While 1    
_modifierpressed($aAccelerator,$main_Gui)
    sleep(100)
WEnd

func actions()
        MsgBox(0,"",GUICtrlRead(@GUI_CTRLID))
EndFunc

;===============================================================================
;
; Function Name:   _API_SetLayeredWindowAttributes
; Description::    Sets Layered Window Attributes:) See MSDN for more informaion
; Parameter(s):   
;                  $hwnd - Handle of GUI to work on
;                  $i_transcolor - Transparent color
;                  $Transparency - Set Transparancy of GUI
;                  $isColorRef - If True, $i_transcolor is a COLORREF-Strucure, else an RGB-Color
; Requirement(s):  Layered Windows
; Return Value(s): Success: 1
;                  Error: 0
;                   @error: 1 to 3 - Error from DllCall
;                   @error: 4 - Function did not succeed - use
;                               _WinAPI_GetLastErrorMessage or _WinAPI_GetLastError to get more information
; Author(s):       Prog@ndy
;
;===============================================================================
;
Func _API_SetLayeredWindowAttributes($hwnd, $i_transcolor, $Transparency = $trans, $isColorRef = False)
   
Local Const $AC_SRC_ALPHA = 1
Local Const $ULW_ALPHA = 2
Local Const $LWA_ALPHA = 0x2
Local Const $LWA_COLORKEY = 0x1
    If Not $isColorRef Then
        $i_transcolor = Hex(String($i_transcolor), 6)
        $i_transcolor = Execute('0x00' & StringMid($i_transcolor, 5, 2) & StringMid($i_transcolor, 3, 2) & StringMid($i_transcolor, 1, 2))
    EndIf
    Local $Ret = DllCall("user32.dll", "int", "SetLayeredWindowAttributes", "hwnd", $hwnd, "long", $i_transcolor, "byte", $Transparency, "long", $LWA_COLORKEY + $LWA_ALPHA)
    Select
        Case @error
            Return SetError(@error,0,0)
        Case $ret[0] = 0
            Return SetError(4,0,0)
        Case Else
            Return 1
    EndSelect
EndFunc;==>_API_SetLayeredWindowAttributes
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


func _guisetaccelerators($accelerate,$winname)
    ReDim $accelerate[UBound($accelerate)][2]
    GUISetAccelerators($accelerate,$winname)
    Global $avChildren
    $hWnd = WinGetHandle($winname)
    WinListChildren($hWnd, $avChildren)
EndFunc

;Created by Authenticity
;modified by Picea892
Func WinListChildren($hWnd, ByRef $avArr)
    If UBound($avArr, 0) <> 2 Then
        Local $avTmp[10][5] = [[0]]
        $avArr = $avTmp
    EndIf
    
    Local $hChild = _WinAPI_GetWindow($hWnd, $GW_CHILD)
    
    While $hChild
        If $avArr[0][0]+1 > UBound($avArr, 1)-1 Then ReDim $avArr[$avArr[0][0]+10][5]
        $avArr[$avArr[0][0]+1][0] = $hChild
        $avArr[$avArr[0][0]+1][1] = _WinAPI_GetWindowText($hChild)
        $control_loc=ControlGetPos($hWnd,"",$hChild)

        $avArr[$avArr[0][0]+1][2] = $control_loc[0]
        $avArr[$avArr[0][0]+1][3] = $control_loc[1]
        $avArr[0][0] += 1
        WinListChildren($hChild, $avArr)
        $hChild = _WinAPI_GetWindow($hChild, $GW_HWNDNEXT)
    WEnd
    
    ReDim $avArr[$avArr[0][0]+1][6]
EndFunc

func _modifierpressed($cceler,$guiname)
    local $dll32 = DllOpen("user32.dll")
    if WinActive($guiname,"") and not WinExists("accelerators","") then
        
        if _IsPressed("10",$dll32) then ;shift
            createoverlay("+",$guiname)
        elseif _IsPressed("11",$dll32) then ;ctrl
            createoverlay("^",$guiname)
        elseif _IsPressed("12",$dll32) then ;alt
            createoverlay("!",$guiname)
        EndIf
    ElseIf  not _IsPressed("10",$dll32) and not _IsPressed("11",$dll32) and not _IsPressed("12",$dll32) and WinExists("accelerators","") then
        GUIDelete($accelgui)
        Return
    EndIf

EndFunc

func createoverlay($modifier,$guinam)
    local $transcolour="0xABCDEF"
    local $WS_EX_NOACTIVATE = 0x08000000
    local $winactive=WinGetHandle("","")
    Local $winlocation=WinGetPos($guinam)
    Global $accelgui = GUICreate("accelerators", $winlocation[2], $winlocation[3],$winlocation[0],$winlocation[1],$WS_POPUP, BitOR($WS_EX_LAYERED,$WS_EX_NOACTIVATE))
    WinSetOnTop($accelgui,"",1)
    GUISetBkColor($transcolour,$accelgui)

    for $i=1 to $avChildren[0][0]
        ;Global $cont=ControlGetPos($main_Gui,"",GUICtrlGetHandle($but[$i]))
            ;       ToolTip($avChildren[$i][0])
            ;Sleep(1000)
    
        for $a= 0 to UBound($aAccelerator)-1

            if $aAccelerator[$a][2]=$avChildren[$i][0] and StringLeft($aAccelerator[$a][0],1)= $modifier then
                $avChildren[$i][4]=GUICtrlCreateLabel(StringRight($aAccelerator[$a][0],StringLen($aAccelerator[$a][0])-1), $avChildren[$i][2]+2, $avChildren[$i][3]+2,11,13,$SS_CENTER)
                GUICtrlSetBkColor(-1,"0xFFFFFF")
            EndIf
        Next
    Next
_API_SetLayeredWindowAttributes($accelgui,$transcolour,200)
GUISetState(@SW_SHOWNOACTIVATE,$accelgui)
EndFunc

post-45064-12507184188814_thumb.jpg

Edited by picea892

Share this post


Link to post
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
Sign in to follow this  
Followers 0