Announcement

Collapse
No announcement yet.

SwitchToThisWindow

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • SwitchToThisWindow

    In looking for a way to bring a Window to the foreground AND
    activate it, I came across the following "undocumented" API
    call on codepile.com:

    // void SwitchToThisWindow(
    // HWND hWnd, // Handle to the window that should be activated
    // BOOL bRestore // Restore the window if it is minimized
    // );

    Seems to work great on Win95/98/98SE. In PB/CC you use it thus:


    DECLARE SUB SwitchToThisWindow LIB "USER32.DLL" _
    ALIAS "SwitchToThisWindow" _
    (BYVAL hWnd AS LONG, BYVAL lRestore AS LONG)

    %WIN_TRUE = 1
    %WIN_FALSE = 0

    hWnd = FindWindow(BYVAL 0, "Window Title")

    SwitchToThisWindow hWnd, %WIN_TRUE


    Passing WIN_TRUE in lRestore will cause the window to be restored
    if it was minimized (unminimize, if you will), and passing the
    WIN_FALSE value will leave the window "as is".


    ------------------

  • #2
    On topic commentary for the lurkers:

    This subject has been discussed a few times before... the problem is that that API is not guaranteed to work in all situations, and I understand that it was "plugged" in Win2K (but was available in the Beta's and possibly in some early pressings). There are no known functions that will reliably work in all versions of Windows.

    If you search the BBS for "switchtothiswindow" or "attachthreadinput" you'll find the previous discussions and code that is more reliably than this undocumented function.

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      I should add that I'm a database programmer and not a Windows API specialist. I also have the advantage of being able to work in a controlled environment. In other words, it works for me in the very well-known environment I have to work with, but it is not guaranteed to work all the time in every scenario.

      In this instance, I needed a way to activate a window and feed it events via keybd_event. This method solved my problem, which was a short-term requirement (ie, literally tens of thousands of keystrokes that could be read from an input file.)

      Like Lance and others, I don't advocate the use of undocumented features -- be they Win32 API calls or "nuances" of a language -- for commercial work. On the other hand, if you have a singular requirement and the tool is available...

      If anyone discovers the "right" way to do this, please post a link here to the solution.


      ------------------

      Comment

      Working...
      X