Results 1 to 2 of 2

Thread: Tough one.. minimize an external application :S

  1. #1

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172

    Tough one.. minimize an external application :S

    I wonder if it is possible to minimize an external application , like with its handle or something (not sure how to get that either)..


    any help to get me on the way is welcome...
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  2. #2
    Lively Member tom_hotspur's Avatar
    Join Date
    Aug 2002
    Location
    Stafford
    Posts
    96
    I've not used this code for a long long time (its in vb6 as well sorry) but it may help you.

    Basically i can't remember the specifics of how it works just what i used to use it for!

    Basically if it checks if the app is open and then if activates (if desired).

    VB Code:
    1. Private Const SW_HIDE = 0
    2. Private Const SW_SHOWNORMAL = 1
    3. Private Const SW_NORMAL = 1
    4. Private Const SW_SHOWMINIMIZED = 2
    5. Private Const SW_SHOWMAXIMIZED = 3
    6. Private Const SW_MAXIMIZE = 3
    7. Private Const SW_SHOWNOACTIVATE = 4
    8. Private Const SW_SHOW = 5
    9. Private Const SW_MINIMIZE = 6
    10. Private Const SW_SHOWMINNOACTIVE = 7
    11. Private Const SW_SHOWNA = 8
    12. Private Const SW_RESTORE = 9
    13. Private Const SW_SHOWDEFAULT = 10
    14. Private Const SW_MAX = 10
    15.  
    16. Private Declare Function apiFindWindow Lib "user32" Alias _
    17.     "FindWindowA" (ByVal strClass As String, _
    18.     ByVal lpWindow As String) As Long
    19.  
    20. Private Declare Function apiSendMessage Lib "user32" Alias _
    21.     "SendMessageA" (ByVal hWnd As Long, ByVal Msg As Long, ByVal _
    22.     wParam As Long, lParam As Long) As Long
    23.    
    24. Private Declare Function apiSetForegroundWindow Lib "user32" Alias _
    25.     "SetForegroundWindow" (ByVal hWnd As Long) As Long
    26.    
    27. Private Declare Function apiShowWindow Lib "user32" Alias _
    28.     "ShowWindow" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
    29.    
    30. Private Declare Function apiIsIconic Lib "user32" Alias _
    31.     "IsIconic" (ByVal hWnd As Long) As Long
    32.  
    33.  
    34. '******************************************
    35.  
    36. Function fIsAppRunning(ByVal strAppName As String, _
    37.         Optional fActivate As Boolean) As Boolean
    38.     Dim lngH As Long, strClassName As String
    39.     Dim lngX As Long, lngTmp As Long
    40.     Const WM_USER = 1024
    41.     On Local Error GoTo fIsAppRunning_Err
    42.     fIsAppRunning = False
    43.     Select Case LCase$(strAppName)
    44.         Case "excel":       strClassName = "XLMain"
    45.         Case "word":        strClassName = "OpusApp"
    46.         Case "access":      strClassName = "OMain"
    47.         Case "powerpoint95": strClassName = "PP7FrameClass"
    48.         Case "powerpoint97": strClassName = "PP97FrameClass"
    49.         Case "notepad":     strClassName = "NOTEPAD"
    50.         Case "paintbrush":  strClassName = "pbParent"
    51.         Case "wordpad":     strClassName = "WordPadClass"
    52.         Case "notes":       strClassName = "NOTES" ''lotus notes
    53.         Case "lock":        strClassName = "#32770(Dialog)" 'lotus notes password box
    54.         Case "enquiry":     strClassName = "ThunderRT6MDIForm" 'art enquiry database
    55.         Case Else:          strClassName = ""
    56.     End Select
    57.    
    58.     If strClassName = "" Then
    59.         lngH = apiFindWindow(vbNullString, strAppName)
    60.     Else
    61.         lngH = apiFindWindow(strClassName, vbNullString)
    62.     End If
    63.    
    64.     If lngH <> 0 Then
    65.         apiSendMessage lngH, WM_USER + 18, 0, 0
    66.         lngX = apiIsIconic(lngH)
    67.        
    68.         If lngX <> 0 Then
    69.             lngTmp = apiShowWindow(lngH, SW_SHOWNORMAL)
    70.         End If
    71.        
    72.         If fActivate Then
    73.             lngTmp = apiSetForegroundWindow(lngH)
    74.         End If
    75.        
    76.         fIsAppRunning = True
    77.     End If
    78. fIsAppRunning_Exit:
    79.     Exit Function
    80. fIsAppRunning_Err:
    81.     fIsAppRunning = False
    82.     Resume fIsAppRunning_Exit
    83. End Function

    if you notice the line

    VB Code:
    1. lngTmp = apiShowWindow(lngH, SW_SHOWNORMAL)

    why not change it to
    VB Code:
    1. lngTmp = apiShowWindow(lngH, SW_MINIMIZE)

    or use one of the other constants and see what happens.

    oh yeah i think to get the windows handles you can use spy++??

    hope it helps?
    tom

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width