Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 185
  • Last Modified:

Windows98 API

Is there any way to make another application's form invisible with VB6 Prof.
0
burntout
Asked:
burntout
1 Solution
 
burntoutAuthor Commented:
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
 
ArkCommented:
What information about this form (caption,handle) do you have?
Cheers
0
 
NazdorCommented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
MattiCommented:
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
 
AzraSoundCommented:
'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
 
burntoutAuthor Commented:
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
 
AzraSoundCommented:
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
 
burntoutAuthor Commented:
Thanx AzraSound! What is the Constant to make it stop being on top?  I promiss this is the last question. :-)
0
 
AzraSoundCommented:
Public Const HWND_NOTOPMOST = -2
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now