How to simulate "MsgBox"

Ask for help, how to use AHK_H, etc.
arcticir
Posts: 694
Joined: 17 Nov 2013, 11:32

How to simulate "MsgBox"

21 Aug 2017, 07:46

I tried using the following code instead of "MsgBox".
It is very fast and supports selecting / editing / copying text
  Even loading a few MB of text is also extremely responsive.

But the "WinWaitClose" command brought a huge disaster.
We know that a script can have multiple "MsgBox" windows at the same time,
Before you click "OK", the thread is in a paused state.
This is very friendly.
And "WinWaitClose" is the opposite
It hinders other threads,
Even if other processes use "Accessible" to view this window,
It will make this process stagnant.
I spent a lot of time looking for the cause of the process of stagnation.

I try to find a perfect solution like "MsgBox" treat threads

I think, can we make precise opening / closing of threads?
E.g:

Code: Select all

test(){
	;
	gui.show()
	;A_CurrentThread
	gui.OnEvent("Close",func("Closegui").Bind(A_CurrentThread))
	Pause("off",A_CurrentThread)
	k.Destroy()
}


CloseGui(id){
	Pause("on",id)
}
So, can add a variable that marks the thread?
In order to accurately control the state of the thread.
What do you think?

Code: Select all

test(p*){
	static i:=0,_:=LoadLibrary("MsFtEdit.dll")
	i++
	if p.Length()
	{
		if p.Length()=1
			s:=isobject(s:=p.1)?ov(s):s
		else
			s:=ov(p)
	} else
		s:=i
	Varsetcapacity(Buf, strPut(s,"CP0"), 0),StrPut(s, &Buf, "CP0"),Varsetcapacity(SetText,8,0)
	k:=GuiCreate(),h:=A_ScreenHeight*0.7,w:=A_ScreenWidth*0.7
	r :=k.Add("Custom", "ClassRICHEDIT50W x0 y0 0x0004 0X0040 0x200000 w" w " h" h),r.Focus()
	SendMessage_(r.hwnd,0x0461,&SetText, &Buf)
	k.show("w" w " h" h)
	WinWaitClose("ahk_id " k.hwnd)
	k.Destroy()
	return
}
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: How to simulate "MsgBox"

21 Aug 2017, 15:58

Thread Id can be retrieved via A_ThreadId.
Try PostThreadMessage(A_ThreadId, 65306) to pause the thread.
arcticir
Posts: 694
Joined: 17 Nov 2013, 11:32

Re: How to simulate "MsgBox"

21 Aug 2017, 18:10

I do not understand.
Take this example, how to restore the earliest suspended "A" thread?

Code: Select all

SetTimer "a",-100
SetTimer "t",-1000
;Press the key sequentially: {b} {c} {s}
; The "S" key will be used to restore "a" thread
return
a:
ToolTip "pause Thread a"
PostThreadMessage(A_ThreadId, 65306) 
pause("on",0)
MsgBox "restore a"
return

b::
ToolTip "pause Thread b"
PostThreadMessage(A_ThreadId, 65306) 
pause("on",0)
MsgBox "restore b"
return
c::
ToolTip "pause Thread c"
PostThreadMessage(A_ThreadId, 65306) 
pause("on",0)
MsgBox "restore c"
return

s::
pause("off")
return

t:
pause("off")
MsgBox "Thread t"
return

In addition, can there be any way to achieve this example of the program?

Code: Select all

test(){
	;
	gui.show()
	;A_CurrentThread
	gui.OnEvent("Close",func("Closegui").Bind(A_CurrentThread))
	Pause("off",A_CurrentThread)
	k.Destroy()
}


CloseGui(id){
	Pause("on",id)
}
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: How to simulate "MsgBox"

22 Aug 2017, 16:46

You can't pause a pseudo thread, it must be a real thread.

For some reason PostThreadMessage does not work, probably because of Messages sent by PostThreadMessage are not associated with a window.

Try this:

Code: Select all

aThread:=ExeThread("#Persistent`nSetTimer `"a`", 100`nReturn`na:`nToolTip A_TickCount `" - `" A_ThreadId`nReturn")
Sleep 1000
aThreadHwnd:=aThread.ahkgetvar("A_ScriptHwnd")
b::
  PostMessage_(aThreadHwnd, 0x111, 65306) 
return

Esc::ExitApp
arcticir
Posts: 694
Joined: 17 Nov 2013, 11:32

Re: How to simulate "MsgBox"

22 Aug 2017, 18:13

This simply means that "65306" has the same functionality as "pause".
It does not solve the "pause" can not solve the problem.
thanks.

===========

I found a way to accurately restore a suspended thread.

Code: Select all

#MaxThreads 7
#MaxThreadsPerHotkey 8
A_pauseid:={base:{id:0}},A_pausename,A_pauselist:=[]
SetTimer "a",-100
SetTimer "t",-1000
;Press the key sequentially: {b} {c} {s}
; The "S" key will be used to restore "a" thread
return
a:

ToolTip "pause Thread a"
A_pauseid.push(ErrorLevel:=A_pauseid.base.id++)
A_pauselist["a"]:=ErrorLevel
PostThreadMessage(A_ThreadId, 65306) 
pause("on",0)
if A_pausename!=ErrorLevel and A_IsPaused
pause("off",0)
MsgBox "restore a"
return

b::
ToolTip "pause Thread b"
A_pauseid.push(ErrorLevel:=A_pauseid.base.id++)
A_pauselist["b"]:=ErrorLevel
pause("on",0)
if A_pausename!=ErrorLevel and A_IsPaused
pause("off",0)
MsgBox "restore b"
return
c::
ToolTip "pause Thread c"
A_pauseid.push(ErrorLevel:=A_pauseid.base.id++)
A_pauselist["c"]:=ErrorLevel
pause("on",0)
if A_pauselist[A_pausename]!=ErrorLevel and A_IsPaused
pause("off",0)
MsgBox "restore c"
return

s::
A_pausename:="b"
pause("off")
return

t:
pause("off")
MsgBox "Thread t"
return

Return to “Ask for Help”

Who is online

Users browsing this forum: No registered users and 20 guests