i'm pretty sure that you can get the handle of an application as soon as you shell it.
Do you have to use the ShellExecute method, or can you use shell?
Printable View
i'm pretty sure that you can get the handle of an application as soon as you shell it.
Do you have to use the ShellExecute method, or can you use shell?
To Open it I'm currently using-
UCalcID = ShellExecute(frmMain.hwnd, "open", Application.Path & "UCalc.exe", "-fast", Application.Path, SW_SHOWNORMAL)
To Close it I attempted-
PostMessage UCalcID, WM_CLOSE, CLng(0), CLng(0)
but it didn't work...
I also attempted SendMessage to close and FindWindow to find whether it was running but both didn't work...
That's because it ShellExecute returns a ErrorSuccess value, not a handle.
try this:
VB Code:
Option Explicit Private Type PROCESS_INFORMATION hProcess As Long hThread As Long dwProcessId As Long dwThreadId As Long End Type Private Type STARTUPINFO cb As Long lpReserved As String lpDesktop As String lpTitle As String dwX As Long dwY As Long dwXSize As Long dwYSize As Long dwXCountChars As Long dwYCountChars As Long dwFillAttribute As Long dwFlags As Long wShowWindow As Integer cbReserved2 As Integer lpReserved2 As Long hStdInput As Long hStdOutput As Long hStdError As Long End Type Private Declare Function CreateProcess Lib "kernel32" _ Alias "CreateProcessA" _ (ByVal lpApplicationName As String, _ ByVal lpCommandLine As String, _ lpProcessAttributes As Any, _ lpThreadAttributes As Any, _ ByVal bInheritHandles As Long, _ ByVal dwCreationFlags As Long, _ lpEnvironment As Any, _ ByVal lpCurrentDriectory As String, _ lpStartupInfo As STARTUPINFO, _ lpProcessInformation As PROCESS_INFORMATION) As Long Private Declare Function OpenProcess Lib "kernel32.dll" _ (ByVal dwAccess As Long, _ ByVal fInherit As Integer, _ ByVal hObject As Long) As Long Private Declare Function TerminateProcess Lib "kernel32" _ (ByVal hProcess As Long, _ ByVal uExitCode As Long) As Long Private Declare Function CloseHandle Lib "kernel32" _ (ByVal hObject As Long) As Long Const SYNCHRONIZE = 1048576 Const NORMAL_PRIORITY_CLASS = &H20& Private Sub Form_Click() Dim pInfo As PROCESS_INFORMATION Dim sInfo As STARTUPINFO Dim sNull As String Dim lSuccess As Long Dim lRetValue As Long sInfo.cb = Len(sInfo) lSuccess = CreateProcess(sNull, _ "Calc.exe", _ ByVal 0&, _ ByVal 0&, _ 1&, _ NORMAL_PRIORITY_CLASS, _ ByVal 0&, _ sNull, _ sInfo, _ pInfo) MsgBox "Calculator has been launched!" lRetValue = TerminateProcess(pInfo.hProcess, 0&) lRetValue = CloseHandle(pInfo.hThread) lRetValue = CloseHandle(pInfo.hProcess) MsgBox "Calculator has terminated!" End Sub
Try that ? ;)
This is what I was working from on ShellExecute. (From www.vbapi.com) Is this incorrect then?
--------------------
If successful, the function returns a handle to the instance of the application which the function started. If an error occured, the function returns either 0 (indicating a lack of memory) or one of the following flags:
etc. etc.
--------------------
Also, how would I be able to tell if the program is running ?
I don't have that spy.exe program that is mentioned on these forums a few times and couldn't find it with a search... Anywhere to get it?
Or is there some other way to determine if the sys tray program is running?
EDIT: Oh yeah, the code you listed above works perfectly... Thanks alot! You made my day...
No probs man
I thought you still needed help until i read that edit :rolleyes:
can u figure out this?
Private Sub Timer1_Timer()
Static isFirstFrame As Boolean
If isFristFrame Then
TrayIcon.Icon = LoadPicture("pic1.ico")
Else
TrayIcon.Icon = LoadPicture("pic2.ico")
End If
modifyIcon 'method that call API to change icon in the tray
isFirstFrame = Not isFirstFrame
End Sub
Private Sub Form_Load()
Set trayIcon = New TrayIcon
Set trayIcon.OwnerForm = Me
trayIcon.Visible = True
Timer1.Enabled = true
Timer1.Interval = 250
End Sub
Private Sub Command1_Click()
MsgBox "test....."
End Sub
sorry, err click....
My question: I use timer to get animated icon in my app(suppose 2 frames). It works well. But when I click button Command1 to do some operation, say a msgbox pop up, then the animation stop until that operation is finished. I hope the icon is always animated no matter what happen.
do u have any suggstion? thanks.