Sign in to follow this  
Followers 0
ijourneaux

PC is at login screen - _GUICtrlTreeView_SetSelected($hWnd, $hItem) is not successful

8 posts in this topic

I have a script that works correctly when the PC is logged into but failes when the PC is at the login screen.

The command in question that is failing is 

_GUICtrlTreeView_SetSelected($hWnd, $hItem)

where I am selecting an item in a treeview.

This might not be surprising since hte control is behind the login screen. Is there a way to control the tree view directly?

Ian

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

 

The command in question that is failing is 

_GUICtrlTreeView_SetSelected($hWnd, $hItem)

where I am selecting an item in a treeview.

 

I don't think that problem is in mentioned function.

I think that you incorectly obtained wrong (zero?) handle to treeview by using some function depending on active window which is wrong on locked station.

Show your code for getting treeview's hWnd ...

Also look here

https://www.autoitscript.com/wiki/FAQ#Why_doesn.27t_my_script_work_on_a_locked_workstation.3F

Edited by Zedna

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Also very important is to distinguish between two very different states:

- user is looged in and station is only locked

- user is not looged in

Login screen can occur at both of them ...

Edited by Zedna

Share this post


Link to post
Share on other sites

In my case, the user is logged and the station is locked.

It seems I have a valid handle to the treeview using

$IFMTreeView = ControlGetHandle($InfostoreTitle, "", "[CLASS:TreeViewWndClass; INSTANCE:2]")
 
and a call to 
 
$hWnd = _GUICtrlTreeView_GetCount($IFMTreeView)
 
retruns the correct count, in my case 3.
 
I try to select items in the tree using
 
if(_GUICtrlTreeView_SetSelected($hWnd, $hItem) = False) then Return False
if(_GUICtrlTreeView_SetFocused($hWnd, $hItem) = False) then Return False
if(_GUICtrlTreeView_ClickItem($hWnd, $hItem) = False) then Return False
(overkill)
 
Nothing is returned False
 
2015-04-13 12:14:27 : hWnd = 0x01EF03BC
2015-04-13 12:14:27 : hItem = 0x03CC1418
 
Where $hItem is obtained by 
 
$hItem = _GUICtrlTreeView_GetFirstItem($hWnd)
or
$hItem1 = _GUICtrlTreeView_GetFirstChild($IFMTreeView, $hItem)
 
 
This worked if the workstation is not locked.
 
If there isn't anything obviously wrong here, I will create a brief version that illustrates the problem.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

In pulling together an example, I may have figured out the problem. It is the ClickItem function. I was advancing down a branch using SetSelected. Then clicking on the item to have it load data. THis is not working when the PC is locked.

#Include <GuiTreeView.au3>
;##################################
; Options
;##################################
Opt("WinTitleMatchMode", 2)     ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
sleep(5000)
    $IFMTreeView = ControlGetHandle("InfoStore", "", "[CLASS:TreeViewWndClass; INSTANCE:2]")
    consolewrite($IFMTreeView & " : " & @error & @crlf)
    $IFMTreeCount = _GUICtrlTreeView_GetCount($IFMTreeView)
    consolewrite($IFMTreeCount & @crlf)
    $PMReel = _GUICtrlTreeView_GetFirstItem($IFMTreeView)

    $PMReelText = _GUICtrlTreeView_GetText($IFMTreeView, $PMReel)
    consolewrite("PMReel = " & $PMReelText  & "; " & $PMReel & @crlf)

    $OMCReel1 = _GUICtrlTreeView_GetFirstChild($IFMTreeView, $PMReel)
    $OMCReel1Text = _GUICtrlTreeView_GetText($IFMTreeView, $OMCReel1)
    consolewrite("OMCReel1 = " & $OMCReel1Text  & "; " & $OMCreel1 & @crlf)
    consolewrite(_GUICtrlTreeView_Expand($IFMTreeView) & @crlf)
    consolewrite(_GUICtrlTreeView_SetSelected($IFMTreeView, $OMCReel1) & @crlf)
    consolewrite(_GUICtrlTreeView_SetFocused($IFMTreeView, $OMCReel1) & @crlf)
    consolewrite(_GUICtrlTreeView_SetSelected($IFMTreeView, $PMReel, False) & @crlf)
    consolewrite(_GUICtrlTreeView_ClickItem($IFMTreeView, $OMCReel1) & @crlf)
Edited by ijourneaux

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

There are Mousexxx functions in _GUICtrlTreeView_ClickItem() so this can't work on locked station

because it will click only on locked desktop and not on treeview which is hidden (overlapped) behind this desktop.

Func _GUICtrlTreeView_ClickItem($hWnd, $hItem, $sButton = "left", $bMove = False, $iClicks = 1, $iSpeed = 0)
    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)

    Local $tRect = _GUICtrlTreeView_DisplayRectEx($hWnd, $hItem, True)
    If @error Then Return SetError(@error, @error, 0)
    ; Always click on the left-most portion of the control, not the center.  A
    ; very wide control may be off-screen which means clicking on it's center
    ; will click outside the window.
    Local $tPoint = _WinAPI_PointFromRect($tRect, False)
    _WinAPI_ClientToScreen($hWnd, $tPoint)
    Local $iX, $iY
    _WinAPI_GetXYFromPoint($tPoint, $iX, $iY)
    Local $iMode = Opt("MouseCoordMode", 1)
    If Not $bMove Then
        Local $aPos = MouseGetPos()
        _WinAPI_ShowCursor(False)
        MouseClick($sButton, $iX, $iY, $iClicks, $iSpeed)
        MouseMove($aPos[0], $aPos[1], 0)
        _WinAPI_ShowCursor(True)
    Else
        MouseClick($sButton, $iX, $iY, $iClicks, $iSpeed)
    EndIf
    Opt("MouseCoordMode", $iMode)
    Return 1
EndFunc   ;==>_GUICtrlTreeView_ClickItem

If you need to simulate invoking some functions inside external application after click in its treeview then I would recommend to analyze internal messages/WM_COMMANDS sent by treeview after clicking. You can use utility WinSpector for this.

Then you can only select desired treeview item and then call _SendMessage() with apropriate command (WM_COMMAND?) ...

EDIT: Search this forum for WinSpector, this technique was discussed here already ...

Edited by Zedna

Share this post


Link to post
Share on other sites

Thanks. Will take a looks at Winspector. Since we control the source of the application I am trying to control, I have asked the the behavior of the treeview to make it easier to control but not sure If I will get much traction on that.

Share this post


Link to post
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
Sign in to follow this  
Followers 0