Jump to content

Accelerator Tables


Lazycat
 Share

Recommended Posts

This is really cool man. I like it that your doing work that could ultimatly help a lot of people. :)

Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 
Link to comment
Share on other sites

Bad news :)

On my WIN98SE with AutoIt 3.2.8.1 it's not working.

- I must add Global Const $WM_COMMAND = 0x0111 - but it's not problem

- nothing happens (only ding sound) if any keyboard shortcut is invoked - Ctrl+O or Alt+X

Same for me with XP pro sp2 Au3 - 3.2.8.1

Const is declared for Beta 3.2.9.3 but again, only ding sound.

Link to comment
Share on other sites

Same for me with XP pro sp2 Au3 - 3.2.8.1

Const is declared for Beta 3.2.9.3 but again, only ding sound.

I think this is due latest version changes. Something from massive DllCall changes, struct alignment and native pointer support - maybe all in complex. I'm tried some older betas what I have, code start working from about 3.2.9.10, 3.2.9.8 give "corrupt stack" error on the TranslateAccelerator call, prior versions don't work at all.

Link to comment
Share on other sites

I think this is due latest version changes. Something from massive DllCall changes, struct alignment and native pointer support - maybe all in complex. I'm tried some older betas what I have, code start working from about 3.2.9.10, 3.2.9.8 give "corrupt stack" error on the TranslateAccelerator call, prior versions don't work at all.

With some minor changes, ptr should be handle after reading up on the functions. This works for me without crashing on WinXP Pro SP2 3.2.9.10 and 3.2.9.14

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $MyAccelTable

Global $FVIRTKEY = 0x1
Global $FNOINVERT = 0x2
Global $FSHIFT = 0x4
Global $FCONTROL = 0x8
Global $FALT = 0x10

$hGUI = GUICreate("GUI", 426, 205, -1, -1)
$hButton = GUICtrlCreateButton("Button", 170, 112, 75, 25)
$hFile = GUICtrlCreateMenu("File")
$hFileOpen = GUICtrlCreateMenuItem("Open File" & @TAB & "Ctrl+O", $hFile)
_GUICtrlSetAccelerator($MyAccelTable, $hFileOpen, "^o")
GUICtrlCreateMenuItem("", $hFile)
$hExit = GUICtrlCreateMenuItem("Exit" & @TAB & "Alt+X", $hFile)
_GUICtrlSetAccelerator($MyAccelTable, $hExit, "!X")
GUISetState(@SW_SHOW)

_GUIAcceleratorTableInit($MyAccelTable)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND_FUNC")

GUISetState(@SW_SHOW)

While 1
    _GUIAcceleratorProcessMsg($hGUI, $MyAccelTable)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hFileOpen
            FileOpenDialog("Bla", "", "All (*.*)")
        Case $hExit
            _GUIAcceleratorTableFree($MyAccelTable)
            Exit
        Case $hButton
            MsgBox(0, "Button", "Ok")
    EndSwitch
WEnd

Func WM_COMMAND_FUNC($hWnd, $MSG, $wParam, $lParam)
    If BitAND($wParam, 0xF0000) = 0x10000 Then
        ; Autoit not support WM_COMMAND sent with "accelerator" flag
        ; so remove it and post message again with the same control id
        $wParam = BitAND($wParam, BitNOT(0x10000))
        DllCall("user32.dll", "int", "PostMessage", "hwnd", $hWnd, _
                "int", $WM_COMMAND, _
                "wparam", $wParam, _
                "lparam", $lParam)
        Return 0
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND_FUNC

Func _GUIAcceleratorProcessMsg($hWnd, $hAccel)
    Local $hDll = DllOpen("user32.dll")
    Local $MSG = DllStructCreate("hwnd;uint;int;int;dword;int;int")
    DllCall($hDll, "int", "GetMessage", "ptr", DllStructGetPtr($MSG), "hwnd", $hWnd, "uint", 0, "uint", 0)
    $ret = DllCall($hDll, "int", "TranslateAccelerator", "hwnd", $hWnd, "hwnd", $hAccel, "ptr", DllStructGetPtr($MSG))
    If Not $ret[0] Then
        DllCall($hDll, "int", "TranslateMessage", "ptr", DllStructGetPtr($MSG))
        DllCall($hDll, "int", "DispatchMessage", "ptr", DllStructGetPtr($MSG))
    EndIf
    DllClose($hDll)
EndFunc   ;==>_GUIAcceleratorProcessMsg

Func _GUIAcceleratorTableFree($hAccel)
    DllCall("user32.dll", "int", "DestroyAcceleratorTable", "hwnd", $hAccel)
EndFunc   ;==>_GUIAcceleratorTableFree

Func _GUIAcceleratorTableInit(ByRef $pTable)
    Local $tagACCEL = "byte;short;short"
    Local $fVirt, $key
    If Not IsArray($pTable) Or UBound($pTable) < 2 Then SetError(1, 0, False)
    Local $sData = ""
    For $i = 1 To $pTable[0][0]
        $sData &= $tagACCEL & ";"
    Next
    $sData = StringTrimRight($sData, 1)
    Local $pData = DllStructCreate($sData)
    For $i = 1 To $pTable[0][0]
        _TranslateKeys($pTable[$i][1], $fVirt, $key)
        DllStructSetData($pData, $i * 3 - 2, $fVirt)
        DllStructSetData($pData, $i * 3 - 1, $key)
        DllStructSetData($pData, $i * 3, $pTable[$i][0])
    Next
    $ret = DllCall("user32.dll", "hwnd", "CreateAcceleratorTable", "ptr", DllStructGetPtr($pData), "int", $pTable[0][0])
    If @error Or $ret[0] = 0 Then SetError(2, 0, 1) ; Creating table was not succeed
    $pTable = $ret[0]
    Return True
EndFunc   ;==>_GUIAcceleratorTableInit

Func _TranslateKeys($sHotkey, ByRef $fVirt, ByRef $key)
    $fVirt = 0
    $sHotkey = StringReplace($sHotkey, "^", "", 1)
    If @extended = 1 Then $fVirt = BitOR($fVirt, $FCONTROL, $FVIRTKEY)
    $sHotkey = StringReplace($sHotkey, "!", "", 1)
    If @extended = 1 Then $fVirt = BitOR($fVirt, $FALT, $FVIRTKEY)
    $sHotkey = StringReplace($sHotkey, "+", "", 1)
    If @extended = 1 Then $fVirt = BitOR($fVirt, $FSHIFT, $FVIRTKEY)
    If StringLen($sHotkey) = 1 Then
        $key = Asc(StringUpper($sHotkey))
    Else
        ; Here become long case for special keys
        Switch $sHotkey
            Case "{SPACE}"
                $key = 32
            Case "{ENTER}"
                $key = 13
        EndSwitch
    EndIf
EndFunc   ;==>_TranslateKeys

Func _GUICtrlSetAccelerator(ByRef $pTable, $nCtrlID, $sHotkey)
    If Not IsArray($pTable) Then
        Local $tmpTable[1][2] = [[0, 0]]
        $pTable = $tmpTable
    EndIf
    $pTable[0][0] += 1

    Local $curIdx = $pTable[0][0]

    ReDim $pTable[$curIdx + 1][2]
    $pTable[$curIdx][0] = $nCtrlID
    $pTable[$curIdx][1] = $sHotkey
EndFunc   ;==>_GUICtrlSetAccelerator

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

Who said, besides you, that WeaponX is disturbing us? People ask those questions quite often.

Edit:

And, he is not asking the question continually or persistenly.

Exactly, that's the point! They ask the same questions over and over and over....

I don't understand what the argument is about. Why is it so darn hard to understand that, by taking 5 minutes to do some research on your own, the information will be of much greater benefit, than if someone just told you the answer?

Yelling at someone who points out one of your faults is NOT the way to encourage willingness to help.

Link to comment
Share on other sites

Exactly, that's the point! They ask the same questions over and over and over....

I don't understand what the argument is about. Why is it so darn hard to understand that, by taking 5 minutes to do some research on your own, the information will be of much greater benefit, than if someone just told you the answer?

Yelling at someone who points out one of your faults is NOT the way to encourage willingness to help.

Don't start this B.S. again. I don't think LazyCat appreciates his thread being hi-jacked with arguments.

@Zedna, I don't have Win9x to test so don't know what is happening there, guess you can say you've been "dinged for using Win98".

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