Solved

Windows98 API

Posted on 2000-04-10
9
174 Views
Last Modified: 2010-05-02
Is there any way to make another application's form invisible with VB6 Prof.
0
Comment
Question by:burntout
9 Comments
 
LVL 2

Author Comment

by:burntout
ID: 2703081
Well first of all I have never messed with the API before.  I the handle is the name listed when your press Ctrl+Alt+Del  Right?  It will always be the same program.   Sorry for making this difficult.
0
 
LVL 28

Expert Comment

by:Ark
ID: 2703062
What information about this form (caption,handle) do you have?
Cheers
0
 
LVL 4

Expert Comment

by:Nazdor
ID: 2703143
What level of 'invisibility' are you looking for?

There was a similar question recently (don't have a link, but title "simple vb security" ) to stop the program from being killed with cntrl-alt-delete.

Otherwise, you want to look at 'SetWindowPos()' with SWP_HIDEWINDOW.

You need the hWnd of the window, but that's all - you can get that if you know the Caption, by using cycling through the windows using GetWindow() and using GetWindowText() to compare the caption.

VBNet (http://www.mvps.org/vbnet/index.html) has some good articles for cycling through windows to find the one you want - look there rather than me copying and pasting their code.


When you have the hWnd (window handle), you need to do:

Private Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const SWP_HIDEWINDOW = &H80

Public Sub HideIt(hWnd as Long)
  SetWindowPos hWnd, 0, 0, 0, 0, 0, SWP_HIDEWINDOW
End Sub



I've not tested this though, so someone will probably have a better solution.

0
Technology Partners: 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!

 
LVL 14

Expert Comment

by:Matti
ID: 2703472
Hi!

Why don't you try someting else to cover that, the bad visibility might be
unwanted feature among many users.


Option Explicit

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If UnloadMode = 3 Then
Cancel = True
MsgBox "Sorry, You can't do this!"
End If
End Sub

Need moore then 4 as Unloadmode constant
will stop the exit Windows process.


Ps I only comment this because it is a alternative!

Matti
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 250 total points
ID: 2704258
'PLACE TWO COMMAND BUTTONS AND A TEXTBOX ON YOUR FORM
'CODE REQUIRES EXACT WINDOW TITLE IN ORDER TO FUNCTION
'*****************************************************
'
'
'MODULE CODE
'
'
'*****************************************************

DefLng A-Z

Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long

Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long

'-- Constants for ShowWindow()
Public Const SW_HIDE = 0
Public Const SW_NORMAL = 1
Public Const SW_SHOWMINIMIZED = 2
Public Const SW_SHOWMAXIMIZED = 3
Public Const SW_SHOWNOACTIVATE = 4
Public Const SW_SHOW = 5
Public Const SW_MINIMIZE = 6
Public Const SW_SHOWMINNOACTIVE = 7
Public Const SW_SHOWNA = 8
Public Const SW_RESTORE = 9
Public Const SW_SHOWDEFAULT = 10


'*****************************************************
'
'
'FORM CODE
'
'
'*****************************************************


Private Function FindShellWindow() As Long
    Dim hWnd As Long
    On Error Resume Next

    hWnd = FindWindow(CLng(0), Text1.Text)

    If hWnd <> 0 Then
        FindShellWindow = hWnd
    End If

End Function

Private Sub HideShowWindow(ByVal hWnd As Long, _
    Optional ByVal Hide As Boolean = False)
    Dim lngShowCmd As Long
    On Error Resume Next

    If Hide = True Then
        lngShowCmd = SW_HIDE
    Else
        lngShowCmd = SW_SHOW
    End If

    Call ShowWindow(hWnd, lngShowCmd)

End Sub

Private Sub Command1_Click()
    Dim hWnd As Long
    On Error Resume Next

    '-- Find the window we're
    ' looking for and then hide it
    hWnd = FindShellWindow()

    If hWnd <> 0 Then
        Call HideShowWindow(hWnd)
    End If

End Sub

Private Sub Command2_Click()
    Dim hWnd As Long
    On Error Resume Next

    hWnd = FindShellWindow()

    If hWnd <> 0 Then
        Call HideShowWindow(hWnd, True)
    End If

End Sub

Private Sub Form_Load()
    Command1.Caption = "Show Window"
    Command2.Caption = "Hide Window"
    Text1.Text = "Enter name of window you wish to hide/show"
End Sub


0
 
LVL 2

Author Comment

by:burntout
ID: 2704443
Well I want to thank you guys for your help. Nazdor I think your idea would have worked, but AzraSound's was all right there in front of me.  I am now out of points, and have another question if another App has a model form and I have the hWnd can I make it not model, I want to be able to have my App in front of the other app.  If anyone has an answer it would be of great help if you would send it to me via Email at chris@323tech.com  Thanx again.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2704468
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const HWND_TOPMOST = -1
Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long


Function StayOnTop(Form As Form)
    Dim lFlags As Long
    Dim lStay As Long

    lFlags = SWP_NOSIZE Or SWP_NOMOVE
    lStay = SetWindowPos(Form.hwnd, HWND_TOPMOST, 0, 0, 0, 0, lFlags)
End Function



that code will keep your form always on top
0
 
LVL 2

Author Comment

by:burntout
ID: 2704714
Thanx AzraSound! What is the Constant to make it stop being on top?  I promiss this is the last question. :-)
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2704775
Public Const HWND_NOTOPMOST = -2
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

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