Sign in to follow this  
Followers 0
Juanola

[SOLVED] Context menu options execute very late the instructions

8 posts in this topic

#1 ·  Posted (edited)

I start one function where every number of one list of numbers of one listview add his value with one.

I have one context menu in the listview with options, but I select one option for execute and it execute the function very late!!!

Is there any solution for execute the instructions in the same time what I select the option of the context menu?

Somebody could help me or improve my script?

Thank you.

It is my script.

#include <GuiButton.au3>
#include <GuiStatusBar.au3>
#include <GuiEdit.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiConstants.au3>
#include <GuiListView.au3>


Opt("GuiOnEventMode", 1)
Opt("GuiCloseOnEsc", 0)

$Debug_LV = False

Global $gui, $gcList, $gcS_List, $stop = 1, $gcStart, $gcStop, $gcList_Menu, $gcM_E_Start, $gcM_E_Stop, $closed, $hHook, $hStub_KeyProc, $gcL_M_number

    $hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam")
    $hmod = _WinAPI_GetModuleHandle(0)
    $hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hStub_KeyProc), $hmod)
    
    _gui()
    _menu()
    _listview()
    _insert_listview()
        
    GUICtrlSetOnEvent($gcList, "_Window")
    GUICtrlSetOnEvent($gcStop, "_Window")
    GUICtrlSetOnEvent($gcStart, "_Window")
    GUICtrlSetOnEvent($gcM_E_Start, "_Window")
    GUICtrlSetOnEvent($gcM_E_Stop, "_Window")
    
    GUICtrlSetOnEvent($gcL_M_number,"_number")
    
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Window", $GUI)
    GUISetOnEvent($GUI_EVENT_MAXIMIZE, "_Window", $GUI)
    GUISetOnEvent($GUI_EVENT_RESTORE, "_Window", $GUI)
    GUISetOnEvent($GUI_EVENT_MINIMIZE, "_Window", $GUI)

    GUIRegisterMsg(78, "WM_Notify_Events")
    
    GUISetState(@SW_SHOW, $GUI)
        
    While 1
        Sleep(10)
    WEnd
    
    GUIDelete()

func _gui() 
    $GUI = GUICreate("Numbers",170,400)
    $w=60
    $h=30
    $gcStart = GUICtrlCreateButton("Start <F5>", 20, 8, $w, $h)
    $gcStop = GUICtrlCreateButton("Stop <F6>", 100, 8, $w, $h)
    
    GUICtrlSetState($gcStop, $GUI_DISABLE)
EndFunc

Func _menu()
    $gcM_menu = GUICtrlCreateMenu("&Menu")
        $gcM_E_Start = GUICtrlCreateMenuItem("&Start" & @TAB & "F5", $gcM_menu)
        $gcM_E_Stop = GUICtrlCreateMenuItem("&Stop" & @TAB & "F6", $gcM_menu)
        
    GUICtrlSetState($gcM_E_Stop, $GUI_DISABLE)
endfunc

func _listview()
    $gcList = GUICtrlCreateListView("Number", 15, 50, 100,300)
    
    _GUICtrlListView_SetColumnWidth($gcList, 0, 60)

    $gcList_Menu = GUICtrlCreateContextMenu($gcList)
    $gcL_M_number = GUICtrlCreateMenuItem("Number is...", $gcList_Menu)
EndFunc

func _insert_listview()

for $i=0 to 50000
    $item=GUICtrlCreateListViewItem($i+1, $gcList)
next

EndFunc

Func _Window()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            Exit
            
        Case $GUI_EVENT_MAXIMIZE
            GUISetState(@SW_MAXIMIZE, $GUI)
            
        Case $GUI_EVENT_MINIMIZE
            GUISetState(@SW_MINIMIZE, $GUI)

        Case $GUI_EVENT_RESTORE
            If BitAND(WinGetState($GUI), 32) = 32 Then
                GUISetState(@SW_MAXIMIZE, $GUI)
            Else
                GUISetState(@SW_RESTORE, $GUI)
            EndIf
            
        Case $gcStart, $gcM_E_Start
            _Start(True)

        Case $gcStop, $gcM_E_Stop
            _Stop(True)
    EndSwitch
EndFunc   ;==>_Window

Func _Start($aEnable)
    If _GUICtrlListView_GetItemCount($gcList) > 0 Then
        _desha()
        For $i = 0 To _GUICtrlListView_GetItemCount($gcList)-1
                            
                $stop = 0
                
                _add_number()
                If $aEnable = True Then
                    AdlibEnable("_add_number", 1000)
                    
                Else
                    _Stop(True)
                EndIf
                $a = 1
    
                ExitLoop
            
            $a = 0
        Next
        If $a <> 1 Then MsgBox(64, "Select Number!", -1, $GUI)
    EndIf
EndFunc   ;==>_Start

Func _Stop($aEnable)
    _habi()
    
    $stop = 1
    $closed = 0

    AdlibDisable()
EndFunc   ;==>_Stop

Func _add_number()

    $countItem = _GUICtrlListView_GetItemCount($gcList)
    If $countItem > 0 Then
        For $i = 0 To $countItem-1
            _GUICtrlListView_SetItemText($gcList, $i, _GUICtrlListView_GetItemText($gcList, $i, 0)+1, 0)
            If $stop = 1 Then ExitLoop
        Next
    EndIf
EndFunc  

func _number()
    $item=guictrlread(guictrlread($gclist))
    $subitems=stringsplit($item,"|")

    _number_is($subitems[1])
endfunc

func _number_is($number)
    msgbox(16,"Number","The number is " & $number)
EndFunc

Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)
    #forceref $hWndGUI, $MsgID, $wParam
    Local $tagNMHDR, $event
    
    If $wParam = $gcList And GUICtrlGetHandle($gcS_List) <> ControlGetHandle($hWndGUI, "", ControlGetFocus($hWndGUI)) Then
        $tagNMHDR = DllStructCreate("int;int;int", $lParam)
        $event = DllStructGetData($tagNMHDR, 3)
    EndIf
EndFunc   ;==>WM_Notify_Events

func _desha()
    GUICtrlSetState($gcStart, $GUI_DISABLE)
    GUICtrlSetState($gcM_E_Start, $GUI_DISABLE)

    GUICtrlSetState($gcStop, $GUI_ENABLE)
    GUICtrlSetState($gcM_E_Stop, $GUI_ENABLE)
EndFunc

func _habi()
    GUICtrlSetState($gcStart, $GUI_ENABLE)
    GUICtrlSetState($gcM_E_Start, $GUI_ENABLE)
    
    GUICtrlSetState($gcStop, $GUI_DISABLE)
    GUICtrlSetState($gcM_E_Stop, $GUI_DISABLE)
EndFunc

Func _KeyProc($nCode, $wParam, $lParam)
    Local $tKEYHOOKS
    $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
    If $nCode < 0 Then
        Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
    EndIf
    If $wParam = $WM_KEYDOWN Then
        EvaluateKey(DllStructGetData($tKEYHOOKS, "vkCode"))
    EndIf
    Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc   ;==>_KeyProc

Func OnAutoItExit()
    _WinAPI_UnhookWindowsHookEx($hHook)
    DllCallbackFree($hStub_KeyProc)
EndFunc   ;==>OnAutoItExit

Func EvaluateKey($keycode)
    If BitAND(WinGetState($GUI), 8) Then
        If $keycode = 116 Then
            If _IsEnable($gcStart) Then
                _Start(True)
            EndIf
        ElseIf $keycode = 117 Then
            If _IsEnable($gcStop) Then
                _Stop(True)
            EndIf
        Else
            Return
        EndIf
    EndIf
EndFunc   ;==>EvaluateKey

Func _IsEnable($hID)
    If BitAND(GUICtrlGetState($hID), $GUI_ENABLE) = $GUI_ENABLE Then
        Return True
    Else
        Return False
    EndIf
EndFunc    ;==>_IsEnable
Edited by Juanola

Share this post


Link to post
Share on other sites



Func _add_number()

    $countItem = _GUICtrlListView_GetItemCount($gcList)
    If $countItem > 0 Then
        For $i = 0 To $countItem-1
                       
            $msg = GUIGetMsg()
            _GUICtrlListView_SetItemText($gcList, $i, _GUICtrlListView_GetItemText($gcList, $i, 0)+1, 0)
            If $stop = 1 Then ExitLoop
        Next
    EndIf
EndFunc

Why are you calling GUIGetMsg() if you use Opt('GuiOnEventMode', 1)?

Also, I see you're mixing control ID and functions that require control handle. Try to get the control handle in the header and use it in the _Gui* functions.

Share this post


Link to post
Share on other sites

My original script is very long and I have did it little script special for Autoitforums and I haven't erased the line of "Guigetmsg()" what in my original script is disable.

Thank you!!

Share this post


Link to post
Share on other sites

Authenticity please, one help more great...

I'm not one programmer and I'm new, you are one authentic programmer and genius.

I only want what my script working OK.

I only want what the options of the context menu execute the instructions in the same time what I do click on the option.

Please one help.

I have did my script and I can't do it.

Thank you.

Share this post


Link to post
Share on other sites

Hmm, the way you built it only make it react slower or not react at all...

For example:

Why are you hooking the keyboard just to see if F5 or F6 was pressed? Use HotKeySet instead and preform a check in the same _Start and _Stop functions to see if your GUI window was the active and if not just unbind the key like HotKeySet('{F5}') and then Send('{F5}'), then rebind like HotKeySey('{F5}', '_Start') and return from the function. You may need to assign a default value to the function parameters this way but it's still better and clearer.

What is the purpose of this script? to remove the selected item of the list view?

When you process a large loop your script (other than Adlib function) is blocked and while the adlib function is processed your script (other than the Adlib function) is blocked or suspended so you need to think it another way.

In short, what is purpose?

Share this post


Link to post
Share on other sites

Thank you for reply as fast!!!

I hook the keyboard because the function hotkeyset change the function of one key by all the programs of windows and I only want change the function of the key by my program.

The purpose of my program is I have one list de ip's. My program test if every ip is online all the time. I with the context menu select one IP and have one option for connect it ip. But It isn't connect in the same moment in what I select the option, it is connect very late, at the end of the list of the ip's.

Thank you!

Share this post


Link to post
Share on other sites

Added this among other things but it's quite not sophisticated because processing this giant loop with adlib function makes it even slower than it was:

Func _IsPushed()
    If _GUICtrlButton_GetState($ghStop) = 620 Then _Stop(True)
EndFuncoÝ÷ Ø Ý¶«zËZºÚ"µÍÚ[ÛYH  ÑÝZP]Û]LÉÝÂÚ[ÛYH    ÑÝZTÝ]Ð]LÉÝÂÚ[ÛYH  ÑÝZQY]]LÉÝÂÚ[ÛYH ÓÝY]ÐÛÛÝ[Ë]LÉÝÂÚ[ÛYH    ÕÚ[ÝÜÐÛÛÝ[Ë]LÉÝÂÚ[ÛYH ÑÝZPÛÛÝ[Ë]LÉÝÂÚ[ÛYH  ÑÝZSÝY]Ë]LÉÝÂÜ
    ][ÝÑÝZSÛ][[ÙI][ÝËJBÜ
    ][ÝÑÝZPÛÜÙSÛØÉ][ÝË
BÝÙ^TÙ]
    ÌÎNÞÑ_IÌÎNË  ÌÎN×ÔÝ ÌÎNÊBÝÙ^TÙ]
    ÌÎNÞÑIÌÎNË   ÌÎN×ÔÝÜ   ÌÎNÊBÌÍÑXY×ÓH[ÙBÛØ[  ÌÍÙÝZK  ÌÍÙØÓÝ    ÌÍÙÚÝ  ÌÍÙØÔ×ÓÝ    ÌÍÜÝÜHK    ÌÍÙØÔÝ    ÌÍÙØÔÝÜ  ÌÍÙÚÝÜ    ÌÍÙØÓÝÓY[K   ÌÍÙØÓWÑWÔÝ  ÌÍÙØÓWÑWÔÝÜÂH ÌÍØÛÜÙY   ÌÍÙØÓÓWÛ[XÙÝZJ
BÛY[J
BÛÝY]Ê
BÚ[ÙÛÝY]Ê
BÕRPÝÙ]Û][
    ÌÍÙØÓÝ    ][Ý×ÕÚ[ÝÉ][ÝÊBÕRPÝÙ]Û][
    ÌÍÙØÔÝÜ  ][ÝÐØ[ÔÝÜ ][ÝÊBÕRPÝÙ]Û][
    ÌÍÙØÔÝ    ][ÝÐØ[ÔÝ   ][ÝÊBÕRPÝÙ]Û][
    ÌÍÙØÓWÑWÔÝ  ][ÝÐØ[ÔÝ   ][ÝÊBÕRPÝÙ]Û][
    ÌÍÙØÓWÑWÔÝÜ    ][ÝÐØ[ÔÝÜ ][ÝÊBÕRPÝÙ]Û][
    ÌÍÙØÓÓWÛ[X   ][Ý×Û[X][ÝÊBÕRTÙ]Û][
    ÌÍÑÕRWÑUSÐÓÔÑK ][Ý×ÕÚ[ÝÉ][ÝË   ÌÍÙÝZJBÕRTÙ]Û][
    ÌÍÑÕRWÑUSÓPVSRVK  ][Ý×ÕÚ[ÝÉ][ÝË   ÌÍÙÝZJBÕRTÙ]Û][
    ÌÍÑÕRWÑUSÔTÕÔK  ][Ý×ÕÚ[ÝÉ][ÝË   ÌÍÙÝZJBÕRTÙ]Û][
    ÌÍÑÕRWÑUSÓRSSRVK  ][Ý×ÕÚ[ÝÉ][ÝË   ÌÍÙÝZJBÕRTYÚÝÙÊ
Π ][ÝÕÓWÓÝYWÑ][É][ÝÊBÕRTÙ]Ý]JÕ×ÔÒÕË ÌÍÙÝZJBÚ[HBTÛY
L
BÑ[ÕRQ[]J
B[ÈÙÝZJ
BIÌÍÙÝZHHÕRPÜX]J  ][ÝÓ[XÉ][ÝËMÌ

BIÌÍÝÈH
IÌÍÚHÌIÌÍÙØÔÝHÕRPÝÜX]P]Û  ][ÝÔÝ    ÑIÝÉ][ÝË   ÌÍÝË    ÌÍÚ
BIÌÍÙØÔÝÜHÕRPÝÜX]P]Û ][ÝÔÝÜ  ÑÝÉ][ÝËL   ÌÍÝË    ÌÍÚ
BIÌÍÙÚÝÜHÕRPÝÙ][J  ÌÍÙØÔÝÜ
BQÕRPÝÙ]Ý]J ÌÍÙØÔÝÜ  ÌÍÑÕRWÑTÐPJB[[ÈÏOIÝ×ÙÝZB[ÈÛY[J
BIÌÍÙØÓWÛY[HHÕRPÝÜX]SY[J   ][ÝÉ[ÓY[I][ÝÊBIÌÍÙØÓWÑWÔÝHÕRPÝÜX]SY[R][J    ][ÝÉ[ÔÝ ][ÝÈ  [ÈP    [È ][ÝÑI][ÝË   ÌÍÙØÓWÛY[JBIÌÍÙØÓWÑWÔÝÜHÕRPÝÜX]SY[R][J    ][ÝÉ[ÔÝÜ   ][ÝÈ  [ÈP    [È ][ÝÑ][ÝË    ÌÍÙØÓWÛY[JBQÕRPÝÙ]Ý]J ÌÍÙØÓWÑWÔÝÜ    ÌÍÑÕRWÑTÐPJB[[ÈÏOIÝ×ÛY[B[ÈÛÝY]Ê
BIÌÍÙØÓÝHÕRPÝÜX]SÝY]Ê    ][ÝÓ[X][ÝËMK
LLÌ
BIÌÍÙÚÝHÕRPÝÙ][J    ÌÍÙØÓÝ
BWÑÕRPÝÝY]×ÔÙ]ÛÛ[[ÚY
    ÌÍÙÚÝ

BIÌÍÙØÓÝÓY[HHÕRPÝÜX]PÛÛ^Y[J ÌÍÙØÓÝ
BIÌÍÙØÓÓWÛ[XHÕRPÝÜX]SY[R][J   ][ÝÓ[XË][ÝË    ÌÍÙØÓÝÓY[JB[[ÈÏOIÝ×ÛÝY]Â[ÈÚ[ÙÛÝY]Ê
BQÜ    ÌÍÚHHHÈ
LBQÕRPÝÜX]SÝY]Ò][J ÌÍÚK ÌÍÙØÓÝ
BS^[[ÈÏOIÝ×Ú[ÙÛÝY]Â[ÈÕÚ[ÝÊ
BTÝÚ]ÚÕRWÐÝYBPØÙH   ÌÍÑÕRWÑUSÐÓÔÑBBBQ^]BPØÙH ÌÍÑÕRWÑUSÓPVSRVBBBQÕRTÙ]Ý]JÕ×ÓPVSRVK    ÌÍÙÝZJBBPØÙH  ÌÍÑÕRWÑUSÓRSSRVBBBQÕRTÙ]Ý]JÕ×ÓRSSRVK    ÌÍÙÝZJBBPØÙH  ÌÍÑÕRWÑUSÔTÕÔBBBRY]S
Ú[Ù]Ý]J  ÌÍÙÝZJKÌHHÌ[BBBQÕRTÙ]Ý]JÕ×ÓPVSRVK   ÌÍÙÝZJBBBQ[ÙBBBBQÕRTÙ]Ý]JÕ×ÔTÕÔK   ÌÍÙÝZJBBBQ[YQ[ÝÚ]Ú[[ÈÏOIÝ×ÕÚ[ÝÂ[ÈÒÔÚY

BRYÑÕRPÝ]ÛÑÙ]Ý]J ÌÍÙÚÝÜ
HH
[ÔÝÜ
YJB[[Â[ÈÔÝ
    ÌÍØQ[XHHYJBRYÝÚ[XÝ]J  ÌÍÙÝZJH[BRÝÙ^TÙ]
    ÌÎNÞÑ_IÌÎNÊBBTÙ[
    ÌÎNÞÑ_IÌÎNÊBBRÝÙ^TÙ]
    ÌÎNÞÑ_IÌÎNË  ÌÎN×ÔÝ ÌÎNÊBBT]Q[YBRYÝÕRPÝXY
    ÌÍÙØÓÝ
H[BSÙÐÞ
    ][ÝÔÙ[XÝ[XÌÌÎÉ][ÝË    ÌÎNÔÙ[XÝ[XÌÌÎÉÌÎNÊBBT]Q[YBSØØ[    ÌÍÚR][ÈHÑÕRPÝÝY]×ÑÙ]][PÛÝ[
    ÌÍÙÚÝ
BIÌÍÜÝÜHBRY    ÌÍÚR][È ÝÈ[BWÙÚJ
BBBBRY  ÌÍØQ[XH[BBPYX[XJ ÌÎN×ÒÔÚY  ÌÎNËL
BBBQÜ  ÌÍÚHHÈ  ÌÍÚR][ÈHBBBBWÑÕRPÝÝY]×ÔÙ]][U^
    ÌÍÙÚÝ  ÌÍÚKÑÕRPÝÝY]×ÑÙ]][U^
    ÌÍÙÚÝ  ÌÍÚK
H
ÈK
BBBBRY  ÌÍÜÝÜ[^]ÛÜBBS^BBPYXØXJ
BBQ[YQ[ÙBBWÔÝÜ
YJBQ[YBIÌÍØHHB[[ÈÏOIÝ×ÔÝ[ÈÔÝÜ
    ÌÍØQ[XHHYJBRYÝÚ[XÝ]J  ÌÍÙÝZJH[BRÝÙ^TÙ]
    ÌÎNÞÑIÌÎNÊBBTÙ[
    ÌÎNÞÑIÌÎNÊBBRÝÙ^TÙ]
    ÌÎNÞÑIÌÎNË   ÌÎN×ÔÝÜ   ÌÎNÊBBT]Q[YBWÚXJ
BBIÌÍÜÝÜHBIÌÍØÛÜÙYH[[ÈÏOIÝ×ÔÝÜ[ÈØ[ÔÝ

BWÔÝ

B[[Â[ÈØ[ÔÝÜ

BWÔÝÜ

B[[Â[ÈÛ[X
BIÌÍÚ][HHÕRPÝXY
ÕRPÝXY
    ÌÍÙØÓÝ
JBIÌÍÜÝX][ÈHÝ[ÔÜ]
    ÌÍÚ][K   ][Ýß  ][ÝÊBWÛ[XÚÊ    ÌÍÜÝX][ÖÌWJB[[ÈÏOIÝ×Û[X[ÈÛ[XÚÊ   ÌÍÛ[XBSÙÐÞ

    ][ÝÓ[X][ÝË  ][ÝÕH[XÈ ][ÝÈ  [È ÌÍÛ[XB[[ÈÏOIÝ×Û[XÚÂ[ÈÓWÓÝYWÑ][Ê ÌÍÚÛÕRK    ÌÍÓÙÒQ ÌÍÝÔ[K  ÌÍÛ[JBHÙÜÙY   ÌÍÚÛÕRK    ÌÍÓÙÒQ ÌÍÝÔ[BSØØ[    ÌÍÝYÓR  ÌÍÙ][RY  ÌÍÝÔ[HH ÌÍÙØÓÝ[   ÌÍÙÚÝ  ÉÝÈÛÛÛÙ][J   ÌÍÚÛÕRK    ][ÝÉ][ÝËÛÛÛÙ]ØÝÊ ÌÍÚÛÕRJJBBBIÌÍÝYÓRHÝXÝÜX]J  ][ÝÚ[Ú[Ú[   ][ÝË  ÌÍÛ[JBBBIÌÍÙ][HÝXÝÙ]]J ÌÍÝYÓRÊBQ[Y[[ÈÏOIÝÕÓWÓÝYWÑ][Â[ÈÙÚJ
BQÕRPÝÙ]Ý]J ÌÍÙØÔÝ    ÌÍÑÕRWÑTÐPJBQÕRPÝÙ]Ý]J    ÌÍÙØÓWÑWÔÝ  ÌÍÑÕRWÑTÐPJBQÕRPÝÙ]Ý]J    ÌÍÙØÔÝÜ  ÌÍÑÕRWÑSPJBQÕRPÝÙ]Ý]J  ÌÍÙØÓWÑWÔÝÜ    ÌÍÑÕRWÑSPJB[[ÈÏOIÝ×ÙÚB[ÈÚXJ
BQÕRPÝÙ]Ý]J ÌÍÙØÔÝ    ÌÍÑÕRWÑSPJBQÕRPÝÙ]Ý]J  ÌÍÙØÓWÑWÔÝ  ÌÍÑÕRWÑSPJBQÕRPÝÙ]Ý]J  ÌÍÙØÔÝÜ  ÌÍÑÕRWÑTÐPJBQÕRPÝÙ]Ý]J    ÌÍÙØÓWÑWÔÝÜ    ÌÍÑÕRWÑTÐPJB[[ÈÏOIÝ×ÚXB[ÈÒÑ[XJ    ÌÍÚQ
BRY]S
ÕRPÝÙ]Ý]J   ÌÍÚQ
K   ÌÍÑÕRWÑSPJHH   ÌÍÑÕRWÑSPH[BT]YBQ[ÙBBT][ÙBQ[Y[[ÈÏOIÝ×ÒÑ[X

You see the silly Call_Stop and Call_Start? Maybe you're find (for sure) a better way to handle the $aEnable flag variable.

Share this post


Link to post
Share on other sites

THANK YOU!!!!

My script is working OK!!!!

I now understand what you want say me!!

All your help is great and clear.

Thanks Auth!

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