Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 216
  • Last Modified:

GURU's: Maximize a seperate application?

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
jgore
Asked:
jgore
  • 4
  • 3
  • 2
  • +2
1 Solution
 
bhamiltoCommented:
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
 
AzraSoundCommented:
'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
 
yronnenCommented:
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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
yronnenCommented:
Oops..assuming that you've written the second app, of course.

If not, please comment me and I'll withdraw my answer.
0
 
jgoreAuthor Commented:
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
 
jgoreAuthor Commented:
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
 
AzraSoundCommented:
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
 
MinnEECommented:
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
 
AzraSoundCommented:
i had forgotten about this question =/

posting comment as answer
0
 
jgoreAuthor Commented:
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
 
AzraSoundCommented:
you can reject his answer and then accept my comment as an answer
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 4
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now