ChrisL Posted March 11, 2014 Share Posted March 11, 2014 Hello. I'm trying to make a gui button continually call the function while it is pressed. In the example below the number only changes once you release the button, I want it to continually count up or down as long as I pressing the button. I'm sure I've seen this before but can't seem to find it. Thanks expandcollapse popup#include <GUIConstantsEx.au3> Opt("GuiOnEventMode",1) Global $label _Examlple() While 1 Sleep(100) WEnd Func _Examlple() Local $gui $gui = GUICreate("Test",500,200) GUISetOnEvent($GUI_EVENT_CLOSE,"_Exit") GUISetFont(72) $label = GUICtrlCreateLabel("0",20,20,100,100) $upButton = GUICtrlCreateButton("+",300,20,70,70) GUICtrlSetOnEvent($upButton,"_Add") $downButton = GUICtrlCreateButton("-",300,110,70,70) GUICtrlSetOnEvent($downButton,"_Subtract") GUISetState() EndFunc Func _Exit() Exit EndFunc Func _Add() GUICtrlSetData($label,Int(GUICtrlRead($label)) +1) EndFunc Func _Subtract() GUICtrlSetData($label,Int(GUICtrlRead($label)) -1) EndFunc [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
FireFox Posted March 11, 2014 Share Posted March 11, 2014 expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPIShellEx.au3> #include <Misc.au3> Global $_hBtnProc = DllCallbackRegister("_BtnProc", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr") Global $_pBtnProc = DllCallbackGetPtr($_hBtnProc) OnAutoItExitRegister("OnAutoItExit") $hGUI = GUICreate("MyGUI") $iButton1 = GUICtrlCreateButton("Button1", 10, 10, 80, 22) _WinAPI_SetWindowSubclass(GUICtrlGetHandle($iButton1), $_pBtnProc, $iButton1, 0) GUISetState(@SW_SHOW, $hGUI) While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd Func _BtnProc($hWnd, $iMsg, $wParam, $lParam, $ID, $pData) #forceref $pData, $ID Switch $iMsg Case $WM_LBUTTONDOWN While _IsPressed("01") ConsoleWrite("pressed" & @MSEC & @LF) Sleep(10) WEnd EndSwitch Return _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam) EndFunc ;==>_BtnProc Func OnAutoItExit() _WinAPI_RemoveWindowSubclass(GUICtrlGetHandle($iButton1), $_pBtnProc, $iButton1) DllCallbackFree($_hBtnProc) EndFunc ;==>OnAutoItExit Link to comment Share on other sites More sharing options...
johnmcloud Posted March 11, 2014 Share Posted March 11, 2014 Without subclassing and dllcallback ; johnmcloud 2014 #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $hGUI = GUICreate("MyGUI") $iButton1 = GUICtrlCreateButton("Add", 10, 10, 80, 22) $iLabel1 = GUICtrlCreateLabel("0", 10, 50, 25) GUISetState(@SW_SHOW, $hGUI) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch If _ButtonClicked($iButton1) = 1 Then GUICtrlSetData($iLabel1, Int(GUICtrlRead($iLabel1)) + 1) Sleep(100) EndIf WEnd Func _ButtonClicked($iButton) Local $aResult = DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", GUICtrlGetHandle($iButton), "uint", 0xF2, "wparam", 0, "lparam", 0) If @error Then Return 0 If BitAND($aResult[0], 0x4) = 0x4 Then Return 1 EndFunc ;==>_ButtonClicked Link to comment Share on other sites More sharing options...
Danyfirex Posted March 11, 2014 Share Posted March 11, 2014 (edited) Another way using GUIGetCursorInfo. #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Array.au3> $hGUI = GUICreate("MyGUI") $iButton1 = GUICtrlCreateButton("Add", 10, 10, 80, 22) $iLabel1 = GUICtrlCreateLabel("0", 10, 50, 25) GUISetState(@SW_SHOW, $hGUI) Local $iInfo = 0 Local $i = 1 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_PRIMARYDOWN If WinActive($hGUI) Then $iInfo = GUIGetCursorInfo() If $iInfo[2] And $iInfo[4] = $iButton1 Then While $iInfo[2] and $iInfo[4]=$iButton1 $iInfo = GUIGetCursorInfo() GUICtrlSetData($iLabel1, $i) $i += 1 WEnd EndIf EndIf EndSwitch WEnd Saludos Edited March 11, 2014 by Danyfirex Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
ChrisL Posted March 11, 2014 Author Share Posted March 11, 2014 Thanks All! [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire 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