CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2000
    Location
    Georgia
    Posts
    5

    Controlling a application from VB

    I need to know how to control an application from VB. I allready know how to start the application
    using the Shell function. However, the VB Program I am running will hide the application in the back
    ground if minamized.How can I maxamize and or close the application from VB?


  2. #2
    Join Date
    Sep 1999
    Location
    Red Wing, MN USA
    Posts
    312

    Re: Controlling a application from VB

    You can use a couple of APIs to Compare ProcessID's until you find a Match, ie.
    'In a Module..
    private Declare Function GetWindowThreadProcessId Lib "user32" (byval hwnd as Long, lpdwProcessId as Long) as Long
    private Declare Function EnumWindows Lib "user32" (byval lpEnumFunc as Long, byval lParam as Long) as Long

    private lHwnd as Long

    private Function EnumWindowProc(byval hwnd as Long, byval lParam as Long) as Long
    Dim lProcessID as Long
    Call GetWindowThreadProcessId(hwnd, lProcessID)
    If lProcessID = lParam then
    lHwnd = hwnd
    else
    EnumWindowProc = hwnd
    End If
    End Function

    public Function GetProcessIDWindow(byval ProcessID as Long) as Long
    lHwnd = 0
    Call EnumWindows(AddressOf EnumWindowProc, ProcessID)
    GetProcessIDWindow = lHwnd
    End Function


    Then use the ShowWindow() API to Change the Windows State, ie.
    'In a Form..
    private Declare Function ShowWindow Lib "user32" (byval hwnd as Long, byval nCmdShow as Long) as Long
    private Const SW_HIDE = 0
    private Const SW_MAXIMIZE = 3
    private Const SW_MINIMIZE = 6
    private Const SW_NORMAL = 1
    private Const SW_RESTORE = 9

    private Sub Command1_Click()
    Dim lHwnd as Long
    lHwnd = GetProcessIDWindow(Shell("Notepad.exe", vbHide))
    Call ShowWindow(lHwnd, SW_RESTORE)
    End Sub



    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]
    Aaron Young
    Senior Programmer Analyst (Red Wing Software)
    Certified AllExperts Expert

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

Featured