Solved

GURU's:  Maximize a seperate application?

Posted on 2000-04-23
11
194 Views
Last Modified: 2011-04-14
I have a program that writes to another app.

I use:
AppActivate "SynEdit"
SendKeys "Hello", True

and thats fine. However, it only works if this other App (SynEdit)
is NOT minimized.
AppActivate gives it focus, how can I UN-Minimize this other APP?
0
Comment
Question by:jgore
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 2

Expert Comment

by:bhamilto
Comment Utility
Its easy enough to minimize an app but is this really what you would prefer to do?  Would it be more desirable to write to the app regardless of whether it is min or max?
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 100 total points
Comment Utility
'PLACE FOUR 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(vbNullString, 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 Command3_Click()
    Dim hWnd As Long
    On Error Resume Next

    hWnd = FindShellWindow()

    If hWnd <> 0 Then
        Call MinMaxWindow(hWnd, False)
    End If

End Sub

Private Sub Command4_Click()
    Dim hWnd As Long
    On Error Resume Next

    hWnd = FindShellWindow()

    If hWnd <> 0 Then
        Call MinMaxWindow(hWnd, True)
    End If

End Sub

Private Sub Form_Load()
    Command1.Caption = "Show Window"
    Command2.Caption = "Hide Window"
    Command3.Caption = "Minimize Window"
    Command4.Caption = "Maximize Window"
    Text1.Text = "Enter name of window you wish to hide/show"
End Sub

Private Sub MinMaxWindow(ByVal hWnd As Long, Optional ByVal Max As Boolean = True)
    Dim lngShowCmd As Long
    On Error Resume Next

    If Max = True Then
        lngShowCmd = SW_SHOWMAXIMIZED
    Else
        lngShowCmd = SW_SHOWMINIMIZED
    End If

    Call ShowWindow(hWnd, lngShowCmd)
End Sub
0
 
LVL 5

Expert Comment

by:yronnen
Comment Utility
Why not writing you app as an activex exe??

Try doing as follow, assuming that the app you want to send info to is called myapp:
1. In your application project properties change the application to ActiveX exe and set the Start Mode property to "Stand Alone".
You will need to add a module with a "sub Main()" function that will run the first form of you application.

Add a class module (for example myClass) and change its instancing behaivour to 5-multiuse.
In the class add all the functions you want your application to expose, for example "setExternalText (s as string)".

In the client application you can add this:

Dim x as myapp.myClass
set x=getobject("",myapp.myClass)
x.setExternalText "hello"

Now, if the second app is not running, the code will create a new instance of it. If it is already running (no matter if minimized) it will point to the existing running instance of the application, and you'll be able to do whatever you want with it.
0
 
LVL 5

Expert Comment

by:yronnen
Comment Utility
Oops..assuming that you've written the second app, of course.

If not, please comment me and I'll withdraw my answer.
0
 

Author Comment

by:jgore
Comment Utility
To: AzraSound
How easy you seem to do that ;-)
Works great!
Really, what book do you get that stuff from.
Some kind of MS CD collection?
My friend was MSCE and had such a CD collection.
Anyways, thanks a bunch!


To: bhamilto
I wish I could write to other app minimized.
But, I didn't write it.  My program push's text ( food Recipes, programming sub-routines, whatever) to another editor. Any Editor!
I can see now I'll have to spend some time
getting Window Handle names of a few editors.
(Just happen to have a prog to do it).
But it's worth it.


To: yronnen
No, sorry. I didn't write the other App.
My program has to write to many other Apps.

0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:jgore
Comment Utility
To: AzraSound
How easy you seem to do that ;-)
Works great!
Really, what book do you get that stuff from.
Some kind of MS CD collection?
My friend was MSCE and had such a CD collection.
Anyways, thanks a bunch!


To: bhamilto
I wish I could write to other app minimized.
But, I didn't write it.  My program push's text ( food Recipes, programming sub-routines, whatever) to another editor. Any Editor!
I can see now I'll have to spend some time
getting Window Handle names of a few editors.
(Just happen to have a prog to do it).
But it's worth it.


To: yronnen
No, sorry. I didn't write the other App.
My program has to write to many other Apps.

0
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
actually i write a lot of small programs such as these and save them to disk. when the need arises to pull them up again, its just a simple matter of copy/paste.   =)
0
 
LVL 1

Expert Comment

by:MinnEE
Comment Utility
Here's how I do this using VB3 (using MS Calculator as an example):


AppActivate "Calculator"    ' Set Focus; will stay minimized
DoEvents       ' Needed for Windows 98
SendKeys "% " ' Alt + SpaceBar to get control box
SendKeys "{Enter}", True     ' Restores  (First Command in control box)
0
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
i had forgotten about this question =/

posting comment as answer
0
 

Author Comment

by:jgore
Comment Utility
Anyone know how I can Comment yronnen so
he can withdrawl his answer and I can give the points to AzraSound ? Doesn't seem to be a Comment
command anywhere.
0
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
you can reject his answer and then accept my comment as an answer
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
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…

744 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