AutoHotkey Community

It is currently May 26th, 2012, 4:18 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 42 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
PostPosted: November 27th, 2007, 3:46 pm 
Hi,

Sorry to bring up this old topic. It is a very nifty script (icontray.ahk), but I'm experiencing some trouble with it. I modified it to my needs to load a program and then hide the icon from the taskbar. But I have to use sleep so the process exists before it can be hidden. This works when the computer has already started but not after startup.

Code:
Run, csrsmsg.exe, A_WorkingDir, UseErrorLevel
Sleep, 2250

TrayIcons("csrsmsg.exe")


Code:
If !sExeName || (sExeName = sProcess) || (sExeName = pid)
      {
         If sExeName = DUMeter.exe { HideTrayIcon(idn, !(GetTrayIconState(idn) & 0x8))}
         DllCall("ReadProcessMemory", "Uint", hProc, "Uint", iString, "Uint", &wTooltip, "Uint", 128 * 2, "Uint", 0)
         DllCall("WideCharToMultiByte", "Uint", 0, "Uint", 0, "str", wTooltip, "int", -1, "str", sTooltip, "int", 128, "Uint", 0, "Uint", 0)
         sTrayIcons .= "idx: " . A_Index - 1 . " | idn: " . idn . " | Pid: " . pid . " | uID: " . uID . " | MessageID: " . nMsg . " | hWnd: " . hWnd . " | Class: " . sClass . " | Process: " . sProcess . "`n" . "   | Tooltip: " . sTooltip . "`n"
         HideTrayIcon(idn) =>> added this
      }


Might there be a solution for this ? To check if the process exists so I wouldn't have to use the sleep command(which isn't foolproof, and the longer the sleep the greater the chance of the user noticing the icon). Or will does never work while starting up ? Help greatly appreciated.

Thanks,

Tim


Report this post
Top
  
Reply with quote  
PostPosted: November 28th, 2007, 12:05 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
Tim77 wrote:
Might there be a solution for this ? To check if the process exists

May use this:
Code:
Process, Wait, csrsmsg.exe


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 28th, 2007, 1:57 pm 
Thanks for the reply, but it doesn't work.

Code:
Run, csrs.exe, A_WorkingDir, UseErrorLevel

=> This should return 0 as ErrorLevel

Wait: Waits up to Param3 seconds (can contain a decimal point) for a matching process to exist. If Param3 is omitted, the command will wait indefinitely. If a matching process is discovered, ErrorLevel is set to its Process ID (PID). If the command times out, ErrorLevel is set to 0.

Exist: Sets ErrorLevel to the Process ID (PID) if a matching process exists, or 0 otherwise. If the PID-or-Name parameter is blank, the script's own PID is retrieved. An alternate, single-line method to retrieve the script's PID is PID := DllCall("GetCurrentProcessId")

Code:
Process, Exist, csrs.exe

=> So this should give me the pid of the process if it exists. Directly afterwards I should be able to use the HideTrayIcon function but it doesn't work. :? .Anymore suggestions ?

Thanks,

Tim


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 28th, 2007, 2:44 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
Tim77 wrote:
Code:
Run, csrs.exe, A_WorkingDir, UseErrorLevel

=> This should return 0 as ErrorLevel

I noticed you used UseErrorLevel with Run, and I don't think Process Wait essentially delays the retrieval any further than it. So if the former doesn't work then the latter may not work either. Anyway, the simplest solution may be just Loop TrayIcons("csrsmsg.exe") itself after tweaking it so as to return true when it really found one.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 11th, 2008, 5:45 pm 
Offline

Joined: October 9th, 2006, 9:27 am
Posts: 21
Thanks to the author! :shock: :lol:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 12th, 2008, 4:04 am 
Offline

Joined: March 27th, 2008, 2:14 pm
Posts: 700
Might this be suitable for the Lib?

_________________
Scripts - License


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 21st, 2008, 7:25 pm 
Offline

Joined: March 27th, 2008, 2:14 pm
Posts: 700
I changed the TrayIcon and TaskButton scripts to lib functions.

Download lib version:
TrayIcon.ahk
TaskButton.ahk

Not completely tested. I included "GetHotItem" in both. (i didn't test the TrayIcon version)

Some ideas:
How about adding "TB_SETINSERTMARK"? (I don't know if that will even work...)
Would there be an easy way to get a picture of the Button/Icon so you can display it next to the mouse if you're trying to move it?

The msdn url for TB messages: http://msdn.microsoft.com/en-us/library/bb762722%28VS.85%29.aspx

_________________
Scripts - License


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 17th, 2008, 12:49 pm 
Offline

Joined: November 2nd, 2004, 2:43 pm
Posts: 1019
Location: London, UK
Is there a way of getting the taskbar to resize the buttons after hiding one.
If you fill up the task bar and hide one, the buttons do not move to fill in the new space created.

I have tried sending TB_AUTOSIZE but this had no effect.

I have tried monitoring the messages using winspector, but tbh there are hundreds generated. And maybe I am blind, but I cannot see any other messages that could cause windows to resize all the buttons accordingly.


Oh and thanks for the great functions as always, I should have quite nice one to add soon :D

_________________
Steve F AKA Superfraggle

http://r.yuwie.com/superfraggle


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 17th, 2008, 2:32 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
Superfraggle wrote:
Is there a way of getting the taskbar to resize the buttons after hiding one.
If you fill up the task bar and hide one, the buttons do not move to fill in the new space created.

I don't really know as I haven't tried it. You may try TB_DELETEBUTTON instead of TB_HIDEBUTTON to make the buttons AutoSize. If not work, I think you have to resize them manually using TB_SETBUTTONSIZE.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 1st, 2009, 6:17 am 
Offline

Joined: March 27th, 2008, 2:14 pm
Posts: 700
This script is for the TaskBar Buttons only. I recently modified it and released [lib] Remote ToolBar that work on any toolbar control, including the taskbar buttons. For ease of use, I made a TaskBar wrapper for the new library to extend this functionality directly to the Taskbar Buttons.

You will need the above mentioned library to use this.

You can save it as TaskBar.ahk in your library.

Code:
; ############################################################################# TaskBar Functions

TaskBar_GetSwbarId() {
   DetectHiddenWindows, On
   WinGet, ControlList, ControlList, ahk_class Shell_TrayWnd
   RegExMatch(ControlList, "(?<=ToolbarWindow32)\d+(?!.*ToolbarWindow32)", nTB)
   Loop, %nTB%
   {
      ControlGet, hWnd, hWnd,, ToolbarWindow32%A_Index%, ahk_class Shell_TrayWnd
      WinGetClass, sClass, % "ahk_id" DllCall("GetParent", "Uint", hWnd)
      If (sClass <> "MSTaskSwWClass")
         Continue
      ControlGet, hwndTB, hwnd, , ToolbarWindow32%A_Index%, ahk_class Shell_TrayWnd
      Break
   }
   Return   hwndTB
}

TaskBar_Hide(idn, bHide = True) {
   return TB_Hide(TaskBar_GetSwbarId(), idn, bHide)
}

TaskBar_Delete(idx) {
   return TB_Delete(TaskBar_GetSwbarId(), idx)
}

TaskBar_Move(idxOld, idxNew) {
   return TB_Move(TaskBar_GetSwbarId(), idxOld, idxNew)
}

TaskBar_GetHotItem() {
   return TB_GetHotItem(TaskBar_GetSwbarId())
}

TaskBar_SetInsertMark(idx, side=0) {
   return TB_SetInsertMark(TaskBar_GetSwbarId(), idx, side)
}

TaskBar_SetInsertMarkColor(rgb) {
   return TB_SetInsertMarkColor(TaskBar_GetSwbarId(), rgb)
}

TaskBar_SetStyle(styles) {
   return TB_SetStyle(TaskBar_GetSwbarId(), styles)
}

TaskBar_GetStyle() {
   return TB_GetStyle(TaskBar_GetSwbarId())
}

TaskBar_ChangeStyle(add = 0, remove = 0) {
   return TB_ChangeStyle(TaskBar_GetSwbarId(), add, remove)
}

TaskBar_GetItemRect(idx, ByRef RECT) {
   return TB_GetItemRect(TaskBar_GetSwbarId(), idx, RECT)
}

TaskBar_ButtonCount() {
   return TB_ButtonCount(TaskBar_GetSWbarId())
}

TaskBar_AutoSize() {
   TB_AutoSize(TaskBar_GetSWBarId())
}


Many thanks again, Sean! :D

_________________
Scripts - License


Report this post
Top
 Profile  
Reply with quote  
PostPosted: June 12th, 2009, 7:28 pm 
Offline

Joined: June 5th, 2009, 6:00 pm
Posts: 23
I am trying to combine the above tips on how to make a single script that only moves taskbar buttons in any order. But I must be missing something as the left mouse button drag and drop does not work.

Code:
; Make the TaskBar Buttons Movable with LButton Drag and Drop


~LButton::
    MouseGetPos, , , id
    WinGetClass, Class, ahk_id %id%
    if(Class != "Shell_TrayWnd")
        return
    StartPos := GetHotItem()
return
   
~LButton Up::
    MouseGetPos, , , id
    WinGetClass, Class, ahk_id %id%
    if(Class != "Shell_TrayWnd")
        return
    MoveButton(StartPos, GetHotItem())
return


#include TaskButton.ahk

GetHotItem()
{
   idxTB := GetTaskSwBar()
   SendMessage, 0x447, 0, 0, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd   ; TB_GETHOTITEM
   Return ErrorLevel << 32 >> 32
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 20th, 2009, 6:42 pm 
I finally got it to work. I just replaced the gethotitem with hittest. The code is below.

Code:
#Include TaskButton.ahk

~LButton::
    MouseGetPos, , , id
    WinGetClass, Class, ahk_id %id%
    if(Class != "Shell_TrayWnd")
        return
    StartPos := HitTest()
return
   
~LButton Up::
    MouseGetPos, , , id
    WinGetClass, Class, ahk_id %id%
    if(Class != "Shell_TrayWnd")
        return
    MoveButton(StartPos, HitTest())
return

HitTest()
{
   idxTB:=   GetTaskSwBar()
   ControlGet, hWnd, hWnd,, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd
   WinGet, pid, PID, ahk_id %hWnd%
   hProc:=   DllCall("OpenProcess", "Uint", 0x38, "int", 0, "Uint", pid)
   pRB  :=   DllCall("VirtualAllocEx", "Uint", hProc, "Uint", 0, "Uint", 8, "Uint", 0x1000, "Uint", 0x4)
   DllCall("GetCursorPos", "int64P", pt)
   DllCall("ScreenToClient", "Uint", hWnd, "int64P", pt)
   DllCall("WriteProcessMemory", "Uint", hProc, "Uint", pRB, "int64P", pt, "Uint", 8, "Uint", 0)
   idx  :=   DllCall("SendMessage", "Uint", hWnd, "Uint", 0x445, "Uint", 0, "Uint", pRB)   ; TB_HITTEST
   DllCall("VirtualFreeEx", "Uint", hProc, "Uint", pRB, "Uint", 0, "Uint", 0x8000)
   DllCall("CloseHandle"  , "Uint", hProc)
   Return   idx
}


Report this post
Top
  
Reply with quote  
 Post subject: Windows 7?
PostPosted: November 8th, 2009, 6:34 am 
Offline

Joined: June 18th, 2009, 4:39 pm
Posts: 19
Location: Salt Lake City, Utah
Hi,

I'm looking for a way to activate the window next to or previous to the active window as seen on the task bar. (Kind of like Alt+Tab, but slightly different). I was hoping this script could help me out, but it doesn't seem to work in Windows 7. Can anyone perhaps help me out?

Thanks!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 8th, 2009, 7:22 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
This script will not work in Win7, became obsolete on arrival of Win7. I recently succeeded to install 32-bit Windows 7, but haven't look into much about UI stuffs. So, the only one I can suggest atm is to utilize Accessibility and/or UIAutomation.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 9th, 2009, 7:30 pm 
Offline

Joined: June 18th, 2009, 4:39 pm
Posts: 19
Location: Salt Lake City, Utah
Darn. That's too bad.

Well, I'll look into alternative ways of doing this and I'll post back if I figure something out. Thanks!


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 42 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 12 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group