Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

GURU's:  Maximize a seperate application?

Posted on 2000-04-23
11
Medium Priority
?
214 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 400 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

783 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