1 (изменено: Malcev, 2023-11-04 02:29:42)

Тема: AHK: Закрепить приложение на панели задач с недокументированным апи

https://geelaw.blog/entries/msedge-pins
https://github.com/vhanla/W1nDro1d/blob … Pinner.pas

msgbox % GetAllPinned()
pin("C:\Windows\System32\Notepad.exe")
msgbox pinned
unpin("C:\Windows\System32\Notepad.exe")
msgbox unpinned

pin(app)   ; https://geelaw.blog/entries/msedge-pins https://github.com/vhanla/W1nDro1d/blob/main/TaskbarPinner.pas
{
   static oIPinnedList3 := TaskbandPin_Init()
   static FOLDERID_System := SHGetKnownFolderPath("{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}")
   if A_Is64bitOS and (A_PtrSize = 4) and InStr(app, FOLDERID_System)
   {
      msgbox For applications in %FOLDERID_System% need to run script with ahk64.
      exitapp
   }
   pidl := DllCall("Shell32.dll\ILCreateFromPathW", "wstr", app, "ptr")
   if DllCall(NumGet(NumGet(oIPinnedList3+0)+9*A_PtrSize), "ptr", oIPinnedList3, "ptr", pidl)  ; IsPinned
      DllCall(NumGet(NumGet(oIPinnedList3+0)+16*A_PtrSize), "ptr", oIPinnedList3, "ptr", 0, "ptr", pidl, "int", PLMC_EXPLORER := 4)   ; modify
   DllCall("Shell32.dll\ILFree", "ptr", pidl)
}

unpin(app)
{
   static oIPinnedList3 := TaskbandPin_Init()
   static FOLDERID_System := SHGetKnownFolderPath("{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}")
   if A_Is64bitOS and (A_PtrSize = 4) and InStr(app, FOLDERID_System)
   {
      msgbox For applications in %FOLDERID_System% need to run script with ahk64.
      exitapp
   }
   pidl := DllCall("Shell32.dll\ILCreateFromPathW", "wstr", app, "ptr")
   if !DllCall(NumGet(NumGet(oIPinnedList3+0)+9*A_PtrSize), "ptr", oIPinnedList3, "ptr", pidl)  ; IsPinned
      DllCall(NumGet(NumGet(oIPinnedList3+0)+16*A_PtrSize), "ptr", oIPinnedList3, "ptr", pidl, "ptr", 0, "int", PLMC_EXPLORER := 4)   ; modify
   DllCall("Shell32.dll\ILFree", "ptr", pidl)
}

GetAllPinned()
{
   static oIPinnedList3 := TaskbandPin_Init()
   DllCall(NumGet(NumGet(oIPinnedList3+0)+3*A_PtrSize), "ptr", oIPinnedList3, "ptr*", IEnumFullIDList)  ; EnumObjects
   DllCall(NumGet(NumGet(IEnumFullIDList+0)+5*A_PtrSize), "ptr", IEnumFullIDList)   ; reset
   loop
   {
      if DllCall(NumGet(NumGet(IEnumFullIDList+0)+3*A_PtrSize), "ptr", IEnumFullIDList, "uint", 1, "ptr*", pidl, "uint*", null)   ; next
         break
      VarSetCapacity(FilePath, 512, 0)
      DllCall("Shell32.dll\SHGetPathFromIDListW", "ptr", pidl, "str", FilePath)
      FilePaths .= FilePath "`n"
      DllCall("Ole32.dll\CoTaskMemFree", "ptr", pidl)
   }
   return FilePaths
}

TaskbandPin_Init()
{
   static oIPinnedList3
   if !oIPinnedList3
      oIPinnedList3 := ComObjCreate(CLSID_TaskbandPin := "{90AA3A4E-1CBA-4233-B8BB-535773D48449}", IPinnedList3 := "{0DD79AE2-D156-45D4-9EEB-3B549769E940}")
   return oIPinnedList3
}

SHGetKnownFolderPath(FOLDERID, KF_FLAG:=0) {                  ;   By SKAN on D356 @ tiny.cc/t-75602 
Local CLSID, pPath:=""                                        ; Thanks teadrinker @ tiny.cc/p286094
Return Format("{4:}", VarSetCapacity(CLSID, 16, 0)
     , DllCall("ole32\CLSIDFromString", "Str",FOLDERID, "Ptr",&CLSID)
     , DllCall("shell32\SHGetKnownFolderPath", "Ptr",&CLSID, "UInt",KF_FLAG, "Ptr",0, "PtrP",pPath)
     , StrGet(pPath, "utf-16")
     , DllCall("ole32\CoTaskMemFree", "Ptr",pPath))
}

Тема для обсуждения