Jump to content

Detect click on listbox


Recommended Posts

I want to know when it's clicked on, like I want to trigger an update when it's clicked. Here's my current code, it uses ispressed() and winactive()

But this detects any click anywhere on the window, I just want to capture the click for the listbox only.

 

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=SIM32.exe
#AutoIt3Wrapper_UseUpx=y
#AutoIt3Wrapper_Change2CUI=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <GUIEdit.au3>
#include <WindowsConstants.au3>
#include <Inet.au3>
#include "P2PTCP.au3"
#include "DARTIS.au3"
#include <array.au3>
#include <misc.au3>
#include <WindowsConstants.au3>
#include <Memory.au3>
#include <GDIPlus.au3>

Global $precision = TimerInit()
Global $kbp, $gtimer = TimerInit()

Global $session = "NULL", $username, $recipient,$last
Dim $conversations[100][3]
$conversations[0][0]=0
_login()
$Form2 = GUICreate("Secure Interface Module", 612, 456)
$List2 = GUICtrlCreateList("", 0, 0, 145, 435)
$Edit2 = GUICtrlCreateEdit("", 146, 0, 465, 401, $WS_VSCROLL+$ES_AUTOVSCROLL)
GUICtrlSetData(-1, "")
$Input2 = GUICtrlCreateInput("", 152, 408, 377, 21)
$Button2 = GUICtrlCreateButton("Send", 536, 405, 75, 25)
_GUICtrlEdit_SetReadOnly($Edit2, true)
_getcontacts()
_P2P_Start_Node($username, 6667, 25, 1, 25, 1, "0.0.0.0")
_P2P_Register_Event($P2P_MESSAGE, "recv")
_getpeers()
Local $idcontacts = GUICtrlCreateMenu("&Contacts")
Local $managecontacts = GUICtrlCreateMenuItem("Manage Contacts", $idcontacts)
    Local $idFilemenu = GUICtrlCreateMenu("&Encryption")
    Local $generatekey = GUICtrlCreateMenuItem("Generate Keyfile", $idFilemenu)
    Local $selectkey = GUICtrlCreateMenuItem("Select KeyFile", $idFilemenu)
        Local $clearkey = GUICtrlCreateMenuItem("Clear KeyFile", $idFilemenu)
GUISetState(@SW_SHOW)
GUIDelete($hGUI)
$peers = TimerInit()
While 1
    if _IsPressed(01) Then
if WinActive($Form2) Then
$current = _GUICtrlListBox_GetText($list2, _GUICtrlListBox_GetCurSel($list2))
$recipient = $current;update last to current
    _GUICtrlEdit_SetText($Edit2, "")
    for $i=0 to $conversations[0][0]
        if $conversations[$i][0] = $current Then
            GUICtrlSetData($Edit2, $conversations[$i][1])
        ExitLoop
        EndIf
    Next
    EndIf
    EndIf
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $managecontacts
        ShellExecute("https://pdglobal.net/?pid=settings#settings")
        Case $clearkey
            IniWrite(@ScriptDir&"\settings.ini", "userkeys", $current, "NA")
        Case $selectkey
            $keyfile = FileOpenDialog("Select KeyFile for this user", @ScriptDir, "*.kbf(*.kbf)")
            $localkey = FileRead($keyfile)
            IniWrite(@ScriptDir&"\settings.ini", "userkeys", $current, $keyfile)
        for $i=0 to $conversations[0][0]
        if $conversations[$i][0] = $current Then
$conversations[$i][2] = _bang($localkey)
        ExitLoop
        EndIf
    Next
        Case $generatekey
            $saveas = FileSaveDialog("Generate Keyfile", @ScriptDir, "*.kbf(*.kbf)")
            $key = _generate_keyFile()
            if not StringLeft($saveas, 3) = "kbf" Then
                $saveas&="kbf"
            EndIf
            FileWrite($saveas, $key)
        Case $GUI_EVENT_CLOSE
            MsgBox(0, "Exit now?", "Are you sure you want to exit the Secure Interface Module?")
            Exit
        case $Button2
$current = _GUICtrlListBox_GetText($list2, _GUICtrlListBox_GetCurSel($list2))

    $recipient = $current;update last to current
    _GUICtrlEdit_SetText($Edit2, "")
    for $i=0 to $conversations[0][0]
        if $conversations[$i][0] = $current Then
           $conversations[$i][1] &= "Me: "&GUICtrlRead($input2)&@CRLF
            GUICtrlSetData($Edit2, $conversations[$i][1])
        ExitLoop
        EndIf
    Next

if UBound($conversations[$i][2]) > 2 Then
    _p2p_send_message($recipient, _inject($conversations[$i][2], GUICtrlRead($input2)),$username)
Else
    _p2p_send_message($recipient, GUICtrlRead($input2),$username)
EndIf

 GUICtrlSetData($input2, "")
    EndSwitch
    if TimerDiff($peers) > 30000 then
    _getpeers()
    $peers = TimerInit()
    EndIf
WEnd

func _getpeers()
$peerlist = StringSplit(StringTrimLeft(_INetGetSource("https://pdglobal.net/?sid=peerlist"),1), "|")
for $i=1 to $peerlist[0]
    _P2P_Connect($peerlist[$i])
Next
EndFunc

Func _getcontacts()
$clist = StringSplit(StringTrimLeft(_INetGetSource("https://pdglobal.net/?sid=contactslist&session="&$session),1), "|")
$index = 0

    _GUICtrlListBox_ResetContent($list2)
for $i=1 to $clist[0]
    if $clist[$i] <> "" Then
        $conversations[0][0] +=1
    $conversations[$i][0] = $clist[$i]
    $conversations[$i][2] = _bang(FileRead(IniRead(@ScriptDir&"\settings.ini", "userkeys", $clist[$i], "NA")))
    _GUICtrlListBox_AddString($list2, $clist[$i])
    $index += 1
    EndIf
    Next
EndFunc

Func recv($Socket, $message, $from, $error)
    ;_extract($message)
    ConsoleWrite($from&@CRLF)
            for $i=0 to $conversations[0][0]
        if $conversations[$i][0] = $from Then

if UBound($conversations[$i][2]) > 2 Then
            $message = _extract($conversations[$i][2], $message)

EndIf
           $conversations[$i][1] &= $from&": "&$message&@CRLF
GUICtrlSetData($Edit2, $conversations[$i][1])

        ExitLoop
        EndIf
    Next
EndFunc

func _login()
    $Form1 = GUICreate("Secure Interface Module", 280, 331, 192, 124)
GUISetBkColor(0xFFFFFF)
$Group1 = GUICtrlCreateGroup("Username", 48, 128, 185, 57)
$Input1 = GUICtrlCreateInput("", 56, 152, 169, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Password", 48, 195, 185, 57)
$Input2 = GUICtrlCreateInput("", 56, 219, 169, 21, 0x0020)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("Sign In", 64, 272, 155, 25)
$Pic1 = GUICtrlCreatePic(@ScriptDir&"\SIM.jpg", 40, 16, 204, 100)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $username = GUICtrlRead($Input1)
            $password = GUICtrlRead($Input2)
            $auth = _INetGetSource("https://pdglobal.net/?sid=login&usr="&$username&"&pwd="&$password)
            if StringLeft($auth,3) = " 0x" Then
                ;logged in
                $session = StringTrimLeft($auth, 3)
                GUISetState(@SW_HIDE, $Form1)
                loading()
                ExitLoop
            Else
                MsgBox(16, "Error", $auth)
            EndIf

    EndSwitch
WEnd
EndFunc

;coded by UEZ build 2013-05-02, idea taken from http://tympanus.net/codrops/2012/11/14/creative-css-loading-animations/
;AutoIt v3.3.9.21 or higher needed!

Func loading()
Global Const $hDwmApiDll = DllOpen("dwmapi.dll")
Global $sChkAero = DllStructCreate("int;")
DllCall($hDwmApiDll, "int", "DwmIsCompositionEnabled", "ptr", DllStructGetPtr($sChkAero))
Global $bAero = DllStructGetData($sChkAero, 1)
Global $fStep = 0.02
If Not $bAero Then $fStep = 1.5

_GDIPlus_Startup()
Global Const $STM_SETIMAGE = 0x0172; $IMAGE_BITMAP = 0
Global $iW = 400, $iH = 250
Global Const $hGUI = GUICreate("Loading", $iW, $iH, -1, -1, $WS_POPUPWINDOW, $WS_EX_TOPMOST)
GUISetBkColor(0xEEEEEE)
Global Const $iPic = GUICtrlCreatePic("", 0, 0, $iW, $iH)
GUICtrlSetState(-1, $GUI_DISABLE)
WinSetTrans($hGUI, "", 0)
GUISetState()
Global $hHBmp_BG, $hB, $iSleep = 50
GUIRegisterMsg($WM_TIMER, "PlayAnim")
DllCall("user32.dll", "int", "SetTimer", "hwnd", $hGUI, "int", 0, "int", $iSleep, "int", 0)
Global $z, $iPerc = 0

For $z = 1 To 255 Step $fStep
    WinSetTrans($hGUI, "", $z)
Next

EndFunc

Func PlayAnim()
    $hHBmp_BG = _GDIPlus_MonochromaticBlinker($iW, $iH, "Loading... Please Wait")
    $hB = GUICtrlSendMsg($iPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBmp_BG)
    If $hB Then _WinAPI_DeleteObject($hB)
    _WinAPI_DeleteObject($hHBmp_BG)
EndFunc   ;==>PlayAnim

Func _GDIPlus_MonochromaticBlinker($iW, $iH, $sString = "Please wait...", $bHBitmap = True)
    Local Const $hBrushBall1 = _GDIPlus_BrushCreateSolid(0xFF123456)
    Local Const $hBrushBall2 = _GDIPlus_BrushCreateSolid(0x80123456)
    Local Const $hBrushRect = _GDIPlus_BrushCreateSolid(0x90FFFFFF)
    Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH)

    Local Const $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetPixelOffsetMode($hCtxt, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
    _GDIPlus_GraphicsSetSmoothingMode($hCtxt, 2)
    Local Const $hBmp_BG = _GDIPlus_BitmapCreateFromMemory(_Background())
    Local $hBrushTexture = _GDIPlus_TextureCreate($hBmp_BG)
    _GDIPlus_BitmapDispose($hBmp_BG)
    _GDIPlus_GraphicsFillRect($hCtxt, 0, 0, $iW, $iH, $hBrushTexture)
    Local $iRadius, $fCosX, $fSinY, $i, $j = 0, $l = 0
    Local Const $fDeg = ACos(-1) / 180, $iRadius1 = 60, $iRadius2 = $iRadius1 - 16, $iCount = 4, $iW2 = $iW / 2, $iH2 = $iH / 2, $iSizeBall = 32, $iSizeBall2 = $iSizeBall / 2, _
            $fFontSize = 12, $fSpeed = 0.5
    Local $tPoints = DllStructCreate("float[" & $iCount * 2 & "]")
    Local $aColors[15] = [$hBrushBall1, $hBrushBall1, $hBrushBall1, $hBrushBall1, $hBrushBall1, $hBrushBall1, $hBrushBall1, $hBrushBall2, _
            $hBrushBall1, $hBrushBall1, $hBrushBall1, $hBrushBall1, $hBrushBall1, $hBrushBall1, $hBrushBall1]
    Local Static $iAngle = 0, $k
    For $i = 0 To 315 Step 45
        $fCosX = Cos(($i + $iAngle) * $fDeg)
        $fSinY = Sin(($i + $iAngle) * $fDeg)
        If Not Mod($j, 2) Then
            DllStructSetData($tPoints, 1, $iW2 + $fCosX * ($iRadius1 + 3), $l * 2 + 1)
            DllStructSetData($tPoints, 1, $iH2 + $fSinY * ($iRadius1 + 3), $l * 2 + 2)
            $l += 1
        EndIf
        $iRadius = Execute("$iRadius" & 1 + Mod($j, 2))
        _GDIPlus_GraphicsFillEllipse($hCtxt, -$iSizeBall2 + $iW2 + $fCosX * $iRadius, -$iSizeBall2 + $iH2 + $fSinY * $iRadius, $iSizeBall, $iSizeBall, $aColors[Int(7 - $k + $j)])
        $j += 1
    Next
    $k = Mod($k + $fSpeed, 8)
    DllCall($__g_hGDIPDll, "int", "GdipFillPolygon", "handle", $hCtxt, "handle", $hBrushRect, "struct*", $tPoints, "int", $iCount, "int", 0)
    $tPoints = 0
    $iAngle -= 2
    Local Const $hFormat = _GDIPlus_StringFormatCreate()
    Local Const $hFamily = _GDIPlus_FontFamilyCreate("Arial")
    Local Const $hFont = _GDIPlus_FontCreate($hFamily, $fFontSize, 2)
    Local Const $hBrushTxt = _GDIPlus_BrushCreateSolid(0xFF101010)
    Local Const $tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0)
    Local Const $aInfo = _GDIPlus_GraphicsMeasureString($hCtxt, $sString, $hFont, $tLayout, $hFormat)
    DllStructSetData($tLayout, "X", ($iW - DllStructGetData($aInfo[0], "Width")) / 2)
    DllStructSetData($tLayout, "Y", $iH / 2 + $iRadius1 + $iSizeBall)
    _GDIPlus_GraphicsDrawStringEx($hCtxt, $sString, $hFont, $tLayout, $hFormat, $hBrushTxt)

    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_BrushDispose($hBrushTxt)
    _GDIPlus_BrushDispose($hBrushTexture)
    _GDIPlus_GraphicsDispose($hCtxt)
    _GDIPlus_BrushDispose($hBrushBall1)
    _GDIPlus_BrushDispose($hBrushBall2)
    _GDIPlus_BrushDispose($hBrushRect)
    If $bHBitmap Then
        Local $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
        _GDIPlus_BitmapDispose($hBitmap)
        Return $hHBITMAP
    EndIf
    Return $hBitmap
EndFunc   ;==>_GDIPlus_MonochromaticBlinker

;Code below was generated by: 'File to Base64 String' Code Generator v1.12 Build 2013-03-27

Func _Background($bSaveBinary = False, $sSavePath = @ScriptDir)
    Local $Background
    $Background &= 'iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKBAMAAAB/HNKOAAAAD1BMVEXl5eXp6enu7u7g4ODm5uY5xL5yAAAAJElEQVR4Xk3KMQ0AAAwDoNYKGupf2969hBTNsKiKmVDC+P7/AbJBBh6YaCBlAAAAAElFTkSuQmCC'
    Local $bString = Binary(_Base64Decode($Background))
    If $bSaveBinary Then
        Local $hFile = FileOpen($sSavePath & "\hexabump.png", 18)
        FileWrite($hFile, $bString)
        FileClose($hFile)
    EndIf
    Return $bString
EndFunc   ;==>_Background
Func _base64decode($data)
    Local $opcode = "0xC81000005356578365F800E8500000003EFFFFFF3F3435363738393A3B3C3DFFFFFF00FFFFFF000102030405060708090A0B0C0D0E0F10111213141516171819FFFFFFFFFFFF1A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132338F45F08B7D0C8B5D0831D2E9910000008365FC00837DFC047D548A034384C0750383EA033C3D75094A803B3D75014AB00084C0751A837DFC047D0D8B75FCC64435F400FF45FCEBED6A018F45F8EB1F3C2B72193C7A77150FB6F083EE2B0375F08A068B75FC884435F4FF45FCEBA68D75F4668B06C0E002C0EC0408E08807668B4601C0E004C0EC0208E08847018A4602C0E00624C00A46038847028D7F038D5203837DF8000F8465FFFFFF89D05F5E5BC9C21000"
    Local $codebuffer = DllStructCreate("byte[" & BinaryLen($opcode) & "]")
    DllStructSetData($codebuffer, 1, $opcode)
    Local $ouput = DllStructCreate("byte[" & BinaryLen($data) & "]")
    Local $ret = DllCall("user32.dll", "int", "CallWindowProc", "ptr", DllStructGetPtr($codebuffer), "str", $data, "ptr", DllStructGetPtr($ouput), "int", 0, "int", 0)
    Return BinaryMid(DllStructGetData($ouput, 1), 1, $ret[0])
EndFunc

Func _base64encode($data, $linebreak = 76)
    Local $opcode = "0x5589E5FF7514535657E8410000004142434445464748494A4B4C4D4E4F505152535455565758595A6162636465666768696A6B6C6D6E6F707172737475767778797A303132333435363738392B2F005A8B5D088B7D108B4D0CE98F0000000FB633C1EE0201D68A06880731C083F901760C0FB6430125F0000000C1E8040FB63383E603C1E60409C601D68A0688470183F90176210FB6430225C0000000C1E8060FB6730183E60FC1E60209C601D68A06884702EB04C647023D83F90276100FB6730283E63F01D68A06884703EB04C647033D8D5B038D7F0483E903836DFC04750C8B45148945FC66B80D0A66AB85C90F8F69FFFFFFC607005F5E5BC9C21000"
    Local $codebuffer = DllStructCreate("byte[" & BinaryLen($opcode) & "]")
    DllStructSetData($codebuffer, 1, $opcode)
    $data = Binary($data)
    Local $input = DllStructCreate("byte[" & BinaryLen($data) & "]")
    DllStructSetData($input, 1, $data)
    $linebreak = Floor($linebreak / 4) * 4
    Local $oputputsize = Ceiling(BinaryLen($data) * 4 / 3)
    $oputputsize = $oputputsize + Ceiling($oputputsize / $linebreak) * 2 + 4
    Local $ouput = DllStructCreate("char[" & $oputputsize & "]")
    DllCall("user32.dll", "none", "CallWindowProc", "ptr", DllStructGetPtr($codebuffer), "ptr", DllStructGetPtr($input), "int", BinaryLen($data), "ptr", DllStructGetPtr($ouput), "uint", $linebreak)
    Return DllStructGetData($ouput, 1)
EndFunc

 

Link to comment
Share on other sites

  • 4 weeks later...

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