Jump to content

Recommended Posts

Posted

Actually I'm not sure if I gave this thread the proper name, how ever I feel it's OK.

BTW, the idea is to run multiple functions aka loops at once without blocking the main script or freezing the GUI. I believe it's not at once but it looks like it is :-" Because functions can be running while other functions are running :o WTF!

Lets try this out:

I have created 3 scripts, one as the host script (I said host just because it receives messages sent by client scripts (I said client because it sends the message (Nested parenthesis!)))

Note: This are just examples, as soon as you got the idea, there are more things to do and more ways to go.

Example:

WM_USER Get

#include
#include

Global Const $WM_LOOP = $WM_USER + 1
Global Const $WM_FLYER = $WM_USER + 2

GUICreate('WM_USER Get', 600, 400)
Global $lblLoop = GUICtrlCreateLabel('The default value...', 10, 10, 250, 15)

Global $txtTypeHere = GUICtrlCreateInput('', 10, 45, 250, 21)
Global $lblSetHere = GUICtrlCreateLabel('Empty for now...', 10, 71, 250, 15)
Global $btnSetNow = GUICtrlCreateButton('Set Now', 10, 96, 75, 23)

Global $lblInteralLoop = GUICtrlCreateLabel('Internal loop that blocks GUI', 10, 200, 250, 15)
Global $btnInternalLoop = GUICtrlCreateButton('Start Internal Loop', 10, 225, 150, 23)

SplashTextOn('WM_USER Get', "I'm gonna fly...", 160, 90, 0, 0, BitOR(1, 2, 32))

GUIRegisterMsg($WM_LOOP, 'WM_LOOP')
GUIRegisterMsg($WM_FLYER, 'WM_FLYER')
GUISetState()


While (True)
Switch (GUIGetMsg())
Case $GUI_EVENT_CLOSE
Exit
Case $btnSetNow
GUICtrlSetData($lblSetHere, GUICtrlRead($txtTypeHere))
Case $btnInternalLoop
InternalLoop()
EndSwitch
WEnd


Func WM_LOOP($hWnd, $uMsg, $wParam, $lParam)
CallByWM_LOOP(Int($lParam))
EndFunc

Func WM_FLYER($hWnd, $uMsg, $wParam, $lParam)
SplashTextOn('WM_USER Get', "I'm gonna fly...", 160, 90, $wParam, $lParam, BitOR(1, 2, 32))
EndFunc

Func CallByWM_LOOP($i)
GUICtrlSetData($lblLoop, $i)
EndFunc

Func InternalLoop()
For $i = 1 To 500
GUICtrlSetData($lblInteralLoop, $i)
Sleep(10)
Next
EndFunc

WM_LOOP Send

[size=4]#include <WindowsConstants.au3>[/size]

$hWnd = WinGetHandle('WM_USER Get')
$iPid = WinGetProcess($hWnd)

Global Const $WM_LOOP = $WM_USER + 1

For $i = 1000 To 2000
If (Not ProcessExists($iPid)) Then Exit

SendMessage($hWnd, $WM_LOOP, 0, $i)
If (@error) Then Exit

Sleep(5)
Next

Func SendMessage($hWnd, $uMsg, $wParam, $lParam)
Local $Result = DllCall('User32.dll', 'LRESULT', 'SendMessage', _
'HWND', $hWnd, _
'UINT', $uMsg, _
'WPARAM', $wParam, _
'LPARAM', $lParam)

If (@error) Then Return SetError(1, 0, 0)
[size=4]EndFunc[/size]

WM_FLYER Send

[size=4]#include <WindowsConstants.au3>[/size]

$hWnd = WinGetHandle('WM_USER Get')
$iPid = WinGetProcess($hWnd)

Global Const $WM_FLYER = $WM_USER + 2

For $i = 10 To 700 Step 10
If (Not ProcessExists($iPid)) Then Exit

SendMessage($hWnd, $WM_FLYER, $i, $i)
If (@error) Then Exit

Sleep(100)
Next

Func SendMessage($hWnd, $uMsg, $wParam, $lParam)
Local $Result = DllCall('User32.dll', 'LRESULT', 'SendMessage', _
'HWND', $hWnd, _
'UINT', $uMsg, _
'WPARAM', $wParam, _
'LPARAM', $lParam)

If (@error) Then Return SetError(1, 0, 0)
[size=4]EndFunc[/size]

Or download them all at once:

Read more about the WM_USER message.

Recommended way of testing:

Run WM_USER Get, run WM_USER Get and run WM_FLYER Send.

While you can see something! is flying and while you can see the lable is changing in a loop, you can still run the internal loop!

Drop me any comments, it's warmly welcomed.

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
×
×
  • Create New...