Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help! vbHide doesn't work...

4 views
Skip to first unread message

Stefan Selbach

unread,
Oct 9, 2001, 5:47:32 PM10/9/01
to
Hi,
I would like to start a program with Shell(Commandline, vbHide) invisibly.
My problem is that the started program is very penetrant so that it always
hangs itself into the foreground. It should be executed invisible/hidden in
the background however.
What can I do there?
Greetings
Stefan


Stefan Selbach

unread,
Oct 11, 2001, 6:16:18 PM10/11/01
to
No ideas?


Chris Crochet

unread,
Oct 12, 2001, 1:54:52 PM10/12/01
to
"Stefan Selbach" <stefan_...@gmx.de> wrote in message news:<9pvr91$hct$02$1...@news.t-online.com>...

Stefan,

Now THAT'S a problem! :) Solving it requires some familiarity with
the Windows API.

I ripped some code out of some of my programming libraries and threw
it together into an example you should be able to use. It's somewhat
complicated, not well documented and hasn't the best programming
style, but it works.

Basically, it searches the desktop for windows containing certain
captions and hides them. Throw this code into a blank module and
execute LoadStubbornApp from the Debug Window. As configured, it WILL
hide every Notepad on your screen.

Hope this helps.

Chris Crochet

-----

Option Compare Database
Option Explicit


Private Declare Function GetDesktopWindow Lib "user32" () As Long

Private Declare Function GetWindow Lib "user32" (ByVal hWnd As Long,
ByVal wCmd As Long) As Long
Global Const GW_CHILD = 5
Global Const GW_HWNDNEXT = 2

Private Declare Function apiGetWindowText Lib "user32.dll" Alias
"GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal
cch As Long) As Long
Private Declare Function GetClassName Lib "user32.dll" Alias
"GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String,
ByVal nMaxCount As Long) As Long

Private Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long,
ByVal nCmdShow As Long) As Long
Private Const SW_HIDE = 0 ' Hide the window
Private Const SW_SHOW = 5 ' Show the window


Sub LoadStubbornApp()
' Execute your stubborn app here
'Shell "StubbornAppName", vbHide

' Hide the stubborn app. In case the window doesn't appear right
away,
' wait until it does and clobber it. Change *Notepad* to something
that
' matches your stubborn app's title bar.
While Not HideStubbornApp("*Notepad*")
DoEvents
Wend
End Sub


Function HideStubbornApp(ByVal AppCaption As String) As Boolean
Dim Windows() As Variant
Dim NumWindows As Long
Dim i1 As Integer

NumWindows = WindowFind(Windows, , AppCaption, , False)

For i1 = 1 To NumWindows
SetWindowVisible Windows(i1)(0), False
HideStubbornApp = True
Next
End Function


Public Function WindowDesktop() As Long
' Returns the hWnd of the Desktop (wallpaper)
WindowDesktop = GetDesktopWindow()
End Function


Public Function WindowFind(ByRef hWndArray() As Variant, _
Optional ByVal hWndStart As Long = 0, _
Optional ByVal WindowText As String = "*",
_
Optional ByVal ClassName As String = "*", _
Optional ByVal RecurseChildren As Boolean =
True) As Long
' Returns a list of windows based on parameters.
' Returns an array of arrays:
' (1-x)(0) = Window Handle
' (1-x)(1) = Class Name
' (1-x)(2) = Window Text
' (1-x)(3) = Parent Handle
Dim hWnd As Long
Dim sWindowText As String
Dim sClassName As String
'Hold the level of recursion and hold the number of matching windows
Static level As Long
Static found As Long
'Initialize if necessary
If level = 0 Then
found = 0
ReDim hWndArray(0 To 0)
If hWndStart = 0 Then hWndStart = WindowDesktop
End If
'Increase recursion counter
level = level + 1
'Get first child window
hWnd = GetWindow(hWndStart, GW_CHILD)
Do Until hWnd = 0
'Search children by recursion
If RecurseChildren Then Call WindowFind(hWndArray(), hWnd,
WindowText, ClassName, RecurseChildren)
'Get the window text and class name
sWindowText = GetWindowText(hWnd)
sClassName = GetWindowClassName(hWnd)
'Check that window matches the search parameters
If (sWindowText Like WindowText) And (sClassName Like ClassName)
Then
found = found + 1
ReDim Preserve hWndArray(0 To found)
hWndArray(found) = Array(hWnd, sClassName, sWindowText,
hWndStart)
End If
'Get next child window
hWnd = GetWindow(hWnd, GW_HWNDNEXT)
Loop
'Decrement recursion counter
level = level - 1
'Return the number of windows found
WindowFind = found
End Function


Function GetWindowText(ByVal mhWnd As Long) As String
Dim r As Long
Dim sWindowText As String
sWindowText = Space$(255)
r = apiGetWindowText(mhWnd, sWindowText, 255)
GetWindowText = Left(sWindowText, r)
End Function


Function GetWindowClassName(ByVal mhWnd As Long) As String
Dim r As Long
Dim sClassName As String
sClassName = Space(255)
r = GetClassName(mhWnd, sClassName, 255)
GetWindowClassName = Left(sClassName, r)
End Function


Sub SetWindowVisible(ByVal mhWnd As Long, ByVal bVisible As Boolean)
ShowWindow mhWnd, IIf(bVisible, SW_SHOW, SW_HIDE)
End Sub

Dimitri Furman

unread,
Oct 12, 2001, 8:28:48 PM10/12/01
to
On Oct 12 2001, 01:54 pm, tesl...@hotmail.com (Chris Crochet) wrote in
news:5fae81ea.01101...@posting.google.com:

> Basically, it searches the desktop for windows containing certain
> captions and hides them.

But this wouldn't help if the app in question decides to show its window
whenever it feels like it, which seems to be the original problem here...

This would be much easier to approach if the original poster mentioned some
details about the application that needs to be hidden.

Two common approaches are moving the app's window that one wants to hide
off the screen, or using SetParent API to make the app's window a child of
an invisible window. I'm sure there was sample code posted in VB groups.

--
(remove a 9 to reply by email)

Chris Crochet

unread,
Oct 14, 2001, 2:53:22 PM10/14/01
to
Dimitri Furman <dfu...@cloud99.net> wrote in message news:<Xns9138D0582F4B...@207.126.101.100>...

> On Oct 12 2001, 01:54 pm, tesl...@hotmail.com (Chris Crochet) wrote in
> news:5fae81ea.01101...@posting.google.com:
>
> > Basically, it searches the desktop for windows containing certain
> > captions and hides them.
>
> But this wouldn't help if the app in question decides to show its window
> whenever it feels like it, which seems to be the original problem here...

I'm assuming that this is an app which doesn't respond properly to the
WindowStyle parameter of the shell function, of which I have
encountered a few :)

> This would be much easier to approach if the original poster mentioned some
> details about the application that needs to be hidden.

Very true. We'll have to wait for Stefan to write back.

> Two common approaches are moving the app's window that one wants to hide
> off the screen, or using SetParent API to make the app's window a child of
> an invisible window. I'm sure there was sample code posted in VB groups.

Both excellent suggestions, and both would also solve the scenario you
mentioned in which the app's window attempts to reappear periodically.

Note that the SetParent solution is against Microsoft's rules of
etiquette, in that the invisible parent window would belong to a
different (your own) process, and Microsoft says that you cannot set a
window to a parent from a different process. Nevertheless, for now it
does work -- but no guarantees for future versions of Windows.

Chris C.

Stefan Selbach

unread,
Oct 14, 2001, 8:02:14 PM10/14/01
to
Hi Dimitri and Chris,
thanks for your assistance.

> > > Basically, it searches the desktop for windows containing certain
> > > captions and hides them.
> >
> > But this wouldn't help if the app in question decides to show its window
> > whenever it feels like it, which seems to be the original problem
here...
>
> I'm assuming that this is an app which doesn't respond properly to the
> WindowStyle parameter of the shell function, of which I have
> encountered a few :)
>
> > This would be much easier to approach if the original poster mentioned
some
> > details about the application that needs to be hidden.
>
> Very true. We'll have to wait for Stefan to write back.

It is the data analyzing language ACL ( http://www.acl.com/en/default.asp? )
I use it for converting analyzing large ACII-Print-Files. Therefore it is
very useful. But now I'm in trouble because the client wants to use the tool
periodically for himself and you can imagine that it seems not very
professional when you can see running the code line for line...

>
> > Two common approaches are moving the app's window that one wants to hide
> > off the screen, or using SetParent API to make the app's window a child
of
> > an invisible window. I'm sure there was sample code posted in VB groups.
>
> Both excellent suggestions, and both would also solve the scenario you
> mentioned in which the app's window attempts to reappear periodically.
>
> Note that the SetParent solution is against Microsoft's rules of
> etiquette, in that the invisible parent window would belong to a
> different (your own) process, and Microsoft says that you cannot set a
> window to a parent from a different process. Nevertheless, for now it
> does work -- but no guarantees for future versions of Windows.
>
> Chris C.

I will try the code. Perhaps I can run the sub e.g. every second, if this
works.

Thanks,
Stefan


0 new messages