Skip to content

Commit

Permalink
Update BitmapToExplorer
Browse files Browse the repository at this point in the history
  • Loading branch information
iseahound committed Mar 14, 2024
1 parent 9cbf7c7 commit 6f840ef
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 94 deletions.
91 changes: 41 additions & 50 deletions ImagePut (for v1).ahk
Original file line number Diff line number Diff line change
Expand Up @@ -4201,41 +4201,65 @@ class ImagePut {

BitmapToExplorer(pBitmap, default := "") {

; Default directory to desktop.
(default == "") && default := A_Desktop
; Get path of active window.
if (hwnd := WinExist("ahk_class ExploreWClass")) || (hwnd := WinExist("ahk_class CabinetWClass")) {
; script from Lexikos: https://www.autohotkey.com/boards/viewtopic.php?f=83&t=109907
; modified for this by: @TheCrether
; useful for windows 11 explorer tabs support (works with windows 10 explorers too)
tab := this.GetCurrentExplorerTab(hwnd)
if tab {
switch ComObjType(tab.Document, "Class") {
case "ShellFolderView":
directory := tab.Document.Folder.Self.Path
default: ; case "HTMLDocument"
directory := tab.LocationURL
}
}
}
else if (default != "")
directory := default
else
return

; Check if the mouse is pointing to the desktop.
MouseGetPos,,, hwnd
WinGetClass class, ahk_id %hwnd%
if (class ~= "(?i)Progman|WorkerW")
directory := A_Desktop
return this.BitmapToFile(pBitmap, directory)
}

StreamToExplorer(stream, default := "") {

; Get path of active window.
else if (hwnd := WinExist("ahk_class ExploreWClass")) || (hwnd := WinExist("ahk_class CabinetWClass")) {
for window in ComObjCreate("Shell.Application").Windows {
if (window.hwnd == hwnd) {
try directory := window.Document.Folder.Self.Path
if (hwnd := WinExist("ahk_class ExploreWClass")) || (hwnd := WinExist("ahk_class CabinetWClass")) {
; script from Lexikos: https://www.autohotkey.com/boards/viewtopic.php?f=83&t=109907
; modified for this by: @TheCrether
; useful for windows 11 explorer tabs support (works with windows 10 explorers too)
tab := this.GetCurrentExplorerTab(hwnd)
if tab {
switch ComObjType(tab.Document, "Class") {
case "ShellFolderView":
directory := tab.Document.Folder.Self.Path
default: ; case "HTMLDocument"
directory := tab.LocationURL
}
}
}
else
else if (default != "")
directory := default
else
return

return this.BitmapToFile(pBitmap, directory)
return this.StreamToFile(stream, directory)
}

GetCurrentExplorerTab(hwnd) {
; script from Lexikos: https://www.autohotkey.com/boards/viewtopic.php?f=83&t=109907
; modified for this by: @TheCrether
; useful for windows 11 explorer tabs support (works with windows 10 explorers too)
static IID_IShellBrowser := "{000214E2-0000-0000-C000-000000000046}"

activeTab := 0, hwnd := hwnd ? hwnd : WinExist("A")
try
ControlGet, activeTab, Hwnd,, ShellTabWindowClass1, ahk_id %hwnd% ; File Explorer (Windows 11)
ControlGet, activeTab, Hwnd,, ShellTabWindowClass1, ahk_id %hwnd% ; File Explorer (Windows 11)
catch
try
ControlGet, activeTab, Hwnd,, TabWindowClass1, ahk_id %hwnd% ; IE
ControlGet, activeTab, Hwnd,, TabWindowClass1, ahk_id %hwnd% ; IE
for w in ComObjCreate("Shell.Application").Windows {
if (w.hwnd != hwnd)
continue
Expand All @@ -4247,40 +4271,7 @@ class ImagePut {
}
return w
}
return 0
}

StreamToExplorer(stream, default := "") {

; Default directory to desktop.
(default == "") && default := A_Desktop

; Check if the mouse is pointing to the desktop.
MouseGetPos,,, hwnd
WinGetClass class, ahk_id %hwnd%
if (class ~= "(?i)Progman|WorkerW")
directory := A_Desktop

; Get path of active window.
else if (hwnd := WinExist("ahk_class ExploreWClass")) || (hwnd := WinExist("ahk_class CabinetWClass")) {
; script from Lexikos: https://www.autohotkey.com/boards/viewtopic.php?f=83&t=109907
; modified for this by: @TheCrether
; useful for windows 11 explorer tabs support (works with windows 10 explorers too)
tab := this.GetCurrentExplorerTab(hwnd)
if tab {
switch ComObjType(tab.Document, "Class")
{
case "ShellFolderView":
directory := tab.Document.Folder.Self.Path
default: ; case "HTMLDocument"
directory := tab.LocationURL
}
}
}
else
directory := default

return this.StreamToFile(stream, directory)
return 0
}

BitmapToFile(pBitmap, filepath := "", quality := "") {
Expand Down
82 changes: 38 additions & 44 deletions ImagePut.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -4298,27 +4298,52 @@ class ImagePut {

static BitmapToExplorer(pBitmap, default := "") {

; Default directory to desktop.
(default == "") && default := A_Desktop
; Get path of active window.
if (hwnd := WinExist("ahk_class ExploreWClass")) || (hwnd := WinExist("ahk_class CabinetWClass")) {
; script from Lexikos: https://www.autohotkey.com/boards/viewtopic.php?f=83&t=109907
; modified for this by: @TheCrether
; useful for windows 11 explorer tabs support (works with windows 10 explorers too)
tab := this.GetCurrentExplorerTab(hwnd)
if tab {
switch Type(tab.Document) {
case "ShellFolderView":
directory := tab.Document.Folder.Self.Path
default: ; case "HTMLDocument"
directory := tab.LocationURL
}
}
}
else if (default != "")
directory := default
else
return

; Check if the mouse is pointing to the desktop.
MouseGetPos ,, &hwnd
return this.BitmapToFile(pBitmap, directory)
}

if WinGetClass("ahk_id" hwnd) ~= "(?i)Progman|WorkerW"
directory := A_Desktop
static StreamToExplorer(stream, default := "") {

; Get path of active window.
else if (hwnd := WinExist("ahk_class ExploreWClass")) || (hwnd := WinExist("ahk_class CabinetWClass")) {
for window in ComObject("Shell.Application").Windows {
if (window.hwnd == hwnd) {
try directory := window.Document.Folder.Self.Path
if (hwnd := WinExist("ahk_class ExploreWClass")) || (hwnd := WinExist("ahk_class CabinetWClass")) {
; script from Lexikos: https://www.autohotkey.com/boards/viewtopic.php?f=83&t=109907
; modified for this by: @TheCrether
; useful for windows 11 explorer tabs support (works with windows 10 explorers too)
tab := this.GetCurrentExplorerTab(hwnd)
if tab {
switch Type(tab.Document) {
case "ShellFolderView":
directory := tab.Document.Folder.Self.Path
default: ; case "HTMLDocument"
directory := tab.LocationURL
}
}
}
else
else if (default != "")
directory := default
else
return

return this.BitmapToFile(pBitmap, directory)
return this.StreamToFile(stream, directory)
}

static GetCurrentExplorerTab(hwnd) {
Expand All @@ -4340,38 +4365,7 @@ class ImagePut {
}
return w
}
return false
}

static StreamToExplorer(stream, default := "") {

; Default directory to desktop.
(default == "") && default := A_Desktop

; Check if the mouse is pointing to the desktop.
MouseGetPos ,, &hwnd

if WinGetClass("ahk_id" hwnd) ~= "(?i)Progman|WorkerW"
directory := A_Desktop

; Get path of active window.
else if (hwnd := WinExist("ahk_class ExploreWClass")) || (hwnd := WinExist("ahk_class CabinetWClass")) {
; script from Lexikos: https://www.autohotkey.com/boards/viewtopic.php?f=83&t=109907
; modified for this by: @TheCrether
tab := this.GetCurrentExplorerTab(hwnd)
if tab {
switch Type(tab.Document) {
case "ShellFolderView":
directory := tab.Document.Folder.Self.Path
default: ; case "HTMLDocument"
directory := tab.LocationURL
}
}
}
else
directory := default

return this.StreamToFile(stream, directory)
return false
}

static BitmapToFile(pBitmap, filepath := "", quality := "") {
Expand Down

0 comments on commit 6f840ef

Please sign in to comment.