Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
myName = cWndInfo(DllHwnd(""),0) ... IF WinGetActive() == myName THEN Yes!!But I thought it would be more efficient/elegant to do this:
myHnd = DllHwnd("") ... IF cGetFocus() == myHnd THEN Yes!!but it doesn't work. Why not?
Further testing shows that it may have something to do with the program running iconized on a system that is not running the standard Windows EXPLORER shell. This is the original context where this came up. Try this test program:
AddExtender("wwctl44i.dll") myHnd = DllHwnd("") IntControl(54,"",1,0,0) WHILE WinState("") < @NORMAL TimeDelay(1) IF cGetFocus() == myHnd THEN Pause("","I have the focus now!") ENDWHILE ExitWhen I run this, it starts out minimized (as all WB programs do), and when I click on it, it gets the focus, but doesn't announce *until* I de-iconize it. If you are running EXPLORER (such that it shows up in the "task bar"), then you can see the effect by *right* clicking on it, getting the popup menu and then hitting escape. At least on my system, this leaves it as the active window, but does not "de-iconize" it. And, when I do de-iconize it, it then pops up the announcement.
All of this may seem obscure/moot, but the fact is that it does work correctly (under my conditions) if I use the first method (cWndByName and WinActivate), but doesn't work (just sits there) if I try to do it with handles (instead of with window names). I'm curious as to why...
AddExtender("wwctl44i.dll") BoxOpen("","") myHnd = DllHwnd("") hFocus = cGetFocus() IF hFocus == myHnd THEN Message("","My window is active")
But the point, which I have probably not made as clear as I should have, is that a minimized WinBatch script can have the focus (even though WinState("") == @ICON).
Two points regarding this last sentence:
I encounter that difference in definition frequently. If you recall, in Win2K and again in WinXP, I think, Microsoft made some subtle changes to window activation which in turn affected how certain WinBatch functions behave in terms of sending keystrokes and in how the Control Manager extender works, too. Ostensibly, these changes were supposed to improve the end-user experience when an application is trying to alert the user that the application requires some sort of user intervention. The end result that I observe is that there are times when I have a window that is in the foreground in terms of Z-order, but the window that has keyboard focus is actually in the background. When a background application "steals" the keyboard focus, you typically see the taskbar unhide itself [if it was hidden], and the application's button on the taskbar highlights itself until the application is brought to the foreground.
Another issue, glossed over earlier, as it did not appear in the specific test case being discussed, is the difference between a parent window - say a dialog box, and a specific control in the dialog box.
WinGetActive will return the parent window, while as cGetFocus will return the control window.
The key is "the top-level window". That has a specific meaning in Windows terminology. A button can have the input focus but it is never a top level window.
Article ID: W16817
File Created: 2017:07:28:12:58:24
Last Updated: 2007:07:03:13:26:23