Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Windows98 API

Posted on 2000-04-10
9
Medium Priority
?
180 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: 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 1000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

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 trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
Suggested Courses

715 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