taietel Posted January 9, 2011 Posted January 9, 2011 (edited) The issue is not with the Listview, but with with myself. I'm trying to switch to a GUI when the column is clicked, but when the second gui appears, the focus is still on the main gui. So far I failed with GuiSwitch and GuiSetState. Any advice is more than welcome!testLV.au3 Edited January 9, 2011 by taietel Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text
Moderators Melba23 Posted January 9, 2011 Moderators Posted January 9, 2011 taietel,I do not understand what you mean by "the focus is still on the main gui". When I click on the column header the secondary GUI appears and takes focus. If I set the focus to the combo or input using GUICtrlSetState it works without problem. So could you please be a little more specific. However, you do have a MAJOR problem with your script. You are calling a function (_GUI_Sort) from within a message handler when the function contains a blocking infinite loop. This is likely to crash your script in pretty short order - as the Help file clearly states:"Warning: blocking of running user functions which executes window messages with commands such as "Msgbox()" can lead to unexpected behavior, the return to the system should be as fast as possible !!!"The way to do this correctly is to set a flag in the handler and then run the function from your main script like this - look for the <<<<<< lines as usual: expandcollapse popup#include <File.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <TreeViewConstants.au3> #include <WindowsConstants.au3> #include <GuiTreeView.au3> #include <GuiListView.au3> Global $aCSV Global $hGUI, $hSearch Global $IDColumn Global $fColFlag = False ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ;some data Global $aCSV[50], $arItems[UBound($aCSV)] $aCSV[0] = "Col0|Col1|Col2|Col3|Col4" For $i = 1 To 49 $aCSV[$i] = "Item" & $i & " 0|" & "SubItem" & $i & " 1|" & "SubItem" & $i & " 2|" & "SubItem" & $i & " 3|" & "SubItem" & $i & " 4" Next $hForm = GUICreate("CVS Listview", 620, 250, -1, -1) $hListView = GUICtrlCreateListView($aCSV[0], 10, 10, 600, 210) For $i = 1 To UBound($aCSV) - 1 $s_temp = $aCSV[$i] GUICtrlCreateListViewItem($s_temp, $hListView) Next GUISetState() GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") While 1 Sleep(10) Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch If $fColFlag Then ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $fColFlag = False _GUI_Sort() EndIf WEnd Func _GUI_Sort() Local $icnSortaz, $hSortAZ, $icnSortza, $hSortZA, $cboCriteria, $hTVSelect, $btnCancel, $btnClose, $btnOK ;make the GUI at the mouse position: Local $pos = MouseGetPos() Local $iW = 190, $iH = 420 $hGUI = GUICreate("Filter/Sort", $iW, $iH, $pos[0] - $iW + 15, $pos[1] - 15, BitOR($WS_SYSMENU, $WS_POPUP, $WS_BORDER), $WS_EX_TOPMOST);BitOR($WS_EX_TOPMOST, $WS_EX_LAYERED)) GUISetBkColor(0xFFFFFF) ;AZ sort: $icnSortaz = GUICtrlCreateIcon(_Icon_AZ(), -1, 8, 8, 16, 16, BitOR($SS_NOTIFY, $WS_GROUP)) GUICtrlSetCursor(-1, 0) $hSortAZ = GUICtrlCreateLabel("&Sort A to Z", 32, 8, 61, 17) GUICtrlSetCursor(-1, 0) ;ZA sort: $icnSortza = GUICtrlCreateIcon(_Icon_ZA(), -1, 8, 30, 16, 16, BitOR($SS_NOTIFY, $WS_GROUP)) GUICtrlSetCursor(-1, 0) $hSortZA = GUICtrlCreateLabel("S&ort Z to A", 32, 30, 61, 17) GUICtrlSetCursor(-1, 0) ;Filtering: GUICtrlCreateGroup("Filter", 4, 60, $iW - 8, $iH - 100) GUICtrlCreateLabel("Criteria", $iW - 45, 74, 40, 17) GUICtrlSetColor(-1, 0x444444) $cboCriteria = GUICtrlCreateCombo("", 10, 92, $iW - 20, 23) Local $sIfText = "Equals...|Does Not Equal...|Begins With...|Ends With...|Contains...|Does Not Contain..." ;if text, then ... Local $sCriteriaSep = "----------------------------------------" Local $sIfNumber = "Greater Than...|Greater Than Or Equal To...|Less Than...|Less Than Or Equal To...|Between..." ;if number, then ... GUICtrlSetData(-1, $sIfText & "|" & $sCriteriaSep & "|" & $sIfNumber) $hSearch = GUICtrlCreateInput("Search", 10, 120, $iW - 20, 21) GUICtrlSetColor(-1, 0x444444) $hTVSelect = GUICtrlCreateTreeView(10, 146, $iW - 20, 223, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES, $WS_GROUP, $WS_TABSTOP), $WS_EX_CLIENTEDGE) $arItems[0] = GUICtrlCreateTreeViewItem("(Select All)", $hTVSelect) GUICtrlSetState(-1, $GUI_CHECKED) ;fill the treeview with data: For $i = 1 To UBound($aCSV) - 1 $arItems[$i] = GUICtrlCreateTreeViewItem("", $hTVSelect) Local $item = _GUICtrlListView_GetItemTextArray($hListView, $i - 1) GUICtrlSetData(-1, $item[$IDColumn + 1]) GUICtrlSetState(-1, $GUI_CHECKED) Next $btnOK = GUICtrlCreateButton("OK", 10, 386, 75, 25, $WS_GROUP) $btnCancel = GUICtrlCreateButton("Cancel", 106, 386, 75, 25, $WS_GROUP) $btnClose = GUICtrlCreateIcon("shell32.dll", -132, 168, 8, 16, 16, BitOR($SS_NOTIFY, $WS_GROUP)) GUICtrlSetCursor(-1, 0) GUICtrlCreateGroup("", -99, -99, 1, 1) GUICtrlCreatePic("", 1, 1, $iW - 2, $iH - 2, BitOR($GUI_SS_DEFAULT_PIC, $SS_CENTERIMAGE)) GUISetState(@SW_SHOW) GUISetState($hForm, @SW_DISABLE) GUICtrlSetState($cboCriteria, $GUI_FOCUS) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") While 1 Sleep(10) Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $icnSortaz, $hSortAZ ConsoleWrite("sorted A-Z..." & @CRLF) ;test Case $icnSortza, $hSortZA ConsoleWrite("sorted Z-A..." & @CRLF) ;test Case $btnCancel, $btnClose _Close($hGUI) Return ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< You have to get back somehow! Case $arItems[0] ;select all/none... Switch GUICtrlRead($arItems[0]) Case 257 ;check all For $i = 1 To _GUICtrlTreeView_GetCount($hTVSelect) - 1 _GUICtrlTreeView_SetChecked($hTVSelect, $arItems[$i]) Next ConsoleWrite("all checked!..." & @CRLF) ;test Case 260 ;uncheck all For $i = 1 To _GUICtrlTreeView_GetCount($hTVSelect) - 1 _GUICtrlTreeView_SetChecked($hTVSelect, $arItems[$i], False) Next ConsoleWrite("all unchecked!..." & @CRLF) ;test EndSwitch Case $arItems[1] To $arItems[UBound($aCSV) - 1] ;uncheck/check the SelectAll For $i = 1 To _GUICtrlTreeView_GetCount($hTVSelect) - 1;all but first If _GUICtrlTreeView_GetChecked($hTVSelect, $arItems[$i]) = False Then _GUICtrlTreeView_SetChecked($hTVSelect, $arItems[0], False) Next Case $btnOK Local $bifat ;checked values... For $i = 1 To _GUICtrlTreeView_GetCount($hTVSelect) - 1 If _GUICtrlTreeView_GetChecked($hTVSelect, $arItems[$i]) Then $bifat &= $i - 1 & "|" ;listview starts at 0 Next $bifat = StringTrimRight($bifat, 1) ConsoleWrite($bifat & @CRLF) ;test $bifat = "" Case $cboCriteria Local $sCriteria = GUICtrlRead($cboCriteria) If $sCriteria <> $sCriteriaSep Then ConsoleWrite($sCriteria & @CRLF) ;test EndSwitch WEnd EndFunc ;==>_GUI_Sort Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iCode, $tNMHDR, $hWndListView $hWndListView = $hListView If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView, $hListView Switch $iCode Case $LVN_COLUMNCLICK Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam) ;get the number of the column $IDColumn = DllStructGetData($tInfo, "SubItem") ;and show the gui $fColFlag = True ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< EndSwitch EndSwitch Return $__LISTVIEWCONSTANT_GUI_RUNDEFMSG EndFunc ;==>_WM_NOTIFY Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg Local $hWndFrom, $iIDFrom, $iCode, $hWndSearch If Not IsHWnd($hSearch) Then $hWndSearch = GUICtrlGetHandle($hSearch) $hWndFrom = $ilParam $iIDFrom = _WinAPI_LoWord($iwParam) $iCode = _WinAPI_HiWord($iwParam) Switch $hWndFrom Case $hSearch, $hWndSearch Switch $iCode Case $EN_CHANGE ConsoleWrite("changed" & @CRLF) Case $EN_KILLFOCUS ;if nothing was entered, set to default text If GUICtrlRead($hSearch) = "" Then GUICtrlSetData($hSearch, "Search") ConsoleWrite("lost focus" & @CRLF) ;test Case $EN_SETFOCUS ;if focused, delete the default text If GUICtrlRead($hSearch) = "Search" Then GUICtrlSetData($hSearch, "") ConsoleWrite("got focus" & @CRLF) ;test EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND Func _LV_Sort($iMode = 1) Switch $iMode Case 1 ;sort A-Z Case 2 ;sort Z-A Case Else ; EndSwitch EndFunc ;==>_LV_Sort Func _Close($hWnd) GUISetState($hForm, @SW_ENABLE) GUIDelete($hWnd) Return EndFunc ;==>_CloseI left out the icons - they were screrwing up the code tags. Please ask if you do not understand why it should be coded as above - or read the GUIRegisterMsg tutorial in the Wiki. 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
taietel Posted January 9, 2011 Author Posted January 9, 2011 Thanks Melba!I do not understand what you mean by "the focus is still on the main gui"I'm sorry, but that was the worst explanation I thought at the moment... What I had in mind was the following: when I click a column header and the second gui shows, the column header can still be clicked. I want to avoid that.Regarding the blocking, in the _Close() function there is a Return statement and I thought is enough... Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text
Moderators Melba23 Posted January 9, 2011 Moderators Posted January 9, 2011 taietel,Just disable the LV header when you creat the additional GUI: If $fColFlag Then ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ControlDisable($hForm, "", HWnd(_GUICtrlListView_GetHeader($hListView))) $fColFlag = False _GUI_Sort() ControlEnable($hForm, "", HWnd(_GUICtrlListView_GetHeader($hListView))) EndIfAs to the handler question, you really do need to get out of the handler as soon as possible. Remember Windows uses all these messages to keep everything in sync - if you end up blocking a message you can really screw up the system quite quickly. You have a entire GUIGetMsg loop in the function you were calling - if that is not "blocking" then I do not know what is! The best way is to use a flag as I showed above - then the message handler is freed quickly and you can deal with the event in the main loop in slowere time where you interfere with nothing else. 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
taietel Posted January 9, 2011 Author Posted January 9, 2011 Melba, you saved my forehead for slapping it with the keyboard. THANK YOU FOR THE SOLUTION AND THE EXPLANATIONS!!! M.I. Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text
Moderators Melba23 Posted January 9, 2011 Moderators Posted January 9, 2011 taietel,Always delighted to be of assistance. And as a fully paid up member of the "Keyboard Protection League" I have a duty to prevent them from being injured by coders' foreheads! 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
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