Solved

GURU's:  Maximize a seperate application?

Posted on 2000-04-23
11
196 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
ID: 2742948
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
ID: 2742956
'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
ID: 2742990
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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 5

Expert Comment

by:yronnen
ID: 2742992
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
ID: 2743005
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
 

Author Comment

by:jgore
ID: 2743010
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
ID: 2743012
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
ID: 2757825
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
ID: 2757831
i had forgotten about this question =/

posting comment as answer
0
 

Author Comment

by:jgore
ID: 2759010
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
ID: 2759680
you can reject his answer and then accept my comment as an answer
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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 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…
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…

773 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