Jump to content

[SOLVED]$WM_COMMAND for $LBN_DBLCLK of listbox item


JonBMN
 Share

Recommended Posts

I'm trying to make it so that when I double click an item in my $List1 listbox, it will bring up a GUI window that reads all the .log values into the variable and then displays it in another list inside that child window. It should open a .log file that starts with the computer name ($compName) & ".log". Then read all the lines into a variable called $fread which then after its done reading into the variable it would then put that variable's value inside the list. Then close the file.

Do I have the logic correct for doing this. Would my $List1 that I double click have to be able to edit, because that list is $ES_READONLY.

::Here is the GUIRegisterMsg and WM_COMMAND function that I'd like some help with::

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    Local $Child, $lb, $fopen, $fclose, $fread, $count, $i
    $iIDFrom = BitAND($wParam, 0xFFFF) ; low word
    $iCode = BitShift($lParam, 16) ; high word

    Switch $iCode
       Case $LBN_DBLCLK ;sent when user double-clicks a string in the list box
        Switch $iIDFrom
           Case $List1
            $index = _GUICtrlListBox_GetCaretIndex($List1)
            $sText = _GUICtrlListBox_GetText($List1, $index)
            $Child = GUICreate($compName, 600, 500, -1, -1, -1, -1, $GUIhandle)
            $fopen = FileOpen($compName & ".log", 0)
            $count = _FileCountLines($fopen)
                for $i = 0 To $count Step 1
                    $fread &= FileReadLine($fopen, $i) & @CRLF
                Next
             $lb = GUICtrlCreateList("", 10, 10, 580, 480, BitOr($WS_BORDER, $WS_VSCROLL), $ES_READONLY)
             GUICtrlSetData($lb, $fread)
             $fclose = FileClose($fopen)
         EndSelect
     EndSelect
EndFunc
Edited by JonBMN
Link to comment
Share on other sites

  • Moderators

JonBMN,

Pretty close - take a look at this to see how I would do it: ;)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#include <GuiListBox.au3>
#include <EditConstants.au3>

$hGUI = GUICreate("Test", 500, 500)

$cList = GUICtrlCreateList("", 10, 10, 300, 300, BitOr($WS_BORDER, $WS_VSCROLL))
ConsoleWrite($cList & @CRLF)
$sData = ""
For $i = 1 To 20
    $sData &= "|" & "Line " & $i
Next
GUICtrlSetData($cList, $sData)

GUISetState()

GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

Func _WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $lParam

    $iIDFrom = BitAND($wParam, 0xFFFF) ; Low Word
    $iCode = BitShift($wParam, 16) ; Hi Word

    Switch $iCode
        Case $LBN_DBLCLK
            Switch $iIDFrom
                Case $cList
                    $sData = GUICtrlRead($cList) ; Use the native function
                    $sFile = FileRead(@ScriptFullPath) ; Read the file

                    $hChild_1 = GUICreate($sData & " - List", 500, 500, 0, 0, Default, Default, $hGUI)
                    $sLines = StringReplace($sFile, @CRLF, "|") ; Replace the EOL with "|"
                    $cList_1 = GUICtrlCreateList("", 10, 10, 480, 480, BitOr($WS_BORDER, $WS_VSCROLL))
                    GUICtrlSetData($cList_1, $sLines) ; Add to list
                    GUISetState()

                    ; But why not use an edit - it is much simpler
                    $hChild_1 = GUICreate($sData & " - Edit", 500, 500, 600, 0, Default, Default, $hGUI)
                    $cEdit_2 = GUICtrlCreateEdit("", 10, 10, 480, 480, BitOr($GUI_SS_DEFAULT_EDIT, $ES_READONLY))
                    GUICtrlSetData($cEdit_2, $sFile)
                    GUISetState()
                    ControlSend($hChild_1, "", $cEdit_2, "^{HOME}") ; This unselects the text

            EndSwitch
    EndSwitch

EndFunc

Obviously I am reading a different file, but the principles are the same. And lists are by definition "ReadOnly" - but you have to specify the style for an edit. ;)

All clear? :)

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

How would you get it to open a specific Item on double click? I have a list of 3 values yet when I double click it all it brings up is nothing and not the name & ".log"

$sFile = FileRead($compName & ".log") ; Read the file
Edited by JonBMN
Link to comment
Share on other sites

  • Moderators

JonBMN,

Rather difficult to say from just that small snippet, but I would hazard a guess that you need to add a path in there so that the FileRead function knows where to look - at the moment you are most likely assuming that the file is in the same folder as the script. ;)

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

The file is absolutely in the same folder, I'm just having trouble getting the correct name from my double click. Is there anyway to take that double click on the certain value that I selected and include that into the FileRead?

P.S these list values can change so I cannot hardcode a path

Edited by JonBMN
Link to comment
Share on other sites

  • Moderators

JonBMN,

It does help if you actually read the value selected in the list. :whistle:

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

×
×
  • Create New...