Garp99HasSpoken Posted February 24, 2013 Share Posted February 24, 2013 Having a problem with TAB items not calling the onEvent when the tab is clicked to shift focus. I can use the menu options under "Go to..." and hot keys F5/F6 to switch between tabs. In doing so, the appropriate menu options are disabled under Event and Volunteer. However, the same action should occur when I directly click on the tab, but it's not working. expandcollapse popup;Autoit Options ; #NoTrayIcon ;No Tray Icon Opt("GUIOnEventMode", 1) Opt("WinTextMatchMode", 1) ;1=complete, 2=quick Opt("WinTitleMatchMode", 3) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase Opt("GUICloseOnESC", 0) ;1=ESC closes, 0=ESC won't close Opt("GUIResizeMode", 802) ; Opt("GUIResizeMode", 1) #Include <String.au3> #include <Date.au3> #Include <WinAPI.au3> #include <File.au3> #include <GuiTab.au3> ;#include <GDIPlus.au3> #include <GUIListBox.au3> #include <GuiListView.au3> #include <GuiScrollBars.au3> #include <GuiStatusBar.au3> #include <GuiToolbar.au3> ; Constants includes #include <ListViewConstants.au3> #include <TabConstants.au3> #include <ToolbarConstants.au3> #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <DateTimeConstants.au3> #include <GUIConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include "GUIListViewEx.au3" ; Tab groups Global Const $L_VOLUNTEERS = " Volunteers " Global Const $L_VOLUNTEER = "Volunteer" Global Const $L_EVENTS = " Events " Global Const $L_EVENT = "Event" ; Tab items Global Const $T_Event = 0 Global Const $T_Volunteer = 1 ; Menus Global Const $M_EVENT = "Even&t" Global Const $M_VOLUNTEER = "&Volunteer" Global Const $M_OPTIONS = "&Go To..." Global Const $M_ADD = "Add " Global Const $M_EDIT = "Edit " Global Const $M_DELETE = "Delete " ; Prompts Global Const $L_AREYOUSURE = "Are You Sure?" Global Const $L_CANCELEXIT = "Cancel all changes and exit?" ;Versions Info Global $ProgName = "Volunteer Coordinator" Global $VersionBuild = "20130213" ;YEAR|MON|DAY Global $ProgVersion = "0.1" GLOBAL $AboutVersion = "2013.02.13 (" & $ProgVersion & ")" Global $ProgWidth =1024, $ProgHeight = 720 Local $sWidth = 400, $sHeight = 350 Local $hToolbar = 40, $hStatus = 40, $hTabs = $hToolbar+30, $hLists = ($ProgHeight - $hTabs - $hStatus - $hToolbar) #Region ### START Koda GUI section ### Form=R:\AutoIt Examples\koda_2008-09-03\Forms\VolunteerCoordinator.kxf Global $MainForm = GUICreate($ProgName, $ProgWidth, $ProgHeight, (@DesktopWidth - $ProgWidth) / 2, (@DesktopHeight - $ProgHeight) / 2, $WS_SIZEBOX + $WS_SYSMENU ) GUISetState(@SW_HIDE) GUISetBkColor(0xA6CAF0) GUISetOnEvent($GUI_EVENT_CLOSE, "MainFormClose") GUISetOnEvent($GUI_EVENT_MINIMIZE, "") GUISetOnEvent($GUI_EVENT_MAXIMIZE, "") GUISetOnEvent($GUI_EVENT_RESTORE, "") Global $TabVol = GUICtrlCreateTab(1, $hTabs-$hToolbar, $ProgWidth-2, $hToolbar, $TCS_TABS) GUICtrlSetFont(-1, 12, 400, 0, "Arial") GUICtrlSetResizing(-1, $GUI_DOCKAUTO) Global $TabSheetEvents = GUICtrlCreateTabItem($L_EVENTS) GUICtrlSetOnEvent($TabSheetEvents, "ListViewEventsClick") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Tried adding this Global $ListViewEvents = GUICtrlCreateListView( _ "|Date |Type |Volunteers ", _ 2, $hTabs, $ProgWidth-4, $hLists, BitOr($LVS_SHOWSELALWAYS, $LVS_SINGLESEL)) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") ; Initiate LVEx - no count parameter - default insert mark colour (black) $iLV_Events = _GUIListViewEx_Init($ListViewEvents, "", 0, 0, True, True) _GUIListViewEx_SetActive($iLV_Events) EventFullList() _GUICtrlListView_SetColumnWidth($ListViewEvents, 0, 0) ; hidden For $i=1 To 3 _GUICtrlListView_SetColumnWidth($ListViewEvents, $i, $LVSCW_AUTOSIZE_USEHEADER) Next GUICtrlSetOnEvent($ListViewEvents, "ListViewEventsClick") Global $TabSheetVolunteers = GUICtrlCreateTabItem($L_VOLUNTEERS) GUICtrlSetOnEvent($TabSheetVolunteers, "ListViewVolunteersClick") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Tried adding this Global $ListViewVolunteers = GUICtrlCreateListView( _ "|Name |Type |Home |Work |Cell |Address |City |Prov|Postal|Notes ", _ 2, $hTabs, $ProgWidth-4, $hLists, BitOr($LVS_SHOWSELALWAYS, $LVS_SINGLESEL)) GUICtrlSetFont($ListViewVolunteers, 10, 400, 0, "MS Sans Serif") ; Initiate LVEx - no count parameter - default insert mark colour (black) $iLV_Volunteers = _GUIListViewEx_Init($ListViewVolunteers, "", 0, 0, True, True) _GUIListViewEx_SetActive($iLV_Volunteers) VolunteerFullList() _GUICtrlListView_SetColumnWidth($ListViewVolunteers, 0, 0) ; hidden For $i=1 To 10 _GUICtrlListView_SetColumnWidth($ListViewVolunteers, $i, $LVSCW_AUTOSIZE_USEHEADER) Next Local $fSort = False ; passed ByRef _GUICtrlListView_SimpleSort($ListViewVolunteers, $fSort, 1) GUICtrlSetOnEvent($ListViewVolunteers, "ListViewVolunteersClick") GUICtrlCreateTabItem("") ;end of tabs sleep(500) ;==> EVENT menu Local $MenuEvent = GUICtrlCreateMenu($M_EVENT) Local $MenuEventAdd = GUICtrlCreateMenuItem($M_ADD & $L_EVENT & @tab & "F9", $MenuEvent) GUICtrlSetOnEvent(-1, "MenuEventAddClick") Local $MenuEventEdit = GUICtrlCreateMenuItem($M_EDIT & $L_EVENT & @tab & "F10", $MenuEvent) GUICtrlSetOnEvent(-1, "MenuEventEditClick") Local $MenuEventDelete = GUICtrlCreateMenuItem($M_DELETE & $L_EVENT & @tab & "", $MenuEvent) GUICtrlSetOnEvent(-1, "MenuEventDeleteClick") ;==> VOLUNTEER menu Local $MenuVolunteer = GUICtrlCreateMenu($M_VOLUNTEER) Local $MenuVolunteerAdd = GUICtrlCreateMenuItem($M_ADD & $L_VOLUNTEER & @tab & "F11", $MenuVolunteer) GUICtrlSetOnEvent(-1, "MenuVolunteerAddClick") Local $MenuVolunteerEdit = GUICtrlCreateMenuItem($M_EDIT & $L_VOLUNTEER & @tab & "F12", $MenuVolunteer) GUICtrlSetOnEvent(-1, "MenuVolunteerEditClick") Local $MenuVolunteerDelete = GUICtrlCreateMenuItem($M_DELETE & $L_VOLUNTEER & @tab & "", $MenuVolunteer) GUICtrlSetOnEvent(-1, "MenuVolunteerDeleteClick") ;==> OPTIONS menu Local $MenuOptions = GUICtrlCreateMenu($M_OPTIONS) Local $MenuEventDates = GUICtrlCreateMenuItem($L_EVENT & " Dates" & @tab & "F5", $MenuOptions) GUICtrlSetOnEvent(-1, "ListViewEventsClick") Local $MenuVolList = GUICtrlCreateMenuItem($L_VOLUNTEER & " List" & @tab & "F6", $MenuOptions) GUICtrlSetOnEvent(-1, "ListViewVolunteersClick") Local $MainForm_AccelTable[9][2] = [ ["^!t", $MenuEvent],["{F9}", $MenuEventAdd],["{F10}", $MenuEventEdit], ["^!v", $MenuVolunteer],["{F11}", $MenuVolunteerAdd],["{F12}", $MenuVolunteerEdit], ["^!g", $MenuOptions],["{F5}", $MenuEventDates],["{F6}", $MenuVolList] ] GUISetAccelerators($MainForm_AccelTable, $MainForm) Global $StatusBar = _GUICtrlStatusBar_Create($MainForm) _GUICtrlStatusBar_SetSimple($StatusBar) _GUICtrlStatusBar_SetText($StatusBar, "Simple status bar window text goes here.") _GUICtrlStatusBar_SetMinHeight($StatusBar, $hStatus) GUISetFont(10, 400, 0, "MS Sans Serif", $MainForm) GUISetOnEvent($GUI_EVENT_CLOSE, "MainFormClose") GUISetOnEvent($GUI_EVENT_RESTORE, "") GUISetOnEvent($GUI_EVENT_MAXIMIZE, "") GUISetOnEvent($GUI_EVENT_RESIZED, "") _GUIListViewEx_DragRegister(True, False, False) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") #EndRegion ### END Koda GUI section ### GUISwitch($MainForm) GUISetState(@SW_SHOW) ; Set the Events ListView as active ;_GUIListViewEx_SetActive($iLV_Events) ListViewEventsClick() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< should set Volunteer menu options to DISABLED While 1 sleep(100) WEnd GUISetState(@SW_HIDE) GUIDelete() _GUIListViewEx_Close($iLV_Events) _GUIListViewEx_Close($iLV_Volunteers) GUIRegisterMsg($WM_NOTIFY, "") Exit Func MainFormClose() Exit EndFunc ;==>MainFormClose Func EventFullList() _GUIListViewEx_Insert("1|September 23, 2012|AM|Sheila Blue,Dan Black") _GUIListViewEx_Insert("2|December 3, 2012|Afternoon|Dan Black,Paul Green") _GUIListViewEx_Insert("3|February 18, 2013|11:00-18:00|Sheila Blue,Dan Black,Paul Green") _GUIListViewEx_Insert("6|February 14, 2013|Evening|Mary Pigment,Dan Black,Paul Green") _GUIListViewEx_Insert("7|January 31, 2013|All Day|Mary Pigment,Dan Black,Sheila Blue,Paul Green") EndFunc ;==>EventFullList Func VolunteerFullList() _GUIListViewEx_Insert("1|Dan Black|Parent|(514)345-6789|(514)345-9876|(608)345-1234|253 Temple Drive|Montreal|QC|H2N3M4|Coordinator") _GUIListViewEx_Insert("2|Sheila Blue|Other|(514)345-7733|(514)655-4562|(608)345-1234|123 Templeton|Montreal|QC|H2N4Q3|Old Coordinator") _GUIListViewEx_Insert("6|Mary Pigment|Staff|(519)242-2020|(519)356-0176|(519)675-1201|21st Avenue|London|ON|J7S5M9|Principal") _GUIListViewEx_Insert("7|Paul Green|Friend / Family|(514)349-6699|(514)349-5555|(514)698-9857|423 Happle / Apt 12|Toronto|ON|L4P9J8|") EndFunc ;==>VolunteerFullList Func ListViewEventsClick() _GUICtrlTab_SetCurFocus($TabVol, $T_Event) _GUIListViewEx_SetActive($iLV_Events) GUICtrlSetState($MenuEventEdit, $GUI_ENABLE) GUICtrlSetState($MenuEventDelete, $GUI_ENABLE) GUICtrlSetState($MenuVolunteerEdit, $GUI_DISABLE) GUICtrlSetState($MenuVolunteerDelete, $GUI_DISABLE) EndFunc ;==>ListViewEventsClick Func ListViewVolunteersClick() _GUICtrlTab_SetCurFocus($TabVol, $T_Volunteer) _GUIListViewEx_SetActive($iLV_Volunteers) GUICtrlSetState($MenuEventEdit, $GUI_DISABLE) GUICtrlSetState($MenuEventDelete, $GUI_DISABLE) GUICtrlSetState($MenuVolunteerEdit, $GUI_ENABLE) GUICtrlSetState($MenuVolunteerDelete, $GUI_ENABLE) EndFunc ;==>ListViewVolunteersClick Func MenuEventAddClick() ListViewEventsClick() ; CreateEvent(False, $MainForm) MsgBox(0, "Add", "Add new Event", 5) GUISetState(@SW_SHOW) EndFunc ;==>MenuEventAddClick Func MenuEventEditClick() ListViewEventsClick() $id = GUICtrlRead($ListViewEvents) If ($id = 0) Then MsgBox(36, "Error", "Nothing selected in the list for Editing", 5) Else ; InitEvent(GUICtrlRead($id)) ; CreateEvent(True, $MainForm) MsgBox(0, "Edit", "ID (" & $id & ")", 5) EndIf GUISetState(@SW_SHOW) EndFunc ;==>MenuEventEditClick Func MenuEventDeleteClick() ListViewEventsClick() $id = GUICtrlRead($ListViewEvents) If ($id = 0) Then MsgBox(36, "Error", "Nothing selected in the list for deletion.", 5) Else $str = StringSplit(GUICtrlRead($id), "|", 1) if (MsgBox(36, $L_AREYOUSURE, $M_DELETE & $L_EVENT & "'" & $str[2] & ", " & $str[3] & "'?") = 6) Then ; EventDeleteKey($str[1]) _GUIListViewEx_Delete() MsgBox(0, "DELETE'd", "Key (" & $str[1] & ")", 5) EndIf EndIf EndFunc ;==>MenuEventDeleteClick Func MenuVolunteerAddClick() ListViewVolunteersClick() ; CreateVolunteer(False, $MainForm) MsgBox(0, "Add", "Add new Volunteer", 5) GUISetState(@SW_SHOW) EndFunc ;==>MenuVolunteerAddClick Func MenuVolunteerEditClick() ListViewVolunteersClick() $id = GUICtrlRead($ListViewVolunteers) If ($id = 0) Then MsgBox(36, "Error", "Nothing selected in the list for Editing", 5) Else ; InitVolunteer(GUICtrlRead($id)) ; CreateVolunteer(True, $MainForm) MsgBox(0, "Edit", "ID (" & $id & ")", 5) EndIf GUISetState(@SW_SHOW) EndFunc ;==>MenuVolunteerEditClick Func MenuVolunteerDeleteClick() ListViewVolunteersClick() $id = GUICtrlRead($ListViewVolunteers) If ($id = 0) Then MsgBox(36, "Error", "Nothing selected in the list for deletion.", 5) Else $str = StringSplit(GUICtrlRead($id), "|", 1) if (MsgBox(36, $L_AREYOUSURE, $M_DELETE & $L_VOLUNTEER & "'" & $str[2] & "'?") = 6) Then ; VolunteerDeleteKey($str[1]) _GUIListViewEx_Delete() MsgBox(0, "DELETE'd", "Key (" & $str[1] & ")", 5) EndIf EndIf EndFunc ;==>MenuVolunteerDeleteClick Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo $hWndListView1 = GUICtrlGetHandle($ListViewEvents) $hWndListView2 = GUICtrlGetHandle($ListViewVolunteers) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView1 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) $text = _GUICtrlListView_GetItemText($ListViewEvents, DllStructGetData($tInfo, "Index")) _GUICtrlStatusBar_SetText($StatusBar, "You clicked on: " & $text) ; _GUICtrlListView_SetItemSelected($ListViewEvents, DllStructGetData($tInfo, "Index")) Return $GUI_RUNDEFMSG ; No return value Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) $text = _GUICtrlListView_GetItemText($ListViewEvents, DllStructGetData($tInfo, "Index")) _GUICtrlStatusBar_SetText($StatusBar, "You double-clicked on: " & $text) Return $GUI_RUNDEFMSG ; DO EDIT HERE ; No return value Case $NM_RETURN ; The control has the input focus and that the user has pressed the ENTER key $text = _GUICtrlListView_GetItemText($ListViewEvents, DllStructGetData($tInfo, "Index")) _GUICtrlStatusBar_SetText($StatusBar, "You hit ENTER on: " & $text) EndSwitch Case $hWndListView2 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) $text = _GUICtrlListView_GetItemText($ListViewVolunteers, DllStructGetData($tInfo, "Index")) _GUICtrlStatusBar_SetText($StatusBar, "You clicked on: " & $text) ; _GUICtrlListView_SetItemSelected($ListViewVolunteers, DllStructGetData($tInfo, "Index")) ;Return $GUI_RUNDEFMSG ; No return value Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) $text = _GUICtrlListView_GetItemText($ListViewVolunteers, DllStructGetData($tInfo, "Index")) _GUICtrlStatusBar_SetText($StatusBar, "You double-clicked on: " & $text) ;Return $GUI_RUNDEFMSG ; No return value ; DO EDIT HERE Case $NM_RETURN ; The control has the input focus and that the user has pressed the ENTER key $text = _GUICtrlListView_GetItemText($ListViewVolunteers, DllStructGetData($tInfo, "Index")) _GUICtrlStatusBar_SetText($StatusBar, "You hit ENTER on: " & $text) ; No return value ; DO EDIT HERE EndSwitch EndSwitch ; And here we call the UDF WM_NOTIFY handler _GUIListViewEx_WM_NOTIFY_Handler($hWnd, $iMsg, $iwParam, $ilParam) Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 24, 2013 Moderators Share Posted February 24, 2013 Garp99HasSpoken, You need to set an Event for the main Tab control and then see which TabItem has been clicked: expandcollapse popup#include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) $hGUI = GUICreate("Test", 500, 500) GUISetOnEvent($GUI_EVENT_CLOSE, "_On_Exit") $cTab = GUICtrlCreateTab(10, 10, 400, 400) GUICtrlSetOnEvent(-1, "_On_Tab") $cTab_0 = GUICtrlCreateTabItem("Tab 0") $cTab_1 = GUICtrlCreateTabItem("Tab 1") $cTab_2 = GUICtrlCreateTabItem("Tab 2") $cTab_3 = GUICtrlCreateTabItem("Tab 3") GUISetState() While 1 Sleep(10) WEnd Func _On_Tab() Switch GUICtrlRead($cTab) Case 0 MsgBox(0, "Hi", "Tab 0 selected") Case 1 MsgBox(0, "Hi", "Tab 1 selected") Case 2 MsgBox(0, "Hi", "Tab 2 selected") Case 3 MsgBox(0, "Hi", "Tab 3 selected") EndSwitch EndFunc Func _On_Exit() Exit EndFunc All clear? M23  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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
Exit Posted February 24, 2013 Share Posted February 24, 2013 Just to show a shorter solution derived from the above script. #include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) $hGUI = GUICreate("Test", 500, 500) GUISetOnEvent($GUI_EVENT_CLOSE, "_On_Exit") $cTab = GUICtrlCreateTab(10, 10, 400, 400) GUICtrlSetOnEvent(-1, "_On_Tab") $cTab_0 = GUICtrlCreateTabItem("Tab 0") $cTab_1 = GUICtrlCreateTabItem("Tab 1") $cTab_2 = GUICtrlCreateTabItem("Tab 2") $cTab_3 = GUICtrlCreateTabItem("Tab 3") GUISetState() While Sleep(999999) WEnd Func _On_Tab() MsgBox(0, "Hi", "Tab " & GUICtrlRead($cTab) & " selected", 1) EndFunc ;==>_On_Tab Func _On_Exit() Exit EndFunc ;==>_On_Exit App: Au3toCmd       UDF: _SingleScript()                 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 24, 2013 Moderators Share Posted February 24, 2013 Exit,Nothing wrong with what you posted, but if you look inside the posted script, the OP wants to run separate functions depending on the tab clicked. That is why I used a Switch structure in my response as it will best help him in his own code. M23  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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
Garp99HasSpoken Posted February 24, 2013 Author Share Posted February 24, 2013 Thanks again Melba23 -- did the trick. Working now For the benefit of others, here's the fixed code. expandcollapse popup;Autoit Options ; #NoTrayIcon ;No Tray Icon Opt("GUIOnEventMode", 1) Opt("WinTextMatchMode", 1) ;1=complete, 2=quick Opt("WinTitleMatchMode", 3) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase Opt("GUICloseOnESC", 0) ;1=ESC closes, 0=ESC won't close Opt("GUIResizeMode", 802) ; Opt("GUIResizeMode", 1) #Include <String.au3> #include <Date.au3> #Include <WinAPI.au3> #include <File.au3> #include <GuiTab.au3> ;#include <GDIPlus.au3> #include <GUIListBox.au3> #include <GuiListView.au3> #include <GuiScrollBars.au3> #include <GuiStatusBar.au3> #include <GuiToolbar.au3> ; Constants includes #include <ListViewConstants.au3> #include <TabConstants.au3> #include <ToolbarConstants.au3> #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <DateTimeConstants.au3> #include <GUIConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include "GUIListViewEx.au3" ; Tab groups Global Const $L_VOLUNTEERS = " Volunteers " Global Const $L_VOLUNTEER = "Volunteer" Global Const $L_EVENTS = " Events " Global Const $L_EVENT = "Event" ; Tab items Global Const $T_Event = 0 Global Const $T_Volunteer = 1 ; Menus Global Const $M_EVENT = "Even&t" Global Const $M_VOLUNTEER = "&Volunteer" Global Const $M_OPTIONS = "&Go To..." Global Const $M_ADD = "Add " Global Const $M_EDIT = "Edit " Global Const $M_DELETE = "Delete " ; Prompts Global Const $L_AREYOUSURE = "Are You Sure?" Global Const $L_CANCELEXIT = "Cancel all changes and exit?" ;Versions Info Global $ProgName = "Volunteer Coordinator" Global $VersionBuild = "20130213" ;YEAR|MON|DAY Global $ProgVersion = "0.1" GLOBAL $AboutVersion = "2013.02.13 (" & $ProgVersion & ")" Global $ProgWidth =1024, $ProgHeight = 720 Local $sWidth = 400, $sHeight = 350 Local $hToolbar = 40, $hStatus = 40, $hTabs = $hToolbar+30, $hLists = ($ProgHeight - $hTabs - $hStatus - $hToolbar) #Region ### START Koda GUI section ### Form=R:\AutoIt Examples\koda_2008-09-03\Forms\VolunteerCoordinator.kxf Global $MainForm = GUICreate($ProgName, $ProgWidth, $ProgHeight, (@DesktopWidth - $ProgWidth) / 2, (@DesktopHeight - $ProgHeight) / 2, $WS_SIZEBOX + $WS_SYSMENU ) GUISetState(@SW_HIDE) GUISetBkColor(0xA6CAF0) GUISetOnEvent($GUI_EVENT_CLOSE, "MainFormClose") GUISetOnEvent($GUI_EVENT_MINIMIZE, "") GUISetOnEvent($GUI_EVENT_MAXIMIZE, "") GUISetOnEvent($GUI_EVENT_RESTORE, "") Global $TabVol = GUICtrlCreateTab(1, $hTabs-$hToolbar, $ProgWidth-2, $hToolbar, $TCS_TABS) GUICtrlSetOnEvent($TabVol, "TabVolClick") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Tried adding this GUICtrlSetFont(-1, 12, 400, 0, "Arial") GUICtrlSetResizing(-1, $GUI_DOCKAUTO) Global $TabSheetEvents = GUICtrlCreateTabItem($L_EVENTS) Global $ListViewEvents = GUICtrlCreateListView( _ "|Date |Type |Volunteers ", _ 2, $hTabs, $ProgWidth-4, $hLists, BitOr($LVS_SHOWSELALWAYS, $LVS_SINGLESEL)) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") ; Initiate LVEx - no count parameter - default insert mark colour (black) $iLV_Events = _GUIListViewEx_Init($ListViewEvents, "", 0, 0, True, True) _GUIListViewEx_SetActive($iLV_Events) EventFullList() _GUICtrlListView_SetColumnWidth($ListViewEvents, 0, 0) ; hidden For $i=1 To 3 _GUICtrlListView_SetColumnWidth($ListViewEvents, $i, $LVSCW_AUTOSIZE_USEHEADER) Next GUICtrlSetOnEvent($ListViewEvents, "ListViewEventsClick") Global $TabSheetVolunteers = GUICtrlCreateTabItem($L_VOLUNTEERS) GUICtrlSetOnEvent($TabSheetVolunteers, "ListViewVolunteersClick") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Tried adding this Global $ListViewVolunteers = GUICtrlCreateListView( _ "|Name |Type |Home |Work |Cell |Address |City |Prov|Postal|Notes ", _ 2, $hTabs, $ProgWidth-4, $hLists, BitOr($LVS_SHOWSELALWAYS, $LVS_SINGLESEL)) GUICtrlSetFont($ListViewVolunteers, 10, 400, 0, "MS Sans Serif") ; Initiate LVEx - no count parameter - default insert mark colour (black) $iLV_Volunteers = _GUIListViewEx_Init($ListViewVolunteers, "", 0, 0, True, True) _GUIListViewEx_SetActive($iLV_Volunteers) VolunteerFullList() _GUICtrlListView_SetColumnWidth($ListViewVolunteers, 0, 0) ; hidden For $i=1 To 10 _GUICtrlListView_SetColumnWidth($ListViewVolunteers, $i, $LVSCW_AUTOSIZE_USEHEADER) Next Local $fSort = False ; passed ByRef _GUICtrlListView_SimpleSort($ListViewVolunteers, $fSort, 1) GUICtrlSetOnEvent($ListViewVolunteers, "ListViewVolunteersClick") GUICtrlCreateTabItem("") ;end of tabs sleep(500) ;==> EVENT menu Local $MenuEvent = GUICtrlCreateMenu($M_EVENT) Local $MenuEventAdd = GUICtrlCreateMenuItem($M_ADD & $L_EVENT & @tab & "F9", $MenuEvent) GUICtrlSetOnEvent(-1, "MenuEventAddClick") Local $MenuEventEdit = GUICtrlCreateMenuItem($M_EDIT & $L_EVENT & @tab & "F10", $MenuEvent) GUICtrlSetOnEvent(-1, "MenuEventEditClick") Local $MenuEventDelete = GUICtrlCreateMenuItem($M_DELETE & $L_EVENT & @tab & "", $MenuEvent) GUICtrlSetOnEvent(-1, "MenuEventDeleteClick") ;==> VOLUNTEER menu Local $MenuVolunteer = GUICtrlCreateMenu($M_VOLUNTEER) Local $MenuVolunteerAdd = GUICtrlCreateMenuItem($M_ADD & $L_VOLUNTEER & @tab & "F11", $MenuVolunteer) GUICtrlSetOnEvent(-1, "MenuVolunteerAddClick") Local $MenuVolunteerEdit = GUICtrlCreateMenuItem($M_EDIT & $L_VOLUNTEER & @tab & "F12", $MenuVolunteer) GUICtrlSetOnEvent(-1, "MenuVolunteerEditClick") Local $MenuVolunteerDelete = GUICtrlCreateMenuItem($M_DELETE & $L_VOLUNTEER & @tab & "", $MenuVolunteer) GUICtrlSetOnEvent(-1, "MenuVolunteerDeleteClick") ;==> OPTIONS menu Local $MenuOptions = GUICtrlCreateMenu($M_OPTIONS) Local $MenuEventDates = GUICtrlCreateMenuItem($L_EVENT & " Dates" & @tab & "F5", $MenuOptions) GUICtrlSetOnEvent(-1, "ListViewEventsClick") Local $MenuVolList = GUICtrlCreateMenuItem($L_VOLUNTEER & " List" & @tab & "F6", $MenuOptions) GUICtrlSetOnEvent(-1, "ListViewVolunteersClick") Local $MainForm_AccelTable[9][2] = [ ["^!t", $MenuEvent],["{F9}", $MenuEventAdd],["{F10}", $MenuEventEdit], ["^!v", $MenuVolunteer],["{F11}", $MenuVolunteerAdd],["{F12}", $MenuVolunteerEdit], ["^!g", $MenuOptions],["{F5}", $MenuEventDates],["{F6}", $MenuVolList] ] GUISetAccelerators($MainForm_AccelTable, $MainForm) Global $StatusBar = _GUICtrlStatusBar_Create($MainForm) _GUICtrlStatusBar_SetSimple($StatusBar) _GUICtrlStatusBar_SetText($StatusBar, "Simple status bar window text goes here.") _GUICtrlStatusBar_SetMinHeight($StatusBar, $hStatus) GUISetFont(10, 400, 0, "MS Sans Serif", $MainForm) GUISetOnEvent($GUI_EVENT_CLOSE, "MainFormClose") GUISetOnEvent($GUI_EVENT_RESTORE, "") GUISetOnEvent($GUI_EVENT_MAXIMIZE, "") GUISetOnEvent($GUI_EVENT_RESIZED, "") _GUIListViewEx_DragRegister(True, False, False) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") #EndRegion ### END Koda GUI section ### GUISwitch($MainForm) GUISetState(@SW_SHOW) ; Set the Events ListView as active ;_GUIListViewEx_SetActive($iLV_Events) ListViewEventsClick() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< should set Volunteer menu options to DISABLED While 1 sleep(100) WEnd GUISetState(@SW_HIDE) GUIDelete() _GUIListViewEx_Close($iLV_Events) _GUIListViewEx_Close($iLV_Volunteers) GUIRegisterMsg($WM_NOTIFY, "") Exit Func MainFormClose() Exit EndFunc ;==>MainFormClose Func EventFullList() _GUIListViewEx_Insert("1|September 23, 2012|AM|Sheila Blue,Dan Black") _GUIListViewEx_Insert("2|December 3, 2012|Afternoon|Dan Black,Paul Green") _GUIListViewEx_Insert("3|February 18, 2013|11:00-18:00|Sheila Blue,Dan Black,Paul Green") _GUIListViewEx_Insert("6|February 14, 2013|Evening|Mary Pigment,Dan Black,Paul Green") _GUIListViewEx_Insert("7|January 31, 2013|All Day|Mary Pigment,Dan Black,Sheila Blue,Paul Green") EndFunc ;==>EventFullList Func VolunteerFullList() _GUIListViewEx_Insert("1|Dan Black|Parent|(514)345-6789|(514)345-9876|(608)345-1234|253 Temple Drive|Montreal|QC|H2N3M4|Coordinator") _GUIListViewEx_Insert("2|Sheila Blue|Other|(514)345-7733|(514)655-4562|(608)345-1234|123 Templeton|Montreal|QC|H2N4Q3|Old Coordinator") _GUIListViewEx_Insert("6|Mary Pigment|Staff|(519)242-2020|(519)356-0176|(519)675-1201|21st Avenue|London|ON|J7S5M9|Principal") _GUIListViewEx_Insert("7|Paul Green|Friend / Family|(514)349-6699|(514)349-5555|(514)698-9857|423 Happle / Apt 12|Toronto|ON|L4P9J8|") EndFunc ;==>VolunteerFullList Func ListViewEventsClick() _GUICtrlTab_SetCurFocus($TabVol, $T_Event) _GUIListViewEx_SetActive($iLV_Events) GUICtrlSetState($MenuEventEdit, $GUI_ENABLE) GUICtrlSetState($MenuEventDelete, $GUI_ENABLE) GUICtrlSetState($MenuVolunteerEdit, $GUI_DISABLE) GUICtrlSetState($MenuVolunteerDelete, $GUI_DISABLE) EndFunc ;==>ListViewEventsClick Func ListViewVolunteersClick() _GUICtrlTab_SetCurFocus($TabVol, $T_Volunteer) _GUIListViewEx_SetActive($iLV_Volunteers) GUICtrlSetState($MenuEventEdit, $GUI_DISABLE) GUICtrlSetState($MenuEventDelete, $GUI_DISABLE) GUICtrlSetState($MenuVolunteerEdit, $GUI_ENABLE) GUICtrlSetState($MenuVolunteerDelete, $GUI_ENABLE) EndFunc ;==>ListViewVolunteersClick Func TabVolClick() Switch GUICtrlRead($TabVol) Case $T_Event ; MsgBox(0, "Hi", "Event Tab selected") ListViewEventsClick() Case $T_Volunteer ; MsgBox(0, "Hi", "Volunteer Tab selected") ListViewVolunteersClick() EndSwitch EndFunc ;==>TabVolClick Func MenuEventAddClick() ListViewEventsClick() ; CreateEvent(False, $MainForm) MsgBox(0, "Add", "Add new Event", 5) GUISetState(@SW_SHOW) EndFunc ;==>MenuEventAddClick Func MenuEventEditClick() ListViewEventsClick() $id = GUICtrlRead($ListViewEvents) If ($id = 0) Then MsgBox(36, "Error", "Nothing selected in the list for Editing", 5) Else ; InitEvent(GUICtrlRead($id)) ; CreateEvent(True, $MainForm) MsgBox(0, "Edit", "ID (" & $id & ")", 5) EndIf GUISetState(@SW_SHOW) EndFunc ;==>MenuEventEditClick Func MenuEventDeleteClick() ListViewEventsClick() $id = GUICtrlRead($ListViewEvents) If ($id = 0) Then MsgBox(36, "Error", "Nothing selected in the list for deletion.", 5) Else $str = StringSplit(GUICtrlRead($id), "|", 1) if (MsgBox(36, $L_AREYOUSURE, $M_DELETE & $L_EVENT & "'" & $str[2] & ", " & $str[3] & "'?") = 6) Then ; EventDeleteKey($str[1]) _GUIListViewEx_Delete() MsgBox(0, "DELETE'd", "Key (" & $str[1] & ")", 5) EndIf EndIf EndFunc ;==>MenuEventDeleteClick Func MenuVolunteerAddClick() ListViewVolunteersClick() ; CreateVolunteer(False, $MainForm) MsgBox(0, "Add", "Add new Volunteer", 5) GUISetState(@SW_SHOW) EndFunc ;==>MenuVolunteerAddClick Func MenuVolunteerEditClick() ListViewVolunteersClick() $id = GUICtrlRead($ListViewVolunteers) If ($id = 0) Then MsgBox(36, "Error", "Nothing selected in the list for Editing", 5) Else ; InitVolunteer(GUICtrlRead($id)) ; CreateVolunteer(True, $MainForm) MsgBox(0, "Edit", "ID (" & $id & ")", 5) EndIf GUISetState(@SW_SHOW) EndFunc ;==>MenuVolunteerEditClick Func MenuVolunteerDeleteClick() ListViewVolunteersClick() $id = GUICtrlRead($ListViewVolunteers) If ($id = 0) Then MsgBox(36, "Error", "Nothing selected in the list for deletion.", 5) Else $str = StringSplit(GUICtrlRead($id), "|", 1) if (MsgBox(36, $L_AREYOUSURE, $M_DELETE & $L_VOLUNTEER & "'" & $str[2] & "'?") = 6) Then ; VolunteerDeleteKey($str[1]) _GUIListViewEx_Delete() MsgBox(0, "DELETE'd", "Key (" & $str[1] & ")", 5) EndIf EndIf EndFunc ;==>MenuVolunteerDeleteClick Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo $hWndListView1 = GUICtrlGetHandle($ListViewEvents) $hWndListView2 = GUICtrlGetHandle($ListViewVolunteers) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView1 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) $text = _GUICtrlListView_GetItemText($ListViewEvents, DllStructGetData($tInfo, "Index")) _GUICtrlStatusBar_SetText($StatusBar, "You clicked on: " & $text) ; _GUICtrlListView_SetItemSelected($ListViewEvents, DllStructGetData($tInfo, "Index")) Return $GUI_RUNDEFMSG ; No return value Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) $text = _GUICtrlListView_GetItemText($ListViewEvents, DllStructGetData($tInfo, "Index")) _GUICtrlStatusBar_SetText($StatusBar, "You double-clicked on: " & $text) Return $GUI_RUNDEFMSG ; DO EDIT HERE ; No return value Case $NM_RETURN ; The control has the input focus and that the user has pressed the ENTER key $text = _GUICtrlListView_GetItemText($ListViewEvents, DllStructGetData($tInfo, "Index")) _GUICtrlStatusBar_SetText($StatusBar, "You hit ENTER on: " & $text) EndSwitch Case $hWndListView2 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) $text = _GUICtrlListView_GetItemText($ListViewVolunteers, DllStructGetData($tInfo, "Index")) _GUICtrlStatusBar_SetText($StatusBar, "You clicked on: " & $text) ; _GUICtrlListView_SetItemSelected($ListViewVolunteers, DllStructGetData($tInfo, "Index")) ;Return $GUI_RUNDEFMSG ; No return value Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) $text = _GUICtrlListView_GetItemText($ListViewVolunteers, DllStructGetData($tInfo, "Index")) _GUICtrlStatusBar_SetText($StatusBar, "You double-clicked on: " & $text) ;Return $GUI_RUNDEFMSG ; No return value ; DO EDIT HERE Case $NM_RETURN ; The control has the input focus and that the user has pressed the ENTER key $text = _GUICtrlListView_GetItemText($ListViewVolunteers, DllStructGetData($tInfo, "Index")) _GUICtrlStatusBar_SetText($StatusBar, "You hit ENTER on: " & $text) ; No return value ; DO EDIT HERE EndSwitch EndSwitch ; And here we call the UDF WM_NOTIFY handler _GUIListViewEx_WM_NOTIFY_Handler($hWnd, $iMsg, $iwParam, $ilParam) Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now