[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

interacting with another application

Posted on 1998-11-11
5
Medium Priority
?
141 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
[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
  • 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 320 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

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

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…
Suggested Courses

650 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