Jump to content

GUIRegMsg function working twice


kcvinu
 Share

Recommended Posts

Hi all,
I am trying to get the selected item text from a tree view control.
For that i am using this code. Please take a look. In this code, i am using console write function so that i am able to know that the user clicks in an item. This code works perfectly at the first click. But when i click on an item second time, it will work twice, That means, console write will work twice. Same result is at the third and fourth click also. 
 

Func TreeView_WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview
    $hWndTreeview =  $tv1
    If Not IsHWnd($tv1) Then $hWndTreeview = GUICtrlGetHandle($tv1)

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndTreeview
            Switch $iCode
                Case $TVN_SELCHANGINGW                  
                    ConsoleWrite("Clicked" & @CRLF)
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

 

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

You should know better by now, post a script that shows the problem, not a snippet that someone has to build the script around. No way we'll be able to recreate your exact script, so there's no way we'll know where the issue is.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Oh, sorry. I thought that, if you could see the problem from this function. OK. here is is the full code Please see the attached au3 file

 

IniCreator.au3

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

I don't know well about treeviews but this seems to work

Func TreeView_WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview
    $hWndTreeview =  $tv1
    If Not IsHWnd($tv1) Then $hWndTreeview = GUICtrlGetHandle($tv1)
    Static $hItem0

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Local $cntr = 0
    Switch $hWndFrom
        Case $hWndTreeview
            Switch $iCode
                Case $TVN_SELCHANGEDW
                    ; Insert your code here
                    $hItem = _GUICtrlTreeView_GetSelection ($hWndTreeview)
                    If $hItem <> $hItem0 Then
                        ConsoleWrite("Clicked " & _GUICtrlTreeView_GetText($hWndTreeview, $hItem) & @CRLF)
                        $hItem = $hItem0
                    EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Edit
There is probably certainly an easier way   :huh:

Edited by mikell
Link to comment
Share on other sites

Thanks @mikell . I would like to know what is that easier way. 

 

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

It's probably a Windows related issue and probably has nothing to do with AutoIt.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

@BrewManNH So you mean that the code is alright. ?

Edit - @BrewManNH No. That's not right. I have tested it in my laptop(win 8.1 64 bit) and my pc (win 8 32bit). Both gave same result.

 

Edited by kcvinu
Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

@mikell As per your corrections, i can't get the result in first click. Rest is ok.

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

I was referring to the original proposition that the message handler is getting called twice on a single click. I'd guess that's a Windows issue and isn't an AutoIt one, and workarounds are the only thing you can do to get them to work the way you want them to.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

kcvinu,
What about this ?

Func TreeView_WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview
    $hWndTreeview =  $tv1
    If Not IsHWnd($tv1) Then $hWndTreeview = GUICtrlGetHandle($tv1)

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Local $cntr = 0
    Switch $hWndFrom
        Case $hWndTreeview
            Switch $iCode
            Case $TVN_SELCHANGEDW
                $txt = GuiCtrlRead($tv1, 1)
                If $txt <> "" Then ConsoleWrite("Clicked " & $txt & @CRLF)
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

 

Link to comment
Share on other sites

@mikell Same result. Nothing happens at the first click. Then everything is ok

 

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

I'm not sure if you meant this.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiTreeView.au3>
#include <MsgBoxConstants.au3>

GUICreate("My GUI with treeview", 350, 215)

Global $idTreeview = GUICtrlCreateTreeView(6, 6, 100, 150, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
Local $idGeneralitem = GUICtrlCreateTreeViewItem("General", $idTreeview)
GUICtrlSetColor(-1, 0x0000C0)
Local $idDisplayitem = GUICtrlCreateTreeViewItem("Display", $idTreeview)
GUICtrlSetColor(-1, 0x0000C0)
Local $idAboutitem = GUICtrlCreateTreeViewItem("About", $idGeneralitem)
Local $idCompitem = GUICtrlCreateTreeViewItem("Computer", $idGeneralitem)
GUICtrlCreateTreeViewItem("User", $idGeneralitem)
GUICtrlCreateTreeViewItem("Resolution", $idDisplayitem)
GUICtrlCreateTreeViewItem("Other", $idDisplayitem)

Local $idStartlabel = GUICtrlCreateLabel("TreeView Demo", 190, 90, 100, 20)
Local $idAboutlabel = GUICtrlCreateLabel("This little scripts demonstates the using of a treeview-control.", 190, 70, 100, 60)
GUICtrlSetState(-1, $GUI_HIDE) ; Hides the "aboutlabel"-text during initialization
Local $idCompinfo = GUICtrlCreateLabel("Name:" & @TAB & @ComputerName & @CRLF & "OS:" & @TAB & @OSVersion & @CRLF & "SP:" & @TAB & @OSServicePack, 120, 30, 200, 80)
GUICtrlSetState(-1, $GUI_HIDE) ; Hides the "compinfo"-text during initialization

GUICtrlCreateLabel("", 0, 170, 350, 2, $SS_SUNKEN)
Local $idTogglebutton = GUICtrlCreateButton("&Toggle", 35, 185, 70, 20)
Local $idInfobutton = GUICtrlCreateButton("&Info", 105, 185, 70, 20)
Local $idStatebutton = GUICtrlCreateButton("Col./Exp.", 175, 185, 70, 20)
Local $idCancelbutton = GUICtrlCreateButton("&Cancel", 245, 185, 70, 20)

GUICtrlSetState($idGeneralitem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON)) ; Expand the "General"-item and paint in bold
GUICtrlSetState($idDisplayitem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON)) ; Expand the "Display"-item and paint in bold

GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "TreeView_WM_NOTIFY")

While 1
    Sleep(100)
WEnd


Func TreeView_WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam,$lParam

    ; Create NMTREEVIEW structure
    Local $tStruct = DllStructCreate($tagNMTREEVIEW, $lParam)
    Local $iEvent = DllStructGetData($tStruct, "code")
    Select
        Case $wParam = $idTreeview
            Switch $iEvent
                Case $TVN_SELCHANGEDW
                    Local $hItem = DllStructGetData($tStruct, "NewParam")
                    ConsoleWrite(_GUICtrlTreeView_GetText($idTreeview, $hItem) & @CRLF)
            EndSwitch
    EndSelect
    $tStruct = 0
    Return 0

EndFunc   ;==>TreeView_WM_NOTIFY

Saludos

Link to comment
Share on other sites

This:

Func On_WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    #forceref $hWnd, $Msg
    ;wparam = cid, lparam = pnmh
    If $wParam = $cTree Then
        Local $tNMHDR = DllStructCreate("hwnd hTree;uint;int code", $lParam)
        Local $code = DllStructGetData($tNMHDR, "code")
        Local $hTree = HWnd(DllStructGetData($tNMHDR, "hTree"))
        Switch $code
            Case $TVN_BEGINLABELEDITA, $TVN_BEGINLABELEDITW
                $bTreeEdit = True
                _SendMessage($hTree, $TVM_GETEDITCONTROL, 0, 0)
            Case $TVN_ENDLABELEDITW, $TVN_ENDLABELEDITW
                $bTreeEdit = False
                Return 1
            Case $TVN_SELCHANGEDW
                Local $tNMTREEVIEW = DllStructCreate($tagNMTREEVIEW, $lParam)
                Local $hSel = DllStructGetData($tNMTREEVIEW, "NewhItem")
                If $hSel > 0 Then
                    Local $sTxt = "Currently selected: " & _GUICtrlTreeView_GetText($hTree, $hSel) & " (item handle " & $hSel & ")"
                    GUICtrlSetData($idLblInfo, $sTxt)
                    ConsoleWrite($sTxt & @CRLF)
                EndIf
            Case Else
        EndSwitch
        ;
    EndIf
EndFunc   ;==>On_WM_NOTIFY

works for me.

Link to comment
Share on other sites

@Danyfirex Your code is working perfect in my function. Thanks. 

@AutoBert I will check your code later and will inform you the result. Thanks.

Edited by kcvinu
Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

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

×
×
  • Create New...