Here's a code example:
Code: Select all
processID.l = RunProgram("someprogram.exe","","",#PB_Program_Open)
Delay(10000)
KillProgram(processID)
CloseProgram(processID)
Code: Select all
processID.l = RunProgram("someprogram.exe","","",#PB_Program_Open)
Delay(10000)
KillProgram(processID)
CloseProgram(processID)
I see. I'm no good at API stuff, but is it possible to kill it in a "nice" way, by maybe using sendmessage telling it to close?Fred wrote:KillProgram() really kills the program, with no chance to correctly exits. That's why its icon is still remaining, and you will have to inform the explorer process than it needs to refresh it's systray bar.
Code: Select all
SendMessage_(hWnd, #WM_SYSCOMMAND, #SC_CLOSE, 0)(
Code: Select all
; Structure NOTIFYICONDATA
; cbSize.l
; hWnd.i
; uID.l
; uFlags.l
; uCallbackMessage.l
; hIcon.i
; szTip.c[64]
; EndStructure
Structure m_NOTIFYICONDATA
cbSize.i
hwnd.i
uId.i
uFlags.i
uCallBackMessage.i
hIcon.i
szTip.s{64}
EndStructure
ImportC "SHELL32.LIB"
Shell_NotifyIcon_.i(dwMessage.i, pnid.i) As "_Shell_NotifyIconA"
EndImport
Define.i hWnd, hIcon
Define.m_NOTIFYICONDATA nid
hwnd = GetDesktopWindow_()
hicon = ExtractIcon_(0,"c:\windows\notepad.exe",0)
With nid
\cbSize = SizeOf(nid)
\hWnd = hWnd
\uId = #Null
\uFlags = #NIF_ICON | #NIF_TIP | #NIF_MESSAGE
\uCallBackMessage = #WM_MOUSEMOVE
\hIcon = hicon
\szTip = "Some Text Here" + Chr(0)
EndWith
Shell_NotifyIcon_(#NIM_ADD, nid)
;--> PB cmd does not work --> AddSysTrayIcon(0,hWnd,hicon)
Debug "...Hold mouse over SysTray icon now..."
Delay(5000)
Debug "...Attempting to remove SysTray icon..."
Debug ""
Shell_NotifyIcon_(#NIM_DELETE, nid)
Debug "...Quitting in 3 sec..."
DestroyIcon_(hIcon)
Delay(3000)
End
http://www.purebasic.fr/english/viewtop ... =5&t=28500whertz wrote: I've looked through the forum but can't seem to find anything.
Thanks srod, I got this working but I found out when you do this, it just minimizes the program. So I really do need to kill it with killprogram. Has anyone found a solution in PB to remove the lingering tray icon??srod wrote:If you can find the handle of the main window (use FindWindow_()) then try sending the following message :
Code: Select all
SendMessage_(hWnd, #WM_SYSCOMMAND, #SC_CLOSE, 0)(
Code: Select all
PostMessage_(hWnd,#WM_CLOSE,0,0)
That just makes it open up from the tray, and minimizes it again. I think the only way is killprogram.UserOfPure wrote:To close a program via its handle, use this:
Don't use SendMessage because it won't work with folder windows (at least it doesn't for me).Code: Select all
PostMessage_(hWnd,#WM_CLOSE,0,0)
Not on XP. I've been using it to close apps on XP for years. It's basically the same as doing Alt+F4 on the app. What OS are you using it with?whertz wrote:That just makes it open up from the tray, and minimizes it again.
I understand what you are saying, but sending it Alt+F4 minimizes it, it is just the way the program works. It's like when you press the close button on some apps, they minimize instead. BTW I'm using XP too.UserOfPure wrote:Not on XP. I've been using it to close apps on XP for years. It's basically the same as doing Alt+F4 on the app. What OS are you using it with?whertz wrote:That just makes it open up from the tray, and minimizes it again.
Code: Select all
Procedure DoNotCall()
CreateImage(1, 10,10)
EndProcedure
Code: Select all
Procedure DoNotCall()
CreateImage(1, 10,10)
EndProcedure
ImportC "SHELL32.LIB"
Shell_NotifyIcon_.i(dwMessage.i, pnid.i) As "_Shell_NotifyIconA"
EndImport
Define.i hWnd, hIcon
Define.NOTIFYICONDATA nid
hwnd = GetDesktopWindow_()
hicon = ExtractIcon_(0,"c:\windows\notepad.exe",0)
With nid
\cbSize = SizeOf(nid)
\hWnd = hWnd
\uId = #Null
\uFlags = #NIF_ICON | #NIF_TIP | #NIF_MESSAGE
\uCallBackMessage = #WM_MOUSEMOVE
\hIcon = hicon
PokeS(@\szTip, "Some Text Here")
EndWith
Shell_NotifyIcon_(#NIM_ADD, nid)
;AddSysTrayIcon(0,hWnd,hicon)
Debug "...Hold mouse over SysTray icon now..."
Delay(5000)
Debug "...Attempting to remove SysTray icon..."
Debug ""
Shell_NotifyIcon_(#NIM_DELETE, nid)
Debug "...Quitting in 3 sec..."
DestroyIcon_(hIcon)
Delay(3000)
End