Jump to content

Prevent a script from paused


 Share

Recommended Posts

How can i prevent a script from paused state when i call context menu?

#include <GuiConstants.au3>
#include <GuiListView.au3>
#include <GuiMenu.au3>

Global Enum $idMenuOpen, $idMenuSave
Dim $pos = 10

$hGui = GUICreate("Test", 300, 200)

$label = GUICtrlCreateLabel("label", 10, 180, 25, 15)
;GUICtrlSetBkColor(-1, 0xFF0000)

$hListView = _GUICtrlListView_Create($hGui, "Items|SubItems", 10, 10, 280, 160, -1, $WS_EX_CLIENTEDGE)

_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))

GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU")

GUISetState()

Do
    If $pos >= 300 Then $pos = 0
    $pos += 1
    GUICtrlSetPos($label, $pos, 180)
    Sleep(10)
Until GUIGetMsg() = -3

Func WM_CONTEXTMENU($hWnd, $Msg, $wParam, $lParam)
    Local $hMenu
    
    $hMenu = _GUICtrlMenu_CreatePopup()
    
    _GUICtrlMenu_InsertMenuItem($hMenu, 0, "Open", $idMenuOpen)
    _GUICtrlMenu_InsertMenuItem($hMenu, 1, "Save", $idMenuOpen)
    
    _GUICtrlMenu_TrackPopupMenu($hMenu, $wParam)
    
    _GUICtrlMenu_DestroyMenu($hMenu)
    
    Return $GUI_RUNDEFMSG
EndFunc
Link to comment
Share on other sites

  • Moderators

There's no MultiThreading so make use of AdlibEnable or run 2 scripts.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

There's no MultiThreading so make use of AdlibEnable or run 2 scripts.

Already tried AdlibEnable. That still utilizes the main AutoIt thread. The _GUICtrlMenu_TrackPopupMenu() makes a call to a function in the OS shell that suspends the thread that is doing the call until a value can be returned. As a result, the main AutoIt thread is halted until this function returns, similar to the way the Msgbox() function halts AutoIt.

You could write a work-around in another language that supports multithreading and call the work-around function from a compiled dll, but that would be quite complicated. In this case, using two scripts would probably be the way to go.

- The Kandie Man ;-)

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Link to comment
Share on other sites

So don't be rude when it is your fault for phrasing the question wrong, or not being detailed enough.

Sorry guys. :)

Already tried AdlibEnable

No. Still paused.

Has done so:

#include <GuiConstants.au3>
#include <GuiListView.au3>
#include <GuiMenu.au3>

Global Enum $idMenuOpen, $idMenuSave
Global $EventId = 1, $Elapse = 80
Dim $pos = 10

$hGui = GUICreate("Test", 300, 200)

$label = GUICtrlCreateLabel("label", 10, 180, 25, 15)
;GUICtrlSetBkColor(-1, 0xFF0000)

$hListView = _GUICtrlListView_Create($hGui, "Items|SubItems", 10, 10, 280, 160, -1, $WS_EX_CLIENTEDGE)

_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))

GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU")

GUIRegisterMsg($WM_TIMER, "WM_TIMER")

DllCall("User32.dll", "int", "SetTimer", "hwnd", $hGui, "int", $EventId, "int", $Elapse, "int", 0)

GUISetState()

Do
Until GUIGetMsg() = -3

DllCall("user32.dll", "int", "KillTimer", "hwnd", $hGui, "int", $EventId)

Func WM_CONTEXTMENU($hWnd, $Msg, $wParam, $lParam)
    Local $hMenu
    
    $hMenu = _GUICtrlMenu_CreatePopup()
    
    _GUICtrlMenu_InsertMenuItem($hMenu, 0, "Open", $idMenuOpen)
    _GUICtrlMenu_InsertMenuItem($hMenu, 1, "Save", $idMenuOpen)
    
    _GUICtrlMenu_TrackPopupMenu($hMenu, $wParam)
    
    _GUICtrlMenu_DestroyMenu($hMenu)
    
    Return $GUI_RUNDEFMSG
EndFunc

Func WM_TIMER($hWnd, $Msg, $wParam, $lParam)
    If $pos >= 300 Then $pos = 0
    $pos += 2
    GUICtrlSetPos($label, $pos, 180)
EndFunc
Link to comment
Share on other sites

This is one way to do it:

#include <GuiConstants.au3>
#include <GuiListView.au3>
#include <GuiMenu.au3>

Global Const $WS_EX_CLIENTEDGE  = 0x00000200
Global Const $WM_CONTEXTMENU = 0x007B

Global Enum $idMenuOpen, $idMenuSave

Global $sDllTmp = @TempDir & "\MoveControl.dll"
FileInstall("MoveControl.dll",$sDllTmp,1)

Global $hdll_MoveControl = DllOpen($sDllTmp)
IF @error Then
    ConsoleWrite("!> Error.  Unable to open MoveControl.dll. @error="&@error&@LF)
    Exit 1
EndIf

$hGui = GUICreate("Test", 300, 200)

$label = GUICtrlCreateLabel("label", 10, 180, 25, 15)
;GUICtrlSetBkColor(-1, 0xFF0000)

$hListView = _GUICtrlListView_Create($hGui, "Items|SubItems", 10, 10, 280, 160, -1, $WS_EX_CLIENTEDGE)

_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))

GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU")

GUISetState()

DllCall($hdll_MoveControl,"int:cdecl","ScrollText","hwnd",GUICtrlGetHandle($label))

Do
    Sleep(10)
Until GUIGetMsg() = -3

Func WM_CONTEXTMENU($hWnd, $Msg, $wParam, $lParam)
   
    Local $hMenu
   
    $hMenu = _GUICtrlMenu_CreatePopup()
   
    _GUICtrlMenu_InsertMenuItem($hMenu, 0, "Open", $idMenuOpen)
    _GUICtrlMenu_InsertMenuItem($hMenu, 1, "Save", $idMenuOpen)
    _GUICtrlMenu_TrackPopupMenu($hMenu, WinGetHandle($hGui))
    _GUICtrlMenu_DestroyMenu($hMenu)
   
    Return $GUI_RUNDEFMSG
EndFunc

Func OnAutoItExit()
    Local $iRet
    If Not @exitCode Then
        ConsoleWrite("-> Stopping Scrolling Thread"&@LF)
        $iRet = DllCall($hdll_MoveControl,"int:cdecl","StopThread")
        If Ubound($iRet) = 1 Then
            ConsoleWrite("+> StopThread()="&$iRet[0]&@LF)
            ConsoleWrite("+> Thread Stopped Successfully"&@LF)
        Else
            ConsoleWrite("!> StopThread() Dll Call Errored"&@LF)
        EndIf
        DllClose($hdll_MoveControl)
    EndIf
    GUIDelete($hGui)
    FileDelete($sDllTmp)
EndFunc

The required Dll:

MoveControl.dll

- The Kandie Man ;-)

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Link to comment
Share on other sites

Sorry guys. :)

No. Still paused.

Has done so:

#include <GuiConstants.au3>
#include <GuiListView.au3>
#include <GuiMenu.au3>

Global Enum $idMenuOpen, $idMenuSave
Global $EventId = 1, $Elapse = 80
Dim $pos = 10

$hGui = GUICreate("Test", 300, 200)

$label = GUICtrlCreateLabel("label", 10, 180, 25, 15)
;GUICtrlSetBkColor(-1, 0xFF0000)

$hListView = _GUICtrlListView_Create($hGui, "Items|SubItems", 10, 10, 280, 160, -1, $WS_EX_CLIENTEDGE)

_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))

GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU")

GUIRegisterMsg($WM_TIMER, "WM_TIMER")

DllCall("User32.dll", "int", "SetTimer", "hwnd", $hGui, "int", $EventId, "int", $Elapse, "int", 0)

GUISetState()

Do
Until GUIGetMsg() = -3

DllCall("user32.dll", "int", "KillTimer", "hwnd", $hGui, "int", $EventId)

Func WM_CONTEXTMENU($hWnd, $Msg, $wParam, $lParam)
    Local $hMenu
    
    $hMenu = _GUICtrlMenu_CreatePopup()
    
    _GUICtrlMenu_InsertMenuItem($hMenu, 0, "Open", $idMenuOpen)
    _GUICtrlMenu_InsertMenuItem($hMenu, 1, "Save", $idMenuOpen)
    
    _GUICtrlMenu_TrackPopupMenu($hMenu, $wParam)
    
    _GUICtrlMenu_DestroyMenu($hMenu)
    
    Return $GUI_RUNDEFMSG
EndFunc

Func WM_TIMER($hWnd, $Msg, $wParam, $lParam)
    If $pos >= 300 Then $pos = 0
    $pos += 2
    GUICtrlSetPos($label, $pos, 180)
EndFunc
Works fine but why create and destroy the menu every time?

#include <GuiConstants.au3>
#include <GuiListView.au3>
#include <GuiMenu.au3>

Global Enum $idMenuOpen, $idMenuSave
Global $EventId = 1, $Elapse = 80
Dim $pos = 10

$hGui = GUICreate("Test", 300, 200)

$label = GUICtrlCreateLabel("label", 10, 180, 25, 15)
;GUICtrlSetBkColor(-1, 0xFF0000)

$hListView = _GUICtrlListView_Create($hGui, "Items|SubItems", 10, 10, 280, 160, -1, $WS_EX_CLIENTEDGE)

_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))

GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU")

GUIRegisterMsg($WM_TIMER, "WM_TIMER")

DllCall("User32.dll", "int", "SetTimer", "hwnd", $hGui, "int", $EventId, "int", $Elapse, "int", 0)

$hMenu = _GUICtrlMenu_CreatePopup()
 _GUICtrlMenu_InsertMenuItem($hMenu, 0, "Open", $idMenuOpen)
 _GUICtrlMenu_InsertMenuItem($hMenu, 1, "Save", $idMenuOpen)
 
 GUISetState()
Do
Until GUIGetMsg() = -3

 _GUICtrlMenu_DestroyMenu($hMenu)
DllCall("user32.dll", "int", "KillTimer", "hwnd", $hGui, "int", $EventId)

Func WM_CONTEXTMENU($hWnd, $Msg, $wParam, $lParam)
   
    _GUICtrlMenu_TrackPopupMenu($hMenu, $wParam)
   
    Return $GUI_RUNDEFMSG
EndFunc

Func WM_TIMER($hWnd, $Msg, $wParam, $lParam)
    If $pos >= 300 Then $pos = 0
    $pos += 2
    GUICtrlSetPos($label, $pos, 180)
EndFunc
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

The Kandie Man

Nice example! Posted Image I like this fluent label move :) This example be need to me in future time. Thank you!

martin

why create and destroy the menu every time?

Ha ha. Yes! You are right. Thanks! ;)
Link to comment
Share on other sites

  • 4 weeks later...

Well, I was testing this example, and i think i found a bug.

If you doble click the sistray icon, the script will pause. :)

thats not what we want. right?

You can help! Donate to AutoIt! or, visit ClimatePREDICTION.netMy posts:Travian Bot Example (100+ servers) BETAHow to Host you code/app for free! (unlimited team number) (Public or Private)"Sir, we're surrounded!" "Excellent. We can attack in any direction!"
Link to comment
Share on other sites

Well, I was testing this example, and i think i found a bug.

If you doble click the sistray icon, the script will pause. :)

thats not what we want. right?

Just add a Opt("TrayAutoPause", 0) in a script begin. :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...