Jump to content

WM_NOTIFY opening listview selecttion in new window


fcg
 Share

Recommended Posts

Hi,

I'm looking for a way to open a new window based on the item I have selected in the listview. I was able to get the doubleclick functionality to work and I can get a msgbox popup to function properly however, when I try to open a new window the application hangs. Any and all help or suggestion on this are greatly appreciated.

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <DateTimeConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <ListBoxConstants.au3>
#include <GuiListView.au3>

Local $Company, $email, $phone, $build, $SRS_Ticket, $Ticket_Id, $ticket_select, $close, $update_tick, $update_cust, $ticket_info, $msg, $ticket_list

$New_Ticket = GUICreate("View Tickets", 981, 753, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_TABSTOP))
$Menu_file = GUICtrlCreateMenu("File")
$Menu_Create = GUICtrlCreateMenuItem("Create New Ticket", $Menu_file)
$f_name = GUICtrlCreateInput("", 100, 37, 121, 21)
$fn_srch = GUICtrlCreateButton("Search", 221, 37, 75, 21)
$l_name = GUICtrlCreateInput("", 100, 77, 121, 21)
$ln_srch = GUICtrlCreateButton("Search", 221, 77, 75, 21)
$Company = GUICtrlCreateInput("", 100, 117, 121, 21)
$comp_srch = GUICtrlCreateButton("Search", 221, 117, 75, 21)
$phone = GUICtrlCreateInput("", 100, 157, 121, 21)
$phon_srch = GUICtrlCreateButton("Search", 221, 157, 75, 21)
$email = GUICtrlCreateInput("", 100, 197, 121, 21)
$email_srch = GUICtrlCreateButton("Search", 221, 197, 75, 21)
$product = GUICtrlCreateCombo("", 400, 37, 145, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
$prod_srch = GUICtrlCreateButton("Search", 545, 37, 75, 21)
$version = GUICtrlCreateCombo("", 400, 77, 40, 25)
$version1 = GUICtrlCreateCombo("", 450, 77, 95, 25)
$version_srch = GUICtrlCreateButton("Search", 545, 77, 75, 21)
$build = GUICtrlCreateInput("", 400, 117, 145, 21)
$build_srch = GUICtrlCreateButton("Search", 545, 117, 75, 21)
$assigned = GUICtrlCreateCombo("", 400, 157, 145, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
$assign_srch = GUICtrlCreateButton("Search", 545, 157, 75, 21)
$SRS_Ticket = GUICtrlCreateInput("", 400, 197, 145, 21)
$srs_srch = GUICtrlCreateButton("Search", 545, 197, 75, 21)
$Date1 = GUICtrlCreateDate("", 730, 37, 145, 21, $DTS_SHORTDATEFORMAT)
$date_srch = GUICtrlCreateButton("Search", 875, 37, 75, 21)
$Ticket_Id = GUICtrlCreateInput("", 730, 77, 145, 21)
$tick_srch = GUICtrlCreateButton("Search", 875, 77, 75, 21)
$Cust_type = GUICtrlCreateCombo("", 730, 117, 145, 25)
$cust_srch = GUICtrlCreateButton("Search", 875, 117, 75, 21)
$reps = GUICtrlCreateCombo("", 730, 157, 145, 25)
$assoc_srch = GUICtrlCreateButton("Search", 875, 157, 75, 21)
$Extended = GUICtrlCreateCheckbox("Extended Support", 732, 200, 121, 17)
$extend_srch = GUICtrlCreateButton("Search", 875, 197, 75, 21)
$Priority = GUICtrlCreateCombo("", 100, 248, 121, 25)
$Priority_srch = GUICtrlCreateButton("Search", 221, 247, 75, 21)
$Status = GUICtrlCreateCombo("", 400, 248, 145, 25)
$Status_srch = GUICtrlCreateButton("Search", 545, 247, 75, 21)
$Created_by_combo = GUICtrlCreateCombo("", 730, 248, 145, 25)
$created_by_srch = GUICtrlCreateButton("Search", 875, 247, 75, 21)
$view_tick = GUICtrlCreateButton("View Ticket", 425, 310, 107, 25)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$reload_list = GUICtrlCreateButton("Reload List", 700, 310, 107, 25)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$new_tick = GUICtrlCreateButton("New Ticket", 150, 310, 107, 25)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$assign = GUICtrlCreateLabel("Assign To", 320, 160, 51, 17)
$pdct = GUICtrlCreateLabel("Product", 320, 40, 41, 17)
$ver = GUICtrlCreateLabel("Version", 320, 80, 39, 16)
$bld = GUICtrlCreateLabel("Build", 320, 120, 75, 17)
$SRS = GUICtrlCreateLabel("SRS Ticket #", 320, 200, 69, 17)
$mail = GUICtrlCreateLabel("Email", 20, 200, 29, 17)
$phon = GUICtrlCreateLabel("Phone #", 20, 160, 45, 17)
$comp = GUICtrlCreateLabel("Company", 20, 120, 48, 17)
$cus_type = GUICtrlCreateLabel("Customer Type", 650, 120, 75, 17)
$rep = GUICtrlCreateLabel("Sales Associate", 650, 160, 79, 17)
$name_l = GUICtrlCreateLabel("Last Name", 20, 80, 55, 17)
$name_f = GUICtrlCreateLabel("First Name", 20, 40, 54, 17)
$tick = GUICtrlCreateLabel("Ticket ID", 650, 77, 48, 17)
$Label1 = GUICtrlCreateLabel("Date", 650, 37, 27, 17)
$prior = GUICtrlCreateLabel("Priority", 20, 250, 35, 17)
$Stat = GUICtrlCreateLabel("Status", 320, 250, 34, 17)
$crt_by_lbl = GUICtrlCreateLabel("Created By", 650, 250, 70, 17)
GUISetState(@SW_SHOW)

_Reset_List()

Func _Reset_List()
    $pos_tick = ControlGetPos("", "", $view_tick)
    $pos_gui = ControlGetPos("", "", $New_Ticket)
    If $pos_gui[2] == 987 Then
        $new_y_pos = $pos_tick[1] + 40
        $new_width = $pos_gui[2] - 50
        $new_height = $pos_gui[3] - 400
    Else
        If $pos_gui[2] > 987 Then
            $new_y_pos = $pos_tick[1] + 55
            $new_width = $pos_gui[2] - 60
            $new_height = $pos_gui[3] - 500
        EndIf
    EndIf
    $ticket_list = GUICtrlCreateListView("Ticket #", 24, $new_y_pos, $new_width, $new_height)
    GUICtrlCreateListViewItem("10001", $ticket_list)
    _GUICtrlListView_RegisterSortCallBack($ticket_list)
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
EndFunc   ;==>_Reset_List


While $msg <> $GUI_EVENT_CLOSE
    $msg = GUIGetMsg()
    Select
        Case $msg = $ticket_list
            _GUICtrlListView_SortItems($ticket_list, GUICtrlGetState($ticket_list))
        Case $msg = $view_tick
            $ticket_select = StringLeft(GUICtrlRead(GUICtrlRead($ticket_list)), 5)
            If $ticket_select <> 0 Then

                MsgBox(48, "Ticket Selected", $ticket_select)
            Else
                MsgBox(48, "No Ticket Selected", "Please select a ticket to view")
            EndIf
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
    $hWndListView = $ticket_list
    If Not IsHWnd($ticket_list) Then $hWndListView = GUICtrlGetHandle($ticket_list)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                    $ticket_select = _GUICtrlListView_GetItemText($ticket_list, $tInfo)
                    _test()
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _test()
    MsgBox(0, "", $ticket_select)
    $ticket_info = GUICreate("Customer Ticket Information", 864, 639, -1, -1)
    $Tab_Set = GUICtrlCreateTab(8, 50, 844, 544)
    $TabSheet1 = GUICtrlCreateTabItem("Ticket Information")
    $TabSheet2 = GUICtrlCreateTabItem("Update Ticket")
    $update_tick = GUICtrlCreateButton("Update", 406, 560, 75, 25)
    $TabSheet3 = GUICtrlCreateTabItem("Edit Customer Information")
    $update_cust = GUICtrlCreateButton("Update", 406, 560, 75, 25)
    GUICtrlCreateTabItem("")
    GUISetState(@SW_SHOW)

    While $msg <> $GUI_EVENT_CLOSE
        $msg = GUIGetMsg()
        Select
            Case $msg = $update_tick
                MsgBox(0, "Ticket info", "Ticket information updated")
            Case $msg = $update_cust
                MsgBox(0, "Customer info", "Customer information updated")
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
        EndSelect
    WEnd
    Exit
EndFunc   ;==>_test
Link to comment
Share on other sites

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <DateTimeConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <ListBoxConstants.au3>
#include <GuiListView.au3>

Local $Company, $email, $phone, $build, $SRS_Ticket, $Ticket_Id, $ticket_select, $close, $update_tick, $update_cust, $ticket_info = 999999, $msg, $ticket_list

$New_Ticket = GUICreate("View Tickets", 981, 753, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_TABSTOP))
$Menu_file = GUICtrlCreateMenu("File")
$Menu_Create = GUICtrlCreateMenuItem("Create New Ticket", $Menu_file)
$f_name = GUICtrlCreateInput("", 100, 37, 121, 21)
$fn_srch = GUICtrlCreateButton("Search", 221, 37, 75, 21)
$l_name = GUICtrlCreateInput("", 100, 77, 121, 21)
$ln_srch = GUICtrlCreateButton("Search", 221, 77, 75, 21)
$Company = GUICtrlCreateInput("", 100, 117, 121, 21)
$comp_srch = GUICtrlCreateButton("Search", 221, 117, 75, 21)
$phone = GUICtrlCreateInput("", 100, 157, 121, 21)
$phon_srch = GUICtrlCreateButton("Search", 221, 157, 75, 21)
$email = GUICtrlCreateInput("", 100, 197, 121, 21)
$email_srch = GUICtrlCreateButton("Search", 221, 197, 75, 21)
$product = GUICtrlCreateCombo("", 400, 37, 145, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
$prod_srch = GUICtrlCreateButton("Search", 545, 37, 75, 21)
$version = GUICtrlCreateCombo("", 400, 77, 40, 25)
$version1 = GUICtrlCreateCombo("", 450, 77, 95, 25)
$version_srch = GUICtrlCreateButton("Search", 545, 77, 75, 21)
$build = GUICtrlCreateInput("", 400, 117, 145, 21)
$build_srch = GUICtrlCreateButton("Search", 545, 117, 75, 21)
$assigned = GUICtrlCreateCombo("", 400, 157, 145, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
$assign_srch = GUICtrlCreateButton("Search", 545, 157, 75, 21)
$SRS_Ticket = GUICtrlCreateInput("", 400, 197, 145, 21)
$srs_srch = GUICtrlCreateButton("Search", 545, 197, 75, 21)
$Date1 = GUICtrlCreateDate("", 730, 37, 145, 21, $DTS_SHORTDATEFORMAT)
$date_srch = GUICtrlCreateButton("Search", 875, 37, 75, 21)
$Ticket_Id = GUICtrlCreateInput("", 730, 77, 145, 21)
$tick_srch = GUICtrlCreateButton("Search", 875, 77, 75, 21)
$Cust_type = GUICtrlCreateCombo("", 730, 117, 145, 25)
$cust_srch = GUICtrlCreateButton("Search", 875, 117, 75, 21)
$reps = GUICtrlCreateCombo("", 730, 157, 145, 25)
$assoc_srch = GUICtrlCreateButton("Search", 875, 157, 75, 21)
$Extended = GUICtrlCreateCheckbox("Extended Support", 732, 200, 121, 17)
$extend_srch = GUICtrlCreateButton("Search", 875, 197, 75, 21)
$Priority = GUICtrlCreateCombo("", 100, 248, 121, 25)
$Priority_srch = GUICtrlCreateButton("Search", 221, 247, 75, 21)
$Status = GUICtrlCreateCombo("", 400, 248, 145, 25)
$Status_srch = GUICtrlCreateButton("Search", 545, 247, 75, 21)
$Created_by_combo = GUICtrlCreateCombo("", 730, 248, 145, 25)
$created_by_srch = GUICtrlCreateButton("Search", 875, 247, 75, 21)
$view_tick = GUICtrlCreateButton("View Ticket", 425, 310, 107, 25)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$reload_list = GUICtrlCreateButton("Reload List", 700, 310, 107, 25)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$new_tick = GUICtrlCreateButton("New Ticket", 150, 310, 107, 25)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$assign = GUICtrlCreateLabel("Assign To", 320, 160, 51, 17)
$pdct = GUICtrlCreateLabel("Product", 320, 40, 41, 17)
$ver = GUICtrlCreateLabel("Version", 320, 80, 39, 16)
$bld = GUICtrlCreateLabel("Build", 320, 120, 75, 17)
$SRS = GUICtrlCreateLabel("SRS Ticket #", 320, 200, 69, 17)
$mail = GUICtrlCreateLabel("Email", 20, 200, 29, 17)
$phon = GUICtrlCreateLabel("Phone #", 20, 160, 45, 17)
$comp = GUICtrlCreateLabel("Company", 20, 120, 48, 17)
$cus_type = GUICtrlCreateLabel("Customer Type", 650, 120, 75, 17)
$rep = GUICtrlCreateLabel("Sales Associate", 650, 160, 79, 17)
$name_l = GUICtrlCreateLabel("Last Name", 20, 80, 55, 17)
$name_f = GUICtrlCreateLabel("First Name", 20, 40, 54, 17)
$tick = GUICtrlCreateLabel("Ticket ID", 650, 77, 48, 17)
$Label1 = GUICtrlCreateLabel("Date", 650, 37, 27, 17)
$prior = GUICtrlCreateLabel("Priority", 20, 250, 35, 17)
$Stat = GUICtrlCreateLabel("Status", 320, 250, 34, 17)
$crt_by_lbl = GUICtrlCreateLabel("Created By", 650, 250, 70, 17)
GUISetState(@SW_SHOW)

_Reset_List()

Func _Reset_List()
    $pos_tick = ControlGetPos("", "", $view_tick)
    $pos_gui = ControlGetPos("", "", $New_Ticket)
    If $pos_gui[2] == 987 Then
        $new_y_pos = $pos_tick[1] + 40
        $new_width = $pos_gui[2] - 50
        $new_height = $pos_gui[3] - 400
    Else
        If $pos_gui[2] > 987 Then
            $new_y_pos = $pos_tick[1] + 55
            $new_width = $pos_gui[2] - 60
            $new_height = $pos_gui[3] - 500
        EndIf
    EndIf
    $ticket_list = GUICtrlCreateListView("Ticket #", 24, $new_y_pos, $new_width, $new_height)
    GUICtrlCreateListViewItem("10001", $ticket_list)
    _GUICtrlListView_RegisterSortCallBack($ticket_list)
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
EndFunc   ;==>_Reset_List


While true
    $msg = GUIGetMsg(1)
    Switch $msg[1]
        Case $New_Ticket
            Switch $msg[0]
                Case $ticket_list
                    _GUICtrlListView_SortItems($ticket_list, GUICtrlGetState($ticket_list))
                Case $view_tick
                    $ticket_select = StringLeft(GUICtrlRead(GUICtrlRead($ticket_list)), 5)
                    If $ticket_select <> 0 Then

                        MsgBox(48, "Ticket Selected", $ticket_select)
                    Else
                        MsgBox(48, "No Ticket Selected", "Please select a ticket to view")
                    EndIf
                Case $GUI_EVENT_CLOSE
                    Exit
            EndSwitch
        Case $ticket_info
            Switch $msg[0]
                Case $update_tick
                    MsgBox(0, "Ticket info", "Ticket information updated")
                Case $update_cust
                    MsgBox(0, "Customer info", "Customer information updated")
                Case $GUI_EVENT_CLOSE
                    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $GUI_EVENT_CLOSE = ' & $GUI_EVENT_CLOSE & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
                    GUIDelete($ticket_info)
            EndSwitch
    EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
    $hWndListView = $ticket_list
    If Not IsHWnd($ticket_list) Then $hWndListView = GUICtrlGetHandle($ticket_list)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                    $ticket_select = _GUICtrlListView_GetItemText($ticket_list, $tInfo)
                    _test()
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _test()
    MsgBox(0, "", $ticket_select)
    $ticket_info = GUICreate("Customer Ticket Information", 864, 639, -1, -1)
    $Tab_Set = GUICtrlCreateTab(8, 50, 844, 544)
    $TabSheet1 = GUICtrlCreateTabItem("Ticket Information")
    $TabSheet2 = GUICtrlCreateTabItem("Update Ticket")
    $update_tick = GUICtrlCreateButton("Update", 406, 560, 75, 25)
    $TabSheet3 = GUICtrlCreateTabItem("Edit Customer Information")
    $update_cust = GUICtrlCreateButton("Update", 406, 560, 75, 25)
    GUICtrlCreateTabItem("")
    GUISetState(@SW_SHOW)
EndFunc   ;==>_test

I edited a few your script, i am not sure about the main problem, but moving the loop part outside the function it works i use GuiGetMsg(1) to check for both Guis in the main loop... i guess that not returning anyting for the Reguster function is an issue... i also do a few changes that you can correct if you dont want.. i use more the switch that select, and i change while $msg <> $GUI_EVENT_CLOSE to While True... it seems a little redundant for me, but you can change it back i f you want.

Link to comment
Share on other sites

Problem is that you call test() directly from WM_NOTIFY handler.

In WM_NOTIFY handler set only flag (global variable) and test this flag in main GUI message loop,

when flag is set to ON then call your test() from here (main GUI message loop).

This was answered here on the forum already.

Search WM_NOTIFY for examples with this solution.

Link to comment
Share on other sites

Hi,

It's as Zedna said, or just create the 2nd gui hidden and use show and hide as needed

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <DateTimeConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <ListBoxConstants.au3>
#include <GuiListView.au3>

Local $Company, $email, $phone, $build, $SRS_Ticket, $Ticket_Id, $ticket_select, $close, $update_tick, $update_cust, $ticket_info, $msg, $ticket_list

Global $ticket_info, $Tab_Set, $TabSheet1, $TabSheet2, $update_tick, $TabSheet3, $update_cust

$New_Ticket = GUICreate("View Tickets", 981, 753, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_TABSTOP))
$Menu_file = GUICtrlCreateMenu("File")
$Menu_Create = GUICtrlCreateMenuItem("Create New Ticket", $Menu_file)
$f_name = GUICtrlCreateInput("", 100, 37, 121, 21)
$fn_srch = GUICtrlCreateButton("Search", 221, 37, 75, 21)
$l_name = GUICtrlCreateInput("", 100, 77, 121, 21)
$ln_srch = GUICtrlCreateButton("Search", 221, 77, 75, 21)
$Company = GUICtrlCreateInput("", 100, 117, 121, 21)
$comp_srch = GUICtrlCreateButton("Search", 221, 117, 75, 21)
$phone = GUICtrlCreateInput("", 100, 157, 121, 21)
$phon_srch = GUICtrlCreateButton("Search", 221, 157, 75, 21)
$email = GUICtrlCreateInput("", 100, 197, 121, 21)
$email_srch = GUICtrlCreateButton("Search", 221, 197, 75, 21)
$product = GUICtrlCreateCombo("", 400, 37, 145, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
$prod_srch = GUICtrlCreateButton("Search", 545, 37, 75, 21)
$version = GUICtrlCreateCombo("", 400, 77, 40, 25)
$version1 = GUICtrlCreateCombo("", 450, 77, 95, 25)
$version_srch = GUICtrlCreateButton("Search", 545, 77, 75, 21)
$build = GUICtrlCreateInput("", 400, 117, 145, 21)
$build_srch = GUICtrlCreateButton("Search", 545, 117, 75, 21)
$assigned = GUICtrlCreateCombo("", 400, 157, 145, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
$assign_srch = GUICtrlCreateButton("Search", 545, 157, 75, 21)
$SRS_Ticket = GUICtrlCreateInput("", 400, 197, 145, 21)
$srs_srch = GUICtrlCreateButton("Search", 545, 197, 75, 21)
$Date1 = GUICtrlCreateDate("", 730, 37, 145, 21, $DTS_SHORTDATEFORMAT)
$date_srch = GUICtrlCreateButton("Search", 875, 37, 75, 21)
$Ticket_Id = GUICtrlCreateInput("", 730, 77, 145, 21)
$tick_srch = GUICtrlCreateButton("Search", 875, 77, 75, 21)
$Cust_type = GUICtrlCreateCombo("", 730, 117, 145, 25)
$cust_srch = GUICtrlCreateButton("Search", 875, 117, 75, 21)
$reps = GUICtrlCreateCombo("", 730, 157, 145, 25)
$assoc_srch = GUICtrlCreateButton("Search", 875, 157, 75, 21)
$Extended = GUICtrlCreateCheckbox("Extended Support", 732, 200, 121, 17)
$extend_srch = GUICtrlCreateButton("Search", 875, 197, 75, 21)
$Priority = GUICtrlCreateCombo("", 100, 248, 121, 25)
$Priority_srch = GUICtrlCreateButton("Search", 221, 247, 75, 21)
$Status = GUICtrlCreateCombo("", 400, 248, 145, 25)
$Status_srch = GUICtrlCreateButton("Search", 545, 247, 75, 21)
$Created_by_combo = GUICtrlCreateCombo("", 730, 248, 145, 25)
$created_by_srch = GUICtrlCreateButton("Search", 875, 247, 75, 21)
$view_tick = GUICtrlCreateButton("View Ticket", 425, 310, 107, 25)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$reload_list = GUICtrlCreateButton("Reload List", 700, 310, 107, 25)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$new_tick = GUICtrlCreateButton("New Ticket", 150, 310, 107, 25)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$assign = GUICtrlCreateLabel("Assign To", 320, 160, 51, 17)
$pdct = GUICtrlCreateLabel("Product", 320, 40, 41, 17)
$ver = GUICtrlCreateLabel("Version", 320, 80, 39, 16)
$bld = GUICtrlCreateLabel("Build", 320, 120, 75, 17)
$SRS = GUICtrlCreateLabel("SRS Ticket #", 320, 200, 69, 17)
$mail = GUICtrlCreateLabel("Email", 20, 200, 29, 17)
$phon = GUICtrlCreateLabel("Phone #", 20, 160, 45, 17)
$comp = GUICtrlCreateLabel("Company", 20, 120, 48, 17)
$cus_type = GUICtrlCreateLabel("Customer Type", 650, 120, 75, 17)
$rep = GUICtrlCreateLabel("Sales Associate", 650, 160, 79, 17)
$name_l = GUICtrlCreateLabel("Last Name", 20, 80, 55, 17)
$name_f = GUICtrlCreateLabel("First Name", 20, 40, 54, 17)
$tick = GUICtrlCreateLabel("Ticket ID", 650, 77, 48, 17)
$Label1 = GUICtrlCreateLabel("Date", 650, 37, 27, 17)
$prior = GUICtrlCreateLabel("Priority", 20, 250, 35, 17)
$Stat = GUICtrlCreateLabel("Status", 320, 250, 34, 17)
$crt_by_lbl = GUICtrlCreateLabel("Created By", 650, 250, 70, 17)
GUISetState(@SW_SHOW, $New_Ticket)

_Reset_List()

$ticket_info = GUICreate("Customer Ticket Information", 864, 639, -1, -1)
$Tab_Set = GUICtrlCreateTab(8, 50, 844, 544)
$TabSheet1 = GUICtrlCreateTabItem("Ticket Information")
$TabSheet2 = GUICtrlCreateTabItem("Update Ticket")
$update_tick = GUICtrlCreateButton("Update", 406, 560, 75, 25)
$TabSheet3 = GUICtrlCreateTabItem("Edit Customer Information")
$update_cust = GUICtrlCreateButton("Update", 406, 560, 75, 25)
GUICtrlCreateTabItem("")
GUISetState(@SW_HIDE, $ticket_info)



Func _Reset_List()
    $pos_tick = ControlGetPos("", "", $view_tick)
    $pos_gui = ControlGetPos("", "", $New_Ticket)
    If $pos_gui[2] == 987 Then
        $new_y_pos = $pos_tick[1] + 40
        $new_width = $pos_gui[2] - 50
        $new_height = $pos_gui[3] - 400
    Else
        If $pos_gui[2] > 987 Then
            $new_y_pos = $pos_tick[1] + 55
            $new_width = $pos_gui[2] - 60
            $new_height = $pos_gui[3] - 500
        EndIf
    EndIf
    $ticket_list = GUICtrlCreateListView("Ticket #", 24, $new_y_pos, $new_width, $new_height)
    GUICtrlCreateListViewItem("10001", $ticket_list)
    _GUICtrlListView_RegisterSortCallBack($ticket_list)
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
EndFunc   ;==>_Reset_List


While 1
    ;$aMsg[0] = 0 or Event ID or Control ID
    ;$aMsg[1] = The window handle the event is from
    ;$aMsg[2] = The control handle the event is from (if applicable)
    ;$aMsg[3] = The current X position of the mouse cursor (relative to the GUI window)
    ;$aMsg[4] = The current Y position of the mouse cursor (relative to the GUI window)
    $aMsg = GUIGetMsg(1)
    Switch $aMsg[0]
        Case $ticket_list
            _GUICtrlListView_SortItems($ticket_list, GUICtrlGetState($ticket_list))
        Case $view_tick
            $ticket_select = StringLeft(GUICtrlRead(GUICtrlRead($ticket_list)), 5)
            If $ticket_select <> 0 Then

                MsgBox(48, "Ticket Selected", $ticket_select)
            Else
                MsgBox(48, "No Ticket Selected", "Please select a ticket to view")
            EndIf
        Case $update_tick
            MsgBox(0, "Ticket info", "Ticket #" & $ticket_select & " information updated")
        Case $update_cust
            MsgBox(0, "Customer info", "Customer information updated")
        Case $GUI_EVENT_CLOSE
            If $aMsg[1] = $ticket_info Then
                GUISetState(@SW_HIDE, $ticket_info)
            Else
                Exit
            EndIf
    EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
    $hWndListView = $ticket_list
    If Not IsHWnd($ticket_list) Then $hWndListView = GUICtrlGetHandle($ticket_list)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                    $ticket_select = _GUICtrlListView_GetItemText($ticket_list, DllStructGetData($tInfo, "Index"))
                    WinSetTitle($ticket_info, "", "Customer Ticket #" & $ticket_select & " Information")
                    GUISetState(@SW_SHOW, $ticket_info)
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Cheers

Link to comment
Share on other sites

After adding more data in the list I noticed that the value returned is always the same no matter which sub-item I select. I have tried different variations of the WM_NOTIFY function I have found in the forums but no luck. Sorry for seeing this in the original post.

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <DateTimeConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <ListBoxConstants.au3>
#include <GuiListView.au3>

Local $Company, $email, $phone, $build, $SRS_Ticket, $Ticket_Id, $ticket_select, $close, $update_tick, $update_cust, $ticket_info = 999999, $msg, $ticket_list

$New_Ticket = GUICreate("View Tickets", 981, 753, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_TABSTOP))
$Menu_file = GUICtrlCreateMenu("File")
$Menu_Create = GUICtrlCreateMenuItem("Create New Ticket", $Menu_file)
$f_name = GUICtrlCreateInput("", 100, 37, 121, 21)
$fn_srch = GUICtrlCreateButton("Search", 221, 37, 75, 21)
$l_name = GUICtrlCreateInput("", 100, 77, 121, 21)
$ln_srch = GUICtrlCreateButton("Search", 221, 77, 75, 21)
$Company = GUICtrlCreateInput("", 100, 117, 121, 21)
$comp_srch = GUICtrlCreateButton("Search", 221, 117, 75, 21)
$phone = GUICtrlCreateInput("", 100, 157, 121, 21)
$phon_srch = GUICtrlCreateButton("Search", 221, 157, 75, 21)
$email = GUICtrlCreateInput("", 100, 197, 121, 21)
$email_srch = GUICtrlCreateButton("Search", 221, 197, 75, 21)
$product = GUICtrlCreateCombo("", 400, 37, 145, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
$prod_srch = GUICtrlCreateButton("Search", 545, 37, 75, 21)
$version = GUICtrlCreateCombo("", 400, 77, 40, 25)
$version1 = GUICtrlCreateCombo("", 450, 77, 95, 25)
$version_srch = GUICtrlCreateButton("Search", 545, 77, 75, 21)
$build = GUICtrlCreateInput("", 400, 117, 145, 21)
$build_srch = GUICtrlCreateButton("Search", 545, 117, 75, 21)
$assigned = GUICtrlCreateCombo("", 400, 157, 145, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
$assign_srch = GUICtrlCreateButton("Search", 545, 157, 75, 21)
$SRS_Ticket = GUICtrlCreateInput("", 400, 197, 145, 21)
$srs_srch = GUICtrlCreateButton("Search", 545, 197, 75, 21)
$Date1 = GUICtrlCreateDate("", 730, 37, 145, 21, $DTS_SHORTDATEFORMAT)
$date_srch = GUICtrlCreateButton("Search", 875, 37, 75, 21)
$Ticket_Id = GUICtrlCreateInput("", 730, 77, 145, 21)
$tick_srch = GUICtrlCreateButton("Search", 875, 77, 75, 21)
$Cust_type = GUICtrlCreateCombo("", 730, 117, 145, 25)
$cust_srch = GUICtrlCreateButton("Search", 875, 117, 75, 21)
$reps = GUICtrlCreateCombo("", 730, 157, 145, 25)
$assoc_srch = GUICtrlCreateButton("Search", 875, 157, 75, 21)
$Extended = GUICtrlCreateCheckbox("Extended Support", 732, 200, 121, 17)
$extend_srch = GUICtrlCreateButton("Search", 875, 197, 75, 21)
$Priority = GUICtrlCreateCombo("", 100, 248, 121, 25)
$Priority_srch = GUICtrlCreateButton("Search", 221, 247, 75, 21)
$Status = GUICtrlCreateCombo("", 400, 248, 145, 25)
$Status_srch = GUICtrlCreateButton("Search", 545, 247, 75, 21)
$Created_by_combo = GUICtrlCreateCombo("", 730, 248, 145, 25)
$created_by_srch = GUICtrlCreateButton("Search", 875, 247, 75, 21)
$view_tick = GUICtrlCreateButton("View Ticket", 425, 310, 107, 25)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$reload_list = GUICtrlCreateButton("Reload List", 700, 310, 107, 25)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$new_tick = GUICtrlCreateButton("New Ticket", 150, 310, 107, 25)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$assign = GUICtrlCreateLabel("Assign To", 320, 160, 51, 17)
$pdct = GUICtrlCreateLabel("Product", 320, 40, 41, 17)
$ver = GUICtrlCreateLabel("Version", 320, 80, 39, 16)
$bld = GUICtrlCreateLabel("Build", 320, 120, 75, 17)
$SRS = GUICtrlCreateLabel("SRS Ticket #", 320, 200, 69, 17)
$mail = GUICtrlCreateLabel("Email", 20, 200, 29, 17)
$phon = GUICtrlCreateLabel("Phone #", 20, 160, 45, 17)
$comp = GUICtrlCreateLabel("Company", 20, 120, 48, 17)
$cus_type = GUICtrlCreateLabel("Customer Type", 650, 120, 75, 17)
$rep = GUICtrlCreateLabel("Sales Associate", 650, 160, 79, 17)
$name_l = GUICtrlCreateLabel("Last Name", 20, 80, 55, 17)
$name_f = GUICtrlCreateLabel("First Name", 20, 40, 54, 17)
$tick = GUICtrlCreateLabel("Ticket ID", 650, 77, 48, 17)
$Label1 = GUICtrlCreateLabel("Date", 650, 37, 27, 17)
$prior = GUICtrlCreateLabel("Priority", 20, 250, 35, 17)
$Stat = GUICtrlCreateLabel("Status", 320, 250, 34, 17)
$crt_by_lbl = GUICtrlCreateLabel("Created By", 650, 250, 70, 17)
GUISetState(@SW_SHOW)

_Reset_List()

Func _Reset_List()
    $pos_tick = ControlGetPos("", "", $view_tick)
    $pos_gui = ControlGetPos("", "", $New_Ticket)
    If $pos_gui[2] == 987 Then
        $new_y_pos = $pos_tick[1] + 40
        $new_width = $pos_gui[2] - 50
        $new_height = $pos_gui[3] - 400
    Else
        If $pos_gui[2] > 987 Then
            $new_y_pos = $pos_tick[1] + 55
            $new_width = $pos_gui[2] - 60
            $new_height = $pos_gui[3] - 500
        EndIf
    EndIf
    $ticket_list = GUICtrlCreateListView("Ticket #", 24, $new_y_pos, $new_width, $new_height)
    GUICtrlCreateListViewItem("10001", $ticket_list)
    GUICtrlCreateListViewItem("10002", $ticket_list)
    GUICtrlCreateListViewItem("10003", $ticket_list)
    _GUICtrlListView_RegisterSortCallBack($ticket_list)
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
EndFunc   ;==>_Reset_List


While true
    $msg = GUIGetMsg(1)
    Switch $msg[1]
        Case $New_Ticket
            Switch $msg[0]
                Case $ticket_list
                    _GUICtrlListView_SortItems($ticket_list, GUICtrlGetState($ticket_list))
                Case $view_tick
                    $ticket_select = StringLeft(GUICtrlRead(GUICtrlRead($ticket_list)), 5)
                    If $ticket_select <> 0 Then

                        MsgBox(48, "Ticket Selected", $ticket_select)
                    Else
                        MsgBox(48, "No Ticket Selected", "Please select a ticket to view")
                    EndIf
                Case $GUI_EVENT_CLOSE
                    Exit
            EndSwitch
        Case $ticket_info
            Switch $msg[0]
                Case $update_tick
                    MsgBox(0, "Ticket info", "Ticket information updated")
                Case $update_cust
                    MsgBox(0, "Customer info", "Customer information updated")
                Case $GUI_EVENT_CLOSE
                    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $GUI_EVENT_CLOSE = ' & $GUI_EVENT_CLOSE & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
                    GUIDelete($ticket_info)
            EndSwitch
    EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
    $hWndListView = $ticket_list
    If Not IsHWnd($ticket_list) Then $hWndListView = GUICtrlGetHandle($ticket_list)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                    $ticket_select = _GUICtrlListView_GetItemText($ticket_list, $tInfo)
                    _test()
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _test()
    MsgBox(0, "", $ticket_select)
    $ticket_info = GUICreate("Customer Ticket Information", 864, 639, -1, -1)
    $Tab_Set = GUICtrlCreateTab(8, 50, 844, 544)
    $TabSheet1 = GUICtrlCreateTabItem("Ticket Information")
    $TabSheet2 = GUICtrlCreateTabItem("Update Ticket")
    $update_tick = GUICtrlCreateButton("Update", 406, 560, 75, 25)
    $TabSheet3 = GUICtrlCreateTabItem("Edit Customer Information")
    $update_cust = GUICtrlCreateButton("Update", 406, 560, 75, 25)
    GUICtrlCreateTabItem("")
    GUISetState(@SW_SHOW)
EndFunc   ;==>_test
Link to comment
Share on other sites

mmmh i don`t have experience with lists, maybe there is another way, but this work..

Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
;~                   $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
;~                  $item = DllStructGetData($tInfo,2)
                    $item = _GUICtrlListView_GetHotItem($ticket_list)
                    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $item = ' & $item & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
                    $ticket_select = _GUICtrlListView_GetItemText($ticket_list, $item)
                    _test()
            EndSwitch
    EndSwitch
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...