Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[SOLVED]Extract programs icon in systray


  • Please log in to reply
16 replies to this topic
nothere
  • Members
  • 242 posts
  • Last active: Jul 04 2015 12:55 AM
  • Joined: 25 Jul 2010
kenn, I tried changing your code so that it would accept an icon and did not have any luck, where did I go wrong?
;=================Coke by kenn===============

ptr := A_PtrSize = 8 ? "ptr" : "uint"

sfi_size := A_PtrSize + 8 + (A_IsUnicode ? 680 : 340)

if !sfi_size   ;for AHK Basic

   sfi_size := 340

VarSetCapacity(sfi, sfi_size)



FileName := A_WinDir "\notepad.exe"

;http://msdn.microsoft.com/en-us/library/windows/desktop/bb762179%28v=vs.85%29.aspx

DllCall("Shell32\SHGetFileInfo" . (A_IsUnicode ? "W":"A"), "str", FileName

            , "uint", 0, ptr, &sfi, "uint", sfi_size, "uint", 0x101) ; ; 0x101 is SHGFI_ICON+SHGFI_SMALLICON



hIcon := NumGet(sfi, 0)



Gui, Margin, 20, 20

;Gui, Add, Text, w64 h64 hwndmypic1 0x3 ; 0x3 = SS_ICON

Gui, Add, Button, w64 h64 hwndmypic1 0x40 ; 0x40 = BS_ICON

SendMessage, BM_SETIMAGE := 0xF7, hIcon, 0,, Ahk_ID %mypic1%

Gui, Show

Return



GuiClose:

ExitApp

“No other God have I but Thee; born in a manger, died on a tree.” Martin Luther

kenn
  • Members
  • 407 posts
  • Last active: Jan 14 2015 08:16 PM
  • Joined: 11 Oct 2010
Actually what you posted is not my code, in previous page I added link to actual author of the script.
I think you wanted this script,
ptr := A_PtrSize =8 ? "ptr" : "uint"   ;for AHK Basic
FileName := A_WinDir "\notepad.exe"
hIcon := DllCall("Shell32\ExtractAssociatedIcon" (A_IsUnicode ? "W" : "A")
   , ptr, DllCall("GetModuleHandle", ptr, 0, ptr)
   , str, FileName
   , "ushort*", lpiIcon
   , ptr)   ;only supports 32x32
STM_SETICON := 0x0170
Gui, Margin, 20, 20
Gui, Add, Text, w64 h64 hwndmypic1 0x3
SendMessage, STM_SETICON, hIcon, 0,, Ahk_ID %mypic1%

Gui, Show

Return
SavehIconAsBMP(hIcon, A_ScriptDir "\notepad.bmp")

SavehIconAsBMP(hIcon, sFile) {
   if pToken := Gdip_Startup() {
      pBitmap := Gdip_CreateBitmapFromHICON(hIcon)
      Gdip_SaveBitmapToFile(pBitmap, sFile)
      Gdip_DisposeImage(pBitmap)
      Gdip_Shutdown(pToken)
      return true
   }
      return false
}

My Scripts
Ain’t No Shame in Asking for Help!