Sign in to follow this  
Followers 0
ReFran

Problem with WinActivate($handle)

9 posts in this topic

#1 ·  Posted (edited)

Hi,

with using WinList() I store a Winhandle ($handle = 0x00270492) in a listview.

Later on I will use it in WinActivate($handle). But that doesn't work.

For testing I wrote the given handle ($handleSaved = "0x00270492") manual in and use it in WinActivate.

That also doesn't work.

If I compare via Winlist the actual given handle from Winlist with $handleSaved

I get the result: both are the same.

But if I use in WinActivate the actual given handle it works, if I use $handleSaved it doesn't work.

Attached the (poor) testing script.

Let it rune once to note a $handleSaved. In the second run it should activate the saved window.

best regards, Reinhard

PS: I know that I can activate the Window bay using the comparison and WinList() again, but I think there is a more direct way.

$var = WinList()
$handleSaved = "0x00040440";"0x00270492"
$Test = "N"

For $i = 1 to $var[0][0]
; Only display visble windows that have a title
  If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then
    $handle = $var[$i][1]
    consolewrite($handle &@LF)
    if $handleSaved = $handle then $Test = "Y"
    $OK = MsgBox(1, "Details", "Title=" & $var[$i][0] & @LF & "Handle=" & $var[$i][1] &@lf&@lf _ 
    &"WinActivate?"&"  "&isbinary($handle)&":"&isHWND($handle)&":"&$Test)
    if $OK = 1 then WinActivate($handleSaved)
    $Test = "N"
  EndIf
Next

Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then 
    Return 1
  Else
    Return 0
  EndIf

EndFunc
Edited by ReFran

Share this post


Link to post
Share on other sites



I can't replicate cause I'm not sure what this line is... WinActivate($handleSE)

Whats $handleSE meant to be?

Excuse me.

I used $handleSE in my origin, but thought on a public basic $handleSaved is better.

I change it in above script.

Thanks, Reinhard

Share this post


Link to post
Share on other sites

Mmmh,

is it my bad explanation/english or does that really not work.

Also negative answers are welcome.

br, Reinhard

Share this post


Link to post
Share on other sites

You need to remember the handle changes every time you close/open the window. I'm not sure if this is your problem but I usually check the PID of the process against the returned info (handle/title). If it is the same then I store that handle in a Global variable. This may also be your problem.

Share this post


Link to post
Share on other sites

That's not the problem.

The process is running,

the comparison part say the values are equal,

but I don't get the stored or typed in value to act as HWnd.

I can set up a workaround, but I think it's a bug, or?

br, Reinhard

Attached some more testing:

;;; 0x0066055C = Running process of Total commander

Opt ("WinTitleMatchMode", 4)
GLOBAL $handleGlobal = 0x0066055C
$handle = "0x0066055C"
 
; Winactivate($handleGlobal); as goblal - don't work
; WinActivate(0x0066055C); manual typed in - don't work
; WinActivate($handle);as saved string - don't work
$handleBin = Binary($handle)
; Winactivate($handleBin);dont work

Share this post


Link to post
Share on other sites

Here's what I do, it might help you out. I don' have the program you're using so I can't test myself but this might give you a hint or something. Hope it helps somehow.

$list = WinList("Total commander")
For $i = 1 To $list[0][0]
    If WinGetProcess($list[$i][0]) = $PID Then
        Global $handle = $list[$i][1]
    EndIf
Next

Share this post


Link to post
Share on other sites

Mmmh,

that works somehow. Will test it more and then see if I use that or my workaround (reactivate handle value to hwnd).

It drives me crazy if I think I can write it in some few minutes

and then I need hours to get it to work.

Thank you very much for your testing and solution,

have to go out for some fresh air ;-)

Reinhard

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