Page 1 of 1

Help with Search

Posted: 09 Feb 2018, 01:51
by MonuKashyap
I am making simple search program, and i m trying to kill current busy thread, and dont no how to do that.
any help please?

here's my script, in this script i want to make work the stop button.

Code: Select all

gui, font, s20
gui, add, edit
gui, add, button, gfind vSrchButton default, Find
gui, show
return

Find:
count++
if count=1
Guicontrol,, SrchButton, Stop
loop
{
tooltip % a_Index "`n" count
if count=2
Break
}
msgbox done.
Guicontrol,, SrchButton, Find
Return

esc::
guiclose:
exitapp

Re: Help with Search

Posted: 09 Feb 2018, 02:47
by divanebaba
MonuKashyap wrote:... kill current busy thread ...
Could be helpful to know, what kind of thread you want to close.
Is it an AHK-tread? Is it same script you want to close, while you are reloading?
Or a damned game you want to play instead of doing usefull things? :mrgreen: :mrgreen:

Re: Help with Search

Posted: 09 Feb 2018, 06:37
by MonuKashyap
divanebaba wrote:
MonuKashyap wrote:... kill current busy thread ...
Could be helpful to know, what kind of thread you want to close.
Is it an AHK-tread? Is it same script you want to close, while you are reloading?
Or a damned game you want to play instead of doing usefull things? :mrgreen: :mrgreen:
I Want to kill the loop by stop button which is present in the same script
and
if you didn't understand anything, simply run the script then you will definitely understand what i want to do.
and thanks for reply

Re: Help with Search

Posted: 09 Feb 2018, 15:07
by Odlanir
A workaround:

Code: Select all

WM_LBUTTONDOWN() {
    global count
    If (A_Gui) {
        GuiControlGet,text,,SrchButton     
        if ( text = "Stop")
            count = 2
    }
}

gui, font, s20
gui, add, edit
gui, add, button, gfind vSrchButton default, Find
gui, show
return

Find:
count++
if count=1
Guicontrol,, SrchButton, Stop
OnMessage(0x0201, "WM_LBUTTONDOWN")
loop
{
tooltip % a_Index "`n" count
if count=2
Break
}
msgbox done.
tooltip,
Guicontrol,, SrchButton, Find
Return

Re: Help with Search

Posted: 11 Feb 2018, 01:00
by MonuKashyap
Odlanir wrote:A workaround:

Code: Select all

WM_LBUTTONDOWN() {
    global count
    If (A_Gui) {
        GuiControlGet,text,,SrchButton     
        if ( text = "Stop")
            count = 2
    }
}

gui, font, s20
gui, add, edit
gui, add, button, gfind vSrchButton default, Find
gui, show
return

Find:
count++
if count=1
Guicontrol,, SrchButton, Stop
OnMessage(0x0201, "WM_LBUTTONDOWN")
loop
{
tooltip % a_Index "`n" count
if count=2
Break
}
msgbox done.
tooltip,
Guicontrol,, SrchButton, Find
Return


The whole code works!! But Only First Time.. AND with click only (need enter button too)
Then it needs to reload.
any more help??

Re: Help with Search  Topic is solved

Posted: 11 Feb 2018, 02:46
by MonuKashyap
Well,, Thank you all for replies.. I really appreciate your help and suggestion.
and
I found my solution in this code,-

gui, font, s20
gui, add, edit
gui, add, button, x10 y110 w100 gfind vSrchButton Default, Find
gui, add, button, x10 y110 w100 gstop vStopButton Default, Stop
Guicontrol, hide, StopButton
Guicontrol, disable, StopButton
gui, show
return

Stop:
Stop:=1
Guicontrol, hide, StopButton
Guicontrol, disable, StopButton
Guicontrol, Show, Srchbutton
Guicontrol, Enable, Srchbutton
tooltip
Return

Find:
Guicontrol, hide, Srchbutton
Guicontrol, disable, Srchbutton
Guicontrol, Show, StopButton
Guicontrol, Enable, StopButton
Stop:=0
loop
{
tooltip % a_Index "`n" count
if Stop
Break
}
msgbox done.
Return

esc::
guiclose:
exitapp



I found this trick by spending more time on goolge, ahk forum, and many more experiments...
Hope this trick helps you too for some task in future..
Thanks once again to everyone.

Re: Help with Search

Posted: 11 Feb 2018, 03:39
by garry
thank you all for help
@MonuKashyap , this is your script below ( just used CODE for better readable and little modified as example for me to keep it ) , the variable 'count' was empty , can use if wanted ( here it's same as a_index )
added guicontrol for Edit
as title = How to start and break a loop with ONE button

Code: Select all

;-- https://autohotkey.com/boards/viewtopic.php?f=5&t=43986
;-- test start / stop break a loopX & GUI example

;- example GUI,2: / not needed to write '2:' if define first as 'NEW'
;- GUI,2: New,, Example   ;- only write once '2:'
#warn
Setworkingdir,%a_scriptdir%
count:=0

Gui,2: default
gui,2: font, s20
gui,2: add, edit , vED1 right cGray
gui,2: add, button, x10  y110 w100 gStart vStartButton Default, Start
gui,2: add, button, x10  y110 w100 gStop  vStopButton  Default, Stop

gui,2: add, button, x150 y110 w160 gCalc center,Calculator

Guicontrol,2: hide   , StopButton
Guicontrol,2: disable, StopButton
gui,2: show,,Loop_Test
return

calc:
run,calc
return

Stop:
Stop:=1
Guicontrol,2: hide   , StopButton
Guicontrol,2: disable, StopButton
Guicontrol,2: Show   , Startbutton
Guicontrol,2: Enable , Startbutton
tooltip
Return

Start:
Guicontrol,2: hide   , Startbutton
Guicontrol,2: disable, Startbutton
Guicontrol,2: Show   , StopButton
Guicontrol,2: Enable , StopButton
Stop:=0
loop
{
; do something until STOP
count++
Guicontrol,2:,ed1,%count%
tooltip, % "A_Index=" . a_Index . "`nCount=" . count
if Stop
  Break
}
msgbox, 262208,STOP ,Loop stopped`nYou can start again ( if wanted ),3
Return

esc::
2guiclose:
exitapp

Re: Help with Search

Posted: 11 Feb 2018, 04:23
by Odlanir
With minor mods the code I gave you works all the time, also with enter key.

Code: Select all

#SingleInstance, force
#NoEnv
#Persistent
WM_LBUTTONDOWN() {
    global count
    If (A_Gui) {
        GuiControlGet,text,,SrchButton     
        if ( text = "Stop")
            count = 2
    }
}
gui, font, s20
gui, add, edit
gui, add, button, gfind vSrchButton default, Find
gui, show
return

Find:
count++
if count=1
Guicontrol,, SrchButton, Stop
OnMessage(0x0201, "WM_LBUTTONDOWN"), OnMessage(0x100, "WM_LBUTTONDOWN")
loop
{
tooltip % a_Index "`n" count
    if (count=2) {
        count := 0
        Break
    }
}
msgbox done.
tooltip,
Guicontrol,, SrchButton, Find
Return

Re: Help with Search

Posted: 11 Feb 2018, 09:33
by garry
@Odlanir , thank you again for the good short example