Solved

GURU's:  Maximize a seperate application?

Posted on 2000-04-23
11
199 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
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 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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA filters 2 70
Sub or Function is not defined 6 51
VBA to find and replace multiline text from VBA modules 8 89
checkbox to hide entire section 10 58
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…
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…

685 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