JusGellin Posted December 1, 2008 Share Posted December 1, 2008 How can other controls like edit detect a mouse click clicked them? I tried the following without any success. Thanks. #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 633, 447, 193, 125) $Edit1 = GUICtrlCreateEdit("", 48, 16, 433, 161, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL)) GUICtrlSetData(-1, "") $Edit2 = GUICtrlCreateEdit("", 48, 216, 433, 161, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL)) GUICtrlSetData(-1, "") GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Edit1 ConsoleWrite("I'm in Edit1" & @cr) Case $Edit2 ConsoleWrite("I'm in Edit2" & @cr) EndSwitch WEnd Link to comment Share on other sites More sharing options...
rasim Posted December 1, 2008 Share Posted December 1, 2008 (edited) How can other controls like edit detect a mouse click clicked them? I tried the following without any success. Thanks.Easy way: #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 633, 447, 193, 125) $Edit1 = GUICtrlCreateEdit("", 48, 16, 433, 161, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL)) GUICtrlSetData(-1, "") $Edit2 = GUICtrlCreateEdit("", 48, 216, 433, 161, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL)) GUICtrlSetData(-1, "") GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_PRIMARYDOWN $aCurInfo = GUIGetCursorInfo() If (@error = 0) And ($aCurInfo[4] <> 0) Then ConsoleWrite("Clicked on control ID: " & $aCurInfo[4] & @LF) EndSwitch WEnd Edited December 1, 2008 by rasim Link to comment Share on other sites More sharing options...
JusGellin Posted December 1, 2008 Author Share Posted December 1, 2008 Easy way: #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 633, 447, 193, 125) $Edit1 = GUICtrlCreateEdit("", 48, 16, 433, 161, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL)) GUICtrlSetData(-1, "") $Edit2 = GUICtrlCreateEdit("", 48, 216, 433, 161, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL)) GUICtrlSetData(-1, "") GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_PRIMARYDOWN $aCurInfo = GUIGetCursorInfo() If (@error = 0) And ($aCurInfo[4] <> 0) Then ConsoleWrite("Clicked on control ID: " & $aCurInfo[4] & @LF) EndSwitch WEnd Thanks for helping me see how I can do that. I know I can use infotool to get the class id's for each edit control. Is there a way to programmically determine the control id's for the edit controls? So in the program it would tell me that $Edit1 would have a control id of 3 and $Edit2 would have a control id of 4. Then I could use a case statement to tell me the name of the edit control that was clicked. Thanks Link to comment Share on other sites More sharing options...
JusGellin Posted December 1, 2008 Author Share Posted December 1, 2008 (edited) (I figured out how to do this using the api functions. Thanks again, I've learned a lot) I tried editing my reply but it messed up the code. So here it is again: #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> $Form1 = GUICreate("Form1", 633, 447, 193, 125) $Edit1 = GUICtrlCreateEdit("", 48, 16, 433, 161, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL)) GUICtrlSetData(-1, "") $Edit1id = number(_WinAPI_GetDlgCtrlID(GUICtrlGetHandle($Edit1))) $Edit2 = GUICtrlCreateEdit("", 48, 216, 433, 161, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL)) GUICtrlSetData(-1, "") $Edit2id = number(_WinAPI_GetDlgCtrlID(GUICtrlGetHandle($Edit2))) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_PRIMARYDOWN $aCurInfo = GUIGetCursorInfo() If (@error = 0) And ($aCurInfo[4] <> 0) Then Switch $aCurInfo[4] Case $Edit1id ConsoleWrite("I'm in Edit1" & @cr) Case $Edit2id ConsoleWrite("I'm in Edit2" & @cr) EndSwitch EndIf EndSwitch WEnd Edited December 1, 2008 by JusGellin Link to comment Share on other sites More sharing options...
Malkey Posted December 1, 2008 Share Posted December 1, 2008 (I figured out how to do this using the api functions. Thanks again, I've learned a lot) I tried editing my reply but it messed up the code. So here it is again: #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> $Form1 = GUICreate("Form1", 633, 447, 193, 125) $Edit1 = GUICtrlCreateEdit("", 48, 16, 433, 161, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_WANTRETURN, $WS_VSCROLL)) GUICtrlSetData(-1, "") $Edit1id = Number(_WinAPI_GetDlgCtrlID(GUICtrlGetHandle($Edit1))) $Edit2 = GUICtrlCreateEdit("", 48, 216, 433, 161, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_WANTRETURN, $WS_VSCROLL)) GUICtrlSetData(-1, "") $Edit2id = Number(_WinAPI_GetDlgCtrlID(GUICtrlGetHandle($Edit2))) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_PRIMARYDOWN $aCurInfo = GUIGetCursorInfo() If (@error = 0) And ($aCurInfo[4] <> 0) Then Switch $aCurInfo[4] Case $Edit1id ConsoleWrite("I'm in Edit1" & @CR) Case $Edit2id ConsoleWrite("I'm in Edit2" & @CR) EndSwitch EndIf EndSwitch WEndI think $Edit1id = number(_WinAPI_GetDlgCtrlID(GUICtrlGetHandle($Edit1))) ; and $Edit2id = number(_WinAPI_GetDlgCtrlID(GUICtrlGetHandle($Edit2))) can be shortened to $Edit1id = $Edit1; and $Edit2id = $Edit2 Link to comment Share on other sites More sharing options...
JusGellin Posted December 1, 2008 Author Share Posted December 1, 2008 I think$Edit1id = number(_WinAPI_GetDlgCtrlID(GUICtrlGetHandle($Edit1))) ; and$Edit2id = number(_WinAPI_GetDlgCtrlID(GUICtrlGetHandle($Edit2)))can be shortened to$Edit1id = $Edit1; and $Edit2id = $Edit2Wow!! much simpler. Thanks. I would never have known that since it just looks like a direct equality statement. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now