jennico Posted April 14, 2007 Posted April 14, 2007 (edited) hi there, i want to ask you if there is a kind of function that is able to retrieve the control that has just been clicked by mouse. the background is that i have a gui with >4000 controls and it lasts a long time until the getmsg loop reaches the control just clicked with quite a delay. it could be a faster way to react on mouseclick (_IsPressed("01")) and then retrieve the control clicked. but i didn't find a function that retrieves the clicked control id. well, it could be found by using the mouse coordinates and then find the control there, but this is not very smart. or does it work with controlgetfocus? any idea or maybe i oversaw a function ? kind regards j. Edited April 14, 2007 by jennico Spoiler I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.Don't forget this IP: 213.251.145.96
Will66 Posted April 14, 2007 Posted April 14, 2007 I find GUIOnEventMode is handy for situations where controls are created dynamically and might suite your situation. You'll have to change the rest of your code to be compatible though. Opt("GUIOnEventMode", 1) eg: $ReportsMenu = GUICtrlCreateMenu ("&Reports") GUICtrlCreateMenuitem ("Open",$ReportsMenu) GUICtrlSetOnEvent(-1, "ReportsMenu_clicked") Func ReportsMenu_clicked() Dim $menutext = GUICtrlRead(@GUI_CTRLID, 1) ; return the text of the menu item MsgBox(0,"",$menutext) ; returns "Open" EndFunc
jennico Posted April 14, 2007 Author Posted April 14, 2007 (edited) hello again, i solved the problem and found a very smart method to register mouse clicks on controls without using the "getmsg" method, which needs a long time until the loop has reached the clicked control. you can mix the method with the normal getmsg routine in order to be able to register other controls clicked. i will add the code because maybe someone will find it useful. it is especially effective on large control arrays as they will be used e.g. in simple games or maybe touchscreen surfaces. the code creates an array of 4000 picture controls in the parent window which will change their images on click. adittionally there are two child windows with button controls adressed in the "normal" way (getmsg). i won't post the function section because the script is going to be too long, so you have to add something to make it work. the script retrieves the clicked picture so fast that you can even use it as a drawing program when you drag the mouse clicked over a line of controls. thank you for your attention j. expandcollapse popup#NoTrayIcon #include<string.au3> #include<GuiConstants.au3> #Include<Misc.au3> Opt("MouseCoordMode",2) $modus=16 $xwindow=80 $ywindow=50 $breite=800 $hoehe=520 $zellgrosse=10 $max=10 $filename="Unbenannt" $a="" Global $parent,$child,$symbole,$neu,$offnen,$speichern,$speichernu,$grosse,$erganzen, $zufall,$rander,$beenden,$grosser,$spalte,$zeile,$zell,$zuruck,$vor,$temp,$tmp Dim $quadrat[$xwindow][$ywindow],$wert[$xwindow][$ywindow],$zelle[17],$symbol[10] For $y=0 To $ywindow-1 For $x=0 To $xwindow-1 $wert[$x][$y]=0 Next Next _gui() ;------------------------------gui abfrage-------------------------------------------- While 1 $msg=GuiGetMsg() ; this is my idea to call the control area : very fast !!! If _IsPressed("01") Then $a=ControlGetFocus("Toras Labyrinth","") If $a="static1" Then $control=ControlGetPos("Toras Labyrinth","","Static1") $pos=MouseGetPos() If $pos[0]-$control[0]>0 And $pos[1]-$control[1]>0 And $pos[0]-$control[0]<$xwindow*$control[2] And $pos[1]-$control[1]<$ywindow*$control[3] Then ;this line is only necessary to filter clicks outside the array area $x=Int(($pos[0]-$control[0])/$control[2]) $y=Int(($pos[1]-$control[1])/$control[3]) _drehen() EndIf EndIf EndIf ; end of my idea If $msg=$neu Then _neu() If $msg=$offnen Then _offnen() If $msg=$speichern Then _speichern() If $msg=$speichernu Then _speichernu() If $msg=$zuruck Then _zuruck() If $msg=$vor Then _vor() If $msg=$grosse Then _grosse() If $msg=$grosser Then _grosser() If $msg=$erganzen Then _erganzen() If $msg=$zufall Then _zufall() If $msg=$rander Then _rander() ; this would be the "normal" way of retrieving control actions, very slow ; For $y=0 To $ywindow-1 ; For $x=0 To $xwindow-1 ; If $msg=$quadrat[$x][$y] Then _drehen() ; Next ; Next For $j=0 To 16 If $msg=$zelle[$j] Then _modus() Next For $i=0 To 9 If $msg=$symbol[$i] Then _symbol() Next If $msg=$GUI_EVENT_CLOSE Or $msg=$beenden Then _beenden() WEnd ;------------------------------funktioneen-------------------------------------------- Func _gui() ProgressOn("Toras Labyrinth","",$a&" wird geladen...") DirCreate("save") $parent=GUICreate("Tora",$breite,$hoehe,-1,-1,BitOr($WS_POPUP,$WS_MAXIMIZEBOX,$WS_CAPTION, $WS_SYSMENU,$WS_MINIMIZEBOX,$WS_THICKFRAME)) GuiSetIcon(@SystemDir&"\cmmon32.exe",0) $datei=GuiCtrlCreateMenu("Datei") $neu=GuiCtrlCreateMenuItem("&Neu",$datei) GuiCtrlCreateMenuItem("",$datei) $offnen=GuiCtrlCreateMenuItem("&Laden",$datei) $speichern=GuiCtrlCreateMenuItem("&Speichern",$datei) $speichernu=GuiCtrlCreateMenuItem("Speichern unter...",$datei) GuiCtrlCreateMenuItem("",$datei) $drucken=GuiCtrlCreateMenuItem("&Drucken",$datei) GUICtrlSetState($drucken,$GUI_DISABLE) GuiCtrlCreateMenuItem("",$datei) $beenden=GuiCtrlCreateMenuItem("&Beenden",$datei) $bearbeiten=GuiCtrlCreateMenu("Bearbeiten") $zuruck=GuiCtrlCreateMenuItem("&Zurück",$bearbeiten) GUICtrlSetState($zuruck,$GUI_DISABLE) $vor=GuiCtrlCreateMenuItem("&Vorwärts",$bearbeiten) GUICtrlSetState($vor,$GUI_DISABLE) GuiCtrlCreateMenuItem("",$bearbeiten) $spalte=GuiCtrlCreateMenuItem("Spalte entfernen",$bearbeiten) GUICtrlSetState($spalte,$GUI_DISABLE) $zeile=GuiCtrlCreateMenuItem("Zeile entfernen",$bearbeiten) GUICtrlSetState($zeile,$GUI_DISABLE) $zell=GuiCtrlCreateMenuItem("Zelle / Symbol entfernen",$bearbeiten) GUICtrlSetState($zell,$GUI_DISABLE) GuiCtrlCreateMenuItem("",$bearbeiten) $grosse=GuiCtrlCreateMenuItem("Labyrinthgröße ändern (neues Labyrinth)",$bearbeiten) $grosser=GuiCtrlCreateMenuItem("Labyrinth vergrößern (Labyrinth beibehalten)",$bearbeiten) $ansicht=GuiCtrlCreateMenu("Ansicht") $verkleinern=GuiCtrlCreateMenuItem("Verkleinern",$ansicht) $vergrossern=GuiCtrlCreateMenuItem("Vergrößern",$ansicht) If $zellgrosse=$max Then GUICtrlSetState($vergrossern,$GUI_DISABLE) $extras=GuiCtrlCreateMenu("Extras") $rander=GuiCtrlCreateMenuItem("Labyrinth&ränder schließen",$extras) $erganzen=GuiCtrlCreateMenuItem("Labyrinth&wände ergänzen",$extras) GuiCtrlCreateMenuItem("",$extras) $zufall=GuiCtrlCreateMenuItem("Zufallslabyrinth erzeugen",$extras) $j=0 For $y=0 To $ywindow-1 For $x=0 To $xwindow-1 $j=$j+1 ProgressSet(Round($j*100/(($ywindow-1)*($xwindow-1)))) $quadrat[$x][$y]=GUICtrlCreatePic($wert[$x][$y]&".bmp",$x*$zellgrosse,$y*$zellgrosse, $zellgrosse,$zellgrosse) GUICtrlSetResizing($quadrat[$x][$y],904);$GUI_DOCKALL) Next Next ProgressSet(100,"...fertig") GUISetState() ;------------------------------child zellen-------------------------------------------- $child=GUICreate(" Zellen ",682,63,Round(@DesktopWidth/2-$xwindow*$zellgrosse/2+270), Round(@DesktopHeight/2-$ywindow*$zellgrosse/2-11),$WS_EX_MDICHILD,$WS_EX_OVERLAPPEDWINDOW,$parent) GuiSetIcon("TLabyrinth.exe",0) For $j=0 To 15 $zelle[$j]=GUICtrlCreateButton("",$j*40+40,0,40,40,$BS_BITMAP) GUICtrlSetImage($zelle[$j],$j&".bmp") Next $zelle[16]=GUICtrlCreateButton("",0,0,40,40,$BS_icon) GUICtrlSetImage($zelle[16],"TLabyrinth.exe") GUISetState() ;------------------------------child symbole------------------------------------------- $symbole=GUICreate(" Symbole",80,248,Round(@DesktopWidth/2-$xwindow*$zellgrosse/2-40), Round(@DesktopHeight/2-$ywindow*$zellgrosse/2+80),$WS_EX_MDICHILD,$WS_EX_OVERLAPPEDWINDOW,$parent) GUISetBkColor(0xFFFFFF) $symbol[0]=GUICtrlCreateButton("",10,10,40,40,$BS_icon) GUICtrlSetImage(-1,"TLabyrinth.exe") $symbol[1]=GUICtrlCreateButton("º",51,10,40,40,BitOr($SS_CENTER,$SS_SUNKEN),$WS_EX_WINDOWEDGE) GUICtrlSetFont(-1,25,500,0,"Comic Sans MS") $symbol[2]=GUICtrlCreateButton("S",11,51,40,40,BitOr($SS_CENTER,$SS_SUNKEN),$WS_EX_WINDOWEDGE) GUICtrlSetFont(-1,25,1000,0,"Arial Bold") $symbol[3]=GUICtrlCreateButton("Z",51,51,40,40,BitOr($SS_CENTER,$SS_SUNKEN),$WS_EX_WINDOWEDGE) GUICtrlSetFont(-1,25,1000,0,"Arial Bold") $symbol[4]=GUICtrlCreateButton("E",11,91,40,40,BitOr($SS_CENTER,$SS_SUNKEN),$WS_EX_WINDOWEDGE) GUICtrlSetFont(-1,25,1000,0,"Arial Bold") $symbol[5]=GUICtrlCreateButton("A",51,91,40,40,BitOr($SS_CENTER,$SS_SUNKEN),$WS_EX_WINDOWEDGE) GUICtrlSetFont(-1,25,1000,0,"Arial Bold") $symbol[6]=GUICtrlCreateButton("â⬢",11,131,40,40,BitOr($SS_CENTER,$SS_SUNKEN),$WS_EX_WINDOWEDGE) GUICtrlSetFont(-1,30,1000,0,"Arial Bold") $symbol[7]=GUICtrlCreateButton("*",51,131,40,40,BitOr($SS_CENTER,$SS_SUNKEN),$WS_EX_WINDOWEDGE) GUICtrlSetFont(-1,30,600,0,"Arial Bold") $symbol[8]=GUICtrlCreateButton("X",11,171,40,40,BitOr($SS_CENTER,$SS_SUNKEN),$WS_EX_WINDOWEDGE) GUICtrlSetFont(-1,23,1000,0,"Arial Bold") $symbol[9]=GUICtrlCreateButton("¤",51,171,40,40,BitOr($SS_CENTER,$SS_SUNKEN),$WS_EX_WINDOWEDGE) GUICtrlSetFont(-1,40,400,0,"Arial Bold") GUISetState() ProgressOff() EndFunc a message to the programmers: thanks a lot for this wonderful program and what a pity that there can only be used 4096 controls. maybe this could be changed in further versions ? Edited April 15, 2007 by jennico Spoiler I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.Don't forget this IP: 213.251.145.96
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