Solved

interacting with another application

Posted on 1998-11-11
5
132 Views
Last Modified: 2010-04-30
I used a shell function to open a application.. I want to set a form's width to the same width of the application that I had openned. I have tried using the simple
     frmMain.width= screen.activeform.width, and this is no working.
0
Comment
Question by:mjh2
  • 3
  • 2
5 Comments
 
LVL 15

Expert Comment

by:ameba
ID: 1444384
Do you know the title of the main form of that application?
0
 
LVL 15

Expert Comment

by:ameba
ID: 1444385
In fact, you don't need Title. Can you add more points, and I will post nice code - "your form follows the application you shelled".
0
 

Author Comment

by:mjh2
ID: 1444386
Adjusted points to 25
0
 

Author Comment

by:mjh2
ID: 1444387
Adjusted points to 80
0
 
LVL 15

Accepted Solution

by:
ameba earned 80 total points
ID: 1444388
Start new project in vb, add command button and timer to your form and paste this code:

' Form which Shells and follows shelled window
' Created by Bruno Paris, email ameba@zg.tel.hr
Option Explicit
' API declarations
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOACTIVATE = &H10
Private Const SWP_SHOWWINDOW = &H40
Private Const SWP_NOMOVE = &H2
Private Const SWP_HIDEWINDOW = &H80
Private Const SWP_NOZORDER = &H4
Private Const GW_HWNDNEXT = 2
Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function IsIconic Lib "user32" (ByVal hwnd As Long) As Long
Private 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
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function IsWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
' private variables
Private m_useHwnd As Long ' window to follow

Private Sub Command1_Click()
    Dim ProcessID As Long, PID As Long
    On Error Resume Next
    ProcessID = Shell("Notepad", vbNormalFocus)
    If Err Then Exit Sub
    On Error GoTo 0
    m_useHwnd = FindWindow(vbNullString, vbNullString)
    Do Until m_useHwnd = 0
        If GetParent(m_useHwnd) = 0 Then
            Call GetWindowThreadProcessId(m_useHwnd, PID)
            If PID = ProcessID Then Exit Do
        End If
        m_useHwnd = GetWindow(m_useHwnd, GW_HWNDNEXT)
    Loop
    Timer1.Interval = 500
    Timer1.Enabled = True
End Sub

Private Sub Form_Load()
    Command1.Top = 30
    Height = 70 * Screen.TwipsPerPixelY
End Sub

Private Sub Timer1_Timer()
    On Error Resume Next
    If IsWindow(m_useHwnd) = 0 Then
        Timer1.Enabled = False
        Move 100, 100
        Beep
        AppActivate Me
        Exit Sub
    End If
    If IsIconic(m_useHwnd) Then
        WindowState = vbMinimized
    Else
        WindowState = vbNormal
    End If
    ' Get the rectangle describing the window
    Dim WindowRect As RECT
    GetWindowRect m_useHwnd, WindowRect
    ' position form
    Dim tmpLeft As Single, tmpTop As Single, tmpWidth As Single
    tmpLeft = WindowRect.Left * Screen.TwipsPerPixelX
    tmpTop = (WindowRect.Bottom - 6) * Screen.TwipsPerPixelY
    tmpWidth = (WindowRect.Right - WindowRect.Left) * Screen.TwipsPerPixelX
    If Left <> tmpLeft Or Top <> tmpTop Or Width <> tmpWidth Then
        Move tmpLeft, tmpTop, tmpWidth
        SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOSIZE Or SWP_NOMOVE
    End If
End Sub

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

895 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

11 Experts available now in Live!

Get 1:1 Help Now