AutoHotkey Community

It is currently May 27th, 2012, 6:06 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 31 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject:
PostPosted: November 5th, 2005, 7:41 pm 
Offline

Joined: September 25th, 2005, 4:31 pm
Posts: 610
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 November 29th, 2005, 12:42 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 5th, 2005, 7:56 pm 
Offline

Joined: August 24th, 2005, 5:17 pm
Posts: 1237
:shock: 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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 5th, 2005, 8:39 pm 
Offline

Joined: September 25th, 2005, 4:31 pm
Posts: 610
evl wrote:
:shock: 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
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 5th, 2005, 9:57 pm 
Offline

Joined: August 24th, 2005, 5:17 pm
Posts: 1237
Wow!

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

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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 5th, 2005, 10:50 pm 
Offline

Joined: August 24th, 2005, 5:17 pm
Posts: 1237
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 5th, 2005, 10:53 pm 
Offline

Joined: September 25th, 2005, 4:31 pm
Posts: 610
evl wrote:
See how easy it is when I guide you through the process? :lol:


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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 6th, 2005, 2:14 am 
Offline

Joined: August 24th, 2005, 5:17 pm
Posts: 1237
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 10th, 2005, 11:44 am 
Offline

Joined: September 25th, 2005, 4:31 pm
Posts: 610
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
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 14th, 2005, 5:08 pm 
Offline

Joined: August 24th, 2005, 5:17 pm
Posts: 1237
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 14th, 2005, 11:35 pm 
Offline

Joined: September 25th, 2005, 4:31 pm
Posts: 610
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 16th, 2005, 9:12 pm 
Offline

Joined: August 24th, 2005, 5:17 pm
Posts: 1237
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 :lol:

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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 16th, 2005, 9:37 pm 
Offline

Joined: September 25th, 2005, 4:31 pm
Posts: 610
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 27th, 2005, 9:46 pm 
Offline

Joined: February 24th, 2005, 8:45 am
Posts: 278
Can these commands (get process name,path,folder) get added in AHK soon PLEASE ? :( 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
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Win7 64Bit RTM
PostPosted: September 29th, 2009, 11:15 am 
Offline

Joined: June 14th, 2008, 7:47 pm
Posts: 56
Location: Sydney, Australia
Seems that in Win7 64Bit RTM does not work.

Any work around?

_________________
Thanks, Yogui.
_____________________________


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Small bug in script
PostPosted: March 16th, 2010, 8:14 am 
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".


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: rbrtryn and 3 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