AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Find out a process name?
Goto page Previous  1, 2, 3  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Wish List
View previous topic :: View next topic  
Author Message
shimanov



Joined: 25 Sep 2005
Posts: 610

PostPosted: Sat Nov 05, 2005 6:41 pm    Post subject: Reply with quote

For those still interested:

Code:
Process, Exist
pid := ErrorLevel

MsgBox, % "pid = " pid "`n`nname = " GetModuleFileNameEx( pid )
return

GetModuleFileNameEx( p_pid )
{
   if A_OSVersion in WIN_95,WIN_98,WIN_ME
   {
      MsgBox, This Windows version (%A_OSVersion%) is not supported.
      return
   }

   /*
      #define PROCESS_VM_READ           (0x0010)
      #define PROCESS_QUERY_INFORMATION (0x0400)
   */
   h_process := DllCall( "OpenProcess", "uint", 0x10|0x400, "int", false, "uint", p_pid )
   if ( ErrorLevel or h_process = 0 )
   {
      MsgBox, [OpenProcess] failed
      return
   }
   
   name_size = 255
   VarSetCapacity( name, name_size )
   
   result := DllCall( "psapi.dll\GetModuleFileNameExA", "uint", h_process, "uint", 0, "str", name, "uint", name_size )
   if ( ErrorLevel or result = 0 )
      MsgBox, [GetModuleFileNameExA] failed
   
   DllCall( "CloseHandle", "uint", h_process ) ; Corrected by Moderator! 2010-03-16
   
   return, name
}


Last edited by shimanov on Mon Nov 28, 2005 11:42 pm; edited 1 time in total
Back to top
View user's profile Send private message
evl



Joined: 24 Aug 2005
Posts: 1237

PostPosted: Sat Nov 05, 2005 6:56 pm    Post subject: Reply with quote

Shocked You're on a roll!

Closely related, but probably much harder to do, if not impossible at the moment with AHK - can you think of a way to get the icon associated with a process (i.e. the one that would be displayed on the taskbar). This would save all the "MUICache" trouble altogether.

I searched through the forum and didn't find any scripts that could do this.
Back to top
View user's profile Send private message
shimanov



Joined: 25 Sep 2005
Posts: 610

PostPosted: Sat Nov 05, 2005 7:39 pm    Post subject: Reply with quote

evl wrote:
Shocked You're on a roll!


It has been fun.

Quote:
can you think of a way to get the icon associated with a process (i.e. the one that would be displayed on the taskbar).


Well, now you are just greedy (not LOL, but amusement)...

putting together the pieces of the puzzle, you realize:

Code:
DetectHiddenWindows, Off

Gui, Add, Edit, x5 y5 w200 h100
Gui, Add, Picture, x5 y110 w100 h100, c:\program files\autohotkey\autohotkey.exe
Gui, Add, Button, x115 y190 w90 h20 gShowNext, Show Next
Gui, Show, x100 y100 w210 h215

WS_EX_APPWINDOW = 0x40000
WS_EX_TOOLWINDOW = 0x80

GW_OWNER = 4

WinGet, list, List

loop, %list%
{
   wid := list%A_Index%
   
   WinGet, es, ExStyle, ahk_id %wid%
   
   if ( ( ! DllCall( "GetWindow", "uint", wid, "uint", GW_OWNER ) and ! ( es & WS_EX_TOOLWINDOW ) )
         or ( es & WS_EX_APPWINDOW ) )
   {
      WinGet, pid, PID, ahk_id %wid%
   
      WinGetClass, class, ahk_id %wid%
      WinGetTitle, title, ahk_id %wid%
      
      name := GetModuleFileNameEx( pid )
      
      GuiControl,, Edit1, [%wid%, %class%]`n`n%title%
      GuiControl,, Static1, %name%
      
      pause
   }
}
return

GuiClose:
ExitApp

ShowNext:
   pause, Off
return

GetModuleFileNameEx( p_pid )
{
   if A_OSVersion in WIN_95,WIN_98,WIN_ME
   {
      MsgBox, This Windows version (%A_OSVersion%) is not supported.
      return
   }

   /*
      #define PROCESS_VM_OPERATION      (0x0008)
      #define PROCESS_VM_READ           (0x0010)
      #define PROCESS_QUERY_INFORMATION (0x0400)
   */
   h_process := DllCall( "OpenProcess", "uint", 0x8|0x10|0x400, "int", false, "uint", p_pid )
   if ( ErrorLevel or h_process = 0 )
   {
      MsgBox, [OpenProcess] failed
      return
   }
   
   name_size = 255
   VarSetCapacity( name, name_size )
   
   result := DllCall( "psapi.dll\GetModuleFileNameExA", "uint", h_process, "uint", 0, "str", name, "uint", name_size )
   if ( ErrorLevel or result = 0 )
      MsgBox, [GetModuleFileNameExA] failed
   
        DllCall( "CloseHandle", "uint", h_process ) ; Corrected by Moderator! 2010-03-16
   
   return, name
}
Back to top
View user's profile Send private message
evl



Joined: 24 Aug 2005
Posts: 1237

PostPosted: Sat Nov 05, 2005 8:57 pm    Post subject: Reply with quote

Wow!

See how easy it is when I guide you through the process? Laughing

Maybe you should post that in the "Scripts & Functions" forum as it's a really straightforward demonstration of getting which windows are on the taskbar, process paths and their window icons.
Back to top
View user's profile Send private message
evl



Joined: 24 Aug 2005
Posts: 1237

PostPosted: Sat Nov 05, 2005 9:50 pm    Post subject: Reply with quote

Where it does have a failing is with the icons for "windows components" such as Disk Defragmenter (Windows XP), which displays the mmc.exe icon instead of the window's icon which is extracted from shell32.dll.

Another case is with the AutoHotkey help file - when launched on its own from the start menu, it has the correct icon (and is running as hh.exe), but launched from inside PSPad, the script picks up the PSPad.exe icon as the help file seems to run as part of that process and not a seperate one.
Back to top
View user's profile Send private message
shimanov



Joined: 25 Sep 2005
Posts: 610

PostPosted: Sat Nov 05, 2005 9:53 pm    Post subject: Reply with quote

evl wrote:
See how easy it is when I guide you through the process? Laughing


Sure. It's teamwork.

Quote:
Maybe you should post that in the "Scripts & Functions" forum as it's a really straightforward demonstration of getting ... their window icons.


Not quite. I was a bit overzealous. While the icons retrieved by the script happened to be correct, there is a possibility that the actual icons displayed will differ.

I'll review window classes later and post the correction.
Back to top
View user's profile Send private message
evl



Joined: 24 Aug 2005
Posts: 1237

PostPosted: Sun Nov 06, 2005 1:14 am    Post subject: Reply with quote

evl wrote:
Where it does have a failing is with the icons for "windows components" such as Disk Defragmenter (Windows XP), which displays the mmc.exe icon instead of the window's icon which is extracted from shell32.dll.

Another case is with the AutoHotkey help file - when launched on its own from the start menu, it has the correct icon (and is running as hh.exe), but launched from inside PSPad, the script picks up the PSPad.exe icon as the help file seems to run as part of that process and not a seperate one.



It seems like the command needed is a Sendmessage with WM_GETICON, if only there was some way of then displaying the result (e.g. in my case, adding it to an image list (in a list view)) since it only seems to take file names as a source.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowmessages/wm_geticon.asp
Back to top
View user's profile Send private message
shimanov



Joined: 25 Sep 2005
Posts: 610

PostPosted: Thu Nov 10, 2005 10:44 am    Post subject: Reply with quote

evl wrote:
It seems like the command needed is a Sendmessage with WM_GETICON


That should be right, but unfortunately, that message may fail to retrieve an icon.

MSDN wrote:
When an application receives this message, it can return a handle


... it can also not. These exceptional cases were tricky to resolve.

The following works for the exceptional cases you cited and others that I have tested.

Code:
Gui, Add, Edit, x5 y5 w400 h200 -Wrap ReadOnly HScroll
Gui, Add, Picture, x5 y210 +0x3
Gui, Add, Button, x315 y220 w90 h20 gShowNext, Show Next
Gui, Show, x10 y10 w410 h245

Process, Exist
WinGet, hw_this, ID, ahk_class AutoHotkeyGUI ahk_pid %ErrorLevel%

WS_EX_APPWINDOW = 0x40000
WS_EX_TOOLWINDOW = 0x80

GW_OWNER = 4

WinGet, list, List

loop, %list%
{
   wid := list%A_Index%
   
   WinGet, es, ExStyle, ahk_id %wid%
   
   if ( ( ! DllCall( "GetWindow", "uint", wid, "uint", GW_OWNER ) and ! ( es & WS_EX_TOOLWINDOW ) )
         or ( es & WS_EX_APPWINDOW ) )
   {
      WinGet, pid, PID, ahk_id %wid%
   
      WinGetClass, class, ahk_id %wid%
      WinGetTitle, title, ahk_id %wid%
      
      GuiControl,, Edit1, %
         ( Join
            "pid = " pid
            "`n`nwid = " wid
            "`nclass = " class
            "`ntitle = " title
            "`n`nfile name = " GetModuleFileNameEx( pid )
         )

      ;WM_GETICON
      ;   ICON_SMALL          0
      ;   ICON_BIG            1
      ;   ICON_SMALL2         2
      SendMessage, 0x7F, 1, 0,, ahk_id %wid%
      h_icon := ErrorLevel
      if ( ! h_icon )
      {
         SendMessage, 0x7F, 2, 0,, ahk_id %wid%
         h_icon := ErrorLevel
         if ( ! h_icon )
         {
            SendMessage, 0x7F, 0, 0,, ahk_id %wid%
            h_icon := ErrorLevel
            if ( ! h_icon )
            {
               ; GCL_HICON           (-14)
               h_icon := DllCall( "GetClassLong", "uint", wid, "int", -14 )
               
               if ( ! h_icon )
               {
                  ; GCL_HICONSM         (-34)
                  h_icon := DllCall( "GetClassLong", "uint", wid, "int", -34 )
                  
                  if ( ! h_icon )
                  {
                     ; IDI_APPLICATION     32512
                     h_icon := DllCall( "LoadIcon", "uint", 0, "uint", 32512 )
                  }
               }
            }
         }
      }

      ;STM_SETIMAGE        0x0172
      ;   IMAGE_ICON          1
      SendMessage, 0x172, 1, h_icon, Static1, ahk_id %hw_this%
      
      pause
   }
}
return

GuiClose:
ExitApp

ShowNext:
   pause, Off
return

GetModuleFileNameEx( p_pid )
{
   if A_OSVersion in WIN_95,WIN_98,WIN_ME
   {
      MsgBox, This Windows version (%A_OSVersion%) is not supported.
      return
   }

   /*
      #define PROCESS_VM_OPERATION      (0x0008) 
      #define PROCESS_VM_READ           (0x0010)
      #define PROCESS_QUERY_INFORMATION (0x0400) 
   */
   h_process := DllCall( "OpenProcess", "uint", 0x8|0x10|0x400, "int", false, "uint", p_pid )
   if ( ErrorLevel or h_process = 0 )
   {
      MsgBox, [OpenProcess] failed
      return
   }
   
   name_size = 255
   VarSetCapacity( name, name_size )
   
   result := DllCall( "psapi.dll\GetModuleFileNameExA", "uint", h_process, "uint", 0, "str", name, "uint", name_size )
   if ( ErrorLevel or result = 0 )
      MsgBox, [GetModuleFileNameExA] failed
   
   DllCall( "CloseHandle", h_process )
   
   return, name
}
Back to top
View user's profile Send private message
evl



Joined: 24 Aug 2005
Posts: 1237

PostPosted: Mon Nov 14, 2005 4:08 pm    Post subject: Reply with quote

I've been playing around with the code today and getting it to display a list of icons and their window titles in a gui for all running programs (like an alt-tab replacement). (I did have a look into getting the icons into a listview, but it seems way more complicated than the static control picture replacement method!)

I managed to find one type of window that doesn't get listed. Some of the settings windows found in control panel, in Windows XP, (e.g. "Date and Time", "Sounds and Audio Devices" and "Taskbar and Start Menu") do display in the normal alt-tab list but not on the taskbar.
Back to top
View user's profile Send private message
shimanov



Joined: 25 Sep 2005
Posts: 610

PostPosted: Mon Nov 14, 2005 10:35 pm    Post subject: Reply with quote

evl wrote:
(like an alt-tab replacement).
...
settings windows found in control panel


There are differences between taskbar and task switcher characteristics.

I could not find any documentation to describe the task switcher (via Alt+Tab). From what I can infer, windows of the dialog class are an exception for the task switcher; but, you will have to fully characterize the circumstances of their appearance in that function.

As for the Control Panel applets, let's take the "Date and Time" applet as an example. I have only been able to determine that the associated icon is located in its file (timedate.cpl). If that is true, then it will be necessary to establish a window to file mapping. One method is a static mapping of window title to file:

title = Date and Time Properties
file = timedate.cpl

Another method is to determine the applet launched with RunDll32 by parsing the command line. This will require remote process access.

evl wrote:
get the icon associated with a process (i.e. the one that would be displayed on the taskbar


However, the goal was to replicate the taskbar functionality.

evl wrote:
(I did have a look into getting the icons into a listview, but it seems way more complicated than the static control picture replacement method!)


Check the following:

1. LVM_GETIMAGELIST = 0x1000+2
2. ImageList_Add
Code:

LVSIL_NORMAL = 0
LVSIL_SMALL = 1
LVSIL_STATE = 2
Back to top
View user's profile Send private message
evl



Joined: 24 Aug 2005
Posts: 1237

PostPosted: Wed Nov 16, 2005 8:12 pm    Post subject: Reply with quote

For finding the control panel windows (and those of at least one other program) that appear on the Alt-Tab list, I found that they all have the ahk_class #32770. I've only assigned a generic icon so far since it's not really a big issue for me.

And for the insertion of the icons into the icon list, someone missed a good opportunity to tell me to RTFM since I found it in the large ListView example in the manual Laughing

I'm working on an Alt-Tab replacement with icons and window titles in a listview, which I'll post the code for as soon as I've tidied it up a bit, since I saw someone else asked about that in another Alt-Tab replacement thread.
Back to top
View user's profile Send private message
shimanov



Joined: 25 Sep 2005
Posts: 610

PostPosted: Wed Nov 16, 2005 8:37 pm    Post subject: Reply with quote

evl wrote:
#32770


aka, dialog class

evl wrote:
someone missed a good opportunity to tell me to RTFM


I assumed you had referred to the manual first. And... I would never say something like that, given that I believe you have made an honest attempt to solve the problem yourself.

evl wrote:
I found it in the large ListView example in the manual


You're right. This time I didn't read the manual.

Chris's examples are often above and beyond expectation.

evl wrote:
I'm working on an Alt-Tab replacement with icons and window titles in a listview, which I'll post the code for as soon as I've tidied it up a bit, since I saw someone else asked about that in another Alt-Tab replacement thread.


This will be a good concept demonstration, as well as, practically useful.
Back to top
View user's profile Send private message
sosaited



Joined: 24 Feb 2005
Posts: 278

PostPosted: Sun Nov 27, 2005 8:46 pm    Post subject: Reply with quote

Can these commands (get process name,path,folder) get added in AHK soon PLEASE ? Sad i "guess" it will be easy since the "method" is known to some extent.
_________________
My small "thanks" to AHK in shape of these dedicated 3d images
Back to top
View user's profile Send private message
Yogui



Joined: 14 Jun 2008
Posts: 56
Location: Sydney, Australia

PostPosted: Tue Sep 29, 2009 10:15 am    Post subject: Win7 64Bit RTM Reply with quote

Seems that in Win7 64Bit RTM does not work.

Any work around?
_________________
Thanks, Yogui.
_____________________________
Back to top
View user's profile Send private message
GregL
Guest





PostPosted: Tue Mar 16, 2010 7:14 am    Post subject: Small bug in script Reply with quote

I posted details in another thread which uses a modified version of your function, shimanov, but the same fix needs to be applied here - the call to DllCall() on the second last line is missing the second type parameter of "UInt".
Back to top
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Wish List All times are GMT
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group