Jump to content

Error with GuiCtrlRead()


Go to solution Solved by gottygolly,

Recommended Posts

I've been working on some different code here and there and I saw a post about double clicking in a GuiCtrlCreateListView(). So I decided to just mess around with it and learn it as good as I can. However the problem I am having is I have a line: GuiCtrlRead(GuiCtrlRead($var)), it can read the $var but it will read it as: Example.exe| and it won't run because of the " | ".

Anyone know the error?

#include <File.au3>
#include<guiconstants.au3>
$gui = GUICreate("GUI",300,300,-1,-1)
GUIRegisterMsg($WM_NOTIFY,"WM_NOTIFY")
$b = GUICtrlCreateButton("Load",10,10,100,20)
$list = GUICtrlCreateListView("Swf List",5,40,290,260)
Global $DoubleClicked = False
GUISetState()
While 1
   If $DoubleClicked Then
      double()
      $DoubleClicked = False
      EndIf
   $msg = GUIGetMsg(1)
   Switch $msg[1]
   Case $gui
      Switch $msg[0]
      Case -3
         Exit
      Case $b
         GUICtrlCreateListViewItem("notepad.exe",$list)
      EndSwitch
   EndSwitch
WEnd
Func WM_NOTIFY($hWnd, $MsgID, $wParam, $lParam)
    Local $tagNMHDR, $event, $hwndFrom, $code
    $tagNMHDR = DllStructCreate("int;int;int", $lParam)
    If @error Then Return 0
    $code = DllStructGetData($tagNMHDR, 3)
    If $wParam = $list And $code = -3 Then $DoubleClicked = True
    Return $GUI_RUNDEFMSG
 EndFunc
 Func double()
    $go = GUICtrlRead(GUICtrlRead($list))
    ShellExecute($go)
    EndFunc
Link to comment
Share on other sites

  • Moderators

gottygolly,

There is no error - GUICtrlRead adds a delimiter at the end of the ListView content. If you add another column to the ListView like this you can see that the same thing happens:

#include <File.au3>
#include<guiconstants.au3>

$gui = GUICreate("GUI", 300, 300, -1, -1)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
$b = GUICtrlCreateButton("Load", 10, 10, 100, 20)
$list = GUICtrlCreateListView("Swf List|    ", 5, 40, 290, 260)
Global $DoubleClicked = False
GUISetState()

While 1
    If $DoubleClicked Then
        double()
        $DoubleClicked = False
    EndIf
    $msg = GUIGetMsg(1)
    Switch $msg[1]
        Case $gui
            Switch $msg[0]
                Case -3
                    Exit
                Case $b
                    GUICtrlCreateListViewItem("notepad.exe|3", $list)
            EndSwitch
    EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $MsgID, $wParam, $lParam)
    Local $tagNMHDR, $event, $hwndFrom, $code
    $tagNMHDR = DllStructCreate("int;int;int", $lParam)
    If @error Then Return 0
    $code = DllStructGetData($tagNMHDR, 3)
    If $wParam = $list And $code = -3 Then $DoubleClicked = True
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func double()
    $go = GUICtrlRead(GUICtrlRead($list))
    ShellExecute($go)
EndFunc   ;==>double
So you need to use StringTrimRight to remove the added delimiter - then you will get what you require. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Thanks for the help Melba.

I tried to insert the StringTrimRight() like you said to do but it seems to be doing anything. I might be doing something wrong can you point it out?

#include <File.au3>
#include<guiconstants.au3>
$gui = GUICreate("GUI",300,300,-1,-1)
GUIRegisterMsg($WM_NOTIFY,"WM_NOTIFY")
$b = GUICtrlCreateButton("Load",10,10,100,20)
$list = GUICtrlCreateListView("Swf List",5,40,290,260)
Global $DoubleClicked = False
GUISetState()
While 1
   If $DoubleClicked Then
      double()
      $DoubleClicked = False
      EndIf
   $msg = GUIGetMsg(1)
   Switch $msg[1]
   Case $gui
      Switch $msg[0]
      Case -3
         Exit
      Case $b
         $fr = StringTrimRight("notepad.exe",0)
         GuiCtrlCreateListViewItem($fr,$list)
      EndSwitch
   EndSwitch
WEnd
Func WM_NOTIFY($hWnd, $MsgID, $wParam, $lParam)
    Local $tagNMHDR, $event, $hwndFrom, $code
    $tagNMHDR = DllStructCreate("int;int;int", $lParam)
    If @error Then Return 0
    $code = DllStructGetData($tagNMHDR, 3)
    If $wParam = $list And $code = -3 Then $DoubleClicked = True
    Return $GUI_RUNDEFMSG
 EndFunc
 Func double()
    $go = GUICtrlRead(GUICtrlRead($list))
    ShellExecute($go)
    EndFunc
Edited by gottygolly
Link to comment
Share on other sites

  • Moderators

gottygolly,

As it is GUICtrlRead that returns the extra delimiter, it is that string that you need to trim: ;)

$go = StringTrimRight(GUICtrlRead(GUICtrlRead($list)), 1)
M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...