Jump to content

Need MsgBox in GUIRegisterMsg().


is8591
 Share

Recommended Posts

Running GUI in OnEvent and using Notify to catch ListView ItemChange event.

There are times when contents of ListView point to INI sections which were deleted, so need to inform that section was deleted and Default will be used.

Any suggestions are welcomed.

Thank you.

Link to comment
Share on other sites

Here is a small part of the code to illustrate it. When you click on items in ListView Msgbox will pop up. ClickOK to close the Msgbox and the cursor becomes Drag-and-Drop. I tested my full code for several days and that's the only problem I have noticed, everything else seems to work OK.

I don't know if anything outside my code is going to mess up if I delay the GuiRegisterMsg(). But if cursor the only problem - how can I prevent cursor changing.

As far as telling later: When user clicks on ListView he selects operational profile, I have to load profile parameters into separate GUIs. So normally I give user a chance to select a different profile instead of Default.

My whole script is Event driven - any suggestions how I can be out of GuiRegisterMsg() and then show the warning.

#include <GUIConstants.au3>
#Include <GuiListView.au3>

Global Const $WM_NOTIFY = 0x004E

;ListView Events
Global Const $NM_FIRST = 0
Global Const $NM_LAST = (-99)
Global Const $NM_OUTOFMEMORY = ($NM_FIRST - 1)
Global Const $NM_CLICK = ($NM_FIRST - 2)
Global Const $NM_DBLCLK = ($NM_FIRST - 3)
Global Const $LVN_FIRST = -100;
Global Const $LVN_ITEMCHANGED = ($LVN_FIRST-1)

Opt("GUIOnEventMode", 1)

$Accounts1 = GUICreate("GUI", 481, 294, 203, 126)
GUISetOnEvent($GUI_EVENT_CLOSE, "Accounts1Close")
$lv = GUICtrlCreateListView(" | ", 133, 94, 266, 58,BitOR($LVS_SHOWSELALWAYS, $LVS_SINGLESEL,$LVS_NOCOLUMNHEADER),BitOR($LVS_EX_FULLROWSELECT,$LVS_EX_FLATSB))
GUICtrlSetCursor(-1, 2)
GUICtrlCreateListViewItem("abc|def", $lv)
GUICtrlCreateListViewItem("ghi|klm", $lv)
GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")

GUISetState(@SW_SHOW)

While 1
    Sleep(100)
WEnd

Func Accounts1Close()
    Exit
EndFunc

; WM_NOTIFY event handler for listview
Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)
    #forceref $hWndGUI, $MsgID, $wParam
    Local $nNotifyCode = _HiWord($wParam)
    Local $nID = _LoWord($wParam)
    Local $tagNMHDR, $event, $hwndFrom, $code
    $tagNMHDR = DllStructCreate("int;int;int;uint;uint;uint;int;int", $lParam) ;     NMHDR hdr; iItem; iSubItem; uNewState; uOldState; uChanged; ptAction;

    If @error Then Return
    $event = DllStructGetData($tagNMHDR, 3)
;ConsoleWrite("Event:"&$nID & "::" & $nNotifyCode & "::" & $event & @CRLF)
    Select
    Case $wParam = $lv
        Select
            ;Case $event = $NM_CLICK
            ;    ListView_Click ()
            ;Case $event = $NM_DBLCLK
            ;    ListView_DoubleClick ()
            Case $event = $LVN_ITEMCHANGED
                If DllStructGetData($tagNMHDR, 6) = 3 And DllStructGetData($tagNMHDR, 7) = 0 And DllStructGetData($tagNMHDR, 8) = 8 Then lv_Change()
            EndSelect
    EndSelect
    $tagNMHDR = 0
    $event = 0
    $lParam = 0
     Return $GUI_RUNDEFMSG
 EndFunc   ;==>WM_Notify_Events
 
Func _HiWord($x)
    Return BitShift($x, 16)
EndFunc   ;==>_HiWord

Func _LoWord($x)
    Return BitAND($x, 0xFFFF)
EndFunc   ;==>_LoWord


;fill in listview header
Func lv_Change()
;   Local $a = _GUICtrlListViewGetItemText($lv_MrSch,-1,2)
;   GUICtrlSetData($dt_MrSch, _GUICtrlListViewGetItemText($lv_MrSch,-1,0))
;   If StringInStr($av_StrSet[9], $a) =0 Then
        MsgBox(48,"test","")
;       $a = "default"
;   EndIf
EndFunc
Link to comment
Share on other sites

Now I haven't really gotten into your code and your task that much, so won't say anything about different implementations, but here's a couple of quick ways to fix your problem...

Run that message box as separate process, like this:

Run(@AutoItExe & ' /AutoIt3ExecuteLine "MsgBox(0, ''Hello World!'', ''Hi!'')"')

Or add a LVN_BEGINDRAG handler to your WM_NOTIFY function, and return it if it's caused by your messagebox:

;start of the script:
Global $fNoDrag = False
...
...
;part of your WM_NOTIFY:
            Case $event = $LVN_ITEMCHANGED
                If DllStructGetData($tagNMHDR, 6) = 3 And DllStructGetData($tagNMHDR, 7) = 0 And DllStructGetData($tagNMHDR, 8) = 8 Then
                    lv_Change()
                EndIf
            Case $event = -109;$LVN_BEGINDRAG
                If $fNoDrag Then 
                    $fNoDrag = False
                    Return 0
                EndIf
        EndSelect
...
...
;when you have to show your messagebox:
MsgBox(48,"test","")
$fNoDrag = True
Edited by Siao

"be smart, drink your wine"

Link to comment
Share on other sites

Now I haven't really gotten into your code and your task that much, so won't say anything about different implementations, but here's a couple of quick ways to fix your problem...

Run that message box as separate process, like this:

Run(@AutoItExe & ' /AutoIt3ExecuteLine "MsgBox(0, ''Hello World!'', ''Hi!'')"')

Or add a LVN_BEGINDRAG handler to your WM_NOTIFY function, and return it if it's caused by your messagebox:

;start of the script:
Global $fNoDrag = False
...
...
;part of your WM_NOTIFY:
            Case $event = $LVN_ITEMCHANGED
                If DllStructGetData($tagNMHDR, 6) = 3 And DllStructGetData($tagNMHDR, 7) = 0 And DllStructGetData($tagNMHDR, 8) = 8 Then
                    lv_Change()
                EndIf
            Case $event = -109;$LVN_BEGINDRAG
                If $fNoDrag Then 
                    $fNoDrag = False
                    Return 0
                EndIf
        EndSelect
...
...
;when you have to show your messagebox:
MsgBox(48,"test","")
$fNoDrag = True
Thank you this takes care of the cursor.
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...