Sign in to follow this  
Followers 0
HarryBeasant

Help to get a script to run on button click

11 posts in this topic

Hello,

I would like this function;

Func _ReduceMemory($i_PID = -1)

If $i_PID <> -1 Then

Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID)

$ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])

DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])

Else

$ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)

EndIf

Return $ai_Return[0]

EndFunc ;==>_ReduceMemory

to be ran when a button it pressed;

$Button_1 = GUICtrlCreateButton("Clean RAM", 105, 65, 120)

Please help?!

Share this post


Link to post
Share on other sites



Bump?

Share this post


Link to post
Share on other sites

HarryBeasant,

Welcome to the AutoIt forum. :)

But please do not bump your posts within 24 hours. :mellow:

Remember this is not a 24/7 support forum - those who answer are only here because they like helping others and have some time to spare. You just have to wait until someone who knows something about your particular problem, and is willing to help, comes online. Be patient and someone will answer eventually - like this.

You will need to create a GUI to hold the $Button_1 control. Then you will either have to look for the event message sent by the button press within a GUIGetMsg loop or else use the OnEvent mode to intercept it directly.

If all that sounds like Chinese, then reading the Help file (at least the first few sections - Using AutoIt, Tutorials and the first couple of References) will help you enormously. You should also look at the excellent tutorials that you will find here and here - you will find other tutorials in the Wiki (the link is at the top of the page).

There are even video tutorials on http://www.youtube.com/results?search_qu...oit+tutorial&search_type=&aq=0 if you prefer watching to reading.

You know where we are if you get into difficulties. :)

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

Thanks for the reply, i have this code at the top, i really can't figure these "case statements" it will really help if you could give me an example of a button when clicked running any command in code please

#include <GUIConstantsEx.au3>

#include <StaticConstants.au3>

$GUI = GUICreate("RAM Monitor", 321, 121, 270, 173)

$menumenu = GUICtrlCreateMenu("Menu")

$menuitem = GUICtrlCreateMenuItem("Help", $menumenu)

GUICtrlSetState(-1, $GUI_DEFBUTTON)

$Button_1 = GUICtrlCreateButton("Clean RAM", 105, 65, 120)

$Progress = GUICtrlCreateProgress(0, 1, 320, 27)

GUISetState(@SW_SHOW)

Share this post


Link to post
Share on other sites

HarryBeasant,

You read those tutorials very quickly! :mellow:

Seriously, this is absolutely basic stuff - if you cannot get your controls to action than there is little point in coding. This example shows how to do it:

#include <GUIConstantsEx.au3>
$hGUI = GUICreate("Test", 200, 200)
$hButton = GUICtrlCreateButton("Test", 60, 80, 80, 30)
GUISetState()
While 1
Switch GUIGetMsg()
  Case $GUI_EVENT_CLOSE
   Exit
  Case $hButton
   MsgBox(0, "Pressed", "Test")
EndSwitch
WEnd

Now go and read those tutorials! :)

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

thanks! last question, that ram cleaning script, where abouts in that code you just wrote would it go?

Share this post


Link to post
Share on other sites

HarryBeasant,

You can put it at the end like this: :mellow:

#include <GUIConstantsEx.au3>
$hGUI = GUICreate("Test", 200, 200)
$hButton = GUICtrlCreateButton("Test", 60, 80, 80, 30)
GUISetState()
While 1
Switch GUIGetMsg()
  Case $GUI_EVENT_CLOSE
   Exit
  Case $hButton
   _DoIt() ; Call the function here
EndSwitch
WEnd
Func _DoIt() ; Define the function here
MsgBox(0, "Pressed", "Test")
EndFunc

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

#8 ·  Posted (edited)

Bare with me here mate.

While 1
Switch GUIGetMsg()
  Case $GUI_EVENT_CLOSE
   Exit
  Case $Button_1
   _DoIt($Button_1) ; Call the function here
EndSwitch
WEnd
Func _DoIt(_ReduceMemory()
Func _ReduceMemory($i_PID = -1)
        If $i_PID <> -1 Then
                Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID)
                Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])
                DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])
        Else
                Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
        EndIf
        Return $ai_Return[0]
EndFunc;==> _ReduceMemory()
While 1
        Sleep(100)
WEnd)
MsgBox(0, "Pressed", "Test")
EndFunc
Edited by HarryBeasant

Share this post


Link to post
Share on other sites

HarryBeasant,

Close, but no cigar! :)

#include <GUIConstantsEx.au3>
$hGUI = GUICreate("Test", 200, 200)
$hButton = GUICtrlCreateButton("Test", 60, 80, 80, 30)
GUISetState()
While 1
Switch GUIGetMsg()
  Case $GUI_EVENT_CLOSE
   Exit
  Case $hButton
   _ReduceMemory() ; Call the function here
EndSwitch
WEnd
Func _ReduceMemory($i_PID = -1)
If $i_PID <> -1 Then
  Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID)
  $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])
  DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])
Else
  $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
EndIf
Return $ai_Return[0]
EndFunc   ;==>_ReduceMemory

But I am not sure you should be playing with DllCalls if you cannot get them to run without so much help..... :mellow:

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

thanks for all your awesome help!!!

Share this post


Link to post
Share on other sites

HarryBeasant,

Here is a cleaned-up version of your script - take a good look and you will see where I have changed it and added comments to explain why:

#include <GUIConstantsEx.au3>
;
$GUI = GUICreate("RAM Monitor", 321, 121, 270, 173)
$menumenu = GUICtrlCreateMenu("Menu")
$menuitem = GUICtrlCreateMenuItem("Help", $menumenu)
$Button_1 = GUICtrlCreateButton("Clean RAM", 105, 65, 120)
$Progress = GUICtrlCreateProgress(0, 1, 320, 27)
GUICtrlCreateLabel("Current Memory Usage: ", 4, 32, 120, 20)
$Label1 = GUICtrlCreateLabel("", 124, 32, 200, 20) ; Create the label here so you can update it later
GUISetState(@SW_SHOW)
;
; Start a timer with a value to gurantee a quick response
$iBegin = 0
;
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $Button_1
   _ReduceMemory() ; Call the function here
EndSwitch
If TimerDiff($iBegin) > 5000 Then ; Do this every 5 secs - the intial 0 value means we do it as sson as we get here the first time
  $mem = MemGetStats()
  GUICtrlSetData($Progress, $mem[0] + 1) ; A trick to get Vista/Win7 progress bars to fill instantly
  GUICtrlSetData($Progress, $mem[0])
  ; Update the label - do not create a new one each time
  GUICtrlSetData($Label1, Round(($mem[1] / 100 * $mem[0]) / 1024) & " MB / " & Round($mem[1] / 1024, 0) & " MB " & " (" & $mem[0] & "% Load)")
  ; Reset the timer
  $iBegin = TimerInit()
EndIf
WEnd
;
Func _ReduceMemory($i_PID = -1)
SplashTextOn("RAM Cleaning", "In progress")
Sleep(1000) ; So you can see the splash screen
If $i_PID - 1 Then
  Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID)
  $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])
  DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])
Else
  $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
EndIf
SplashOff()
Return $ai_Return[0]
EndFunc   ;==>_ReduceMemory

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

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
Sign in to follow this  
Followers 0

  • Similar Content

    • au3leecher
      By au3leecher
      Hellow everybody,
      I tryed to manipulate a game called "Assault Cube" which is a easy beginning in coding. I run the code but the wished value doesn't change, i don't understand why.
      The Pointers are fine, I checked that the pointers don't change every time while restart the game.
      My Code:
      <snip>
      _____________________________________________________________________________________________________________________________________________________________________________________________
      Checklist:
      The Offsets are 18C & 4
      In Cheat Engine: ("ac_client.exe"+0010F418) <- Pointer
      4 Bytes = 'dword'
       
    • thoms
      By thoms
      Hello Forum,
      As said in the title, I'm searching a way to disable all tabstops in a GUI. My GUI includes 15 buttons and 3 edit controls.
      My questions:
      - is there a way to disable all tabstops at a time
      - is there a way to list all controls of a GUI and then disable tabstops one by one
      - or should I use the following line after each button creation:
      _WinAPI_SetWindowLong(GUICtrlGetHandle(-1), $GWL_STYLE, BitAND(_WinAPI_GetWindowLong(GUICtrlGetHandle(-1), $GWL_STYLE), BitNOT($WS_TABSTOP))) Thanks in advance for your valuable help!
      Thoms
      Edit: or maybe disable TAB key? I don't remember how to do!
    • AppSoftwareVld
      By AppSoftwareVld
      Hello,
       
      I need this for a project and I don't find a method for the next problem.
      I want when I click a button to create a variable ("$variable1") so if I press one more time to create one more ("$variable2") and create more and more how many times you press the button.
       
      Do you have an idea ? 
      Thank you for your attention !
    • rte7
      By rte7
      Hello. We work with the BMC Remedy site to manage incidents and would like to automate the processes of clicking through this button code:
      <a href="javascript:" class="btn btn3d menu" style="top:21; left:184; width:21; height:21;"> <img class="btnimg" src="../../../../resources/images/mt_sprites.gif" alt="menu category issue" title=""> </a> I use firefox with mozrepl and autoit with include FF.au3
      I need your help
      I read the topic https://www.autoitscript.com/forum/topic/95595-ffau3-v0601b-10/ but I could not run the code from the listed commands
      ...
      It is necessary to press the button and from the list of the menu of cahorsations to select the item = "zone of trust abonent"
      Screen # 1 http://joxi.ru/52aJK7bh4a7ypA or below.
      1) Press button
      <a href="javascript:" class="btn btn3d menu" style="top:21; left:184; width:21; height:21;"> <img class="btnimg" src="../../../../resources/images/mt_sprites.gif" alt="menu category issue" title=""> </a>
      2) After pressing the button, I need to choose in this menu of 4 items to select an item called "zone of trust abonent", Screen # 2 - http://joxi.ru/p27gwQKHo71VQ2
      html code table items
      <table class="MenuTable" cellpadding="0" cellspacing="0" style="width: 179px;"> <tbody class="MenuTableBody"> <tr class="MenuTableRow"> <td class="MenuEntryName" nowrap="">zone of trust abonent</td> <td class="MenuEntryNoSub" arvalue="zone of trust abonent"></td> </tr> <tr class="MenuTableRow"><td class="MenuEntryName" nowrap="">zone of trust operator</td> <td class="MenuEntryNoSub" arvalue="zone of trust operator"></td> </tr> <tr class="MenuTableRow"><td class="MenuEntryName" nowrap="">zone of trust third operator</td> <td class="MenuEntryNoSub" arvalue="zone of trust third operator"></td></tr> <tr class="MenuTableRow"><td class="MenuEntryNameHover" nowrap="">No settings</td> <td class="MenuEntryNoSubHover" arvalue="No settings"></td> </tr> </tbody> </table>
       
       
      More in detail, I choose from the menu item "zone of trust abonent" Screen # 3 - http://joxi.ru/GrqVq4ZIQEPW4m

       
      3) The choice is made, Screen # 4 http://joxi.ru/v297w6aC3PovLr
      <textarea class="text sr " wrap="off" id="arid_WIN_0_1000002488" cols="20" maxlen="60" style="top:21; left:0; width:179; height:21;" armenu="CFG:PRC:CategoryHPD-Res-T1-Q" mstyle="2" arautoc="1" arautocmb="1" arautocak="0" arautoctt="400" rows="1"> </textarea>
       
      It's all. I would be very grateful to you =) !!!!!!!!!!
      Here are more detailed codes in the attachment. 
      button1.txt
      menu - table.txt
      all.txt
    • nacerbaaziz
      By nacerbaaziz
      Hello
      How are you
      I have a question, please.
      I've created a window and i need
      when i run the script if it detect an other copy from the same script was runing
       the script close the first copy Automatically and run a new copy
      I want an example to understand it