Info Posted July 7, 2009 Share Posted July 7, 2009 ? Link to comment Share on other sites More sharing options...
picea892 Posted July 7, 2009 Share Posted July 7, 2009 Someone will come along and tell you there is a better way to do it, they always do......but this works for me and I find it simple enough. CODE#include <GUIConstantsEx.au3> #include <Array.au3> Global $buts dim $buts[5] Example() Func Example() Local $Button_1, $Button_2, $msg $example=GUICreate("My GUI Button", 300,100,-1,-1); will create a dialog box that when displayed is centered $left=10 For $i=1 to UBound($buts)-1 $buts[$i] = GUICtrlCreateButton("Button "&$i, $left, 30, 50,50) $left=$left+60 Next GUISetState() ; Run the GUI until the dialog is closed While 1 $hover=GUIGetCursorInfo(WinGetHandle($example,"")) For $i=1 to UBound($buts)-1 if $hover[4]= $buts[$i] and $hover[2]=1 then MsgBox(0,"Button "&$i&" pressed","left button") if $hover[4]= $buts[$i] and $hover[3]=1 then MsgBox(0,"Button "&$i&" pressed","right button") Next $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit 0 EndSelect Sleep(50) WEnd EndFunc ;==>Example Link to comment Share on other sites More sharing options...
wraithdu Posted July 7, 2009 Share Posted July 7, 2009 (edited) That does the job, if not a little wasteful on CPU cycles. Here's mine. #include <GuiConstantsEx.au3> $gui = GUICreate("GUI", 200, 200) $button1 = GUICtrlCreateButton("Button1", 10, 10) $button2 = GUICtrlCreateButton("Button2", 70, 10) ConsoleWrite("button1 id: " & $button1 & @CRLF) ConsoleWrite("button2 id: " & $button2 & @CRLF) GUISetState() Do $msg = GUIGetMsg() Switch $msg Case $button1 ConsoleWrite("left-click button1" & @CRLF) Case $button2 ConsoleWrite("left-click button2" & @CRLF) Case $GUI_EVENT_SECONDARYDOWN $iID = GUIGetCursorInfo($gui) ConsoleWrite("right-click id: " & $iID[4] & @CRLF) EndSwitch Until ($msg = $GUI_EVENT_CLOSE) Now I think that's about it for free code for you today. Time to go learn something on your own. You'll notice that blank 'help me' requests are frowned upon. Show some effort, what you've tried, and that you're interested in learning something instead of being spoon fed, and you're more likely to get some friendly help. Edited July 7, 2009 by wraithdu Link to comment Share on other sites More sharing options...
wraithdu Posted July 7, 2009 Share Posted July 7, 2009 Cause I feel like showing off this evening. expandcollapse popup#include <GuiConstantsEx.au3> #include <WinAPI.au3> #include <ButtonConstants.au3> #include <WindowsConstants.au3> $fRightClick = False $gui = GUICreate("GUI", 200, 200) $button1 = GUICtrlCreateButton("Button1", 10, 10) $button2 = GUICtrlCreateButton("Button2", 70, 10) GUISetState() Do $msg = GUIGetMsg() Switch $msg Case $button1 If $fRightClick Then ConsoleWrite("right-click button1" & @CRLF) Else ConsoleWrite("left-click button1" & @CRLF) EndIf $fRightClick = False Case $button2 If $fRightClick Then ConsoleWrite("right-click button2" & @CRLF) Else ConsoleWrite("left-click button2" & @CRLF) EndIf $fRightClick = False Case $GUI_EVENT_SECONDARYDOWN $iID = GUIGetCursorInfo($gui) If $iID[4] <> 0 Then $fRightClick = True $word = _WinAPI_MakeLong($iID[4], $BN_CLICKED) _SendMessage($gui, $WM_COMMAND, $word, GUICtrlGetHandle($iID[4])) EndIf EndSwitch Until ($msg = $GUI_EVENT_CLOSE) Link to comment Share on other sites More sharing options...
Info Posted July 7, 2009 Author Share Posted July 7, 2009 (edited) Why do you think I've done nothing else but asking for "free codes"? Because you and Melba showed some in my first topic? Just to let you know, I don't use any of the codes you both gave me. Thank you for this code. Edited July 7, 2009 by Info Link to comment Share on other sites More sharing options...
picea892 Posted July 7, 2009 Share Posted July 7, 2009 I suppose 0% CPU usage is quite high. Link to comment Share on other sites More sharing options...
dantay9 Posted July 8, 2009 Share Posted July 8, 2009 @picea892Your code uses up more cpu cycles and therefore uses more memory. It isn't a very high user, but there is not reason to waste cpu if you don't have to. Link to comment Share on other sites More sharing options...
wraithdu Posted July 8, 2009 Share Posted July 8, 2009 (edited) @Info I say that because in neither topic did you show any of your own code or propose anything that you tried (even if you failed). The only code you posted was skeleton at best, and you event asked if M23 could 'plug' his example into it. That's frstrating at best to those of us that regularly help out with examples. Show some initiative. @picea892 Loops are fine when necessary, but inefficient in this context. Not only does the loop itself use more CPU, there's a Sleep() in there that may kinda 'lag' a response, and GuiGetMsg() itself has some 'sleep' built into it when there are no messages in the queue (approx 15ms) so will lag the loop some more. I'm not saying it's bad, just there are better alternatives. Why does everyone have to take criticism so negatively and personal? Edited July 8, 2009 by wraithdu Link to comment Share on other sites More sharing options...
picea892 Posted July 8, 2009 Share Posted July 8, 2009 Your right on both counts Wraithdu 1) Any amount of efficiency should be sought after 2) Can`t take this stuff personal. I`m here to learn after all. Picea Link to comment Share on other sites More sharing options...
Info Posted July 8, 2009 Author Share Posted July 8, 2009 Picea, your signature is amazing. Link to comment Share on other sites More sharing options...
wraithdu Posted July 8, 2009 Share Posted July 8, 2009 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