I use shellexecute to run another program but I want my vb application minimized when I click the cmdbutton. How can I do that? :confused:
Printable View
I use shellexecute to run another program but I want my vb application minimized when I click the cmdbutton. How can I do that? :confused:
Form1.WindowState = 1
or use these VB constants:
vbMinimized
vbMaximized
vbNormal
Does it work for you?
Yes its working for me. But I want to minimize not only my application but any other applications that running on taskbar. If possible I want to fire the 'show desktop' quick launch. Is there any API call can do this?
VB Code:
Option Explicit Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Type POINTAPI X As Long Y As Long End Type Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Private Type WINDOWPLACEMENT length As Long flags As Long showCmd As Long ptMinPosition As POINTAPI ptMaxPosition As POINTAPI rcNormalPosition As RECT End Type Private Declare Function GetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long Private Declare Function SetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long Private Const SW_SHOWMINIMIZED = 2 Private Const SW_SHOWMAXIMIZED = 3 Private Const SW_SHOWNORMAL = 1 ' Find the target window and minimize, maximize, ' or restore it. Private Sub cmdGo_Click() Dim app_hwnd As Long Dim wp As WINDOWPLACEMENT ' Find the target. app_hwnd = FindWindow(vbNullString, txtTargetName.Text) ' Get the window's current placement information. wp.length = Len(wp) GetWindowPlacement app_hwnd, wp ' Set the appropriate action. If optPlacement(0).Value Then ' Minimize. wp.showCmd = SW_SHOWMINIMIZED ElseIf optPlacement(1).Value Then ' Maximize. wp.showCmd = SW_SHOWMAXIMIZED Else ' Restore. wp.showCmd = SW_SHOWNORMAL End If ' Perform the action. SetWindowPlacement app_hwnd, wp End Sub
There is something like above. Is it ok?
You can see for yourself here.