Go Premium for a chance to win a PS4. Enter to Win


More Window API

Posted on 1998-08-23
Medium Priority
Last Modified: 2012-08-14
Im trying to make a Window hidden from all sight.  Using these declarations:

Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Global Const SW_HIDE = 0
Global Const SW_MAXIMIZE = 3
Global Const SW_MINIMIZE = 6
Global Const SW_SHOWNA = 8
Global Const SW_RESTORE = 9

along with these procedures:

Dim ProG%, Q%
ProG% = FindWindow("ThunderForm", Me.Caption)
Q% = ShowWindow(ProG%, SW_MINIMIZE)  
Q% = ShowWindow(ProG%, SW_HIDE)      

but the window will only minimize and dissappear in the Design Environment.  Any ideas?
Question by:xlunax
  • 6
  • 5
  • 3
  • +4

Expert Comment

ID: 1430567
If I recall, the Class Name changes when you compile to the name of your exe.
LVL 10

Expert Comment

ID: 1430568
try this....

Dim ProG as Long

 ProG = FindWindow("ThunderForm", Me.Caption)
 ShowWindow(ProG, SW_HIDE)

I hope this helps =)

Viktor Ivanov
LVL 10

Expert Comment

ID: 1430569
Actually let me ask you this question... What is that that you are trying to do?

Viktor Ivanov
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 10

Expert Comment

ID: 1430570
I'm not a VB programmer and was wondering what does the % simbol stand for after you declare a variable like

Dim Prog%


Viktor Ivanov

Expert Comment

ID: 1430572
1. Victor - he's declaring a var as an integer type
2. If you think there's only one window with a particular caption use
i. GetWindow API call to enumerate thru all the Top Level Windows in a loop
ii. Then using GetWindowTextA to get their captions and compare against the string
To be honest, I don't think this is anyworse that looking by class name (which could also produce multiple hits, but at least this way you could look for and somehow handle more than one match).


Author Comment

ID: 1430573
I actually found the problem, the form class is ThunderRT5form, but what im trying to do is make the program read all keystrokes.  The Old code i wrote in VB3 worked, except the form had to be minimized.  I was really wondering how to make a form invisible completly from all view (Taskbar, and tasklist) and have it read all keystrokes and mouse movements,

Expert Comment

ID: 1430574
See if it works for you.

TITLE   :How to Hide a VB App from the Task List and ALT+TAB Order
PRODUCT :Microsoft Visual Basic for Windows
PROD/VER:2.00 3.00
KEYWORDS:kbprg kbcode

The information in this article applies to:

- Standard and Professional Editions of Microsoft Visual Basic for
  Windows, versions 2.0 and 3.0


This article demonstrates how to create an application that is invisible
to the Windows Task List and to the fast ALT+TAB switching order.


All Visual Basic applications have a background window that handles all
messages for the application and all calls to the VBRUN300.DLL. This
background window is also the owner and parent of all non-MDI child forms.
You can use the GetWindow and ShowWindow Windows API functions to hide
this background window.

To be eligible for removal from the ALT+TAB order, an application cannot
have any visible forms. The background window is visible, but you can
use GetWindow to return the background or owner window's handle, and then
use the handle and ShowWindow to make the window invisible.

Step-by-Step Example

This example hides itself from the Windows Task List and ALT+TAB order.

1. Start a New Project in Visual Basic. Form1 is created by default.

2. Add a timer control (Timer1) to the form.

3. Add the following declarations to the general declarations section:

   ' Enter each of the following Declare statements as one, single line:
   Declare Function ShowWindow Lib "User" (ByVal hWnd As Integer,
      ByVal nCmdShow As Integer) As Integer
   Declare Function GetWindow Lib "User" (ByVal hWnd As Integer,
      ByVal wCmd As Integer) As Integer
   Const SW_HIDE = 0
   Const GW_OWNER = 4

4. Add the following code to the load event of Form1:

   Sub Form_Load ()

      Dim OwnerhWnd As Integer
      Dim ret As Integer

      ' Make sure the form is invisible:
      form1.Visible = False

      ' Set interval for timer for 5 seconds, and make sure it is enabled:
      timer1.Interval = 5000
      timer1.Enabled = True

      ' Grab the background or owner window:
      OwnerhWnd = GetWindow(Me.hWnd, GW_OWNER)
      ' Hide from task list:
      ret = ShowWindow(OwnerhWnd, SW_HIDE)

   End Sub

5. Add the following code to the Timer event of the Timer1 control to
   verify that the program is running and to allow you to exit the program:

   Sub Timer1_Timer ()

      Dim ret As Integer

      ' Display a message box:
    ret = MsgBox("Visible by Alt+Tab. Cancel to Quit", 1, "Invisible Form")
      ' If cancel clicked, end the program:
      If ret = 2 Then
         timer1.Enabled = False
         Unload Me
      End If

   End Sub

6. Save the project as INVIS.MAK and create an executable entitled

7. Run the program by double-clicking INVIS.EXE in File Manager or by using
   the Run option in Program Manager. When you run the program, there
   should be no visible forms and the program title should not appear in
   the Task List or in the ALT+TAB order. After five seconds, the
   application should display the message box. Then the program should be
   visible to the ALT+TAB order, but not the Task List. Click the Cancel
   button to exit the application, or click OK to allow it to continue to


Author Comment

ID: 1430575
Man I dont know what you were thinking.  Number 1 Im using Vb5 so 32 bit declares are needed.  Number 2, That code didn;t hide it from the task list at all, in fact it somehow made my entire Taskbar disappear....any one else?  Remmber Im trying to make an invisble form that will read all key strokes and mouse movements.
LVL 10

Expert Comment

ID: 1430576
Did you try my code....it's on the top....

ShowWindow(Application.Handle, SW_HIDE)

Find the application's handle and then put it where it says Application.handle...

That is suppose to be working =)

Viktor Ivanov

Expert Comment

ID: 1430578
You can capture mouse events by API call CaptureMouse and ReleaseMouse.

Expert Comment

ID: 1430579
About keystrokes:  you can easily do it on C using good old interrupt vectors, 9h, i beleive for keyboard. That will give you access to all key combinations: even such as CTRL-ALT-DEL will be caught by you before Windows will react.
LVL 10

Expert Comment

ID: 1430580
Of course it's an easy task ...that's exactly what he needs to do as long as he is sure that he knows what the handle of the application is =)

Viktor Ivanov
LVL 10

Expert Comment

ID: 1430581
Are you allowed to use assembler in VB???

Viktor Ivanov

Expert Comment

ID: 1430582
No, that's why C is THE solution.

Expert Comment

ID: 1430583
You know, it is hard to do system programming in VB

Expert Comment

ID: 1430584
About hiding a form: what you can do is to make TSR (terminate-and-stay-resident). The program will end by remain in memory, just like anti-viruses (and viruses) are made. Then, when you need a user to work with your app, you can react to a certain keystroke and run another part of the program, Windows-based. After a user is done, it will end, but TSR will remain in memory, and cycle will repeat.

In short:
Your program can consist of two parts: 1. TSR. This is a short program that will capture keystrokes and mouse activity, and call another part of the program if needed. TSR will reside in memory being invisible to user.
2nd part of your program is usual Windows application that provides GUI. It is called by TSR, and terminated by it.
1st and 2nd parts are independant progs, but the 1st one can call the 2nd one.

Accepted Solution

jf26028 earned 400 total points
ID: 1430585
You could forget the entire visibility issue and just move the form way off the screen..
Form1.Left = -10000
Form1.ShowInTaskbar = False

The form will be hidden from the user unless they press
Ctrl+Alt+Del.  If you can put up with that, then this is your solution.  If not, then you may still want to chase after the invisible solution.  

Author Comment

ID: 1430586
sorry i tooks so long but yes it worked thank you =)

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question