Jump to content

2 small issues.


Valnurat
 Share

Recommended Posts

I have combobox, ListControl and a button.

#include <ComboConstants.au3>
#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#Include <AD.au3>
#include <Array.au3>

;Opt('MustDeclareVars', 1)

Global $aResult[0][2]
Local $aNames[4] = ["DKSO","DKKO","SELU","SEES"]
Local $hGUI = GUICreate("Find Computer Owner", 300, 200)
; Create a combobox control.
Local $idComboBox = GUICtrlCreateCombo("", 2, 2, 296, 20, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL,  $CBS_SORT)) ;$WS_VSCROLL
Local $idMylist = GUICtrlCreateList("", 2, 24, 296, 140)
GUICtrlSetLimit(-1, 200) ; to limit horizontal scrolling
Local $idClos = GUICtrlCreateButton("Close", 210, 170, 85, 25)
_AD_Open()
_GUICtrlComboBox_BeginUpdate($idComboBox)
Local $sFill = ""
For $i = 0 to UBound($aNames) -1
    Local $aUserInfo = _AD_GetObjectsInOU("OU=company,DC=ad,DC=company,DC=org","(&(objectCategory=Person)(objectclass=user)(sAMAccountName=" & $aNames[$i] & "*))","","distinguishedName,cn")
    if @error Then
        MsgBox(0,@error,@extended)
        Exit
    EndIf
    For $x = $aUserInfo[0][0] To 1 Step -1
        If $aUserInfo[$x][0] = "" Or StringInStr($aUserInfo[$x][0], "Resources") > 0 Or StringInStr($aUserInfo[$x][0], "Leavers") > 0 Or StringInStr($aUserInfo[$x][0], "Administration") > 0 Then
            _ArrayDelete($aUserInfo, $x)
        EndIf
    Next
    _ArrayConcatenate($aResult, $aUserInfo, 1)
Next
_ArrayDisplay($aResult, 'AD ' & UBound($aResult))
for $i = 0 To UBound($aResult) -1
    If $aResult[$i][0] <> "" Then
        $sFill &= $aResult[$i][1] & "|"
    EndIf
Next
$sFill = StringTrimRight($sFill, 1)
GUICtrlSetData($idComboBox, $sFill, "")
_GUICtrlComboBox_EndUpdate($idComboBox)
   ; Display the GUI.
GUISetState(@SW_SHOW, $hGUI)
Local $sComboRead = ""
; Loop until the user exits.
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $idClos
            ExitLoop
        Case $idComboBox
            $sComboRead = GUICtrlRead($idComboBox)
            Local $iIdx = _ArraySearch($aResult,$sComboRead,0,0,0,0,1,1)
            GUICtrlSetData($idMylist, "|")
            Local $aComputerOwner = _AD_GetObjectsInOU("OU=company,DC=AD,DC=company,DC=ORG","(&(objectclass=computer)(managedby=" & $aResult[$iIdx][0] & "))",Default,"cn")
            If $aComputerOwner <> "" Then
                For $i = 1 to $aComputerOwner[0]
                    GUICtrlSetData($idMylist, $aComputerOwner[$i] & "|")
                Next
            Else
                GUICtrlSetData($idMylist, "No computer|")
            EndIf
    EndSwitch
WEnd
_AD_Close()

; Delete the previous GUI and all controls.
GUIDelete($hGUI)

How can I, when keypressed, change the name in the combobox runtime instead of using the mouse to scroll down to the name I want?

How can I dobbelt click with mouse on the computername in my ListControl to start another application?

Yours sincerely

Kenneth.

Link to comment
Share on other sites

  • Moderators

@Valnurat you have been around long enough to know you need to wait 24 hours before bumping your thread.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Link to comment
Share on other sites

As requested.

#include <WindowsConstants.au3>
#include <ComboConstants.au3>
#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#Include <AD.au3>
#include <Array.au3>

Opt('MustDeclareVars', 1)

Global $aResult[0][2]
Local $hGUI = GUICreate("Find Computer Owner", 300, 200)
; Create a combobox control.
Local $idComboBox = GUICtrlCreateCombo("", 2, 2, 296, 20, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL, $WS_VSCROLL, $CBS_SORT)) ;$WS_VSCROLL
Local $idMylist = GUICtrlCreateList("", 2, 24, 296, 140)
GUICtrlSetLimit(-1, 200) ; to limit horizontal scrolling
Local $idClos = GUICtrlCreateButton("Close", 210, 170, 85, 25)
_GUICtrlComboBox_BeginUpdate($idComboBox)
Local $sFill = ""
$sFill = "Aardwolf|Adouri|African black crake|African buffalo|African bush squirrel|African clawless otter|African darter|African elephant|African fish eagle"
GUICtrlSetData($idComboBox, $sFill, "")
_GUICtrlComboBox_EndUpdate($idComboBox)
   ; Display the GUI.
GUISetState(@SW_SHOW, $hGUI)
Local $sComboRead = ""
; Loop until the user exits.
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $idClos
            ExitLoop
        Case $idComboBox
            $sComboRead = GUICtrlRead($idComboBox)
            MsgBox(0,"",$sComboRead)
    EndSwitch
WEnd

; Delete the previous GUI and all controls.
GUIDelete($hGUI)

 

Yours sincerely

Kenneth.

Link to comment
Share on other sites

If the combobox control is focused/selected, the arrow keys already seem to work.  Do you want the keys to always change the selection whether the control has focus or not?  

If so, I think you can either do so with a custom message handler, by employing GuiSetAccelerators and dummy controls, or using HotKeys.  For the double-click on the listview, I think you're only option is to create a custom message handler.  

The _GUICtrlListView_Create help file example has a working example of how to handle the double click of a listview control.  There is a lot of extra (commented out) code in the WM_NOTIFY function (which is the custom message handler), but may be worth having a look to further understand message events. The piece that is relevant to the double click action/message is where it says Case $NM_DBLCLK.  I pasted in the example below, but removed the other messages/cases and commented out lines.  Double-clicking an item in the listview prints debug info into the console of the SciTE editor.

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

Global $g_hListView

Example()

Func Example()
    Local $hGUI, $hImage
    $hGUI = GUICreate("(UDF Created) ListView Create", 400, 300)

    $g_hListView = _GUICtrlListView_Create($hGUI, "", 2, 2, 394, 268)
    _GUICtrlListView_SetExtendedListViewStyle($g_hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
    GUISetState(@SW_SHOW)

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    ; Load images
    $hImage = _GUIImageList_Create()
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($g_hListView, 0xFF0000, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($g_hListView, 0x00FF00, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($g_hListView, 0x0000FF, 16, 16))
    _GUICtrlListView_SetImageList($g_hListView, $hImage, 1)

    ; Add columns
    _GUICtrlListView_InsertColumn($g_hListView, 0, "Column 1", 100)
    _GUICtrlListView_InsertColumn($g_hListView, 1, "Column 2", 100)
    _GUICtrlListView_InsertColumn($g_hListView, 2, "Column 3", 100)

    ; Add items
    _GUICtrlListView_AddItem($g_hListView, "Row 1: Col 1", 0)
    _GUICtrlListView_AddSubItem($g_hListView, 0, "Row 1: Col 2", 1)
    _GUICtrlListView_AddSubItem($g_hListView, 0, "Row 1: Col 3", 2)
    _GUICtrlListView_AddItem($g_hListView, "Row 2: Col 1", 1)
    _GUICtrlListView_AddSubItem($g_hListView, 1, "Row 2: Col 2", 1)
    _GUICtrlListView_AddItem($g_hListView, "Row 3: Col 1", 2)

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
    ; Local $tBuffer
    $hWndListView = $g_hListView
    If Not IsHWnd($g_hListView) Then $hWndListView = GUICtrlGetHandle($g_hListView)

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    _DebugPrint("$NM_DBLCLK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode & @CRLF & _
                            "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @CRLF & _
                            "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @CRLF & _
                            "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @CRLF & _
                            "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @CRLF & _
                            "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @CRLF & _
                            "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @CRLF & _
                            "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @CRLF & _
                            "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @CRLF & _
                            "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags"))
                    ; No return value
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _DebugPrint($s_Text, $sLine = @ScriptLineNumber)
    ConsoleWrite( _
            "!===========================================================" & @CRLF & _
            "+======================================================" & @CRLF & _
            "-->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text & @CRLF & _
            "+======================================================" & @CRLF)
EndFunc   ;==>_DebugPrint

Take not that the custom message handler only deals with handles and not AutoIt control IDs.  In the example, the WM_COMMAND function ensures the control handle is used, so no need or worry to have to change your ListView from the Native control creation func to the UDF version.

$hWndListView = $g_hListView
If Not IsHWnd($g_hListView) Then $hWndListView = GUICtrlGetHandle($g_hListView)


Try some things out and let us know if/when you get stuck.

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