Solved

More Window API

Posted on 1998-08-23
18
435 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
ID: 1430567
If I recall, the Class Name changes when you compile to the name of your exe.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1430568
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
ID: 1430569
Actually let me ask you this question... What is that that you are trying to do?

Regards,
Viktor Ivanov
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 10

Expert Comment

by:viktornet
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%

???

Regards,
Viktor Ivanov
0
 
LVL 8

Expert Comment

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


0
 

Author Comment

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

Expert Comment

by:a111a111a111
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
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
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.
0
 
LVL 10

Expert Comment

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

Regards,
Viktor Ivanov
0
 

Expert Comment

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

Expert Comment

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

Expert Comment

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

Regards,
Viktor Ivanov
0
 
LVL 10

Expert Comment

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

Regards,
Viktor Ivanov
0
 

Expert Comment

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

Expert Comment

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

Expert Comment

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

Accepted Solution

by:
jf26028 earned 100 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.  
0
 

Author Comment

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

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

726 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