jack71 Posted January 20, 2015 Posted January 20, 2015 (edited) So I'm writing a script that makes a notepad window ontop, however it can still be minimized via clicking on the notepad taskbar tray icon, which I don't want the user to be able to. I've found that this works great for Vista/7/8.1: Local Const $sCLSID_TaskbarList = "{56FDF344-FD6D-11D0-958A-006097C9A090}" Local Const $sIID_ITaskbarList = "{56FDF342-FD6D-11D0-958A-006097C9A090}" Local Const $sTagITaskbarList = "HrInit hresult(); AddTab hresult(hwnd); DeleteTab hresult(hwnd); ActivateTab hresult(hwnd); SetActiveAlt hresult(hwnd);" Local $oTaskbarList = ObjCreateInterface($sCLSID_TaskbarList, $sIID_ITaskbarList, $sTagITaskbarList) $oTaskbarList.DeleteTab($windowhandle) However on winxp sp3, this doesn't work to remove the taskbar tray icon. Are the first two constants not correct for winxp machines? Thanks. Edited January 20, 2015 by jack71
Moderators SmOke_N Posted January 20, 2015 Moderators Posted January 20, 2015 Tray icons or Taskbar window tabs? Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
jack71 Posted January 20, 2015 Author Posted January 20, 2015 Tray icons or Taskbar window tabs? Tray icons. Not system tray in the far right. The icons in the tray when a program is running, in this example notepad.
Moderators SmOke_N Posted January 20, 2015 Moderators Posted January 20, 2015 So taskbar tab windows. Tray is completely different. Try using ... was going to write code, but remembered someone did something before that I know should work on XP too. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
jack71 Posted January 20, 2015 Author Posted January 20, 2015 So taskbar tab windows. Tray is completely different. Try using ... was going to write code, but remembered someone did something before that I know should work on XP too. Hmm... that's not working on win 8.1. Also just to clarify even further: I am talking about the "Untitled - Notepad" on the taskbar, next to the pinned chrome and IE icons.
Moderators SmOke_N Posted January 20, 2015 Moderators Posted January 20, 2015 Yes, those are taskbar tabs. You said you needed an XP solution, not a windows 8 solution. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
jack71 Posted January 20, 2015 Author Posted January 20, 2015 Yes, those are taskbar tabs. You said you needed an XP solution, not a windows 8 solution. I need cross platform . I have several machines that have WinXP sp3, Win7 and Win8.1. I guess I can do an OS check and proceed from there. Was hoping there was one solution for all 3 .
Moderators SmOke_N Posted January 20, 2015 Moderators Posted January 20, 2015 Yes, I figured as much... Yes, check the OS with a switch or if/then statement. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
johnmcloud Posted January 21, 2015 Posted January 21, 2015 (edited) Both of this example work on XP and 7 Without ObjCreateInterface ; Johnmcloud - 2015 Run(@WindowsDir & "\notepad.exe", "", @SW_HIDE) $hNotepad = WinWait("[CLASS:Notepad]") _TaskbarTab($hNotepad, 0) MsgBox(4096, "", "Look in the Taskbar. There should no longer be a Notepad entry but Notepad is still running." & @CRLF & @CRLF & "Press OK to continue.") Sleep(1000) _TaskbarTab($hNotepad, 1) MsgBox(4096, "", "Look in the Taskbar and you should see an entry for Notepad." & @CRLF & @CRLF & "Press OK to continue.") WinClose($hNotepad) Func _TaskbarTab($hWnd, $iVisible) Local $hParent = WinGetHandle("[CLASS:Progman]") If $iVisible = 0 Then DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $hWnd, "hwnd", $hParent) WinActivate($hWnd, "") WinSetState($hWnd, "", @SW_SHOW) ElseIf $iVisible = 1 Then DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $hWnd, "hwnd", "") EndIf EndFunc ;==>_TaskbarTab With ObjCreateInterface ; Declare the CLSID, IID and interface description for ITaskbarList. ; It is not necessary to describe the members of IUnknown. Local Const $sCLSID_TaskbarList = "{56FDF344-FD6D-11D0-958A-006097C9A090}" Local Const $sIID_ITaskbarList = "{56FDF342-FD6D-11D0-958A-006097C9A090}" Local Const $sTagITaskbarList = "HrInit hresult(); AddTab hresult(hwnd); DeleteTab hresult(hwnd); ActivateTab hresult(hwnd); SetActiveAlt hresult(hwnd);" ; Create the object. Local $oTaskbarList = ObjCreateInterface($sCLSID_TaskbarList, $sIID_ITaskbarList, $sTagITaskbarList) ; Initialize the iTaskbarList object. $oTaskbarList.HrInit() ; Run Notepad. Run("notepad.exe") ; Wait for the Notepad window to appear and get a handle to it. Local $hNotepad = WinWait("[CLASS:Notepad]") ; Tell the user what to look for. MsgBox(4096, "", "Look in the Taskbar and you should see an entry for Notepad." & @CRLF & @CRLF & "Press OK to continue.") ; Delete the Notepad entry from the Taskbar. $oTaskbarList.DeleteTab($hNotepad) ; Tell the user to look again. MsgBox(4096, "", "Look in the Taskbar. There should no longer be a Notepad entry but Notepad is still running." & @CRLF & @CRLF & "Press OK to continue.") ; Close Notepad. WinClose($hNotepad) Edited January 21, 2015 by johnmcloud
jack71 Posted January 21, 2015 Author Posted January 21, 2015 Both of this example work on XP and 7 Without ObjCreateInterface ; Johnmcloud - 2015 Run(@WindowsDir & "\notepad.exe", "", @SW_HIDE) $hNotepad = WinWait("[CLASS:Notepad]") _TaskbarTab($hNotepad, 0) MsgBox(4096, "", "Look in the Taskbar. There should no longer be a Notepad entry but Notepad is still running." & @CRLF & @CRLF & "Press OK to continue.") Sleep(1000) _TaskbarTab($hNotepad, 1) MsgBox(4096, "", "Look in the Taskbar and you should see an entry for Notepad." & @CRLF & @CRLF & "Press OK to continue.") WinClose($hNotepad) Func _TaskbarTab($hWnd, $iVisible) Local $hParent = WinGetHandle("[CLASS:Progman]") If $iVisible = 0 Then DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $hWnd, "hwnd", $hParent) WinActivate($hWnd, "") WinSetState($hWnd, "", @SW_SHOW) ElseIf $iVisible = 1 Then DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $hWnd, "hwnd", "") EndIf EndFunc ;==>_TaskbarTab With ObjCreateInterface ; Declare the CLSID, IID and interface description for ITaskbarList. ; It is not necessary to describe the members of IUnknown. Local Const $sCLSID_TaskbarList = "{56FDF344-FD6D-11D0-958A-006097C9A090}" Local Const $sIID_ITaskbarList = "{56FDF342-FD6D-11D0-958A-006097C9A090}" Local Const $sTagITaskbarList = "HrInit hresult(); AddTab hresult(hwnd); DeleteTab hresult(hwnd); ActivateTab hresult(hwnd); SetActiveAlt hresult(hwnd);" ; Create the object. Local $oTaskbarList = ObjCreateInterface($sCLSID_TaskbarList, $sIID_ITaskbarList, $sTagITaskbarList) ; Initialize the iTaskbarList object. $oTaskbarList.HrInit() ; Run Notepad. Run("notepad.exe") ; Wait for the Notepad window to appear and get a handle to it. Local $hNotepad = WinWait("[CLASS:Notepad]") ; Tell the user what to look for. MsgBox(4096, "", "Look in the Taskbar and you should see an entry for Notepad." & @CRLF & @CRLF & "Press OK to continue.") ; Delete the Notepad entry from the Taskbar. $oTaskbarList.DeleteTab($hNotepad) ; Tell the user to look again. MsgBox(4096, "", "Look in the Taskbar. There should no longer be a Notepad entry but Notepad is still running." & @CRLF & @CRLF & "Press OK to continue.") ; Close Notepad. WinClose($hNotepad) Thanks Johnmcloud! The 2nd one with objcreate works on win8.1. Going to try that on the winxp machines later! Thanks!
jack71 Posted January 22, 2015 Author Posted January 22, 2015 Just to confirm, your first script works but not the second one on winxp.
johnmcloud Posted January 22, 2015 Posted January 22, 2015 (edited) On my XP Pro SP3 the second one work fine. Don't quote, is unecessary. Edited January 22, 2015 by johnmcloud
jack71 Posted January 22, 2015 Author Posted January 22, 2015 On my XP Pro SP3 the second one work fine. Don't quote, is unecessary. ::shrug:: I don't know why it doesn't work on my end, running SP3 as well. I've ran into one problem with the second script you posted. It does work to remove the taskbar tab, but WinSetOnTop no longer works, whether are put it before your script or after it will not SetOnTop.
jack71 Posted January 24, 2015 Author Posted January 24, 2015 I'm going to try a few more XP solutions that are posted around here, but for sanity sake I installed VirtualBox with WinXP Pro SP3, nothing else and the ObjCreateInterface method does not work.
Solution jack71 Posted January 24, 2015 Author Solution Posted January 24, 2015 For windows xp, this solution works:
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now