Jump to content

How to get notified when user clicks combo boxe's edit area ?


Recommended Posts

Hi all,

How can i get notified when user clicks on a combo box's edit area ? This is my code so far. 

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <ComboConstants.au3>
#include <ListBoxConstants.au3>



Global $btn
; creates a window

Global $Window_0 = GUICreate("My Window", 800, 500, -1, -1, BitOR($WS_SIZEBOX, $WS_MINIMIZEBOX, $WS_MAXIMIZEBOX))
$btn = GUICtrlCreateButton("Click Me", 50, 50, 120, 50)
Global $cmb = GUICtrlCreateCombo("Sample", 50, 150, 300, 50)
GUICtrlSetFont(-1,12,400)
Global $lstbx = GUICtrlCreateList("FirstItem", 400,50, 200, 300)
GUICtrlSetFont(-1,12,400)


GUIRegisterMsg($WM_COMMAND, "MyEventCallback")
GUIRegisterMsg($WM_SIZE, "MyEventCallback")
GUIRegisterMsg($WM_NOTIFY, "NotifyManager")

GUISetState(@SW_SHOW)
GUICtrlSetData($cmb, "Item 2|Item 3", "Item 2")
GUICtrlSetData($lstbx,  "Apple|Orange|Pineapple|Grape|Lemon")
Do
    $Event = GUIGetMsg( )

Until $Event = $GUI_EVENT_CLOSE

Func MyEventCallback($hwnd, $message, $wParam, $lParam)
    Select

        Case $message = $WM_COMMAND
            ;----------------------------------------------------------------
            If LoWord($wParam) = $cmb Then ; if control id is combox's Then
                Local $Notification = HiWord($wParam)
                Select
                    Case $Notification = $CBN_DROPDOWN   ; here we check the notification code.
                        ConsoleWrite("$CBN_DROPDOWN Worked " & @MIN & ":" & @SEC & @CRLF)
                    Case $Notification = $CBN_EDITCHANGE   ; here we check the notification code.
                        ConsoleWrite("$CBN_EDITCHANGE Worked " & @MIN & ":" & @SEC & @CRLF)
                    
                    ; **** Here i want add the code for combo box clicking.
                    
                EndSelect
            ;---------------------------------------------------------------------  
            ElseIf LoWord($wParam) = $lstbx Then
                Local $Notification = HiWord($wParam)
                Select
                    Case $Notification = $LBN_SELCHANGE
                        ConsoleWrite("$LBN_SELCHANGE" & @CRLF)
                EndSelect
            EndIf
            ;------------------------------------------------------------------

        Case $message = $WM_SIZE

    EndSelect
    Return $GUI_RUNDEFMSG
EndFunc   ;==>ProGUI_EventCallback

Func NotifyManager($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    ;Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR

    Local $tagNMHDR, $event, $hwndFrom, $code
    $tagNMHDR = DllStructCreate("int;int;int", $lParam)
    If DllStructGetData($tagNMHDR, 3) = $NM_LDOWN Then
        ConsoleWrite("Notify Worked" & @CRLF)
    EndIf

    Return $GUI_RUNDEFMSG
EndFunc

Func LoWord($Variable)
    Return BitAND($Variable, 0xFFFF)
EndFunc

Func HiWord($Variable)
    Return BitShift($Variable, 16)
EndFunc

 

My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to post
Share on other sites

Get a handle to the edit control and subclass the edit control:

#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPIShellEx.au3>

Global $g_idMemo

Example()

Func Example()
  Local $tInfo, $idCombo

  ; Create GUI
  GUICreate("ComboBox Get ComboBox Info", 400, 296)
  $idCombo = GUICtrlCreateCombo("", 2, 2, 396, 296)
  $g_idMemo = GUICtrlCreateEdit("", 2, 32, 396, 266, 0)
  GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
  GUISetState(@SW_SHOW)

  ; Add files
  _GUICtrlComboBox_BeginUpdate($idCombo)
  _GUICtrlComboBox_AddDir($idCombo, @WindowsDir & "\*.exe")
  _GUICtrlComboBox_EndUpdate($idCombo)

  If _GUICtrlComboBox_GetComboBoxInfo($idCombo, $tInfo) Then
    MemoWrite("Handle to the ComboBox .....: " & DllStructGetData($tInfo, "hCombo"))
    MemoWrite("Handle to the Edit Box .....: " & DllStructGetData($tInfo, "hEdit"))
    MemoWrite("Handle to the drop-down list: " & DllStructGetData($tInfo, "hList"))
  EndIf

  Local $hEdit = DllStructGetData($tInfo, "hEdit")
  Local $pMsgHandler = DllCallbackGetPtr( DllCallbackRegister( "MsgHandler", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr" ) )
  _WinAPI_SetWindowSubclass( $hEdit, $pMsgHandler, 1000, 0 ) ; $iSubclassId = 1000, $pData = 0

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

  ; Cleanup
  _WinAPI_RemoveWindowSubclass( $hEdit, $pMsgHandler, 1000 ) ; Unregister message handler
  GUIDelete()
EndFunc   ;==>Example

; Write a line to the memo control
Func MemoWrite($sMessage)
  GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite

; Message handler based on subclassing
Func MsgHandler( $hWnd, $iMsg, $wParam, $lParam, $iSubclassId, $pData )
  Switch $iMsg
    Case $WM_LBUTTONDOWN
      ConsoleWrite( "$WM_LBUTTONDOWN" & @CRLF )
  EndSwitch

  ; Call next function in subclass chain (this forwards WM_COMMAND messages to main GUI (other messages are already forwarded))
  Return DllCall( "comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam )[0]
EndFunc

 

Link to post
Share on other sites

@Earthshine Thank you. Will check it.

@LarsJ Thank you for the reply. Before reading your code, let me ask you a question. In vb.net we have an event named "ComboBox_Mouseclick"  So I assumed that there is a notification message is coming from combo box to parent window if we click the combo. If there is no such messages are coming, then vb.net's mouse click event is using a subclassing techiniq like you did in your reply ? 

Edit note :- Without subclassing, is it impossible ?

Edited by kcvinu

My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to post
Share on other sites

I don't know much about VB.NET, but I don't think standard controls and VB.NET controls are comparable with regard to code. And event messages and notifications are also not comparable.

I think "ComboBox_Mouseclick" is a standard message. It's not implemented through subclassing.

In AutoIt it's impossible without subclassing, because the internal message handler would "eat" all the mouse clicks.

Link to post
Share on other sites

@LarsJ Thanks for the reply. Well, i was playing with some AutoIt code to use all events in AuotIt like we did in any dot net language.  I can use most common notification messages with GuiRegisterMsg.  But this one was very hard. I am glad to know that it is possible with atleast subclassing. I wish if AutoIt's internal msg handler doesn't swallow these notifications. :) 

Edit Note - By the way, i can't find $tagCOMBOBOXINFO structure in AutoIt help file. But i found one in MSDN.  I think although, AutoIt is not allowing us to code in the straight forward method, it will allow us to do these kind of tasks in complex ways. 

Edited by kcvinu

My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to post
Share on other sites
  • Moderators

kcvinu,

Less elegant but seemingly effective:

#include <GUIConstantsEx.au3>
#include <GuiComboBox.au3>
#include <WinAPI.au3>

Global $tInfo, $bFocus = False

Global $Window_0 = GUICreate("My Window", 800, 500)

$btn = GUICtrlCreateButton("Click Me", 50, 50, 120, 50)
Global $cmb = GUICtrlCreateCombo("Sample", 50, 150, 300, 50)

Global $lstbx = GUICtrlCreateList("FirstItem", 400,50, 200, 300)

GUICtrlSetData($cmb, "Item 2|Item 3", "Item 2")
GUICtrlSetData($lstbx,  "Apple|Orange|Pineapple|Grape|Lemon")

GUISetState(@SW_SHOW)

_GUICtrlComboBox_GetComboBoxInfo($cmb, $tInfo)
$hComboEdit = DllStructGetData($tInfo, "hEdit")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    If _WinAPI_GetFocus() = DllStructGetData($tInfo, "hEdit") And $bFocus = False Then
        $bFocus = True
        ConsoleWrite("True" & @CRLF)
    ElseIf _WinAPI_GetFocus() <> DllStructGetData($tInfo, "hEdit") And $bFocus = True Then
        $bFocus = False
        ConsoleWrite("False" & @CRLF)
    EndIf

WEnd

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to post
Share on other sites

@Melba23 Wow ! Thank you for the code. This is amazing. I thought this is impossible without complex stuff like subclassing. But you just proved that it is possible with some api funcs. Although, it won't fire consoleWrite when we clicked second time, because the focus is still on combo's edit control, it is an evidence of the power of win32 api . Anyhow, this aproach is great. 

My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to post
Share on other sites

Hello. Another way...

#include <GUIConstantsEx.au3>
#include <GuiComboBox.au3>
#include <WinAPI.au3>



Global $tInfo
Global $Window_0 = GUICreate("My Window", 800, 500)

$btn = GUICtrlCreateButton("Click Me", 50, 50, 120, 50)
Global $cmb = GUICtrlCreateCombo("Sample", 50, 150, 300, 50)
Global $lstbx = GUICtrlCreateList("FirstItem", 400, 50, 200, 300)

GUICtrlSetData($cmb, "Item 2|Item 3", "Item 2")
GUICtrlSetData($lstbx, "Apple|Orange|Pineapple|Grape|Lemon")
GUISetState(@SW_SHOW)
_GUICtrlComboBox_GetComboBoxInfo($cmb, $tInfo)
Global $hComboEdit = DllStructGetData($tInfo, "hEdit")



While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_PRIMARYDOWN
            _CheckComBoxClickTextArea()

    EndSwitch

WEnd


Func _CheckComBoxClickTextArea()
    Local $g_tStruct = DllStructCreate($tagPOINT)
    DllStructSetData($g_tStruct, "x", MouseGetPos(0))
    DllStructSetData($g_tStruct, "y", MouseGetPos(1))
    Local $hHandleFromPoint=_WinAPI_WindowFromPoint($g_tStruct)
    If $hHandleFromPoint = $hComboEdit Then
    ConsoleWrite("Clicked" & @CRLF)
    EndIf
EndFunc

Saludos

Edited by Danyfirex
Link to post
Share on other sites
  • Moderators

kcvinu,

Quote

 it won't fire consoleWrite when we clicked second time

Then try this:

#include <GUIConstantsEx.au3>
#include <GuiComboBox.au3>
#include <WinAPI.au3>

Global $tInfo

Global $Window_0 = GUICreate("My Window", 800, 500)

$btn = GUICtrlCreateButton("Click Me", 50, 50, 120, 50)
Global $cmb = GUICtrlCreateCombo("Sample", 50, 150, 300, 50)

Global $lstbx = GUICtrlCreateList("FirstItem", 400,50, 200, 300)

GUICtrlSetData($cmb, "Item 2|Item 3", "Item 2")
GUICtrlSetData($lstbx,  "Apple|Orange|Pineapple|Grape|Lemon")

GUISetState(@SW_SHOW)

_GUICtrlComboBox_GetComboBoxInfo($cmb, $tInfo)
$hComboEdit = DllStructGetData($tInfo, "hEdit")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_PRIMARYDOWN
            If _WinAPI_GetFocus() = DllStructGetData($tInfo, "hEdit") Then
                ConsoleWrite("Hit" & @CRLF)
            EndIf

    EndSwitch

WEnd

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to post
Share on other sites

M32 when you open and close the drop down the event is raised too Also when you select alList Item.

 

Saludos

Link to post
Share on other sites
  • Moderators

Danyfirex,

 I see - it is because those actions give focus to the edit. time for another think.....

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to post
Share on other sites
  • Moderators

Et voila!

#include <GUIConstantsEx.au3>
#include <GuiComboBox.au3>
#include <WinAPI.au3>

Global $tInfo

Global $Window_0 = GUICreate("My Window", 800, 500)

$btn = GUICtrlCreateButton("Click Me", 50, 50, 120, 50)
Global $cmb = GUICtrlCreateCombo("Sample", 50, 150, 300, 50)

Global $lstbx = GUICtrlCreateList("FirstItem", 400,50, 200, 300)

GUICtrlSetData($cmb, "Item 2|Item 3", "Item 2")
GUICtrlSetData($lstbx,  "Apple|Orange|Pineapple|Grape|Lemon")

GUISetState(@SW_SHOW)

_GUICtrlComboBox_GetComboBoxInfo($cmb, $tInfo)
$hComboEdit = DllStructGetData($tInfo, "hEdit")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_PRIMARYDOWN
            If _WinAPI_GetFocus() = DllStructGetData($tInfo, "hEdit") And _GUICtrlComboBox_GetDroppedState($cmb) = False Then
                ConsoleWrite("Hit" & @CRLF)
            EndIf
    EndSwitch
WEnd

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to post
Share on other sites
  • Moderators

Danyfirex,

Annoyingly correct! Back to thinking mode.....

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to post
Share on other sites

Another way.

#include <GUIConstantsEx.au3>
#include <GuiComboBox.au3>
#include <WinAPI.au3>
#include <Array.au3>
#include <WinAPIGdi.au3>
Global $tInfo

Global $Window_0 = GUICreate("My Window", 800, 500)

$btn = GUICtrlCreateButton("Click Me", 50, 50, 120, 50)
Global $cmb = GUICtrlCreateCombo("Sample", 50, 150, 300, 50)

Global $lstbx = GUICtrlCreateList("FirstItem", 400, 50, 200, 300)
GUICtrlSetData($cmb, "Item 2|Item 3", "Item 2")
GUICtrlSetData($lstbx, "Apple|Orange|Pineapple|Grape|Lemon")

GUISetState(@SW_SHOW)
_GUICtrlComboBox_GetComboBoxInfo($cmb, $tInfo)
Global $hComboEdit = DllStructGetData($tInfo, "hEdit")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_PRIMARYDOWN
            _CheckComBoxClickTextArea()
    EndSwitch
WEnd

Func _CheckComBoxClickTextArea()
    Local $iX = MouseGetPos(0)
    Local $iY = MouseGetPos(1)
    Local $tRect = _WinAPI_GetWindowRect($hComboEdit)
    Local $iLeft = DllStructGetData($tRect, 1)
    Local $iTop = DllStructGetData($tRect, 2)
    Local $iRight = DllStructGetData($tRect, 3)
    Local $iBottom = DllStructGetData($tRect, 4)
    If _WinAPI_PtInRectEx($iX, $iY, $iLeft, $iTop, $iRight, $iBottom) Then
        ConsoleWrite("Clicked" & @CRLF)
    EndIf
EndFunc   ;==>_CheckComBoxClickTextArea

Saludos

Link to post
Share on other sites

This is can be another way

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

$Window_0 = GUICreate("My Window", 800, 500, -1, -1, BitOR($WS_SIZEBOX, $WS_MINIMIZEBOX, $WS_MAXIMIZEBOX))
$btn = GUICtrlCreateButton("Click Me", 50, 50, 120, 50)

$cmb1 = GUICtrlCreateCombo("Sample1", 50, 150, 300, 50)
$cmb2 = GUICtrlCreateCombo("Sample2", 50, 200, 300, 50)

GUISetState(@SW_SHOW)

Do
    $event = GUIGetMsg()
    Switch $event
        Case $GUI_EVENT_PRIMARYDOWN
            If MouseGetCursor() = 5 Then ConsoleWrite(ControlGetFocus($Window_0) & @CRLF)
    EndSwitch
    Sleep(50)
Until $event = $GUI_EVENT_CLOSE

 

Edited by Deye
Link to post
Share on other sites

 @Melba23, @Danyfirex, @Deye Thanks to all. Each of your code is great and amazing. So, what i learn from this post is --

 If you want to provide mouse click event for your controls like combo, list box etc..

You should...

1. Get the handle of that particular control.

2. Trap the primary down event

3. Check the mouse position. If that is your control's position, call your event handler.

And Deye's technique is little bit different. He checked for mouse cursor. (Brilliant !  ) 

Well, i am in search of how to implement all type of event handling in AutoIt. Thanks for all your inputs. They helped me a lot to learn. :) 

 

Edited by kcvinu

My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

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

    No registered users viewing this page.

  • Similar Content

    • By AFrenchCroissant
      Hello,
      i would like to know why isnt anything displayed on the combo box. i used this example and added it to my code
      Autoit Example :
      #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> Dim $sRegKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" GUICreate("Test", 400, 100) $cCombo_Font = GUICtrlCreateCombo("", 10, 10, 170, 20, 2097474);HELPHERE GUICtrlSetData($cCombo_Font, _RegEnumVal($sRegKey)) $cLabel = GUICtrlCreateLabel("Font preview", 230, 10, 155, 20) GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $cCombo_Font GUICtrlSetFont($cLabel, 10, Default, Default, GUICtrlRead($cCombo_Font)) EndSwitch WEnd Func _RegEnumVal($sKey) Local $i = 1, $sVal, $sResult While 1 $sVal = RegEnumVal($sKey, $i) If @error Then ExitLoop $i += 1 $sResult &= $sVal & "|" WEnd Return StringRegExpReplace($sResult, " \(.*?\)", "") EndFunc ;==>_RegEnumVal And my code:
      #NoTrayIcon #include <Misc.au3> #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <File.au3> #include <GuiEdit.au3> #include <String.au3> #include <GuiRichEdit.au3> #include <GuiToolbar.au3> #include <GuiImageList.au3> $WIDTH = 500 $HEIGHT = 380 $EXT1 = "|Rich Text File (*.rtf)" $EXT2 = "|ODF Text (*.odt)" $EXT3 = "|All Files(*.*)" $EXT = $EXT1 & $EXT2 $SETTINGS = "Settings.ini" Dim $FONTKEY = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" Global $FILESAVE, $FILEOPEN = "", $SAVES, $SAVE, $FILEOPENED = 0 Global Enum $e_idNew = 1000, $e_idOpen, $e_idSave, $e_idHelp $MAINGUI = GUICreate("Text Editor", $WIDTH, $HEIGHT, -1, -1, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE) $TOOLBAR = _GUICtrlToolbar_Create($MAINGUI) _GUIImageList_AddIcon($TOOLBAR, @SystemDir & "\shell.dll", -1) $IMAGES = _GUIImageList_Create(24,24) _GUICtrlToolbar_SetImageList($TOOLBAR, $IMAGES) _GUICtrlToolbar_AddButton($TOOLBAR, $e_idNew, -1);AndHereIfYouCouldTHX _GUICtrlToolbar_AddButton($TOOLBAR, $e_idNew, -2) _GUICtrlToolbar_AddButton($TOOLBAR, $e_idNew, 3) _GUICtrlToolbar_AddButton($TOOLBAR, $e_idNew, 4) _GUICtrlToolbar_AddButtonSep($TOOLBAR) _GUICtrlToolbar_AddButton($TOOLBAR, $e_idNew, 5) _GUICtrlToolbar_AddButton($TOOLBAR, $e_idNew, 6) $EDITBOX = _GUICtrlRichEdit_Create($MAINGUI, "This is a test.", 10, 35, $WIDTH - 20, $HEIGHT - 70, _ BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) $FONTCOMBOBOX = GUICtrlCreateCombo("", $WIDTH - 170, 10, 160, 20, 2097474);HELPMEHERE GUICtrlSetData($FONTCOMBOBOX, _RegEnumVal($FONTKEY));ALSOHERE $FONTSIZECOMBOBOX = GUICtrlCreateCombo("", $WIDTH - 200, 10, 20, 20, 2097474);FuncForPreviousLineAtTheEnd $FILE = GUICtrlCreateMenu("File") $NEW = GUICtrlCreateMenuItem("New", $FILE) $OPEN = GUICtrlCreateMenuItem("Open...", $FILE) $SAVE = GUICtrlCreateMenuItem("Save", $FILE) $SAVEAS = GUICtrlCreateMenuItem("Save As...", $FILE) $PRINT = GUICtrlCreateMenuItem("Print...", $FILE) GUICtrlCreateMenuItem("", $FILE) $EXIT = GUICtrlCreateMenuItem("Exit", $FILE) $EDIT = GUICtrlCreateMenu("Edit") $UNDO = GUICtrlCreateMenuItem("Undo", $EDIT) $REDO = GUICtrlCreateMenuItem("Redo", $EDIT) $SEPARATOR = GUICtrlCreateMenuItem("", $EDIT) $FONT = GUICtrlCreateMenuItem("Font test", $EDIT) $SEPARATOR1 = GUICtrlCreateMenuItem("", $EDIT) $CUT = GUICtrlCreateMenuItem("Cut", $EDIT) $COPY = GUICtrlCreateMenuItem("Copy", $EDIT) $PASTE = GUICtrlCreateMenuItem("Paste", $EDIT) GUISetState(@SW_SHOW & $GUI_ACCEPTFILES) While 1 $Msg = GUIGetMsg() Select Case $Msg = $GUI_EVENT_CLOSE If _GUICtrlEdit_CanUndo($EDITBOX) Then $SAVECHANGES = MsgBox(35, "Text Editor", "Your original file has been modified." & @CRLF & "Would you like to save changes to it?") If $SAVECHANGES = 6 And $FILEOPENED = 0 Then SaveAs() _GUICtrlRichEdit_Destroy($hRichEdit) Exit EndIf If $SAVECHANGES = 6 And $FILEOPENED = 1 Then FileDelete($FILEOPEN) FileWrite($FILEOPEN, GUICtrlRead($EDITBOX)) Exit EndIf If $SAVECHANGES = 7 Then ExitLoop Exit EndIf EndIf If Not _GUICtrlEdit_CanUndo($EDITBOX) Then Exit Case $Msg = $OPEN $FILEOPEN = FileOpenDialog("Open", $FILEOPEN, $EXT) $TEXT = _GUICtrlRichEdit_StreamFromFile($EDITBOX, $FILEOPEN) _GUICtrlRichEdit_ReplaceText($EDITBOX, $TEXT) $FILEOPENED = 1 Case $Msg = $NEW If _GUICtrlEdit_CanUndo($EDITBOX) Then $SAVECHANGES = MsgBox(35, "Text Editor", "Your original file has been modified." & @CRLF & "Would you like to save changes to it?") If $SAVECHANGES = 6 And $FILEOPENED = 0 Then SaveAs() EndIf If $SAVECHANGES = 6 And $FILEOPENED = 1 Then FileDelete($FILEOPEN) FileWrite($FILEOPEN, GUICtrlRead($EDITBOX)) EndIf If $SAVECHANGES = 7 Then GUICtrlSetData($EDITBOX, "") If $SAVECHANGES = 2 Then Sleep(1) EndIf If Not _GUICtrlEdit_CanUndo($EDITBOX) Then GUICtrlSetData($EDITBOX, "") $FILEOPENED = 0 Case $Msg = $EXIT If _GUICtrlEdit_CanUndo($EDITBOX) Then $SAVECHANGES = MsgBox(35, "Text Editor", "Your original file has been modified." & @CRLF & "Would you like to save changes to it?") If $SAVECHANGES = 6 And $FILEOPENED = 0 Then SaveAs() _GUICtrlRichEdit_Destroy($hRichEdit) Exit EndIf If $SAVECHANGES = 6 And $FILEOPENED = 1 Then FileDelete($FILEOPEN) FileWrite($FILEOPEN, GUICtrlRead($EDITBOX)) Exit EndIf If $SAVECHANGES = 7 Then ExitLoop If $SAVECHANGES = 2 Then Sleep(1) EndIf EndIf If Not _GUICtrlEdit_CanUndo($EDITBOX) Then Exit Case $Msg = $SAVEAS GUICtrlSetState($EDITBOX, $GUI_DISABLE) SaveAs() $FILEOPENED = 1 GUICtrlSetState($EDITBOX, $GUI_ENABLE) Case $Msg = $SAVE And $FILEOPENED = 1 FileDelete($FILEOPEN) FileWrite($FILEOPEN, GUICtrlRead($EDITBOX)) _GUICtrlEdit_EmptyUndoBuffer($EDITBOX) Case $Msg = $SAVE And $FILEOPENED = 0 GUICtrlSetState($EDITBOX, $GUI_DISABLE) SaveAs() $FILEOPENED = 1 GUICtrlSetState($EDITBOX, $GUI_ENABLE) Case $Msg = $SAVE And $FILEOPENED = 0 GUICtrlSetState($EDITBOX, $GUI_DISABLE) SaveAs() $FILEOPENED = 1 GUICtrlSetState($EDITBOX, $GUI_ENABLE) Case $Msg = $PRINT $PRINTMSGBOX = MsgBox(35, "Text Editor", "Are you sure you want to print this page?") Select Case $PRINTMSGBOX = 6 If FileExists("Print.txt") Then FileDelete("Print.txt") EndIf FileWrite("Print.txt", GUICtrlRead($EDITBOX)) $PRINTFILE = "Print.txt" _FilePrint($PRINTFILE) FileDelete($PRINTFILE) EndSelect Case $Msg = $UNDO _GUICtrlRichEdit_Undo($EDITBOX) Case $Msg = $REDO _GUICtrlRichEdit_Redo($EDITBOX) Case _GUICtrlEdit_CanUndo($EDITBOX) And $SAVES = 1 GUICtrlSetState($SAVE, $GUI_ENABLE) Case $Msg = $CUT _GUICtrlRichEdit_Cut ($EDITBOX) Case $Msg = $COPY _GUICtrlRichEdit_Copy ($EDITBOX) Case $Msg = $PASTE _GUICtrlRichEdit_Paste ($EDITBOX) Case Not _GUICtrlEdit_CanUndo($EDITBOX) And $SAVES = 0 GUICtrlSetState($SAVE, $GUI_DISABLE) $SAVES = 1 Case $Msg = $FONT _GUICtrlRichEdit_SetFont($EDITBOX, $FONTSIZECOMBOBOX, "Times New Roman") Case $FONTCOMBOBOX _GUICtrlRichEdit_SetFont($EDITBOX, $FONTSIZECOMBOBOX, GUICtrlRead($FONTCOMBOBOX)) EndSelect WEnd Exit Func SaveAs() $FILESAVEAS = FileSaveDialog("Save As", "", "Text Document (*.txt)|All Files (*.*)") If Not @error Then $STRING = StringSplit($FILESAVEAS, ".") If $STRING[0] = 1 Then FileDelete($FILESAVEAS) _GUICtrlRichEdit_StreamToFile($EDITBOX, $FILESAVEAS &".rtf") Else _GUICtrlRichEdit_StreamToFile($EDITBOX, $FILESAVEAS &".rtf") EndIf EndIf EndFunc Func _RegEnumVal($sKey) Local $i = 1, $sVal, $sResult While 1 $sVal = RegEnumVal($sKey, $i) If @error Then ExitLoop $i += 1 $sResult &= $sVal & "|" WEnd Return StringRegExpReplace($sResult, " \(.*?\)", "") EndFunc ;==>_RegEnumVal So the problem is that
      The second combo box is blank Icons in taskbar are not appearing (don't really care for now, .dll file for icon in attachement) problem with $FONTCOMBOBOX = GUICtrlCreateCombo("", 10, 10, 200, 20, Bitor($CBS_SORT,$CBS_DROPDOWN,$CBS_AUTOHSCROLL,$WS_VSCROLL) (BitOR gave me a weird error)
      Thanks !
      Autoit newbie
      ico.dll
    • By dejhost
      Hi.
      I am trying to automate a software called "LabelImg" (https://pypi.org/project/labelImg/).
      My autoit-script is started once I selected a folder with images within LabelImg. Pressing the button "Next Image" or pressing the shortcut "d" (https://github.com/tzutalin/labelImg#Hotkeys) jumps to the next image in the selected folder. This shall happen once per second.
      #include <Misc.au3> #include <MsgBoxConstants.au3> #include <AutoItConstants.au3> Opt("WinTitleMatchMode", 1) Local $hDLL = DllOpen("user32.dll") While 1 If _IsPressed("1B", $hDLL) Then ExitLoop Else Local $temp = WinActivate("labelImg") ConsoleWrite($temp & @CRLF) If WinActivate("labelImg") Then ConsoleWrite("All Set!" & @CRLF) EndIf ;Send("d") Local $temp = MouseClick($MOUSE_CLICK_RIGHT, 50, 200) If $temp <> 1 Then MsgBox(1, "$temp", $temp) ExitLoop EndIf Sleep(1000) EndIf WEnd DllClose($hDLL) So the Send ("d")-command and the MouseClick are alternative methods to jump to the next image. Both fail.
      Both ConsoleWrite's deliver proper feedback (I continiously get the handle and "All set" ).

      Could you tell me what I'm doing wrong? 
      Thank you.
    • By ute_man
      Hi Forum,
      I am struggling to select an IP address from "Server Interface" dropdown (ComboBox2) of tftpd32 client.
      tftpd32 is a TFTP server - TFTPD32 : an opensource IPv6 ready TFTP server/service for windows : TFTP server (pagesperso-orange.fr)
      The IP addresses (and the associated interfaces) are dynamic in ComboBox2.
      What I want to do is to select an item from ComboBox2 which contains a given IP address (eg. 192.168.2.1) - (which is hidden in the picture as it is at the bottom of the list) and fill the edit field with the selection. (Note : the ComboBox items contain the IP address and the Interface name, therefore IP address is just a part of the item)
      I am not sure whether functions such as _GUICtrlComboBox_SelectString() are only to be used with Autoit generated ComboBoxes.
      Please help !!!!
      My code below, it does not select the ComboBox2 item with my IP address 192.168.2.1.
      Local $hWnd=ControlGetHandle("Tftpd32 by Ph. Jounin", "", 4008) Sleep(100) ControlFocus("Tftpd32 by Ph. Jounin", "", $hWnd) Sleep(100) Local $IP = "192.168.2.1" _GUICtrlComboBox_SelectString($HWnd, $IP) ComboBox2 ID = 4008


    • By Rskm
      Hi, recently i created a GUI for some calculations in AutoIT.  The GUI has 2 tabs and on the first tab, it has few inputboxes where i use to click with mouse and start entering the inputs. i recently made some changes in the position of these textboxes. I made this by changing the autoit code file instead of making changes in KODA. Now i cannot click inside these textboxes with mouse. However, i can use TAB key to cycle through/enter input in these input boxes. what could have made the inputboxes not responding to mouseclicks. thanks
    • By Colduction
      Hi, i have a source code of "Danny35d" and i have 2 main question that are:
       How to extract this function's results (Datas are as Array) to combo-box without set number of datas?  When i type 1, 2 in _SystemUsers($AccountType = 0) to get only Local or Domain users, it just give me both of them, it's old problem of this function, please share us debugged code :)❤ #include <Array.au3> $Users = _ArrayToString(_SystemUsers(), "|", 1) ConsoleWrite($Users & @CRLF) #cs =============================================================================== Function: _SystemUsers($AccountType = 0) Description: Return an array with the local or domain username Parameter(s): $AccountType: Local, domain or both username 0 = Local and Domain usernames 1 = Local usernames only 2 = Domain usernames only Returns: An array with the list of usernames - Succeeded @error 1 - Didn't query any username @error 2 - Failed to create Win32_SystemUsers object @error 3 - Invalid $AccountType Author(s): Danny35d #ce =============================================================================== Func _SystemUsers($AccountType = 0) Local $aSystemUsers Local $wbemFlagReturnImmediately = 0x10, $wbemFlagForwardOnly = 0x20 Local $colItems = "", $strComputer = "localhost" If Not StringRegExp($AccountType, '[012]') Then Return SetError(3, 3, '') $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_SystemUsers", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) Then For $objItem In $colItems $Output = StringSplit($objItem.PartComponent, ',') If IsArray($Output) Then $Temp = StringReplace(StringTrimLeft($Output[2], StringInStr($Output[2], '=', 0, -1)), '"', '') If $AccountType = 0 Or ($AccountType = 1 And @ComputerName = $Temp) Then $aSystemUsers &= StringReplace(StringTrimLeft($Output[1], StringInStr($Output[1], '=', 0, -1)), '"', '') & '|' ElseIf $AccountType = 2 And @ComputerName <> $Temp Then $aSystemUsers &= StringReplace(StringTrimLeft($Output[1], StringInStr($Output[1], '=', 0, -1)), '"', '') & '|' EndIf EndIf Next $aSystemUsers = StringTrimRight($aSystemUsers, 1) If $aSystemUsers = '' Then Return(SetError(1, 1, $aSystemUsers)) Return(SetError(0, 0, StringSplit($aSystemUsers, '|'))) Else $aSystemUsers = '' Return(SetError(2, 2, $aSystemUsers)) EndIf EndFunc ;==>_SystemUsers Thanks to your best Team.
×
×
  • Create New...