Results 1 to 8 of 8

Thread: Maximizing Another Application

  1. #1

    Thread Starter
    Member PatrickCorgan's Avatar
    Join Date
    Feb 2001
    Location
    Vashon Island, WA, USA
    Posts
    39

    Question

    I can get both the hWnd and the title bar text of another application. I can transfer focus to the app. But if it is minimized, it stays minimized. How can I restore it?

    Thanks!

  2. #2
    Lively Member markwel's Avatar
    Join Date
    Jan 2001
    Location
    Chennai, India
    Posts
    104
    Hai,

    FindWindow API is useful to Find the Application. After that you should use sendkeys function.


    Dim hWnd As Long
    hWnd = FindWindow(vbNullString, "Microsoft Word")
    If hWnd = 0 Then
    Msgbox "Application Running"
    Endif
    Soma Sundaram R
    3/480, Lakshmana Perumal Street
    Kottivakkam
    Chennai, India

    [email protected]
    http://somasundaram.cjb.com
    Develop Your Own Browser-->http://www.vbsquare.com/internet/browser/

  3. #3
    Lively Member markwel's Avatar
    Join Date
    Jan 2001
    Location
    Chennai, India
    Posts
    104
    Hai,

    You should declare that API Function also

    At Module declaration section, you should paste this.

    Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

    Thanx and Best of Luck.
    Soma Sundaram R
    3/480, Lakshmana Perumal Street
    Kottivakkam
    Chennai, India

    [email protected]
    http://somasundaram.cjb.com
    Develop Your Own Browser-->http://www.vbsquare.com/internet/browser/

  4. #4
    Guest
    Use the ShowWindow API function.


    Code:
    Private Declare Function FindWindow Lib "user32" _
    Alias "FindWindowA" (Byval lpClassName As String, _
    Byval lpWindowName As String) As Long
    
    Private Declare Function ShowWindow Lib "user32" _
    (Byval hwnd As Long, Byval nCmdShow As Long) As _
    Long
    
    Private Const SW_RESTORE = 9
    
    
    Private Sub Command1_Click()
    
        Dim hWin As Long
        hWin = FindWindow("SciCalc", "Calculator")
        If hWin <> 0 Then
            ShowWindow hWin, SW_RESTORE
        End If
        
    End Sub

  5. #5
    Guest
    By the way, markwel, if the handle is 0, the window doesn't exist. Anything other than 0 and there's a handle that exists. And you shouldn't use hWnd as a variable, being that it's already being used in other places. So your code should be like this:


    Code:
    Dim hWin As Long 
    hWin = FindWindow(vbNullString, "Microsoft Word") 
    If hWin <> 0 Then 
        Msgbox "Application Running" 
    End If

  6. #6
    Lively Member markwel's Avatar
    Join Date
    Jan 2001
    Location
    Chennai, India
    Posts
    104
    Yes Mathews. I understand.

    Thanx.
    Soma Sundaram R
    3/480, Lakshmana Perumal Street
    Kottivakkam
    Chennai, India

    [email protected]
    http://somasundaram.cjb.com
    Develop Your Own Browser-->http://www.vbsquare.com/internet/browser/

  7. #7
    Guest
    This will get the Windowname as well as the handle
    Code:
    Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    
    Private Sub Command1_Click()
        
        Dim hCalc As Long
        Dim sName As String * 255
        
        hCalc = FindWindowEx(0, 0, "SciCalc", "Calculator")
        GetWindowText hCalc, sName, 255
        sName = Left(sName, InStr(1, sName, vbNullChar) - 1)
        Print sName
        Print hCalc
        
    End Sub

  8. #8

    Thread Starter
    Member PatrickCorgan's Avatar
    Join Date
    Feb 2001
    Location
    Vashon Island, WA, USA
    Posts
    39

    Thumbs up Thanks

    Got it all figured out. Thanks for all your help!

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