Jump to content

Recommended Posts

Posted

Hey as I don't know exactly how it works I would need backspace and enter key as GUIRegisterMsg. Thanks in advance.

And If someone got a tut on how it works please link it

  • Moderators
Posted

Sturmi.

Why can you not use _IsPressed?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

  • Moderators
Posted

Sturmi,

So use _IsPressed and check if the ListBox has focus.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

Here the modified example script to _GUICtrlListBox_Create:

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

Global $g_hListBox

Example()

Func Example()
    Local $hGUI

    ; Create GUI
    $hGUI = GUICreate("(UDF Created) List Box Create", 400, 296)
    $g_hListBox = _GUICtrlListBox_Create($hGUI, "String upon creation", 2, 2, 396, 296)
    GUISetState(@SW_SHOW)

    MsgBox($MB_SYSTEMMODAL, "Information", "Adding Items")

    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

    ; Add files
    _GUICtrlListBox_BeginUpdate($g_hListBox)
    _GUICtrlListBox_ResetContent($g_hListBox)
    _GUICtrlListBox_InitStorage($g_hListBox, 100, 4096)
    _GUICtrlListBox_Dir($g_hListBox, @WindowsDir & "\win*.exe")
    _GUICtrlListBox_AddFile($g_hListBox, @WindowsDir & "\notepad.exe")
    _GUICtrlListBox_Dir($g_hListBox, "", $DDL_DRIVES)
    _GUICtrlListBox_Dir($g_hListBox, "", $DDL_DRIVES, False)
    _GUICtrlListBox_EndUpdate($g_hListBox)

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>Example

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg
    Local $hWndFrom, $iIDFrom, $iCode, $hWndListBox
    If Not IsHWnd($g_hListBox) Then $hWndListBox = GUICtrlGetHandle($g_hListBox)
    $hWndFrom = $lParam
    $iIDFrom = BitAND($wParam, 0xFFFF) ; Low Word
    $iCode = BitShift($wParam, 16) ; Hi Word

    Switch $hWndFrom
        Case $g_hListBox, $hWndListBox
            Switch $iCode
                Case $LBN_DBLCLK ; Sent when the user double-clicks a string in a list box
                    $iItem=_GUICtrlListBox_GetCurSel($hWndFrom)
                    $s_Text=_GUICtrlListBox_GetText($hWndFrom,$iItem)
                    _DebugPrint("$LBN_DBLCLK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode & @CRLF & _
                            "ItemIndex" & @TAB & $iItem& @CRLF & _
                            "ItemText:" & @TAB & $s_Text)
                    ; no return value
                Case $LBN_ERRSPACE ; Sent when a list box cannot allocate enough memory to meet a specific request
                    _DebugPrint("$LBN_ERRSPACE" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
                Case $LBN_KILLFOCUS ; Sent when a list box loses the keyboard focus
                    _DebugPrint("$LBN_KILLFOCUS" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
                Case $LBN_SELCANCEL ; Sent when the user cancels the selection in a list box
                    _DebugPrint("$LBN_SELCANCEL" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
                Case $LBN_SELCHANGE ; Sent when the selection in a list box has changed
                    _DebugPrint("$LBN_SELCHANGE" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
                Case $LBN_SETFOCUS ; Sent when a list box receives the keyboard focus
                    _DebugPrint("$LBN_SETFOCUS" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; no return value
            EndSwitch
    EndSwitch
    ; Proceed the default AutoIt3 internal message commands.
    ; You also can complete let the line out.
    ; !!! But only 'Return' (without any value) will not proceed
    ; the default AutoIt3-message in the future !!!
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

Func _DebugPrint($s_Text)
    $s_Text = StringReplace($s_Text, @CRLF, @CRLF & "-->")
    ConsoleWrite("!===========================================================" & @CRLF & _
            "+===========================================================" & @CRLF & _
            "-->" & $s_Text & @CRLF & _
            "+===========================================================" & @CRLF)
EndFunc   ;==>_DebugPrint

 

Posted (edited)
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$hGUI = GUICreate("Form1", 300, 150, -1, -1)
$fENTER = GUICtrlCreateDummy()
$fBACKSPACE = GUICtrlCreateDummy()

$sEdit = GUICtrlCreateEdit("", 10, 10, 100, 100)

Local $aAccelKeys[2][2] = [["{ENTER}", $fENTER],["{BACKSPACE}", $fBACKSPACE]]
GUISetAccelerators($aAccelKeys)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $fENTER
            ConsoleWrite("ENTER" & @CRLF)
            _EnableKey("{ENTER}")
        Case $fBACKSPACE
            ConsoleWrite("BACKSPACE" & @CRLF)
            _EnableKey("{BACKSPACE}")
    EndSwitch
WEnd

Func _EnableKey($sKey)
    GUISetAccelerators("")
    ControlSend($hGUI, "", ControlGetFocus($hGUI, ""), $sKey)
    GUISetAccelerators($aAccelKeys)
EndFunc   ;==>_EnableKey

Alternative to _IsPressed

Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Posted (edited)

@Terenz ,

Your idea will block the enter key and backspace for other controls in that form.

Edited by kcvinu
  Reveal hidden contents

 

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
  • Recently Browsing   0 members

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