More Window API

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?
Who is Participating?
jf26028Connect With a Mentor Commented:
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.  
If I recall, the Class Name changes when you compile to the name of your exe.
try this....

Dim ProG as Long

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

I hope this helps =)

Viktor Ivanov
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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

Viktor Ivanov
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
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).

xlunaxAuthor Commented:
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,
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

xlunaxAuthor Commented:
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.
Did you try my'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
You can capture mouse events by API call CaptureMouse and ReleaseMouse.
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.
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
Are you allowed to use assembler in VB???

Viktor Ivanov
No, that's why C is THE solution.
You know, it is hard to do system programming in VB
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.
xlunaxAuthor Commented:
sorry i tooks so long but yes it worked thank you =)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.