Solved

More Window API

Posted on 1998-08-23
18
432 Views
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_SHOWMINNOACTIVE = 7
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?
0
Comment
Question by:xlunax
  • 6
  • 5
  • 3
  • +4
18 Comments
 
LVL 4

Expert Comment

by:mcix
Comment Utility
If I recall, the Class Name changes when you compile to the name of your exe.
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
try this....

Dim ProG as Long

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

I hope this helps =)

Regards,
Viktor Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
Actually let me ask you this question... What is that that you are trying to do?

Regards,
Viktor Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
I'm not a VB programmer and was wondering what does the % simbol stand for after you declare a variable like

Dim Prog%

???

Regards,
Viktor Ivanov
0
 
LVL 8

Expert Comment

by:Answers2000
Comment Utility
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).


0
 

Author Comment

by:xlunax
Comment Utility
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,
0
 
LVL 3

Expert Comment

by:a111a111a111
Comment Utility
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
OPER/SYS:WINDOWS
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
---------------------------------------------------------------------

SUMMARY
=======

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

MORE INFORMATION
================

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
      End If

   End Sub

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

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
   run.

0
 

Author Comment

by:xlunax
Comment Utility
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.
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
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 =)

Regards,
Viktor Ivanov
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Expert Comment

by:topol
Comment Utility
You can capture mouse events by API call CaptureMouse and ReleaseMouse.
0
 

Expert Comment

by:topol
Comment Utility
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.
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
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 =)

Regards,
Viktor Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
Are you allowed to use assembler in VB???

Regards,
Viktor Ivanov
0
 

Expert Comment

by:topol
Comment Utility
No, that's why C is THE solution.
0
 

Expert Comment

by:topol
Comment Utility
You know, it is hard to do system programming in VB
0
 

Expert Comment

by:topol
Comment Utility
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.
0
 
LVL 1

Accepted Solution

by:
jf26028 earned 100 total points
Comment Utility
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.  
0
 

Author Comment

by:xlunax
Comment Utility
sorry i tooks so long but yes it worked thank you =)
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now