Solved

Windows98 API

Posted on 2000-04-10
9
170 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 27

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
 
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

747 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

12 Experts available now in Live!

Get 1:1 Help Now