Code: Select all
; file name: FG_ScreenClip.ahk
; Screen Clipper
; Fanatic Guru
; Version 1.7 2023 04 23
;[module/script] ScreenClip2Win
;Author: Learning one
;Thanks: Tic, HotKeyIt
; FUNCTIONS
;{-----------------------------------------------
;
;{vvvvv SCW Functions vvvvv
/*
[module/script] ScreenClip2Win
Author: Learning one
Thanks: Tic, HotKeyIt
Creates always on top layered windows from screen clippings. Click in upper right corner to close win. Click and drag to move it.
Uses Gdip.ahk by Tic.
#Include ScreenClip2Win.ahk ; by Learning one
;=== Short documentation ===
SCW_ScreenClip2Win(SetClipboard:=0) ; creates always on top window from screen clipping. Click and drag to select area.
SCW_DestroyAllClipWins() ; destroys all screen clipping windows.
SCW_Win2Clipboard(DeleteBorders:=1) ; copies window to clipboard. By default, removes borders. To keep borders, specify "SCW_Win2Clipboard(0)"
SCW_SetUp(Options="") ; you can change some default options in Auto-execute part of script. Syntax: "<option>.<value>"
StartAfter - module will start to consume GUIs for screen clipping windows after specified GUI number. Default: 80
MaxGuis - maximum number of screen clipping windows. Default: 6
BorderAColor - Default: ff6666ff (ARGB format)
BorderBColor - Default: ffffffff (ARGB format)
DrawCloseButton - on/off draw "Close Button" on screen clipping windows. Default: 0 (off)
AutoMonitorWM_LBUTTONDOWN - on/off automatic monitoring of WM_LBUTTONDOWN message. Default: 1 (on)
SelColor - selection color. Default: Yellow
SelTrans - selection transparency. Default: 80
Example: SCW_SetUp("MaxGuis.30 StartAfter.50 BorderAColor.ff000000 BorderBColor.ffffff00")
;=== Avoid OnMessage(0x201, "WM_LBUTTONDOWN") collision example===
Gui, Show, w200 h200
SCW_SetUp("AutoMonitorWM_LBUTTONDOWN.0") ; turn off auto monitoring WM_LBUTTONDOWN
OnMessage(0x201, "WM_LBUTTONDOWN") ; manualy monitor WM_LBUTTONDOWN
Return
^Lbutton::SCW_ScreenClip2Win() ; click & drag
Esc::ExitApp
#Include Gdip.ahk ; by Tic
#Include ScreenClip2Win.ahk ; by Learning one
WM_LBUTTONDOWN() {
if SCW_LBUTTONDOWN() ; LBUTTONDOWN on module's screen clipping windows - isolate - it's module's buissines
return
else ; LBUTTONDOWN on other windows created by script
MsgBox,,, You clicked on script's window not created by this module,1
}
*/
SCW_Version()
{
return 1.03
}
SCW_DestroyAllClipWins()
{
MaxGuis := SCW_Reg("MaxGuis"), StartAfter := SCW_Reg("StartAfter")
Loop, %MaxGuis%
{
StartAfter++
Gui %StartAfter%: Destroy
}
}
SCW_SetUp(Options="")
{
if !(Options = "")
{
Loop, Parse, Options, %A_Space%
{
Field := A_LoopField
DotPos := InStr(Field, ".")
if (DotPos = 0)
Continue
var := SubStr(Field, 1, DotPos-1)
val := SubStr(Field, DotPos+1)
if var in StartAfter,MaxGuis,AutoMonitorWM_LBUTTONDOWN,DrawCloseButton,BorderAColor,BorderBColor,SelColor,SelTrans
%var% := val
}
}
SCW_Default(StartAfter,80), SCW_Default(MaxGuis,6)
SCW_Default(AutoMonitorWM_LBUTTONDOWN,1), SCW_Default(DrawCloseButton,0)
SCW_Default(BorderAColor,"ff6666ff"), SCW_Default(BorderBColor,"ffffffff")
SCW_Default(SelColor,"Yellow"), SCW_Default(SelTrans,80)
SCW_Reg("MaxGuis", MaxGuis), SCW_Reg("StartAfter", StartAfter), SCW_Reg("DrawCloseButton", DrawCloseButton)
SCW_Reg("BorderAColor", BorderAColor), SCW_Reg("BorderBColor", BorderBColor) ; <---- for thin border dasactivate this line and activate the line below
; SCW_Reg("BorderBColor", BorderBColor) ; <---- for thick border desactivate this line and activate the line above
SCW_Reg("SelColor", SelColor), SCW_Reg("SelTrans",SelTrans)
SCW_Reg("WasSetUp", 1)
if AutoMonitorWM_LBUTTONDOWN
OnMessage(0x201, "SCW_LBUTTONDOWN")
}
SCW_ScreenClip2Win(SetClipboard:=0)
{
static c
if !(SCW_Reg("WasSetUp"))
SCW_SetUp()
StartAfter := SCW_Reg("StartAfter"), MaxGuis := SCW_Reg("MaxGuis"), SelColor := SCW_Reg("SelColor"), SelTrans := SCW_Reg("SelTrans")
c++
if (c > MaxGuis)
c := 1
GuiNum := StartAfter + c
; remove cached image
FileDelete, % SCW_Reg("CacheFolder") "\" GuiNum ".png"
Area := SCW_SelectAreaMod("g" GuiNum " c" SelColor " t" SelTrans)
StringSplit, v, Area, |
if (v3 < 10 and v4 < 10) ; too small area
return
pToken := Gdip_Startup()
if pToken =
{
MsgBox, 64, GDI+ error, GDI+ failed to start. Please ensure you have GDI+ on your system.
return
}
Sleep, 100
pBitmap := Gdip_BitmapFromScreen(Area)
if (SetClipboard=1)
Gdip_SetBitmapToClipboard(pBitmap)
hwnd := SCW_CreateLayeredWinMod(GuiNum,pBitmap,v1,v2, SCW_Reg("DrawCloseButton"))
Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)
return hwnd
}
SCW_SelectAreaMod(Options="")
{
CoordMode, Mouse, Screen
MouseGetPos, MX, MY
loop, parse, Options, %A_Space%
{
Field := A_LoopField
FirstChar := SubStr(Field,1,1)
if FirstChar contains c,t,g,m
{
StringTrimLeft, Field, Field, 1
%FirstChar% := Field
}
}
c := (c = "") ? "Blue" : c, t := (t = "") ? "50" : t, g := (g = "") ? "99" : g
Gui %g%: Destroy
Gui %g%: +AlwaysOnTop -caption +Border +ToolWindow +LastFound
WinSet, Transparent, %t%
Gui %g%: Color, %c%
Hotkey := RegExReplace(A_ThisHotkey,"^(\w* & |\W*)")
While, (GetKeyState(Hotkey, "p"))
{
Sleep, 10
MouseGetPos, MXend, MYend
w := abs(MX - MXend), h := abs(MY - MYend)
X := (MX < MXend) ? MX : MXend
Y := (MY < MYend) ? MY : MYend
Gui %g%: Show, x%X% y%Y% w%w% h%h% NA
}
Gui %g%: Destroy
MouseGetPos, MXend, MYend
If ( MX > MXend )
temp := MX, MX := MXend, MXend := temp
If ( MY > MYend )
temp := MY, MY := MYend, MYend := temp
Return MX "|" MY "|" w "|" h
}
SCW_CreateLayeredWinMod(GuiNum,pBitmap,x,y,DrawCloseButton=0)
{
static CloseButton := 16
BorderAColor := SCW_Reg("BorderAColor"), BorderBColor := SCW_Reg("BorderBColor")
Gui %GuiNum%: -Caption +E0x80000 +LastFound +ToolWindow +AlwaysOnTop +OwnDialogs
Gui %GuiNum%: Show, Na, ScreenClipperWindow
hwnd := WinExist()
Width := Gdip_GetImageWidth(pBitmap), Height := Gdip_GetImageHeight(pBitmap)
hbm := CreateDIBSection(Width+6, Height+6), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc), Gdip_SetSmoothingMode(G, 4), Gdip_SetInterpolationMode(G, 7)
Gdip_DrawImage(G, pBitmap, 3, 3, Width, Height)
Gdip_DisposeImage(pBitmap)
pPen1 := Gdip_CreatePen("0x" BorderAColor, 3), pPen2 := Gdip_CreatePen("0x" BorderBColor, 1)
if DrawCloseButton
{
Gdip_DrawRectangle(G, pPen1, 1+Width-CloseButton+3, 1, CloseButton, CloseButton)
Gdip_DrawRectangle(G, pPen2, 1+Width-CloseButton+3, 1, CloseButton, CloseButton)
}
Gdip_DrawRectangle(G, pPen1, 1, 1, Width+3, Height+3)
Gdip_DrawRectangle(G, pPen2, 1, 1, Width+3, Height+3)
Gdip_DeletePen(pPen1), Gdip_DeletePen(pPen2)
UpdateLayeredWindow(hwnd, hdc, x-3, y-3, Width+6, Height+6)
SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc), Gdip_DeleteGraphics(G)
SCW_Reg("G" GuiNum "#HWND", hwnd)
SCW_Reg("G" GuiNum "#XClose", Width+6-CloseButton)
SCW_Reg("G" GuiNum "#YClose", CloseButton)
Return hwnd
}
SCW_LBUTTONDOWN()
{
MouseGetPos,,, WinUMID
WinGetTitle, Title, ahk_id %WinUMID%
if Title = ScreenClipperWindow
{
PostMessage, 0xA1, 2,,, ahk_id %WinUMID%
KeyWait, Lbutton
CoordMode, mouse, Relative
MouseGetPos, x,y
XClose := SCW_Reg("G" A_Gui "#XClose"), YClose := SCW_Reg("G" A_Gui "#YClose")
if (x > XClose and y < YClose){
Gui %A_Gui%: Destroy
; remove cached image
FileDelete, % SCW_Reg("CacheFolder") "\" A_Gui ".png"
}
return 1 ; confirm that click was on module's screen clipping windows
}
}
SCW_Reg(variable, value="")
{
static
if (value = "")
return kxucfp%variable%pqzmdk
else
kxucfp%variable%pqzmdk = %value%
}
SCW_Default(ByRef Variable,DefaultValue)
{
if (Variable="")
Variable := DefaultValue
}
SCW_Win2Clipboard(DeleteBorders:=1, Hwnd := "")
{
/* ; does not work for layered windows
ActiveWinID := WinExist("A")
pBitmap := Gdip_BitmapFromHWND(ActiveWinID)
Gdip_SetBitmapToClipboard(pBitmap)
*/
if !Hwnd
WinGet, Hwnd, ID, A
WinGetPos, X, Y, W, H, ahk_id %Hwnd%
if DeleteBorders
X+=3, Y+=3, W-=6, H-=6
pToken := Gdip_Startup()
pBitmap := Gdip_BitmapFromScreen(X "|" Y "|" W "|" H)
Gdip_SetBitmapToClipboard(pBitmap)
Gdip_Shutdown(pToken)
}
SCW_Win2File(SavePath,Hwnd := "",DeleteBorders:=1)
{
IfNotExist, %SavePath%
FileCreateDir, %SavePath%
if !Hwnd
WinGet, Hwnd, ID, A
WinGetPos, X, Y, W, H, ahk_id %Hwnd%
if DeleteBorders
X+=3, Y+=3, W-=6, H-=6
pToken := Gdip_Startup()
pBitmap := Gdip_BitmapFromScreen(X "|" Y "|" W "|" H)
FormatTime, TimeStamp ,, yyyy_MM_dd @ HH_mm_ss
FileName := TimeStamp " (" w "x" h ").PNG"
Gdip_SaveBitmapToFile(pBitmap, SavePath FileName)
Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)
return SavePath FileName
}
;}^^^^^ SCW Functions ^^^^^
Email_AttachFile(File, URL:="")
{
try
IsObject(MailItem := ComObjActive("Outlook.Application").CreateItem(olMailItem:=0)) ; Get the Outlook application object if Outlook is open
catch
MailItem := ComObjCreate("Outlook.Application").CreateItem(olMailItem:=0) ; Create if Outlook is not open
MailItem.BodyFormat := (olFormatHTML:=2)
;~ MailItem.TO :="somejunkemail@yahoo.com"
;~ MailItem.CC :="somejunkemail@yahoo.com"
FormatTime, TimeStamp , % RegExReplace(File, "^.*\\|[_ @]|\(.*$"), dddd MMMM d, yyyy h:mm:ss tt
MailItem.Subject :="Screen shot taken : " (TimeStamp) ; Subject line of email
HTMLBody := "
<H2 style='BACKGROUND-COLOR: red'><br></H2>
<HTML>Please find attached the screenshot taken on " TimeStamp "<br><br>"
if URL
HTMLBody .= "
<span style='color:black'>The image can also be accessd here: <a href=""" (URL) """>" (URL) "</a> <br><br></span>"
HTMLBody .= "</HTML>"
MailItem.HTMLBody := HTMLBody
MailItem.Attachments.Add(File)
MailItem.Display
}
Imgur_Post(File, Client)
{
Http := ComObjCreate("WinHttp.WinHttpRequest.5.1")
Img := ComObjCreate("WIA.ImageFile")
Img.LoadFile(File)
/* ; Converts Image to JPG
IP := ComObjCreate("WIA.ImageProcess")
IP.Filters.Add(IP.FilterInfos("Crop").FilterID)
IP.Filters.Add(IP.FilterInfos("Convert").FilterID)
IP.Filters(2).Properties("FormatID").Value:="{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}"
IP.Filters(2).Properties("Quality").Value:=85
Img := IP.Apply(Img)
*/
Data := Img.FileData.BinaryData
Http.Open("POST","https://api.imgur.com/3/upload")
Http.SetRequestHeader("Authorization","Client-ID " Client)
Http.SetRequestHeader("Content-Length",size)
Http.Send(Data)
Codes:=Http.ResponseText
split=":"
RegExMatch(Codes, "U)link" split "(.*)" Chr(34), Match)
URL:=RegExReplace(Match1, "\\")
Return URL
}
Clipboard2Acrobat(SavePathPDF:="") ; Adobe Acrobat must be installed
{
App := ComObjCreate("AcroExch.App")
App.Show()
App.MenuItemExecute("ImageConversion:Clipboard")
if SavePathPDF
{
IfNotExist, %SavePathPDF%
FileCreateDir, %SavePathPDF%
FormatTime, TimeStamp ,, yyyy_MM_dd @ HH_mm_ss
FileName := TimeStamp ".PDF"
AVDoc := App.GetActiveDoc()
PVDoc := AVDoc.GetPDDoc()
PDSaveIncremental := 0x0000 ;/* write changes only */
PDSaveFull := 0x0001 ;/* write entire file */
PDSaveCopy := 0x0002 ;/* write copy w/o affecting current state */
PDSaveLinearized := 0x0004 ;/* write the file linearized for */
PDSaveBinaryOK := 0x0010 ;/* OK to store binary in file */
PDSaveCollectGarbage := 0x0020 ;/* perform garbage collection on */
PVDoc.save(PDSaveFull|PDSaveLinearized, SavePathPDF FileName)
}
}
RelativePath(ByRef Path)
{
RegExMatch(Path,"^(\.*)\\",M), R := StrLen(M1)
if (R=1)
Path := A_ScriptDir SubStr(Path,R+1)
else if (R>1)
Path := SubStr(A_ScriptDir,1,InStr(A_ScriptDir,"\",,0,R-1)) SubStr(Path,R+2)
return Path
}
GuiDefaultFont() { ; by SKAN (modified by just me)
VarSetCapacity(LF, szLF := 28 + (A_IsUnicode ? 64 : 32), 0) ; LOGFONT structure
If DllCall("GetObject", "Ptr", DllCall("GetStockObject", "Int", 17, "Ptr"), "Int", szLF, "Ptr", &LF)
Return {Name: StrGet(&LF + 28, 32), Size: Round(Abs(NumGet(LF, 0, "Int")) * (72 / A_ScreenDPI), 1)
, Weight: NumGet(LF, 16, "Int"), Quality: NumGet(LF, 26, "UChar")}
Return False
}
WaitReleaseAllModifiers()
{
List := "LWin|RWin|LAlt|RAlt|LControl|RControl|LShift|RShift"
while !Done
{
Done := true
Loop Parse, list, |
if (GetKeyState(A_LoopField))
Done := false
Sleep 50
}
}