Jump to content
kcvinu

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

Recommended Posts

kcvinu

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)

 

Share this post


Link to post
Share on other sites
Earthshine

i literally typed in your question to google and got this. i hope it is helpful. 

 

 

  • Like 1

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
LarsJ

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

 

  • Like 2

Share this post


Link to post
Share on other sites
kcvinu

@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)

 

Share this post


Link to post
Share on other sites
LarsJ

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.

  • Like 1

Share this post


Link to post
Share on other sites
kcvinu

@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)

 

Share this post


Link to post
Share on other sites
Melba23

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

  • Like 1

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
kcvinu

@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)

 

Share this post


Link to post
Share on other sites
Danyfirex

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
  • Like 1

Share this post


Link to post
Share on other sites
Melba23

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

  • Like 1

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Danyfirex

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

 

Saludos

  • Like 1

Share this post


Link to post
Share on other sites
Melba23

Danyfirex,

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

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Melba23

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

  • Like 1

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Danyfirex

It still happen when drop close.

 

Saludos

Share this post


Link to post
Share on other sites
Melba23

Danyfirex,

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

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Danyfirex

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

  • Like 1

Share this post


Link to post
Share on other sites
Deye

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
  • Like 1

Share this post


Link to post
Share on other sites
kcvinu

 @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)

 

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

  • Similar Content

    • c1one
      By c1one
      Something simple enough, and I am sure it's an oversight, but I have not been able to track this down. The entire script is attached, but here is the point of failure.
      Note: I am getting the "Error: subscript used on non-accessible variable" but I thought the initial line of:
      AutoItSetOption('MouseCoordMode', 0)
      Should address that issue? 
      <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
      ; Install updates (minimized and updating for many minutes)
      ; Updates Not Installed Screen
         ; Wait for updates to complete
      WinWait("ProSeries Update")
         ; Wait just over 9 minutes to ensure popup is ready (test alternative to WinWait)
      Sleep(550000)
         ; Set focus on Product Licenses window
      WinActivate("ProSeries Update")
         ; Send Mouse Click to Install Now button
      MouseClick ( "left" [, 581, 362 [, clicks = 1 [, speed = 10]]] )
      ; end Installing Updates screen
      >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
       
      Thanks for any insights!
      c1one
      ProSeries2017_No_Customer_Info.au3
    • odaylton
      By odaylton
      Hello everyone ,
      Text translated from Portuguese by google - please apologize for any errors

      Once again I need a light from the gurus of this wonderful website
      I am fanatic by combobox for its usability but I am not able to uncertain images within lists ...
      I know uncertain icons, and cursors but I am not able to insert gif or jpg images.
      1) How to solve this ...
      2) will the path is to convert gif into bmp and then uncertain ... how to do that?
      #include <GUIConstantsEx.au3> #include <GuiImageList.au3> #include <GuiListView.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> ;dados de mouse #include <WinAPIRes.au3> ;COMBO #include <GuiComboBoxEx.au3> ;Fonts #include <FontConstants.au3> ;obter imagem de arquivo #include <GDIPlus.au3> #include <WinAPIGdi.au3> Example() Func Example() Local $hGUI, $hImage, $hCombo, $hFont Local $idListview, $hImage Local $sWow64 = "" Local $Pasta = "C:\WINDOWS\Cursors\3dgarro.cur" Local $PastaROMs = @MyDocumentsDir & "\Stella\ROMs\" ;com barra no final $hGUI = GUICreate("ImageList", 500, 310) GUISetFont(14, 400, 0, "Arial") ;<<<<<<<<<<this does not work for _GUICtrlComboBoxEx_Create $hCombo = _GUICtrlComboBoxEx_Create($hGUI, "", 2, 2, 494, 200) ;GUICtrlSetFont($hCombo, 14, 400, 0, "Arial");<<<<<<<<<<It does not work ; ;Create a handle to a font object $hFont = _WinAPI_CreateFont(30, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Arial') ;Pass the handle to _WinAPI_SetFont _WinAPI_SetFont($hCombo, $hFont) $idListview = GUICtrlCreateListView("", 2, 50, 494, 250, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT)) _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER)) GUISetState(@SW_SHOW) ; Initialize GDI+ library _GDIPlus_Startup() ; Load images $hImage = _GUIImageList_Create(120, 70, 6, 2) ;32,32,5,5) ; $DadosCombo = "Escolha|" & _GUIImageList_Add($hImage, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, 0x0000FF, 120, 70)) ;Local $aCursors[] = [32650, 32512, 32515, 32649, 32651, 32513, 32648, 32646, 32643, 32645, 32642, 32644, 32516, 32514] For $i = 1 To 10 $sFile = FileOpenDialog("Please select an image", $PastaROMs, "Image (*.jpg;*.png;*.bmp;*.gif;*.tif)", BitOR($FD_PATHMUSTEXIST, $FD_FILEMUSTEXIST)) If @error Then Exit MsgBox(BitOR($MB_TOPMOST, $MB_ICONERROR), "Error", "No image file has been selected", 30) $a = _GDIPlus_BitmapCreateFromFile ($sFile);<<<<< ok If @error Or Not $hImage Then MsgBox(BitOR($MB_TOPMOST, $MB_ICONERROR), "Error", "This file isn't supported by GDIPlus!") Else $b=_GUIImageList_Add($hImage, $a);<<<<<< Return -1 $DadosCombo &= "|" & $i & "_img_princ.gif""|" & $b EndIf Next _GUICtrlListView_SetImageList($idListview, $hImage, 1) _GUICtrlComboBoxEx_SetImageList($hCombo, $hImage) ; Add columns _GUICtrlListView_AddColumn($idListview, "Icons - Mouses", 350) ; Add items $a = StringSplit($DadosCombo, "|") For $i = 1 To $a[0] Step 2 _GUICtrlListView_AddItem($idListview, $a[$i], $a[$i + 1]) _GUICtrlComboBoxEx_AddString($hCombo, $a[$i], $a[$i + 1], $a[$i + 1]) Next ;AutoIt_Debugger_Command:Disable_Debug ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() ;AutoIt_Debugger_Command:Enable_Debug EndFunc ;==>Example tks
    • aiter
      By aiter
      I  possibly misunderstood the value of combo boxes, but I thought you could type a value, press enter and the combo box would store that value.
      The reason for wanting this is to store a history of typed commands into the combo box (accepted by pressing enter).
       
      After hours of trying to trap enter on a combobox I realized that the enter event was not registering.
      I had code like this (which used to work on a input box), but it does not for a combobox (because it does not accept enter)
      unc WM_COMMAND($hWnd, $Msg, $wParam, $lParam) Local $nNotifyCode = BitShift($wParam, 16) Local $nID = BitAND($wParam, 0x0000FFFF) If $hWnd = $CmdForm Then If $nID = $ComboInput Then ; useed to work on a normal input box If _IsPressed('0D') Then ; enter was pressed, respond DoCmd() Anyone able to help?
    • dadalt
      By dadalt
      Hi!
      I have a button where I need to close it!
      I was doing through  clicking same position in screen but there are some id's that have different sizes.
      What are the possible ways to click this closable button?
      Is there a way to close it through id? Is there a way to get it's position through it's ID?  
      Thanks in advance!


    • Grasoft
      By Grasoft
      Greetings everyone,
      I'm writing a software that edit an ini file section by section with adding/renaming abilities
      but whenever I manually change the combobox to value other than constducted previously, I cannot get this value.
      THIS is a clean version of the code:
      #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiStatusBar.au3> #include <GuiEdit.au3> #include <MsgBoxConstants.au3> #Region ### START Koda GUI section ### Form=C:\Program Files (x86)\AutoIt3\SciTE\Koda\Forms\QuickRepEditList7.kxf $SecMgr = GUICreate("Sections Manager", 1159, 690) GUISetFont(12, 800, 0, "MS Sans Serif") $EditSec = GUICtrlCreateEdit("", 45, 45, 1090, 644, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_WANTRETURN, $WS_HSCROLL, $ES_NOHIDESEL)) $Edit2 = GUICtrlCreateEdit("", 11, 45, 33, 617, BitOR($ES_RIGHT, $ES_READONLY, $ES_WANTRETURN)) GUICtrlSetData(-1, StringFormat(" 1:\r\n 2:\r\n 3:\r\n 4:\r\n 5:\r\n 6:\r\n 7:\r\n 8:\r\n 9:\r\n10:\r\n11:\r\n12:\r\n13:\r\n14:\r\n15:\r\n16:\r\n17:\r\n18:\r\n19:\r\n20:\r\n21:\r\n22:\r\n23:\r\n24:\r\n25:\r\n26:\r\n27:\r\n28:\r\n29:\r\n30:")) $Label1 = GUICtrlCreateLabel("Select Section:", 7, 13, 126, 24) GUICtrlSetFont(-1, 11, 800, 0, "MS Sans Serif") $Savesec = GUICtrlCreateButton("Save Changes", 375, 7, 129, 33) $NewSec = GUICtrlCreateButton("New Section", 700, 7, 121, 33) $SecDwn = GUICtrlCreateButton("Section Down", 830, 7, 137, 33) $SecUp = GUICtrlCreateButton("Section Up", 980, 7, 129, 33) $copystrs = GUICtrlCreateButton("*******", 507, 7, 73, 33) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") $HeavySep = GUICtrlCreateButton("====", 581, 7, 73, 33) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") Global $SecSel Global $secno Global $secn = "NULLz" Global $sFilePathtemp Global $aArray Global $SecNames Global $secnnew Global $ssecn $SecSel = GUICtrlCreateCombo("", 110, 10, 257, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL)) queysecs() Filledit() GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### $secno=GUICtrlRead($SecSel) $changed=0 While 1 $secn = GUICtrlRead($SecSel) $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE saveeditedmsg() Exit Case $SecSel $secno=GUICtrlRead($SecSel) queysecs() Filledit() Case $Savesec saveeditedmsg() queysecs() Case $NewSec Case $SecDwn Case $SecUp Case $copystrs ClipPut("**************************************************************************************************************************************************************") Case $HeavySep ClipPut("==============================================================================================================================================================") EndSwitch WEnd Func queysecs();query section names $sFilePath = @ScriptDir & "\" & "Txt_Reps.ini" $aArray = IniReadSectionNames($sFilePath) $SecNames = $aArray[1] If $secn = "NULLz" Then $secn = $aArray[1] EndIf If Not @error Then For $i = 2 To $aArray[0] $SecNames = $SecNames & "|" & $aArray[$i] Next GUICtrlSetData($SecSel, "", "") GUICtrlSetData($SecSel, $SecNames, $secn) $secno = $secn EndIf EndFunc ;==>queysecs Func Filledit(); transfer section values on the edit box GUICtrlSetData($EditSec, "") $sFilePath = @ScriptDir & "\" & "Txt_Reps.ini" For $i = 1 To 30 $sRead = IniRead($sFilePath, $secn, $i, "") GUICtrlSetData($EditSec, $sRead & @CRLF, 1) Next GUISetState(@SW_SHOW) EndFunc ;==>Filledit Func saveeditedmsg(); save or rename modified section If $secn <> $secno Then $iMsgBoxAnswer = MsgBox(3, "NEW/RENAME", "Press YES to Add this as NEW section" & @CRLF & "Press NO to rename and save this section from " & $secno & "To" & $secn) Select Case $iMsgBoxAnswer = 6 ;YES $secn = $secno save($secn) $secn = GUICtrlRead($SecSel) $secno = $secn Case 7 ;NO $sFilePath = @ScriptDir & "\" & "Txt_Reps.ini" IniRenameSection($sFilePath, $secno, $secn) save($secn) $secn = GUICtrlRead($SecSel) $secno = $secn EndSelect Else $iMsgBoxAnswer = MsgBox(4, "Do you want to save changes to this section", "Save Section: " & $secn) Select Case $iMsgBoxAnswer = 6 ;yes save($secn) EndSelect EndIf EndFunc ;==>saveeditedmsg ;MsgBox(4, "Do you want to add this to Database?",$secn) Func save($ssecn); save edit control to a file and then rewrite modified values by line order. $sFilePathtemp = FileOpen(@ScriptDir & "\" & "tempo.quickrep", $FO_READ + $FO_OVERWRITE + $FO_CREATEPATH + $FO_UTF8) $sFilePath = @ScriptDir & "\" & "Txt_Reps.ini" FileWrite($sFilePathtemp, GUICtrlRead($EditSec)) $sFilePathtemp = FileOpen(@ScriptDir & "\" & "tempo.quickrep", $FO_READ + $FO_UTF8) For $i = 1 To 30 $sRead = FileReadLine($sFilePathtemp, $i) IniWrite($sFilePath, $ssecn, $i, $sRead) Next GUISetState(@SW_SHOW) EndFunc ;==>save And this is with som test msg boxes to know how to get it
      #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiStatusBar.au3> #include <GuiEdit.au3> #include <MsgBoxConstants.au3> #Region ### START Koda GUI section ### Form=C:\Program Files (x86)\AutoIt3\SciTE\Koda\Forms\QuickRepEditList7.kxf $SecMgr = GUICreate("Sections Manager", 1159, 690) GUISetFont(12, 800, 0, "MS Sans Serif") $EditSec = GUICtrlCreateEdit("", 45, 45, 1090, 644, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_WANTRETURN, $WS_HSCROLL, $ES_NOHIDESEL)) $Edit2 = GUICtrlCreateEdit("", 11, 45, 33, 617, BitOR($ES_RIGHT, $ES_READONLY, $ES_WANTRETURN)) GUICtrlSetData(-1, StringFormat(" 1:\r\n 2:\r\n 3:\r\n 4:\r\n 5:\r\n 6:\r\n 7:\r\n 8:\r\n 9:\r\n10:\r\n11:\r\n12:\r\n13:\r\n14:\r\n15:\r\n16:\r\n17:\r\n18:\r\n19:\r\n20:\r\n21:\r\n22:\r\n23:\r\n24:\r\n25:\r\n26:\r\n27:\r\n28:\r\n29:\r\n30:")) $Label1 = GUICtrlCreateLabel("Select Section:", 7, 13, 126, 24) GUICtrlSetFont(-1, 11, 800, 0, "MS Sans Serif") $Savesec = GUICtrlCreateButton("Save Changes", 375, 7, 129, 33) $NewSec = GUICtrlCreateButton("New Section", 700, 7, 121, 33) $SecDwn = GUICtrlCreateButton("Section Down", 830, 7, 137, 33) $SecUp = GUICtrlCreateButton("Section Up", 980, 7, 129, 33) ;$LineNo = GUICtrlCreateInput("LineNo", 664, 7, 65, 28) $copystrs = GUICtrlCreateButton("*******", 507, 7, 73, 33) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") $HeavySep = GUICtrlCreateButton("====", 581, 7, 73, 33) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") Global $SecSel Global $secno Global $secn = "NULLz" Global $sFilePathtemp Global $aArray Global $SecNames Global $secnnew Global $ssecn $SecSel = GUICtrlCreateCombo("", 110, 10, 257, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL)) queysecs() Filledit() GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### $secno=GUICtrlRead($SecSel) $changed=0 While 1 $secn = GUICtrlRead($SecSel) ;If $secn <> $secno and $changed=0 Then ; $secns = $secn ; $changed=1 ;EndIf $nMsg = GUIGetMsg() ;MsgBox(4, "TEST1?", $secn) Switch $nMsg Case $GUI_EVENT_CLOSE saveeditedmsg() Exit Case $SecSel ;MsgBox(4, "TEST?", GUICtrlRead($SecSel)) ;MsgBox(4, "TEST1?", $secns) ;MsgBox(4, "TEST2?", $secn) $secno=GUICtrlRead($SecSel) ;saveeditedmsg() queysecs() Filledit() ;$changed=0 Case $Savesec saveeditedmsg() queysecs() Case $NewSec Case $SecDwn Case $SecUp Case $copystrs ClipPut("**************************************************************************************************************************************************************") Case $HeavySep ClipPut("==============================================================================================================================================================") EndSwitch ; MsgBox(4, "TEST2?", $secn) WEnd Func queysecs();query section names $sFilePath = @ScriptDir & "\" & "Txt_Reps.ini" $aArray = IniReadSectionNames($sFilePath) $SecNames = $aArray[1] ; MsgBox(4, "test3?", $secn) If $secn = "NULLz" Then $secn = $aArray[1] EndIf If Not @error Then For $i = 2 To $aArray[0] $SecNames = $SecNames & "|" & $aArray[$i] Next GUICtrlSetData($SecSel, "", "") GUICtrlSetData($SecSel, $SecNames, $secn) $secno = $secn ;MsgBox(4, "test4?", $secn) EndIf EndFunc ;==>queysecs Func Filledit(); transfer section values on the edit box GUICtrlSetData($EditSec, "") $sFilePath = @ScriptDir & "\" & "Txt_Reps.ini" For $i = 1 To 30 $sRead = IniRead($sFilePath, $secn, $i, "") GUICtrlSetData($EditSec, $sRead & @CRLF, 1) Next GUISetState(@SW_SHOW) EndFunc ;==>Filledit Func saveeditedmsg(); save or rename modified section If $secn <> $secno Then $iMsgBoxAnswer = MsgBox(3, "NEW/RENAME", "Press YES to Add this as NEW section" & @CRLF & "Press NO to rename and save this section from " & $secno & "To" & $secn) Select Case $iMsgBoxAnswer = 6 ;YES $secn = $secno save($secn) $secn = GUICtrlRead($SecSel) $secno = $secn Case 7 ;NO $sFilePath = @ScriptDir & "\" & "Txt_Reps.ini" IniRenameSection($sFilePath, $secno, $secn) save($secn) $secn = GUICtrlRead($SecSel) $secno = $secn EndSelect Else $iMsgBoxAnswer = MsgBox(4, "Do you want to save changes to this section", "Save Section: " & $secn) Select Case $iMsgBoxAnswer = 6 ;yes save($secn) EndSelect EndIf EndFunc ;==>saveeditedmsg ;MsgBox(4, "Do you want to add this to Database?",$secn) Func save($ssecn); save edit control to a file and then rewrite modified values by line order. $sFilePathtemp = FileOpen(@ScriptDir & "\" & "tempo.quickrep", $FO_READ + $FO_OVERWRITE + $FO_CREATEPATH + $FO_UTF8) $sFilePath = @ScriptDir & "\" & "Txt_Reps.ini" FileWrite($sFilePathtemp, GUICtrlRead($EditSec)) $sFilePathtemp = FileOpen(@ScriptDir & "\" & "tempo.quickrep", $FO_READ + $FO_UTF8) For $i = 1 To 30 $sRead = FileReadLine($sFilePathtemp, $i) IniWrite($sFilePath, $ssecn, $i, $sRead) Next GUISetState(@SW_SHOW) EndFunc ;==>save The ini file withthe au3 attached
      This is how I want: when the user changes the combo, the script will check the text combo. In case of changed text it will ask user if I should rename or add it as a new section and then save. If not changed the text of combo it will ask to save only.
      IF NOT possible, Will it possible with _GUICtrlComboBox__GUICtrlComboBoxEx_Create or _GUICtrlComboBoxEx_Create or not
       
      THANK you very much in advance
      QuickSecEdit.zip
×