Re: Getting/Setting States of VB-Shelled Application Windows

From: MikeD (nobody_at_nowhere.edu)
Date: 09/30/04


Date: Thu, 30 Sep 2004 19:45:20 -0400


"Struggling Rod" <StrugglingRod@discussions.microsoft.com> wrote in message
news:41DDE8AD-6A79-4E92-8F0F-CF1E5F130C01@microsoft.com...
> My VB application launches a windows application (either WordPad or
Notepad)
> using the Shell function..
>
> How can I determine the state of the shelled application's window:
> minimized, restored, or maximized?
>

First, you need to get the hWnd (window handle, which is a value assigned by
Windows when the window is created and which identifies the window) of
either Wordpad or Notepad. VB's Shell function does not return an hWnd.
You'll have to use the API to get that. FindWindow, for example.

After you've got that, there are several different ways of determining if
the app is minimized or maximized. IMO, the easiest way would be to use the
IsIconic and IsZoomed API functions. If both these return 0, then you know
the app is restored. However, GetWindowPlacement would work too (and it's
only one call).

> How do I set the window's state to any of these three possibilities?
>
> I believe the answers lie with one or more of the following API functions:
> ShowWindow, GetWindowPlacement, SetWindowPlacement.

You could use either ShowWindow or SetWindowPlacement for this. I have to
ask though, why don't you set the state when you shell to it? The Shell
function supports this. If the user changes the window state after you've
started the app, you probably shouldn't mess around with it.

>
> Is there a web site that lets me key in one or more keywords and returns
one
> or more descriptions of windows API functions that may solve my problem
along
> with narratives and examples of how to use the API functions?

MSDN Library is the "official" documentation for Windows' API functions (and
Windows programming in general, as well as developing with any of MS's
programming tools, even Office). It's your best source for the most
up-to-date information and is searchable. It's available online at
http://msdn.microsoft.com/library/default.asp. However, much of it
(particularly the API) is documented with C/C++ programmers in mind.
Thusly, any example code included in the documentation is going to be C/C++.
If you're familiar with C/C++ and know how to "translate" it to VB, that
shouldn't be a problem. If you're not familiar with C/C++, then a lot of the
documentation and example code may not make much sense. Because of that,
there are (or used to be) numerous resources for VB programmers. There's a
book named "Visual Basic Programmer's Guide to the Win32 API" by Dan
Appleman that's widely considered as THE book for using the API in VB. As
the title states, it's strictly geared towards VB programmers. There used to
be a web site (apiguide.com or something like that; unfortunately, I forget
exactly what it is and don't even know if it's still around) that provided
VB-centric documentation and example code for API functions. Personally, I
always thought some (actually, quite a few) of the examples were
"questionable"; therefore, I never consulted it much. Other than that, there
are still quite a few VB-classic web sites still around. Many of them delve
into the API quite extensively. Check out www.mvps.org. Karl, Randy, Brad,
and Eduardo all have very good sites. My guess is that the others are
probably decent too. I've just not visited any others so it wouldn't be fair
for me to comment on them one way or the other. The sites from the 4 people
I mentioned don't provide documentation to the API as such. However, they
all provide very good example code. That sample code, in conjunction with
MSDN Library, should help you out a LOT with understanding and using the
Win32 API.

Mike



Relevant Pages

  • Re: newbe about API
    ... Emne: Re: newbe about API ... > I found all these API-CALL strings are finally compiled to ... more than that...and Windows simply takes this to an extreme that this ... DLL, when a weak point is found (which, with Microsoft, is something ...
    (alt.lang.asm)
  • Re: In the Shallow End
    ... When a document claims how an API is supposed to be used and then gives the user examples that actually work, ... Vague in your instance means you have no context to VMS or UNIX of that era. ... Windows offers lots of this stuff. ... That's why Apple had to dump a whole paradigm to plunge ahead and take the lead. ...
    (comp.sys.mac.advocacy)
  • Re: What are the Missing Parts in the CVF Windows API?
    ... Both the documentation and third-party books say that **almost** ... | all of the full functionality of the Windows API, ...
    (comp.lang.fortran)
  • Re: a pre-beginners question: what is the pros and cons of .net, compared to ++
    ... as the windows forms architecture wraps a number of activex ... and retains backwards compatibility with both COM and the classic Win32 api. ... C++ cannot inherently do video capture either, since you have to import COM. ... Outlook or Word or IM programs, each of which would run in managed code ...
    (microsoft.public.dotnet.general)
  • Re: Interpreting a BAS module
    ... unicode and ansi strings. ... applications make calls out to Windows to ask it to do something (e.g. ... you have to utilize an API that is designed to ... AddressOf is also used in subclassing. ...
    (microsoft.public.vb.general.discussion)