Тема: AHK: удобный скрипт для сохранения скриншотов
Скрипт является развитием этой разработки.
ScreenCatcher — скрипт для быстрых скриншотов на AutoHotkey v1
ScreenCatcher делает снимки всего экрана, активного окна или выбранной области. Снимок можно посмотреть в окне предпросмотра, отметить на нём нужное стрелками, рамками или маркером, а затем сохранить в файл, скопировать в буфер обмена или отправить на Imgbb и получить ссылку.
Скрипт пригодится, если нужно быстро вырезать фрагмент экрана, повторно снимать одну и ту же область, подогнать рамку с точностью до пикселя, показать на снимке, куда смотреть, и сразу поделиться картинкой.
Управление — через меню иконки в трее, контекстные меню окна выделения и окна предпросмотра и горячие клавиши.
Что нового
Рисование на превью: свободная линия, прямая линия, стрелка, прямоугольник, эллипс и маркер-выделитель. Нарисованное сохраняется вместе со снимком.
Новое окно справки на HTML: оглавление с переходом к разделам, светлая и тёмная тема, таблица с текущими назначениями горячих клавиш. Размер и положение окна запоминаются.
Основные возможности
снимок всего экрана, активного окна (по видимой рамке, без тени) или выбранной области;
два способа выбрать область: постоянное окно выделения и быстрое выделение мышью поверх экрана;
точная подгонка границ окна выделения по пикселю — колесом мыши или стрелками с модификаторами;
плашки с координатами и размером области;
вывод в файл, в буфер обмена и на Imgbb — в любом сочетании;
форматы файлов png, jpg, bmp, tif, gif, настройка качества JPEG и папки сохранения;
окна предпросмотра: перемещение, масштаб колесом мыши, выбор интерполяции, сохранение в исходном или текущем размере;
рисование на превью с отменой и повтором;
захват курсора мыши на скриншоте;
уведомления о сохранении у иконки в трее;
цвет и прозрачность окна выделения, два варианта подсказок при изменении его размера;
настраиваемые горячие клавиши, в том числе с кнопками мыши;
запуск вместе с Windows;
справка с актуальными назначениями горячих клавиш.
Два способа выбрать область
1. Окно выделения
Полупрозрачное цветное окно, которое можно показать, скрыть, переместить, отправить в центр экрана и растянуть мышью за края и углы. Снимается область, которая находится под ним. Сделать снимок можно двойным кликом по окну или горячей клавишей (по умолчанию F12). Горячая клавиша работает и при скрытом окне: снимается область по его последнему положению.
Рядом с окном показываются две плашки: сверху слева — координаты левого верхнего угла и размер области, снизу справа — координаты правого нижнего угла. В снимок плашки не попадают; при желании их можно отключить.
Для точной подгонки, когда окно выделения активно (кликните по нему), каждая граница сдвигается на 1 пиксель:
левая — Ctrl + колесо или Ctrl + ← / →;
верхняя — Shift + колесо или Shift + ↑ / ↓;
правая — Alt + колесо или Alt + ← / →;
нижняя — Win + колесо или Win + ↑ / ↓.
Через контекстное меню окна (правый клик) открываются настройки, там же можно быстро включить или выключить показ координат, захват курсора и скрытие окна после снимка.
Такой способ удобен, когда нужно:
несколько раз снимать одну и ту же область;
заранее выставить точный размер кадра;
аккуратно подогнать рамку по границам окна, изображения или элемента интерфейса.
2. Быстрое выделение мышью поверх экрана
Одноразовый выбор прямоугольника прямо на экране. По F4 включается режим ожидания: появляется крестик, рядом с ним — координаты курсора; выделение начинается с нажатия левой кнопки мыши. Быстрый вариант — левые Ctrl + Alt + левая кнопка мыши: выделение начинается сразу. Во время протяжки рядом с рамкой видны координаты и размер. Отмена — Esc или правая кнопка мыши. Выделение мышью работает на основном мониторе.
Такой способ удобен, когда нужно быстро снять произвольный фрагмент, не трогая окно выделения.
Предпросмотр
Если предпросмотр включён, после съёмки открывается окно со снимком. Его можно перетаскивать мышью и масштабировать колесом (шаг около 10%, с Ctrl — по одному пикселю). В контекстном меню можно сохранить снимок в исходном или текущем размере, отправить его в конкретное место (файл, буфер обмена, Imgbb), выбрать режим интерполяции, включить рисование или удалить окно. Esc закрывает предпросмотр.
На экране можно держать несколько окон предпросмотра; горячая клавиша (по умолчанию левый Ctrl + Space) по очереди подсвечивает их, чтобы найти нужное.
Рисование на превью
Перед сохранением на снимке можно отметить нужное место. Инструменты:
свободная линия;
прямая линия;
стрелка;
прямоугольник;
эллипс;
маркер — толстая полупрозрачная линия для выделения текста.
Режим рисования включается пунктом «Рисовать» в контекстном меню превью или клавишей D; курсор над превью становится крестиком. Рисуют протяжкой с зажатой левой кнопкой мыши. Shift во время протяжки выравнивает линию и стрелку по горизонтали, вертикали или под 45°, превращает прямоугольник в квадрат, эллипс — в круг, а маркер — в ровную горизонтальную полосу.
Клавиши при активном превью:
D — включить или выключить режим рисования;
1–6 — выбрать инструмент (в порядке списка выше);
[ и ] — уменьшить или увеличить толщину;
Ctrl + Z — отменить, Ctrl + Y или Ctrl + Shift + Z — повторить;
Esc — отменить рисуемую фигуру или выйти из режима рисования.
Цвет и толщина выбираются в контекстном меню; у маркера они свои, у остальных инструментов общие. Пункт «Стереть всё» убирает всё нарисованное, и это тоже можно отменить. Масштаб колесом работает и в режиме рисования — нарисованное масштабируется вместе со снимком. Снимок сохраняется вместе с рисунками и в исходном, и в текущем размере, в любое из назначений. Выбранные инструмент, цвета и толщины запоминаются между запусками.
Вывод снимков
В настройках можно выбрать один или несколько способов вывода: в файл, в буфер обмена, на Imgbb. Например, снимок может одновременно сохраняться в файл, копироваться в буфер обмена и отправляться на Imgbb. После отправки на Imgbb показывается окошко со ссылкой и кнопкой копирования.
Настройка отправки на Imgbb
Зарегистрироваться на Imgbb.
Получить API key на странице api.imgbb.com.
В настройках ScreenCatcher на вкладке «Вывод» включить Imgbb.com и нажать «Применить». Если ключ ещё не задан, скрипт подскажет, что делать, и откроет файл настроек в Блокноте.
Вписать ключ в секцию [Imgbb] файла настроек:
[Imgbb]
ClientID=ВАШ_API_KEYГорячие клавиши по умолчанию
F12 — снимок области под окном выделения;
правый Shift + PrintScreen — снимок активного окна;
PrintScreen — снимок всего экрана;
Pause — показать или скрыть окно выделения;
ScrollLock — окно выделения в центр экрана;
левый Ctrl + Space — подсветить окна предпросмотра по очереди;
F4 — выделить область мышью;
левые Ctrl + Alt + левая кнопка мыши — быстро выделить область мышью;
открыть папку вывода — по умолчанию не назначена.
Эти клавиши можно изменить или очистить в настройках, на вкладке «Горячие клавиши». Клавиши точной подгонки окна выделения и клавиши окна предпросмотра фиксированные.
Настройки
Окно настроек открывается из меню в трее или из контекстного меню окна выделения. Вкладки:
«Цвет» — цвет и прозрачность окна выделения;
«Вывод» — куда отправлять снимки, формат файла, качество JPEG и папка сохранения;
«Настройки» — показ координат, захват курсора, уведомления, предпросмотр, запуск вместе с Windows и вид подсказок при изменении размера окна выделения (изменённые курсоры или цветные маркеры);
«Горячие клавиши» — сочетания клавиш и кнопок мыши; одно сочетание нельзя назначить двум действиям.
Пока окно настроек открыто, рабочие горячие клавиши ScreenCatcher временно отключаются, чтобы не мешать вводу новых сочетаний.
Настройки хранятся в файле ScreenCatcher.ini рядом со скриптом. Если папка со скриптом общая для нескольких компьютеров (например, синхронизируется через облако), каждому можно дать свои настройки: скопируйте или переименуйте ScreenCatcher.ini в ИмяКомпьютера_ScreenCatcher.ini — если такой файл есть, скрипт использует его.
Справка
Справка открывается из меню в трее или из контекстного меню окна выделения. В ней есть оглавление с переходом к разделам, светлая и тёмная тема (переключается кнопкой и запоминается) и таблица с текущими назначениями горячих клавиш. Окно можно растягивать, его размер и положение сохраняются между запусками.
Трей
Клик по иконке в трее показывает или скрывает окно выделения. В меню трея — справка, настройки вывода и программы, показ и скрытие окна выделения, перемещение его в центр экрана, открытие папки вывода и выход.
Кому пригодится
ScreenCatcher полезен, если часто нужно делать технические скриншоты, показывать фрагменты интерфейса с пометками, снимать повторяющиеся области экрана, быстро отправлять изображения по ссылке или держать под рукой несколько окон предпросмотра.
Скрипт написан для AutoHotkey v1.1 (Unicode-версия, 1.1.31 или новее).
#NoEnv
#SingleInstance, force
#MaxHotkeysPerInterval 200
SetWinDelay, 0
SetBatchLines, -1
SetTitleMatchMode, 3
CoordMode, Mouse
OnExit("ShutdownApplication")
FixIE()
global App := {Config: {}, Settings: {}, Menu: {}, Selection: {}, Windows: {}}
App.Selection.Coordinates := {FontName: "Segoe UI", FontSize: 10
, Gap: 5, PaddingX: 6, PaddingY: 3}
hIcon16 := CreateIconFromBase64(GetBase64String(16), 16)
Menu, Tray, Icon, HICON:*%hIcon16%
hIcon32 := CreateIconFromBase64(GetBase64String(32), 32)
DllCall("SendMessage", "Ptr", A_ScriptHwnd, "UInt", WM_SETICON := 0x80, "Ptr", ICON_BIG := 1, "Ptr", hIcon32)
App.GdipToken := GdipStartup()
; секция ключ имя переменной умолчание
IniReadConfigSect("Color-Transparent", "ARGB" , "ARGB" , 0x82FFC700)
IniReadConfigSect("Output_Settings" , "Output" , "Output" , "File"
, "Extension" , "Ext" , "png"
, "JPEG_Quality" , "JPEGQuality" , 100
, "Out_Directory" , "OutDirectory" , A_ScriptDir)
IniReadConfigSect("Program_Settings" , "Capture_Cursor" , "CaptureCursor" , 0
, "Hide_After_Capture", "HideAfterCapture", 0
, "Show_Coordinates" , "ShowCoordinates" , 1
, "Show_Preview" , "ShowPreview" , 1
, "Notify" , "Notify" , 1
, "Resize_Pointers" , "ResizePointers" , "Cursors"
, "InterpolationMode", "InterpolationMode", 3)
IniReadHotkeysSect("Hotkeys" , "GetArea" , "GetArea" , "$F12"
, "GetActiveWindow" , "GetActiveWindow" , ">+PrintScreen"
, "GetScreen" , "GetScreen" , "PrintScreen"
, "ShowHideSelWindow", "ShowHideSelWindow", "Pause"
, "SelWindowToCenter", "SelWindowToCenter", "ScrollLock"
, "SelectPreview" , "SelectPreview" , "<^Space"
, "OpenOutputFolder" , "OpenOutputFolder" , " "
, "SelectAreaOverlay", "SelectAreaOverlay", "F4"
, "QuickSelectAreaOverlay", "QuickSelectAreaOverlay", "<^<!LButton")
NormalizeLoadedSettings()
Menu, Tray, NoStandard
Menu, Tray, Add, Справка, ShowHelp
Menu, Tray, Add
Menu, Tray, Add, Вывод, ShowSettingsFromMenu
Menu, Tray, Add, Настройки, ShowSettingsFromMenu
Menu, Tray, Add
App.Menu.TrayHide := MenuHotkeyCaption("Скрыть окно выделения", App.Hotkeys.ShowHideSelWindow)
App.Menu.TrayShow := MenuHotkeyCaption("Показать окно выделения", App.Hotkeys.ShowHideSelWindow)
App.Menu.TrayCenter := MenuHotkeyCaption("Окно выделения в центр экрана", App.Hotkeys.SelWindowToCenter)
App.Menu.TrayOpenOutDir := MenuHotkeyCaption("Открыть папку вывода", App.Hotkeys.OpenOutputFolder)
Menu, Tray, Add, % App.Menu.TrayShow, ToggleSelectionWindow
Menu, Tray, Add, % App.Menu.TrayCenter, CenterSelectionWindow
Menu, Tray, Add, % App.Menu.TrayOpenOutDir, OpenOutputDirectory
if !A_IsCompiled {
Menu, Tray, Add
Menu, Tray, Add, Редактировать скрипт, EditScript
Menu, Tray, Add, Перезагрузка, ReloadScript
}
Menu, Tray, Add
Menu, Tray, Add, Выход, ShutdownApplication
Menu, MainMenu, Add, Вывод, ShowSettingsFromMenu
Menu, MainMenu, Add, Настройки, ShowSettingsFromMenu
Menu, MainMenu, Add
App.Menu.MainShowCoordinates := "Показывать координаты"
App.Menu.MainCaptureCursor := "Включать курсор в скриншот"
App.Menu.MainHideAfterCapture := "Скрывать это окно после взятия скриншота"
Menu, MainMenu, Add, % App.Menu.MainShowCoordinates, ToggleShowCoordinatesFromMenu
Menu, MainMenu, Add, % App.Menu.MainCaptureCursor, ToggleCaptureCursorFromMenu
Menu, MainMenu, Add, % App.Menu.MainHideAfterCapture, ToggleHideAfterCaptureFromMenu
Menu, MainMenu, Add
App.Menu.MainArea := MenuHotkeyCaption("Сделать скриншот", App.Hotkeys.GetArea)
App.Menu.MainHide := MenuHotkeyCaption("Скрыть окно выделения", App.Hotkeys.ShowHideSelWindow)
App.Menu.MainOpenOutDir := MenuHotkeyCaption("Открыть папку вывода", App.Hotkeys.OpenOutputFolder)
Menu, MainMenu, Add, % App.Menu.MainArea, CaptureAreaScreenshot
Menu, MainMenu, Add, % App.Menu.MainHide, ToggleSelectionWindow
Menu, MainMenu, Add, % App.Menu.MainOpenOutDir, OpenOutputDirectory
Menu, MainMenu, Add
Menu, MainMenu, Add, Справка, ShowHelp
SyncMainMenuChecks()
Menu, Interpolation, Add, Default, SetInterpolationMode
Menu, Interpolation, Add, LowQuality, SetInterpolationMode
Menu, Interpolation, Add, HighQuality, SetInterpolationMode
Menu, Interpolation, Add, Bilinear, SetInterpolationMode
Menu, Interpolation, Add, Bicubic, SetInterpolationMode
Menu, Interpolation, Add, NearestNeighbor, SetInterpolationMode
Menu, Interpolation, Add, HighQualityBilinear, SetInterpolationMode
Menu, Interpolation, Add, HighQualityBicubic, SetInterpolationMode
InterpolationModeString := "Default|LowQuality|HighQuality|Bilinear|"
. "Bicubic|NearestNeighbor|HighQualityBilinear|HighQualityBicubic"
App.Menu.InterpolationItems := StrSplit(InterpolationModeString, "|")
Menu, Interpolation, Check, % App.Menu.InterpolationItems[App.Config.InterpolationMode]
Menu, PreviewSaveToMenu, Add, файл, PreviewSaveToMenuHandling
Menu, PreviewSaveToMenu, Add, буфер обмена, PreviewSaveToMenuHandling
Menu, PreviewSaveToMenu, Add, imgbb.com, PreviewSaveToMenuHandling
Menu, PreviewSaveOriginalToMenu, Add, файл, PreviewSaveToMenuHandling
Menu, PreviewSaveOriginalToMenu, Add, буфер обмена, PreviewSaveToMenuHandling
Menu, PreviewSaveOriginalToMenu, Add, imgbb.com, PreviewSaveToMenuHandling
Menu, PreviewSaveCurrentToMenu, Add, файл, PreviewSaveCurrentToMenuHandling
Menu, PreviewSaveCurrentToMenu, Add, буфер обмена, PreviewSaveCurrentToMenuHandling
Menu, PreviewSaveCurrentToMenu, Add, imgbb.com, PreviewSaveCurrentToMenuHandling
InitPreviewDrawing()
for index, DrawTool in PreviewDrawTools()
Menu, PreviewDrawToolMenu, Add, % PreviewDrawToolItemName(index, DrawTool), PreviewDrawToolMenuHandling, +Radio
for index, DrawColor in PreviewDrawColors()
Menu, PreviewDrawColorMenu, Add, % DrawColor.label, PreviewDrawColorMenuHandling, +Radio
RebuildPreviewDrawWidthMenu()
App.Menu.PreviewDraw := "Рисовать`tD"
App.Menu.PreviewWidth := "Толщина`t[ ]"
App.Menu.PreviewClear := "Стереть всё"
Menu, ScreenShotMenu, Add, Сохранить в первоначальном размере, ScreenShotMenuHandling
Menu, ScreenShotMenu, Add, Сохранить в первоначальном размере в, :PreviewSaveOriginalToMenu
Menu, ScreenShotMenu, Add, Сохранить в текущем размере, ScreenShotMenuHandling
Menu, ScreenShotMenu, Add, Сохранить в текущем размере в, :PreviewSaveCurrentToMenu
Menu, ScreenShotMenu, Add
Menu, ScreenShotMenu, Add, % App.Menu.PreviewDraw, PreviewDrawModeMenuHandling
Menu, ScreenShotMenu, Add, Инструмент, :PreviewDrawToolMenu
Menu, ScreenShotMenu, Add, Цвет, :PreviewDrawColorMenu
Menu, ScreenShotMenu, Add, % App.Menu.PreviewWidth, :PreviewDrawWidthMenu
Menu, ScreenShotMenu, Add, % App.Menu.PreviewClear, PreviewClearMenuHandling
Menu, ScreenShotMenu, Add
Menu, ScreenShotMenu, Add, Удалить, ScreenShotMenuHandling
Menu, ScreenShotMenu2, Add, Интерполяция при изменении размеров, :Interpolation
Menu, ScreenShotMenu2, Add, Сохранить в, :PreviewSaveToMenu
Menu, ScreenShotMenu2, Add, Сохранить, ScreenShotMenuHandling
Menu, ScreenShotMenu2, Add
Menu, ScreenShotMenu2, Add, % App.Menu.PreviewDraw, PreviewDrawModeMenuHandling
Menu, ScreenShotMenu2, Add, Инструмент, :PreviewDrawToolMenu
Menu, ScreenShotMenu2, Add, Цвет, :PreviewDrawColorMenu
Menu, ScreenShotMenu2, Add, % App.Menu.PreviewWidth, :PreviewDrawWidthMenu
Menu, ScreenShotMenu2, Add, % App.Menu.PreviewClear, PreviewClearMenuHandling
Menu, ScreenShotMenu2, Add
Menu, ScreenShotMenu2, Add, Удалить, ScreenShotMenuHandling
Gui, +LastFound -Caption +AlwaysOnTop +Owner
StoreSelectionWindowHwnd()
WinSet, Transparent, 0, % "ahk_id " App.Selection.Hwnd
Gui, Color, % Format("{:X}", App.Config.ARGB & 0xFFFFFF)
Locations = x190 y190|x0 y190|x0 y0|x190 y0|x190 y95|x95 y190|x0 y95|x95 y0
App.Selection.MarkerHwnds := []
Loop, parse, Locations, | ; SS_BITMAP = 0xE
{
Gui, Add, Text, % "w10 h10 +0xE hidden hwndMarkerHwnd " A_LoopField
App.Selection.MarkerHwnds.Push(MarkerHwnd)
}
UpdateMarkerColor()
CreateSelectionCoordinateWindows()
SetResizeHotkeyState("Off")
if !A_Args.Length() {
CenterSelectionWindow()
} else {
opts := "x" (A_ScreenWidth - 200)//2 " y" (A_ScreenHeight - 200)//2 " h200 w200 Hide"
Gui, Show, % opts, ScreenСatcher
}
SetScriptHotkeys(1)
Esc := DllCall("RegisterWindowMessage", "Str", "Esc")
Wheel := DllCall("RegisterWindowMessage", "Str", "Wheel")
OnMessage( Esc, "WM_ESC")
OnMessage(Wheel, "WM_WHEEL")
OnMessage(0x018, "WM_SHOWWINDOW")
OnMessage(0x020, "WM_APP_SETCURSOR")
OnMessage(0x047, "WM_SELECTION_WINDOWPOSCHANGED")
OnMessage(0x201, "WM_LBUTTONDOWN")
OnMessage(0x203, "WM_LBUTTONDBLCLK")
OnMessage(0x204, "WM_RBUTTONDOWN")
OnMessage(0x404, "AHK_NOTIFYICON")
return
;###########################################################################################################
;*************************************** Окно Настроек *****************************************************
;###########################################################################################################
OpenSettingsWindow(ThisMenuItemPos) {
HideHelpWindow()
App.Config.RunOnWinStart := IsRunOnWindowsStartEnabled()
SelectionHwnd := App.Selection.Hwnd
Width := 310, Height := 230
WindowWidth := Width - 1, WindowHeight := Height + 51
Gui, 2:Default
if WindowExistsByHwnd(App.Settings.WindowHwnd) {
if WindowExistsByHwnd(App.Settings.HotkeysHwnd)
Gui, 4:Hide
GuiControl, Choose, % App.Settings.TabHwnd, % ThisMenuItemPos
SuspendScriptHotkeysForSettings()
ShowSettingsWindowNearSelection(SelectionHwnd, WindowWidth, WindowHeight)
UpdateHotkeysTabVisibility()
return
}
SavePreviousSettingsState()
SuspendScriptHotkeysForSettings()
Gui, 2:+LastFound +hwndSettingsHwnd
App.Settings.WindowHwnd := SettingsHwnd
App.Windows[2] := Object("Hwnd", SettingsHwnd)
Gui, Font, s10 q5, Calibri
Gui, Add, Tab3, gUpdateHotkeysTabVisibility x0 y0 w%Width% h%Height% hwndSettingsTabHwnd AltSubmit -Wrap
, % " Цвет| Вывод|Настройки|Горячие клавиши"
App.Settings.TabHwnd := SettingsTabHwnd
GuiControl, Choose, % App.Settings.TabHwnd, % ThisMenuItemPos
;********************************** Первая вкладка "Цвет" ***********************************
Gui, Add, Pic, % "x10 y+10 h184 +0x8 w" Width - 21 ; SS_GRAYFRAME = 0x8
Gui, Font, s10, Segoe UI
Gui, Add, Text, % "Center c5021AC x15 yp+10 w" Width-30, Настройки цвета и прозрачности
Gui, Font, s8 q5, Verdana
Gui, Add, Text, x25 yp+37 w30 cRed Center, Red
Gui, Add, Text, xp-2 yp+30 wp cGreen Center, Green
Gui, Add, Text, xp yp+30 wp cBlue Center, Blue
Gui, Add, Text, xp yp+30 wp cEECC00 Center, Trans
ColorState := App.Settings.Color := Object()
ColorState.Red := (App.Config.ARGB & 0xFF0000)>>16
ColorState.Green := (App.Config.ARGB & 0xFF00)>>8
ColorState.Blue := App.Config.ARGB & 0xFF
ColorState.Trans := App.Config.ARGB>>24
Options := "x65 w" Width - 115 " h20 Range0-255 ToolTip AltSubmit"
Gui, Add, Slider, gUpdateSelectionColorFromGui %Options% yp-91 hwndRedSliderHwnd, % ColorState.Red
Gui, Add, Slider, gUpdateSelectionColorFromGui %Options% yp+30 hwndGreenSliderHwnd, % ColorState.Green
Gui, Add, Slider, gUpdateSelectionColorFromGui %Options% yp+30 hwndBlueSliderHwnd, % ColorState.Blue
Gui, Add, Slider, gUpdateSelectionTransparencyFromGui %Options% yp+30 hwndTransSliderHwnd, % ColorState.Trans
Gui, Add, Text, xp+195 yp-89 w30 cRed Center hwndRedValueHwnd, % ColorState.Red
Gui, Add, Text, xp yp+30 wp cGreen Center hwndGreenValueHwnd, % ColorState.Green
Gui, Add, Text, xp yp+30 wp cBlue Center hwndBlueValueHwnd, % ColorState.Blue
Gui, Add, Text, xp yp+30 wp cEECC00 Center hwndTransValueHwnd, % ColorState.Trans
App.Settings.RedSliderHwnd := RedSliderHwnd
App.Settings.GreenSliderHwnd := GreenSliderHwnd
App.Settings.BlueSliderHwnd := BlueSliderHwnd
App.Settings.TransSliderHwnd := TransSliderHwnd
App.Settings.RedValueHwnd := RedValueHwnd
App.Settings.GreenValueHwnd := GreenValueHwnd
App.Settings.BlueValueHwnd := BlueValueHwnd
App.Settings.TransValueHwnd := TransValueHwnd
;********************************* Вторая вкладка "Вывод" ************************************
Gui, Tab, 2
Gui, Font, s10, Segoe UI
Gui, Add, Text, % "Center c5021AC x5 y+6 w" Width-10, Как сохранять скриншоты:
Gui, Font, s8 q5, Verdana
Gui, Add, Checkbox
, % "gUpdateOutputTargetFromGui x15 yp+25 hwndOutputFileHwnd" (InStr(App.Config.Output, "File") ? " Checked" : ""), В файл
Gui, Add, Checkbox
, % "gUpdateOutputTargetFromGui xp+75 yp hwndOutputClipHwnd" (InStr(App.Config.Output, "Clip") ? " Checked" : ""), В буфер обмена
Gui, Add, Checkbox
, % "gUpdateOutputTargetFromGui xp+125 yp hwndOutputImgbbHwnd" (InStr(App.Config.Output, "Imgbb") ? " Checked" : ""), Imgbb.com
App.Settings.OutputFileHwnd := OutputFileHwnd
App.Settings.OutputClipHwnd := OutputClipHwnd
App.Settings.OutputImgbbHwnd := OutputImgbbHwnd
Gui, Add, Pic, % "x2 yp+26 h2 +0x8 w" Width - 4 ; SS_GRAYFRAME = 0x8
Gui, Font, s10, Segoe UI
Gui, Add, Text, % "Center c5021AC x5 yp+9 w" Width-10, Тип файлов для вывода
Gui, Font, s8 q5, Verdana
Gui, Add, Radio, % "gSetOutputExtensionFromGui x25 yp+23 hwndExtensionPngHwnd" (App.Config.Ext = "png" ? " Checked" : ""), png
Gui, Add, Radio, % "gSetOutputExtensionFromGui xp+55 yp hwndExtensionJpgHwnd" (App.Config.Ext = "jpg" ? " Checked" : ""), jpg
Gui, Add, Radio, % "gSetOutputExtensionFromGui xp+55 yp hwndExtensionBmpHwnd" (App.Config.Ext = "bmp" ? " Checked" : ""), bmp
Gui, Add, Radio, % "gSetOutputExtensionFromGui xp+55 yp hwndExtensionTifHwnd" (App.Config.Ext = "tif" ? " Checked" : ""), tif
Gui, Add, Radio, % "gSetOutputExtensionFromGui xp+55 yp hwndExtensionGifHwnd" (App.Config.Ext = "gif" ? " Checked" : ""), gif
App.Settings.ExtensionPngHwnd := ExtensionPngHwnd
App.Settings.ExtensionJpgHwnd := ExtensionJpgHwnd
App.Settings.ExtensionBmpHwnd := ExtensionBmpHwnd
App.Settings.ExtensionTifHwnd := ExtensionTifHwnd
App.Settings.ExtensionGifHwnd := ExtensionGifHwnd
Gui, Font, s10, Segoe UI
Gui, Add, Text, Left c5021AC x20 yp+23, Качество jpg:
Gui, Add, Slider
, gSetJpegQuality xp+107 yp w128 h20 Range50-100 ToolTip AltSubmit hwndJpegQualitySliderHwnd, % App.Config.JPEGQuality
Gui, Font, s8 q5, Verdana
Gui, Add, Text, Center c5021AC xp+132 yp+2 w30 hwndJpegQualityPercentHwnd, % App.Config.JPEGQuality "`%"
App.Settings.JpegQualitySliderHwnd := JpegQualitySliderHwnd
App.Settings.JpegQualityPercentHwnd := JpegQualityPercentHwnd
Gui, Add, Pic, % "x2 yp+26 h2 +0x8 w" Width - 4 ; SS_GRAYFRAME = 0x8
Gui, Font, s10, Segoe UI
Gui, Add, Text, % "Center c5021AC x5 yp+9 w" Width-10, Папка для сохранения файлов
Gui, Font, s8 q5, Verdana
Gui, Add, Edit, % "hwndOutDirectoryEditHwnd x10 yp+24 h21 w" Width-50, % App.Config.OutDirectory
App.Settings.OutDirectoryEditHwnd := OutDirectoryEditHwnd
Gui, Font, s10
Gui, Add, Button, % "gSelectOutputDirectory x" Width-35 " yp hp w23", ...
;************************** Третья вкладка "Настройки программы" ****************************
Gui, Tab, 3
Gui, Font, s8 q5, Verdana
Gui, Add, Checkbox
, % "x20 y+15 hwndShowCoordinatesHwnd" (App.Config.ShowCoordinates ? " Checked" : "")
, Показывать координаты
Gui, Add, Checkbox
, % "xp yp+25 hwndCaptureCursorHwnd" (App.Config.CaptureCursor ? " Checked" : "")
, Включать курсор в скриншот
Gui, Add, Checkbox, % "xp yp+25 hwndNotifyHwnd" (App.Config.Notify ? " Checked" : "")
, Уведомлять о сохранении скриншота
Gui, Add, Checkbox, % "xp yp+25 hwndShowPreviewHwnd" (App.Config.ShowPreview ? " Checked" : "")
, Показывать скриншот перед сохранением
Gui, Add, Checkbox
, % "xp yp+25 hwndRunOnWinStartHwnd" (App.Config.RunOnWinStart ? " Checked" : "")
, Запускать программу при загрузке системы
App.Settings.CaptureCursorHwnd := CaptureCursorHwnd
App.Settings.ShowCoordinatesHwnd := ShowCoordinatesHwnd
App.Settings.ShowPreviewHwnd := ShowPreviewHwnd
App.Settings.NotifyHwnd := NotifyHwnd
App.Settings.RunOnWinStartHwnd := RunOnWinStartHwnd
; Gui, Add, Pic, % "x2 yp+30 h2 +0x8 w" Width - 4 ; SS_GRAYFRAME = 0x8
Gui, Font, s10, Segoe UI
Gui, Add, Text, % "Center c5021AC x5 yp+25 w" Width-10
, Индикаторы при изменении размеров`nокна выделения
Gui, Font, s8 q5, Verdana
Gui, Add, Radio, xp+14 yp+40 hwndResizeCursorsHwnd, Изменённые курсоры
Gui, Add, Radio, xp+153 yp hwndResizeMarkersHwnd, Цветные маркеры
GuiControl,, % (App.Config.ResizePointers = "Cursors" ? ResizeCursorsHwnd : ResizeMarkersHwnd), 1
App.Settings.ResizeCursorsHwnd := ResizeCursorsHwnd
App.Settings.ResizeMarkersHwnd := ResizeMarkersHwnd
Gui, Tab
;*************************** Четвёртая вкладка "Горячие клавиши" *****************************
HotkeysTabPageHwnd := DllCall("GetWindow", "Ptr", App.Settings.TabHwnd, "UInt", GW_HWNDNEXT := 2)
WinGetPos,,, W, H, ahk_id %HotkeysTabPageHwnd%
Gui, 4: Default
Gui, +Parent%HotkeysTabPageHwnd% -Caption +ToolWindow +hwndHotkeysHwnd
App.Settings.HotkeysHwnd := HotkeysHwnd
Gui, Add, Tab3, % "gFocusSettingsSafeButton x" 5 " y" 5 " w" W - 8 " h" H - 9 " hwndHotkeysSubTabHwnd", Скриншоты|Окна скрипта|Служебные
App.Settings.HotkeysSubTabHwnd := HotkeysSubTabHwnd
Handles := []
HotkeyControls := []
HotkeyNames := ScreenCatcherHotkeyNames()
for k, v in [ "Скриншот под окном выделения"
, "Скриншот активного окна"
, "Скриншот всего экрана"
, "Скрыть/показать окно выделения"
, "Окно выделения в центр экрана"
, "Выделить превью скриншота"
, "Открыть папку вывода"
, "Выбрать область для скриншота"
, "Быстро выделить область для скриншота" ]
{
if k = 4
Gui, Tab, 2
if k = 7
Gui, Tab, 3
Gui, Font, s10, Segoe UI
Gui, Add, Text, % "x0 y+8 w" . (Width - 6) . " Center c5021AC", %v%:
Gui, Font, s11, calibri
Gui, Add, Edit, % "Center ReadOnly x15 y+5 h23 w" . (Width-36) . " hwndhHotkey" . k
SetStaticColor(hHotkey%k%, 0xFFFFFF)
Handles.Push(hHotkey%k%)
Options := "KDMLR"
HotkeyControls.Push([HotkeyNames[k], hHotkey%k%, Options])
}
Hotkey_Register(HotkeyControls*)
SetHotkeyControlsFromVars()
Gui, Show, Hide x0 y0 w%W% h%H%
App.Settings.MessageHandlers := {}
App.Settings.MessageHandlers.WM_COMMAND := Func("WM_COMMAND").Bind(Handles)
App.Settings.MessageHandlers.WM_SETCURSOR := Func("WM_SETCURSOR").Bind(Handles)
OnMessage( 0x111, App.Settings.MessageHandlers.WM_COMMAND )
OnMessage( 0x20, App.Settings.MessageHandlers.WM_SETCURSOR )
;***********************************************************************************************
Gui, 2:Default
Gui, Font, s8 q5, Verdana
Gui, Add, Button, % "gConfirmSettingsFromGui x" Width - 286 " y" Height + 14 " w85 h23", OK
Gui, Add, Button, gApplySettingsFromGui xp+90 yp wp hp, Применить
Gui, Add, Button, gCancelSettingsFromGui xp+90 yp wp hp, Отмена
ShowSettingsWindowNearSelection(SelectionHwnd, WindowWidth, WindowHeight)
return
}
ShowSettingsWindowNearSelection(SelectionHwnd, LogicalWidth, LogicalHeight) {
WindowSize := GetSettingsWindowPhysicalSize(LogicalWidth, LogicalHeight)
ShowOptions := "w" LogicalWidth " h" LogicalHeight
if !WinExist("ahk_id " SelectionHwnd) {
Gui, 2:Show, % ShowOptions, Настройки
return
}
OccupiedRect := GetSelectionOccupiedRect(SelectionHwnd)
SysGet, PrimaryMonitor, MonitorPrimary
SysGet, WorkArea, MonitorWorkArea, %PrimaryMonitor%
Gap := Round(20 * A_ScreenDPI / 96)
MaxX := WorkAreaRight - WindowSize.w
if (MaxX < WorkAreaLeft)
CenteredX := WorkAreaLeft
else
CenteredX := Max(WorkAreaLeft
, Min(OccupiedRect.left
+ (OccupiedRect.right - OccupiedRect.left - WindowSize.w)//2, MaxX))
MaxY := WorkAreaBottom - WindowSize.h
if (MaxY < WorkAreaTop) {
X := CenteredX
Y := WorkAreaTop
} else {
BelowY := OccupiedRect.bottom + Gap
AboveY := OccupiedRect.top - Gap - WindowSize.h
RightX := OccupiedRect.right + Gap
LeftX := OccupiedRect.left - Gap - WindowSize.w
SideY := Max(WorkAreaTop
, Min(OccupiedRect.top
+ (OccupiedRect.bottom - OccupiedRect.top - WindowSize.h)//2, MaxY))
if (BelowY >= WorkAreaTop && BelowY <= MaxY) {
X := CenteredX
Y := BelowY
} else if (AboveY >= WorkAreaTop && AboveY <= MaxY) {
X := CenteredX
Y := AboveY
} else if (RightX >= WorkAreaLeft && RightX <= MaxX) {
X := RightX
Y := SideY
} else if (LeftX >= WorkAreaLeft && LeftX <= MaxX) {
X := LeftX
Y := SideY
} else {
X := CenteredX
Y := Max(WorkAreaTop, Min(BelowY, MaxY))
}
}
Gui, 2:Show, % "x" X " y" Y " " ShowOptions, Настройки
}
GetSelectionOccupiedRect(SelectionHwnd) {
WinGetPos, SelectionX, SelectionY, SelectionWidth, SelectionHeight
, % "ahk_id " SelectionHwnd
Rect := {left: SelectionX, top: SelectionY
, right: SelectionX + SelectionWidth, bottom: SelectionY + SelectionHeight}
Coordinates := App.Selection.Coordinates
if !IsObject(Coordinates)
return Rect
for index, CoordinateHwnd in [Coordinates.TopWindowHwnd, Coordinates.BottomWindowHwnd] {
if !CoordinateHwnd || !DllCall("IsWindowVisible", "Ptr", CoordinateHwnd)
continue
WinGetPos, CoordinateX, CoordinateY, CoordinateWidth, CoordinateHeight
, % "ahk_id " CoordinateHwnd
if (CoordinateWidth = "" || CoordinateHeight = "")
continue
Rect.left := Min(Rect.left, CoordinateX)
Rect.top := Min(Rect.top, CoordinateY)
Rect.right := Max(Rect.right, CoordinateX + CoordinateWidth)
Rect.bottom := Max(Rect.bottom, CoordinateY + CoordinateHeight)
}
return Rect
}
GetSettingsWindowPhysicalSize(LogicalWidth, LogicalHeight) {
WindowSize := App.Settings.WindowSize
if IsObject(WindowSize) && WindowSize.DPI = A_ScreenDPI
return WindowSize
DetectHiddenWindowsWasOn := A_DetectHiddenWindows
Gui, 2:Show, % "w" LogicalWidth " h" LogicalHeight " Hide", Настройки
DetectHiddenWindows, On
WinGetPos,,, PhysicalWidth, PhysicalHeight, % "ahk_id " App.Settings.WindowHwnd
DetectHiddenWindows, %DetectHiddenWindowsWasOn%
App.Settings.WindowSize := {w: PhysicalWidth, h: PhysicalHeight, DPI: A_ScreenDPI}
return App.Settings.WindowSize
}
2GuiEscape() {
CancelSettingsFromGui()
}
2GuiClose() {
CancelSettingsFromGui()
}
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Конец окна Настроек ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ScreenShotMenu() {
ScreenShotMenuHandling()
}
SetInterpolationMode() {
SetInterpolationModeFromMenu(A_ThisMenuItemPos)
}
ReloadScript() {
SelectionHwnd := App.Selection.Hwnd
if WinExist("ahk_id " SelectionHwnd) {
Reload
return
}
Run, % """" A_AhkPath """ /restart """ A_ScriptFullPath """ HideSelection", % A_ScriptDir
ExitApp
}
EditScript() {
Edit
}
ShowHelp() {
global HelpBrowserObject ; ActiveX associated var must be global; parked into App.Help.WB
HideSettingsWindow()
if !IsObject(App.Help)
App.Help := {}
if !App.Help.HasKey("Theme")
App.Help.Theme := GetHelpTheme()
if WindowExistsByHwnd(App.Help.WindowHwnd) {
RenderHelpDocument()
; Reveal with WinShow, not Gui, Show: a bare Gui, Show would revert the
; window to AHK's remembered default geometry and discard the user's
; current position and size.
WinShow, % "ahk_id " App.Help.WindowHwnd
WinActivate, % "ahk_id " App.Help.WindowHwnd
FitHelpBrowser()
return
}
Width := 560, Height := 520 ; logical units for Gui Show; control is fitted in physical px afterwards
Gui, 6:New, +Resize +hwndHelpHwnd, Справка
Gui, 6:Color, % HelpThemeBackColor(App.Help.Theme)
Gui, 6:Margin, 0, 0
App.Help.WindowHwnd := HelpHwnd
; Persist the help window geometry across runs. Kept in App.Help so the
; instance (and its move/size OnMessage hooks) live as long as the window.
; The saved geometry is applied at show time via DoRestore() below.
App.Help.CoordSaver := new SaveGuiCoordsLogical(HelpHwnd, IniFilePath(), "HelpWindow", false)
Gui, 6:Add, ActiveX, % "x0 y0 w" Width " h" Height " vHelpBrowserObject hwndHelpWBHwnd", Shell.Explorer
App.Help.WB := HelpBrowserObject
App.Help.WBHwnd := HelpWBHwnd
App.Help.WB.Silent := true
ComObjConnect(App.Help.WB, "HelpWB_")
; Navigate to a tiny bootstrap document that already carries <!DOCTYPE html>
; and X-UA-Compatible, so MSHTML enters IE standards mode. Content is then
; written into that document and keeps the mode — unlike about:blank, whose
; missing DOCTYPE forces quirks mode where border-radius is ignored.
App.Help.WB.Navigate(HelpBootstrapDocument(App.Help.Theme))
HelpWaitDocumentReady()
RenderHelpDocument()
; Realize the window hidden at the default size (this lays out the control
; without ever showing the default frame), restore the saved full-window
; geometry with WinMove while still hidden, then reveal it with WinShow.
; WinMove sets the whole-window rect (matching WinGetPos used on save);
; Gui, Show's w/h would size only the CLIENT area, and a bare Gui, Show would
; re-apply AHK's remembered default geometry and undo WinMove. WinShow just
; shows the window as-is, so the first visible frame is already correct — no
; flicker.
Gui, 6:Show, % "w" Width " h" Height " Hide", Справка
App.Help.CoordSaver.DoRestore()
WinShow, % "ahk_id " HelpHwnd
WinActivate, % "ahk_id " HelpHwnd
FitHelpBrowser()
return
}
; Bootstrap document with a DOCTYPE so the control starts in IE standards mode.
; Passed straight to Navigate; the themed background avoids a flash before the
; real content is written.
HelpBootstrapDocument(Theme) {
Bg := (Theme = "dark") ? "#0D1117" : "#FFFFFF"
return "about:<!DOCTYPE html><html><head>"
. "<meta http-equiv=""X-UA-Compatible"" content=""IE=edge"">"
. "<style>html,body{height:100%;margin:0;background:" Bg ";overflow:hidden;}</style>"
. "</head><body></body></html>"
}
HelpThemeBackColor(Theme) {
return (Theme = "dark") ? "0D1117" : "FFFFFF"
}
HelpWaitDocumentReady() {
WB := App.Help.WB
if !IsObject(WB)
return false
EndTime := A_TickCount + 3000
Loop {
try {
if (WB.ReadyState = 4 && WB.document.readyState = "complete")
return true
}
if (A_TickCount > EndTime)
return false
Sleep, 10
}
}
; Rewrites the document in place. Only used on first show, reshow and hotkey
; refresh — never on theme toggle (that path swaps stylesheets in JS instead).
; The base document has a DOCTYPE, so the rewritten content stays in standards
; mode. document.write is synchronous, so no readiness wait is needed here.
RenderHelpDocument() {
WB := App.Help.WB
if !IsObject(WB)
return
try {
doc := WB.document
doc.open()
doc.write(BuildHelpHtml(App.Help.Theme))
doc.close()
}
FitHelpBrowser()
}
; Fills the ActiveX control to the client area in physical pixels. GetClientRect
; and MoveWindow share the same pixel space, so this stays correct under any DPI.
FitHelpBrowser() {
if !IsObject(App.Help) || !App.Help.WBHwnd
return
if !WindowExistsByHwnd(App.Help.WindowHwnd)
return
VarSetCapacity(Rect, 16, 0)
DllCall("GetClientRect", "Ptr", App.Help.WindowHwnd, "Ptr", &Rect)
W := NumGet(Rect, 8, "Int")
H := NumGet(Rect, 12, "Int")
if (W <= 0 || H <= 0)
return
DllCall("MoveWindow", "Ptr", App.Help.WBHwnd, "Int", 0, "Int", 0, "Int", W, "Int", H, "Int", true)
}
GetHelpTheme() {
IniRead, Theme, % IniFilePath(), Help, Theme, dark
return (Theme = "light") ? "light" : "dark"
}
; Called on the ahk:theme= round-trip. The page has already switched its own
; look in JavaScript, so here we only persist the choice and repaint the host.
SetHelpTheme(Theme) {
Theme := (Theme = "light") ? "light" : "dark"
App.Help.Theme := Theme
IniWrite, % Theme, % IniFilePath(), Help, Theme
if WindowExistsByHwnd(App.Help.WindowHwnd) {
Gui, 6:Color, % HelpThemeBackColor(Theme)
RelayoutHelpBrowser()
}
}
; Forces MSHTML to rebuild its render tree after a stylesheet swap by resizing
; the control 1px and back in one tick (no message pump between, so no flicker).
RelayoutHelpBrowser() {
if !IsObject(App.Help) || !App.Help.WBHwnd
return
if !WindowExistsByHwnd(App.Help.WindowHwnd)
return
VarSetCapacity(Rect, 16, 0)
DllCall("GetClientRect", "Ptr", App.Help.WindowHwnd, "Ptr", &Rect)
W := NumGet(Rect, 8, "Int")
H := NumGet(Rect, 12, "Int")
if (W <= 0 || H <= 1)
return
DllCall("MoveWindow", "Ptr", App.Help.WBHwnd, "Int", 0, "Int", 0, "Int", W, "Int", H - 1, "Int", true)
DllCall("MoveWindow", "Ptr", App.Help.WBHwnd, "Int", 0, "Int", 0, "Int", W, "Int", H, "Int", true)
}
HelpBrowserExecWB(Command) {
if IsObject(App.Help) && IsObject(App.Help.WB)
try App.Help.WB.ExecWB(Command, 0, 0, 0)
}
IsHelpWindowActive() {
return IsObject(App.Help) && WinActive("ahk_id " App.Help.WindowHwnd)
}
; COM event sink for the help WebBrowser (connected with prefix "HelpWB_").
; Internal "#" anchors use scrollIntoView instead of navigation, so only
; external links and theme switching need interception here.
HelpWB_BeforeNavigate2(pDisp, ByRef URL, ByRef Flags, ByRef TargetFrame, ByRef PostData, ByRef Headers, ByRef Cancel) {
if RegExMatch(URL, "i)^https?://") {
Cancel := true
Run, % URL,, UseErrorLevel
} else if RegExMatch(URL, "i)^ahk:theme=(dark|light)", Match) {
Cancel := true
App.Help.PendingTheme := Match1
SetTimer, ApplyHelpTheme, -1 ; defer to avoid re-entering the WebBrowser from its own event
}
}
ApplyHelpTheme() {
SetHelpTheme(App.Help.PendingTheme)
}
6GuiClose() {
HideHelpWindow()
}
6GuiSize() {
FitHelpBrowser()
}
HideHelpWindow() {
if !IsObject(App.Help)
return
if WindowExistsByHwnd(App.Help.WindowHwnd)
Gui, 6:Hide
}
HideSettingsWindow() {
if WindowExistsByHwnd(App.Settings.HotkeysHwnd)
Gui, 4:Hide
if WindowExistsByHwnd(App.Settings.WindowHwnd) {
Gui, 2:Hide
ResumeScriptHotkeysAfterSettings()
}
}
BuildHelpHtml(Theme) {
Dpi := A_ScreenDPI / 96
LightCss := ScaleCssPx(BuildHelpCss("light"), Dpi)
DarkCss := ScaleCssPx(BuildHelpCss("dark"), Dpi)
IsDark := (Theme = "dark")
InitDark := IsDark ? "true" : "false"
Icon := IsDark ? Chr(0x2600) : Chr(0x263E) ; sun / crescent moon
HotkeysRows := BuildHelpHotkeysRows()
; Legacy continuation section: literal HTML (no ""-doubling); variables are
; inserted via %name% (no % option, so %var% dereferences). Both themes are
; embedded as stylesheets; the JS toggle flips their disabled flags.
Html =
(
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="utf-8">
<style id="help-style-light">
%LightCss%
</style>
<style id="help-style-dark">
%DarkCss%
</style>
</head>
<body>
<div id="help-theme-btn" class="theme-btn" title="Сменить тему" onclick="return toggleHelpTheme();">%Icon%</div>
<div class="wrap">
<h1 id="top">ScreenCatcher</h1>
<p>ScreenCatcher делает снимки экрана, активного окна и произвольной области. Снимок можно сохранить в файл,
скопировать в буфер обмена, открыть в предпросмотре или загрузить на Imgbb.com и получить ссылку.</p>
<div class="toc">
<div class="toc-title">Содержание</div>
<ul>
<li><a href="#" onclick="return scrollToId('capture');">Способы получения скриншота</a></li>
<li><a href="#" onclick="return scrollToId('selwin');">Окно выделения</a></li>
<li><a href="#" onclick="return scrollToId('overlay');">Выделение мышью</a></li>
<li><a href="#" onclick="return scrollToId('preview');">Предпросмотр</a></li>
<li><a href="#" onclick="return scrollToId('draw');">Рисование на превью</a></li>
<li><a href="#" onclick="return scrollToId('output');">Сохранение</a></li>
<li><a href="#" onclick="return scrollToId('hotkeys');">Горячие клавиши</a></li>
<li><a href="#" onclick="return scrollToId('settings');">Настройки</a></li>
</ul>
</div>
<h2 id="capture">Способы получения скриншота</h2>
<ul>
<li>Область под окном выделения — горячей клавишей съёмки области или двойным кликом по самому окну
выделения. При съёмке горячей клавишей окно выделения может быть скрыто: снимается область по его
текущему (последнему) положению.</li>
<li>Активное окно — соответствующей горячей клавишей.</li>
<li>Весь экран — соответствующей горячей клавишей.</li>
<li>Произвольная область мышью — см. раздел «Выделение мышью».</li>
</ul>
<h2 id="selwin">Окно выделения</h2>
<p>Полупрозрачное цветное окно. Разместите его над нужным участком экрана, перемещая и меняя размер, — снимок
захватит то, что оказалось под окном.</p>
<ul>
<li>Показать или скрыть — горячей клавишей или кликом по значку в трее.</li>
<li>В центр экрана — соответствующей горячей клавишей.</li>
<li>Переместить — перетащить окно мышью.</li>
<li>Изменить размер — тянуть за края и углы (вид маркеров или курсоров задаётся в настройках).</li>
</ul>
<p>Точное позиционирование границ, по одному пикселю:</p>
<table class="pos">
<tr>
<th>Граница</th>
<th>Колесо мыши</th>
<th>Клавиши</th>
</tr>
<tr>
<td>Левая</td>
<td>Ctrl + колесо</td>
<td>Ctrl + ← / →</td>
</tr>
<tr>
<td>Верхняя</td>
<td>Shift + колесо</td>
<td>Shift + ↑ / ↓</td>
</tr>
<tr>
<td>Правая</td>
<td>Alt + колесо</td>
<td>Alt + ← / →</td>
</tr>
<tr>
<td>Нижняя</td>
<td>Win + колесо</td>
<td>Win + ↑ / ↓</td>
</tr>
</table>
<p>Клавиши точного позиционирования работают, только когда окно выделения активно (в фокусе).</p>
<p>Рядом с окном показываются плашки с координатами и размером.</p>
<p>Правый клик по окну выделения открывает контекстное меню: открыть «Вывод» и «Настройки», быстро включить или выключить показ координат, захват курсора и скрытие окна после снимка, сделать снимок, скрыть окно выделения, открыть папку вывода и справку.</p>
<h2 id="overlay">Выделение мышью</h2>
<p>Снимок произвольной области прямо поверх экрана.</p>
<ul>
<li>Обычный режим: включите его горячей клавишей — появится перекрестие; зажмите левую кнопку мыши и
протяните прямоугольник, затем отпустите — область будет снята.</li>
<li>Быстрый режим: зажмите горячую клавишу быстрого выделения (по умолчанию левые Ctrl + Alt + левая кнопка
мыши) и сразу тяните прямоугольник; отпустите кнопку — снимок готов.</li>
<li>Отмена: Esc или правая кнопка мыши.</li>
</ul>
<h2 id="preview">Предпросмотр</h2>
<p>Окно со снимком, которое появляется после съёмки (если включено в настройках).</p>
<ul>
<li>Переместить — перетащить мышью.</li>
<li>Изменить размер — колесо мыши над превью (пропорционально, шаг около 10`%); с зажатым Ctrl — по одному
пикселю.</li>
<li>Контекстное меню (правая кнопка): сохранить в исходном или текущем размере, выбрать назначение (файл,
буфер обмена, Imgbb), режим интерполяции, рисование на превью (см. следующий раздел), удалить.</li>
<li>Если открыто несколько превью — горячая клавиша «Выделить превью» подсвечивает их по очереди, чтобы
найти нужное.</li>
</ul>
<h2 id="draw">Рисование на превью</h2>
<p>На превью можно рисовать свободные линии, прямые линии, стрелки, прямоугольники и эллипсы, а также
выделять маркером. Нарисованное сохраняется вместе со снимком — и в исходном, и в текущем размере, в любое
назначение.</p>
<ul>
<li>Включить режим рисования — пункт «Рисовать» в контекстном меню превью или клавиша D. Выбор инструмента,
цвета или толщины тоже включает режим. Над превью в этом режиме курсор становится крестиком.</li>
<li>Клавиши при активном превью: D — включить или выключить режим; 1–6 — инструмент (свободная линия,
линия, стрелка, прямоугольник, эллипс, маркер); [ и ] — толщина меньше или больше. При нажатии
рядом с курсором ненадолго появляется подсказка.</li>
<li>Рисовать — зажать левую кнопку мыши и протянуть. Пока режим включён, превью не перетаскивается мышью.</li>
<li>Shift во время протяжки: линия и стрелка ложатся по горизонтали, вертикали или под 45°, прямоугольник
становится квадратом, эллипс — кругом, маркер — горизонтальной полосой.</li>
<li>Цвет и толщина: у маркера свои, у остальных инструментов общие. Выбранные инструмент, цвета и толщины
запоминаются между запусками.</li>
<li>Отменить — Ctrl+Z, повторить — Ctrl+Y или Ctrl+Shift+Z. Стереть всё нарисованное — пункт «Стереть всё»
в контекстном меню; это действие тоже можно отменить.</li>
<li>Колесо мыши по-прежнему меняет размер превью; нарисованное масштабируется вместе со снимком.</li>
<li>Esc во время протяжки отменяет фигуру, иначе выключает режим рисования; следующий Esc закрывает
превью. Сохранение и удаление превью выключают режим автоматически.</li>
</ul>
<h2 id="output">Сохранение</h2>
<p>Снимок можно направить в файл, буфер обмена и на Imgbb — можно в несколько мест сразу. Формат файла, качество
JPEG и папку вывода задают в настройках; открыть папку вывода можно отдельной горячей клавишей.</p>
<h2 id="hotkeys">Горячие клавиши</h2>
<table class="hk">%HotkeysRows%</table>
<p>Если клавиша не назначена, действие доступно из меню трея. Изменить назначения можно в настройках.</p>
<h2 id="settings">Настройки</h2>
<p>Окно настроек открывается из контекстного меню окна выделения или из меню трея (пункты «Вывод» и
«Настройки») и состоит из четырёх вкладок.</p>
<ul>
<li><b>Цвет</b> — цвет и прозрачность окна выделения (ползунки R, G, B и прозрачности).</li>
<li><b>Вывод</b> — куда направлять снимок (файл, буфер обмена, Imgbb — можно несколько сразу), тип файла
(png, jpg, bmp, tif, gif), качество JPEG и папка для сохранения.</li>
<li><b>Настройки</b> — показывать координаты, включать курсор в скриншот, уведомлять о сохранении,
показывать предпросмотр перед сохранением, запускать программу вместе с Windows, а также вид индикаторов
при изменении размера окна выделения (изменённые курсоры или цветные маркеры).</li>
<li><b>Горячие клавиши</b> — назначение сочетаний по группам «Скриншоты», «Окна скрипта», «Служебные».</li>
</ul>
<p>Пункты «Показывать координаты», «Включать курсор в скриншот» и «Скрывать это окно после взятия скриншота»
можно быстро переключать прямо из контекстного меню окна выделения. Пункт «Скрывать это окно после
взятия скриншота» доступен только в этом меню: если он включён, окно выделения прячется сразу после
съёмки области.</p>
<p>Настройки хранятся в файле ScreenCatcher.ini рядом со скриптом. Если рядом со скриптом есть файл с именем
компьютера в начале (для этого компьютера — %A_ComputerName%_ScreenCatcher.ini), используется он. Так одна
папка со скриптом, синхронизируемая между несколькими компьютерами, хранит для каждого свои настройки:
достаточно скопировать или переименовать ScreenCatcher.ini.</p>
</div>
<script type="text/javascript">
function scrollToId(id) { var e = document.getElementById(id); if (e) { e.scrollIntoView(true); } return false; }
function helpStyle(id) { return document.getElementById(id); }
function applyHelpTheme(dark) { window.helpDark = dark; var l = helpStyle('help-style-light'), d = helpStyle('help-style-dark'); if (l) { l.disabled = dark; } if (d) { d.disabled = !dark; } var b = helpStyle('help-theme-btn'); if (b) { b.innerHTML = dark ? '☀' : '☾'; } }
function toggleHelpTheme() { var dark = !window.helpDark; applyHelpTheme(dark); window.setTimeout(function () { window.location.href = dark ? 'ahk:theme=dark' : 'ahk:theme=light'; }, 0); return false; }
applyHelpTheme(%InitDark%);
</script>
</body>
</html>
)
return Html
}
BuildHelpCss(Theme) {
if (Theme = "dark") {
Bg := "#0D1117", Fg := "#C9D1D9", Head := "#E6EDF3", Link := "#58A6FF"
Border := "#30363D", Panel := "#161B22"
BtnBg := "#30363D", BtnBorder := "#555555"
SbFace := "#30363D", SbTrack := "#0D1117", SbArrow := "#8B949E"
} else {
Bg := "#FFFFFF", Fg := "#24292F", Head := "#1F2328", Link := "#0969DA"
Border := "#D0D7DE", Panel := "#F6F8FA"
BtnBg := "#E1E4E8", BtnBorder := "#CCCCCC"
SbFace := "#D0D7DE", SbTrack := "#FFFFFF", SbArrow := "#57606A"
}
Css := "
( LTrim Join`r`n %
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; }
body {
font-family: Segoe UI, Tahoma, sans-serif;
font-size: 15px;
line-height: 1.5;
background: __BG__;
color: __FG__;
overflow-y: auto;
overflow-x: hidden;
scrollbar-face-color: __SBFACE__;
scrollbar-track-color: __SBTRACK__;
scrollbar-arrow-color: __SBARROW__;
scrollbar-shadow-color: __SBTRACK__;
scrollbar-highlight-color: __SBFACE__;
scrollbar-3dlight-color: __SBFACE__;
scrollbar-darkshadow-color: __SBTRACK__;
}
.wrap { padding: 20px 26px 28px 26px; }
h1 { font-size: 24px; font-weight: 600; color: __HEAD__; margin-bottom: 10px; padding-right: 130px; }
h2 { font-size: 18px; font-weight: 600; color: __HEAD__; margin-top: 22px; margin-bottom: 10px; padding-bottom: 5px; border-bottom: 1px solid __BORDER__; }
p { margin-bottom: 10px; }
ul { margin: 0 0 10px 22px; }
li { margin-bottom: 4px; }
a { color: __LINK__; text-decoration: none; cursor: pointer; }
a:hover { text-decoration: underline; }
.toc { background: __PANEL__; border: 1px solid __BORDER__; border-radius: 6px; padding: 12px 16px; margin-top: 14px; }
.toc-title { font-weight: 600; color: __HEAD__; margin-bottom: 6px; }
.toc ul { margin: 0 0 0 20px; }
.toc li { margin-bottom: 3px; }
table.hk { border-collapse: collapse; width: 100%; margin-bottom: 6px; }
table.hk td { border: 1px solid __BORDER__; padding: 6px 10px; vertical-align: top; }
td.hk-label { width: 70%; }
td.hk-key { font-family: Consolas, monospace; color: __HEAD__; white-space: nowrap; }
table.pos { border-collapse: collapse; width: 100%; margin-bottom: 6px; }
table.pos th, table.pos td { border: 1px solid __BORDER__; padding: 6px 10px; text-align: left; vertical-align: top; }
table.pos th { background: __PANEL__; font-weight: 600; color: __HEAD__; }
.theme-btn { position: fixed; top: 14px; right: 14px; width: 30px; height: 30px; border-radius: 100px; background: __BTNBG__; color: __FG__; border: 1px solid __BTNBORDER__; font-size: 18px; line-height: 28px; text-align: center; cursor: pointer; opacity: 0.86; }
.theme-btn:hover { opacity: 1; border-color: __LINK__; }
)"
Css := StrReplace(Css, "__BG__", Bg)
Css := StrReplace(Css, "__FG__", Fg)
Css := StrReplace(Css, "__HEAD__", Head)
Css := StrReplace(Css, "__LINK__", Link)
Css := StrReplace(Css, "__BORDER__", Border)
Css := StrReplace(Css, "__PANEL__", Panel)
Css := StrReplace(Css, "__BTNBG__", BtnBg)
Css := StrReplace(Css, "__BTNBORDER__", BtnBorder)
Css := StrReplace(Css, "__SBFACE__", SbFace)
Css := StrReplace(Css, "__SBTRACK__", SbTrack)
Css := StrReplace(Css, "__SBARROW__", SbArrow)
return Css
}
BuildHelpHotkeysRows() {
Labels := ScreenCatcherHotkeyLabels()
Rows := ""
for k, HotkeyName in ScreenCatcherHotkeyNames() {
Key := HelpHotkeyText(App.Hotkeys[HotkeyName])
Rows .= "<tr><td class=""hk-label"">" HtmlEscape(Labels[HotkeyName]) "</td>"
. "<td class=""hk-key"">" HtmlEscape(Key) "</td></tr>"
}
return Rows
}
; Scales every "<number>px" in a CSS string by Ratio (A_ScreenDPI / 96). MSHTML
; in an embedded WebBrowser renders CSS px at 96 dpi, so fixed sizes must be
; pre-scaled to match the DPI-scaled host window.
ScaleCssPx(Css, Ratio) {
Out := "", Pos := 1
while (Found := RegExMatch(Css, "(-?\d+(?:\.\d+)?)px\b", M, Pos)) {
Out .= SubStr(Css, Pos, Found - Pos) . Round(M1 * Ratio) . "px"
Pos := Found + StrLen(M)
}
return Out . SubStr(Css, Pos)
}
HtmlEscape(Text) {
Text := StrReplace(Text, "&", "&")
Text := StrReplace(Text, "<", "<")
Text := StrReplace(Text, ">", ">")
Text := StrReplace(Text, """", """)
return Text
}
HelpHotkeyText(HotkeyValue) {
Text := Hotkey_HKToStr(HotkeyValue)
return (Text = "Нет" || !IsHotkeyEnabled(HotkeyValue)) ? "не назначена" : Text
}
WindowExistsByHwnd(Hwnd) {
if !Hwnd
return false
DetectHiddenWindowsWasOn := A_DetectHiddenWindows
DetectHiddenWindows, On
Exists := WinExist("ahk_id " Hwnd)
DetectHiddenWindows, %DetectHiddenWindowsWasOn%
return Exists
}
ShowSettingsFromMenu(ItemName := "", ItemPos := "", MenuName := "") {
OpenSettingsWindow(SettingsTabFromMenu(MenuName, ItemPos))
}
SettingsTabFromMenu(MenuName, ItemPos) {
if (MenuName = "Tray")
return ItemPos - 1
return ItemPos + 1
}
StoreSelectionWindowHwnd() {
WinGet, SelectionHwnd
App.Selection.Hwnd := SelectionHwnd
}
ShutdownApplication() {
SelectionHwnd := App.Selection.Hwnd
Loop {
if (MaxIndex := App.Windows.MaxIndex()) {
Gui, %MaxIndex%:Destroy
App.Windows.Remove(MaxIndex, "")
Sleep, 50
}
} until !MaxIndex
if WinExist("ahk_id " SelectionHwnd)
Melt(SelectionHwnd, App.Config.ARGB>>24, 0)
if IsObject(App.Selection.Overlay)
App.Selection.Overlay.Dispose()
RestoreCursors()
GdipShutdown(App.GdipToken)
SaveSettings()
ExitApp
}
MenuHotkeyCaption(Text, HotkeyValue) {
hk := Hotkey_HKToStr(HotkeyValue)
return Text . (hk = "Нет" ? "" : A_Tab . hk)
}
UpdateMenuHotkeyCaptions() {
SelectionHwnd := App.Selection.Hwnd
NewTrayMenuHide := MenuHotkeyCaption("Скрыть окно выделения", App.Hotkeys.ShowHideSelWindow)
NewTrayMenuShow := MenuHotkeyCaption("Показать окно выделения", App.Hotkeys.ShowHideSelWindow)
NewTrayMenuCenter := MenuHotkeyCaption("Главное окно в центр экрана", App.Hotkeys.SelWindowToCenter)
NewTrayMenuOpenOutDir := MenuHotkeyCaption("Открыть папку вывода", App.Hotkeys.OpenOutputFolder)
NewMainMenuArea := MenuHotkeyCaption("Сделать скриншот", App.Hotkeys.GetArea)
NewMainMenuHide := MenuHotkeyCaption("Скрыть окно выделения", App.Hotkeys.ShowHideSelWindow)
NewMainMenuOpenOutDir := MenuHotkeyCaption("Открыть папку вывода", App.Hotkeys.OpenOutputFolder)
if WinExist("ahk_id " SelectionHwnd)
Menu, Tray, Rename, % App.Menu.TrayHide, % NewTrayMenuHide
else
Menu, Tray, Rename, % App.Menu.TrayShow, % NewTrayMenuShow
Menu, Tray, Rename, % App.Menu.TrayCenter, % NewTrayMenuCenter
Menu, Tray, Rename, % App.Menu.TrayOpenOutDir, % NewTrayMenuOpenOutDir
Menu, MainMenu, Rename, % App.Menu.MainArea, % NewMainMenuArea
Menu, MainMenu, Rename, % App.Menu.MainHide, % NewMainMenuHide
Menu, MainMenu, Rename, % App.Menu.MainOpenOutDir, % NewMainMenuOpenOutDir
App.Menu.TrayHide := NewTrayMenuHide
App.Menu.TrayShow := NewTrayMenuShow
App.Menu.TrayCenter := NewTrayMenuCenter
App.Menu.TrayOpenOutDir := NewTrayMenuOpenOutDir
App.Menu.MainArea := NewMainMenuArea
App.Menu.MainHide := NewMainMenuHide
App.Menu.MainOpenOutDir := NewMainMenuOpenOutDir
}
SaveSettings() {
S_FormatInteger := A_FormatInteger
SetFormat, IntegerFast, H
; секция ключ значение
IniWriteSect("Color-Transparent", "ARGB" , App.Config.ARGB)
SetFormat, IntegerFast, D
IniWriteSect("Output_Settings" , "Output" , App.Config.Output
, "Extension" , App.Config.Ext
, "JPEG_Quality" , App.Config.JPEGQuality
, "Out_Directory" , App.Config.OutDirectory)
IniWriteSect("Program_Settings" , "Capture_Cursor" , App.Config.CaptureCursor
, "Hide_After_Capture" , App.Config.HideAfterCapture
, "Show_Coordinates" , App.Config.ShowCoordinates
, "Show_Preview" , App.Config.ShowPreview
, "Notify" , App.Config.Notify
, "Resize_Pointers" , App.Config.ResizePointers
, "InterpolationMode" , App.Config.InterpolationMode)
; Preview drawing: current tool, pen and marker colours/widths (read by InitPreviewDrawing)
IniWriteSect("Drawing" , "Tool" , App.Drawing.Tool
, "PenColor" , Format("0x{:08X}", App.Drawing.Color)
, "PenWidth" , App.Drawing.Width
, "MarkerColor" , Format("0x{:08X}", App.Drawing.MarkerColor)
, "MarkerWidth" , App.Drawing.MarkerWidth)
IniWriteSect("Hotkeys" , "GetArea" , App.Hotkeys.GetArea
, "GetActiveWindow" , App.Hotkeys.GetActiveWindow
, "GetScreen" , App.Hotkeys.GetScreen
, "ShowHideSelWindow" , App.Hotkeys.ShowHideSelWindow
, "SelWindowToCenter" , App.Hotkeys.SelWindowToCenter
, "SelectPreview" , App.Hotkeys.SelectPreview
, "OpenOutputFolder" , App.Hotkeys.OpenOutputFolder
, "SelectAreaOverlay" , App.Hotkeys.SelectAreaOverlay
, "QuickSelectAreaOverlay", App.Hotkeys.QuickSelectAreaOverlay)
SetFormat, IntegerFast, %S_FormatInteger%
}
SettingsStateVars() {
return "ARGB|Output|ext|JPEGQuality|OutDirectory|CaptureCursor|ShowCoordinates|ShowPreview|Notify|"
. "RunOnWinStart|ResizePointers|GetArea|GetActiveWindow|GetScreen|"
. "ShowHideSelWindow|SelWindowToCenter|SelectPreview|OpenOutputFolder|"
. "SelectAreaOverlay|QuickSelectAreaOverlay"
}
SavePreviousSettingsState(StateVars := "") {
if (StateVars = "")
StateVars := SettingsStateVars()
App.Settings.Previous := {}
Loop, parse, StateVars, |
App.Settings.Previous[A_LoopField] := SettingsStateValue(A_LoopField)
}
RestorePreviousSettingsState(StateVars := "") {
SelectionHwnd := App.Selection.Hwnd
Previous := App.Settings.Previous
if !IsObject(Previous)
return
if (App.Config.ARGB != Previous.ARGB)
ColorChange := App.Config.ARGB
if WinExist("ahk_id " SelectionHwnd)
SetResizePointerTimer("Off")
if (StateVars = "")
StateVars := SettingsStateVars()
Loop, parse, StateVars, |
SetSettingsStateValue(A_LoopField, Previous[A_LoopField])
App.Config.ResizePointers := NormalizeResizePointersValue(App.Config.ResizePointers)
SyncSettingsColorFromARGB()
SetHotkeyControlsFromVars()
if WinExist("ahk_id " SelectionHwnd)
SetResizePointerTimer(50)
if ColorChange {
if WinExist("ahk_id " SelectionHwnd)
Melt(SelectionHwnd, ColorChange>>24, 0), PrevExist := 1
Gui, 1:Color, % Format("{:X}", App.Config.ARGB & 0xFFFFFF)
UpdateMarkerColor()
if PrevExist
PrevExist := "", Melt(SelectionHwnd, App.Config.ARGB>>24, 1)
ColorChange := ""
}
}
SyncSettingsColorFromARGB() {
if !IsObject(App.Settings.Color)
App.Settings.Color := {}
App.Settings.Color.Red := (App.Config.ARGB & 0xFF0000)>>16
App.Settings.Color.Green := (App.Config.ARGB & 0xFF00)>>8
App.Settings.Color.Blue := App.Config.ARGB & 0xFF
App.Settings.Color.Trans := App.Config.ARGB>>24
}
SettingsStateValue(Name) {
for index, HotkeyName in ScreenCatcherHotkeyNames()
if (Name = HotkeyName)
return App.Hotkeys[HotkeyName]
for index, ConfigName in SettingsConfigNames()
if (Name = ConfigName)
return App.Config[ConfigName]
if (Name = "ResizePointers")
return NormalizeResizePointersValue(App.Config.ResizePointers)
if (Name = "InterpolationMode")
return App.Config.InterpolationMode
return ""
}
SetSettingsStateValue(Name, Value) {
for index, HotkeyName in ScreenCatcherHotkeyNames() {
if (Name = HotkeyName) {
App.Hotkeys[HotkeyName] := Value
return
}
}
for index, ConfigName in SettingsConfigNames() {
if (Name = ConfigName) {
App.Config[ConfigName] := Value
return
}
}
if (Name = "ResizePointers")
App.Config.ResizePointers := NormalizeResizePointersValue(Value)
else if (Name = "InterpolationMode")
App.Config.InterpolationMode := Value
}
SettingsConfigNames() {
return [ "ARGB", "Output", "ext", "JPEGQuality", "OutDirectory"
, "CaptureCursor", "ShowCoordinates", "ShowPreview", "Notify", "RunOnWinStart" ]
}
CloseSettingsWindow() {
if IsObject(App.Settings.MessageHandlers) {
OnMessage( 0x111, App.Settings.MessageHandlers.WM_COMMAND, 0 )
OnMessage( 0x20, App.Settings.MessageHandlers.WM_SETCURSOR, 0 )
App.Settings.MessageHandlers := ""
}
Gui, 2:Destroy
ResumeScriptHotkeysAfterSettings()
}
SuspendScriptHotkeysForSettings() {
if App.Settings.ScriptHotkeysSuspended
return
SetScriptHotkeys(0)
App.Settings.ScriptHotkeysSuspended := true
}
ResumeScriptHotkeysAfterSettings() {
if !App.Settings.ScriptHotkeysSuspended
return
App.Settings.ScriptHotkeysSuspended := false
SetScriptHotkeys(1)
}
ApplySettingsFromGui(CtrlHwnd := "", GuiEvent := "", EventInfo := "", EventErrorLevel := "") {
if !ApplyHotkeySettings()
return false
ApplyProgramSettings()
CheckImgbbClientIdOnApply()
SaveSettings()
SavePreviousSettingsState()
return true
}
CheckImgbbClientIdOnApply() {
if !InStr(App.Config.Output, "Imgbb")
return
EnsureImgbbClientId()
}
EnsureImgbbClientId() {
IniPath := IniFilePath()
MissingValue := Chr(1) . "__ScreenCatcherMissing__"
IniRead, ClientID, % IniPath, Imgbb, ClientID, % MissingValue
if (ClientID = MissingValue) {
EmptyValue := ""
IniWrite, % EmptyValue, % IniPath, Imgbb, ClientID
ClientID := ""
}
if (Trim(ClientID) != "")
return ClientID
Message := "Для отправки скриншотов на Imgbb нужен API key.`n`n"
. "Зарегистрируйтесь: https://imgbb.com/`n"
. "Получите ключ: https://api.imgbb.com/`n`n"
. "Впишите ключ в файл " SettingsFileName() ":`n"
. "[Imgbb]`nClientID=..."
SetOwnDialogsForOpenWindows()
MsgBox, 48, Нужен ключ Imgbb, %Message%
Run, % "notepad.exe """ IniPath """"
return ""
}
SetOwnDialogsForOpenWindows() {
if WindowExistsByHwnd(App.Selection.Hwnd)
Gui, 1:+OwnDialogs
if WindowExistsByHwnd(App.Settings.WindowHwnd)
Gui, 2:+OwnDialogs
if WindowExistsByHwnd(App.Settings.HotkeysHwnd)
Gui, 4:+OwnDialogs
if WindowExistsByHwnd(App.Menu.HighlightHwnd) || WinExist("Imgbb.com ahk_class AutoHotkeyGUI")
Gui, 5:+OwnDialogs
if IsObject(App.Help) && WindowExistsByHwnd(App.Help.WindowHwnd)
Gui, 6:+OwnDialogs
if IsObject(App.Selection.Overlay) && IsObject(App.Selection.Overlay.overlay)
&& WindowExistsByHwnd(App.Selection.Overlay.overlay.hwnd)
Gui, SelectionOverlay:+OwnDialogs
for GuiNumber, WindowData in App.Windows {
if IsObject(WindowData) && WindowExistsByHwnd(WindowData.Hwnd)
Gui, %GuiNumber%:+OwnDialogs
}
}
ConfirmSettingsFromGui(CtrlHwnd := "", GuiEvent := "", EventInfo := "", EventErrorLevel := "") {
if !ApplySettingsFromGui()
return false
CloseSettingsWindow()
return true
}
CancelSettingsFromGui(CtrlHwnd := "", GuiEvent := "", EventInfo := "", EventErrorLevel := "") {
RestorePreviousSettingsState()
CloseSettingsWindow()
}
ScreenCatcherHotkeyNames() {
return ["GetArea", "GetActiveWindow", "GetScreen", "ShowHideSelWindow"
, "SelWindowToCenter", "SelectPreview", "OpenOutputFolder"
, "SelectAreaOverlay", "QuickSelectAreaOverlay"]
}
ScreenCatcherHotkeyLabels() {
return { GetArea: "Скриншот под окном выделения"
, GetActiveWindow: "Скриншот активного окна"
, GetScreen: "Скриншот всего экрана"
, ShowHideSelWindow: "Скрыть/показать окно выделения"
, SelWindowToCenter: "Окно выделения в центр экрана"
, SelectPreview: "Выделить превью скриншота"
, OpenOutputFolder: "Открыть папку вывода"
, SelectAreaOverlay: "Начать выделение мышью"
, QuickSelectAreaOverlay: "Быстро выделить область мышью" }
}
ScreenCatcherHotkeyIndex(Name) {
for k, v in ScreenCatcherHotkeyNames() {
if (v = Name)
return k
}
return 0
}
GetScriptHotkeys() {
return { GetArea: App.Hotkeys.GetArea
, GetActiveWindow: App.Hotkeys.GetActiveWindow
, GetScreen: App.Hotkeys.GetScreen
, ShowHideSelWindow: App.Hotkeys.ShowHideSelWindow
, SelWindowToCenter: App.Hotkeys.SelWindowToCenter
, SelectPreview: App.Hotkeys.SelectPreview
, OpenOutputFolder: App.Hotkeys.OpenOutputFolder
, SelectAreaOverlay: App.Hotkeys.SelectAreaOverlay
, QuickSelectAreaOverlay: App.Hotkeys.QuickSelectAreaOverlay }
}
SetHotkeyControlsFromVars() {
for k, name in ScreenCatcherHotkeyNames()
Hotkey_Set(name, App.Hotkeys[name])
}
ApplyHotkeySettings() {
if (Duplicate := FindDuplicateHotkey()) {
ShowDuplicateHotkey(Duplicate)
return false
}
oldHotkeys := GetScriptHotkeys()
for k, name in ScreenCatcherHotkeyNames()
App.Hotkeys[name] := Hotkey_Value(name)
if !ScriptHotkeysEqual(oldHotkeys, GetScriptHotkeys()) {
SetScriptHotkeys(0, oldHotkeys)
if !App.Settings.ScriptHotkeysSuspended
SetScriptHotkeys(1)
UpdateMenuHotkeyCaptions()
}
return true
}
ScriptHotkeysEqual(a, b) {
for k, v in a
if (v != b[k])
return false
return true
}
IsHotkeyEnabled(HotkeyValue) {
return Trim(HotkeyValue) != ""
}
UpdateHotkeysTabVisibility(CtrlHwnd := "", GuiEvent := "", EventInfo := "", EventErrorLevel := "") {
ControlGet, NTab, Tab,,, % "ahk_id " App.Settings.TabHwnd
if NTab = 4
Gui, 4:Show, NA
else
Gui, 4:Show, Hide
}
UpdateSelectionColorFromGui(CtrlHwnd := "", GuiEvent := "", EventInfo := "", EventErrorLevel := "") {
ReadColorControls()
UpdateSelectionColor()
UpdateColorValueLabels()
UpdateMarkerColor()
}
ReadColorControls() {
GuiControlGet, Red, 2:, % App.Settings.RedSliderHwnd
GuiControlGet, Green, 2:, % App.Settings.GreenSliderHwnd
GuiControlGet, Blue, 2:, % App.Settings.BlueSliderHwnd
GuiControlGet, Trans, 2:, % App.Settings.TransSliderHwnd
App.Settings.Color.Red := Red
App.Settings.Color.Green := Green
App.Settings.Color.Blue := Blue
App.Settings.Color.Trans := Trans
}
UpdateColorValueLabels() {
ColorState := App.Settings.Color
GuiControl, 2:, % App.Settings.RedValueHwnd, % ColorState.Red
GuiControl, 2:, % App.Settings.GreenValueHwnd, % ColorState.Green
GuiControl, 2:, % App.Settings.BlueValueHwnd, % ColorState.Blue
GuiControl, 2:, % App.Settings.TransValueHwnd, % ColorState.Trans
}
UpdateSelectionColor() {
ColorState := App.Settings.Color
ColorValue := (ColorState.Red<<16)|(ColorState.Green<<8)|ColorState.Blue
App.Config.ARGB := (App.Config.ARGB & 0xFF000000)|ColorValue
SetFormat, IntegerFast, H
Gui, 1:Color, % ColorValue
SetFormat, IntegerFast, D
}
UpdateSelectionTransparencyFromGui(CtrlHwnd := "", GuiEvent := "", EventInfo := "", EventErrorLevel := "") {
GuiControlGet, Trans, 2:, % App.Settings.TransSliderHwnd
App.Settings.Color.Trans := Trans
UpdateSelectionTransparency()
UpdateColorValueLabels()
}
UpdateMarkerColor() {
MarkerColor := (App.Config.ARGB & 0xFFFFFF)^0xFFFFFF
for index, MarkerHwnd in App.Selection.MarkerHwnds
SetColorToControl(MarkerHwnd, MarkerColor)
}
UpdateSelectionTransparency() {
SelectionHwnd := App.Selection.Hwnd
Trans := App.Settings.Color.Trans
WinSet, Transparent, % Trans, ahk_id %SelectionHwnd%
App.Config.ARGB := Trans<<24|(App.Config.ARGB & 0xFFFFFF)
}
UpdateOutputTargetFromGui(CtrlHwnd := "", GuiEvent := "", EventInfo := "", EventErrorLevel := "") {
UpdateOutputTarget(OutputControlName(CtrlHwnd), CtrlHwnd)
}
OutputControlName(CtrlHwnd) {
switch CtrlHwnd {
case App.Settings.OutputFileHwnd : return "File"
case App.Settings.OutputClipHwnd : return "Clip"
case App.Settings.OutputImgbbHwnd : return "Imgbb"
default: return ""
}
}
UpdateOutputTarget(ControlName, CtrlHwnd := "") {
if (ControlName = "")
return
GuiControlGet, OutVar, 2:, %CtrlHwnd%
if OutVar
App.Config.Output .= ControlName
else {
Output := App.Config.Output
StringReplace, Output, Output, % ControlName,, 1
App.Config.Output := Output
}
}
SetOutputExtensionFromGui(CtrlHwnd := "", GuiEvent := "", EventInfo := "", EventErrorLevel := "") {
SetOutputExtension(OutputExtensionFromHwnd(CtrlHwnd))
}
OutputExtensionFromHwnd(CtrlHwnd) {
switch CtrlHwnd {
case App.Settings.ExtensionPngHwnd: return "png"
case App.Settings.ExtensionJpgHwnd: return "jpg"
case App.Settings.ExtensionBmpHwnd: return "bmp"
case App.Settings.ExtensionTifHwnd: return "tif"
case App.Settings.ExtensionGifHwnd: return "gif"
default: return ""
}
}
SetOutputExtension(Extension) {
if (Extension != "")
App.Config.Ext := Extension
}
SetJpegQuality() {
GuiControlGet, JPEGQualityValue, 2:, % App.Settings.JpegQualitySliderHwnd
App.Config.JPEGQuality := JPEGQualityValue
GuiControl, 2:, % App.Settings.JpegQualityPercentHwnd, % App.Config.JPEGQuality "`%"
}
FocusSettingsSafeButton() {
GuiControl, 2:Focus, Button17
}
ApplyProgramSettings() {
SelectionHwnd := App.Selection.Hwnd
OldResizePointers := App.Config.ResizePointers
OldRunOnWinStart := App.Config.RunOnWinStart
GuiControlGet, CaptureCursorChecked, 2:, % App.Settings.CaptureCursorHwnd
App.Config.CaptureCursor := CaptureCursorChecked
GuiControlGet, ShowCoordinatesChecked, 2:, % App.Settings.ShowCoordinatesHwnd
App.Config.ShowCoordinates := ShowCoordinatesChecked
GuiControlGet, ShowPreviewChecked, 2:, % App.Settings.ShowPreviewHwnd
App.Config.ShowPreview := ShowPreviewChecked
GuiControlGet, NotifyChecked, 2:, % App.Settings.NotifyHwnd
App.Config.Notify := NotifyChecked
GuiControlGet, RunOnWinStartChecked, 2:, % App.Settings.RunOnWinStartHwnd
App.Config.RunOnWinStart := RunOnWinStartChecked
GuiControlGet, CursorsChecked, 2:, % App.Settings.ResizeCursorsHwnd
App.Config.ResizePointers := CursorsChecked ? "Cursors" : "Markers"
if (OldRunOnWinStart != App.Config.RunOnWinStart)
SetRunOnWindowsStart(App.Config.RunOnWinStart)
if (OldResizePointers != App.Config.ResizePointers && WinExist("ahk_id " SelectionHwnd)) {
SetResizePointerTimer("Off", OldResizePointers)
SetResizePointerTimer(50, App.Config.ResizePointers)
}
; Apply the coordinate labels visibility immediately
UpdateSelectionCoordinateWindows()
; Keep the selection window menu checkmarks in sync with the dialog
SyncMainMenuChecks()
}
; Sync the selection window menu checkmarks with App.Config
SyncMainMenuChecks() {
Menu, MainMenu, % (App.Config.ShowCoordinates ? "Check" : "UnCheck"), % App.Menu.MainShowCoordinates
Menu, MainMenu, % (App.Config.CaptureCursor ? "Check" : "UnCheck"), % App.Menu.MainCaptureCursor
Menu, MainMenu, % (App.Config.HideAfterCapture ? "Check" : "UnCheck"), % App.Menu.MainHideAfterCapture
}
ToggleShowCoordinatesFromMenu() {
App.Config.ShowCoordinates := !App.Config.ShowCoordinates
Menu, MainMenu, % (App.Config.ShowCoordinates ? "Check" : "UnCheck"), % App.Menu.MainShowCoordinates
; If the settings window is open, keep its cancel-snapshot in sync so closing
; without confirmation keeps the menu value; confirming still lets the dialog win.
SyncSettingsSnapshotFromMenu("ShowCoordinates", App.Config.ShowCoordinates)
; Apply the coordinate labels visibility immediately
UpdateSelectionCoordinateWindows()
}
ToggleCaptureCursorFromMenu() {
App.Config.CaptureCursor := !App.Config.CaptureCursor
Menu, MainMenu, % (App.Config.CaptureCursor ? "Check" : "UnCheck"), % App.Menu.MainCaptureCursor
; Keep the cancel-snapshot in sync (see ToggleShowCoordinatesFromMenu)
SyncSettingsSnapshotFromMenu("CaptureCursor", App.Config.CaptureCursor)
; CaptureCursor only affects the next capture, nothing to apply now
}
ToggleHideAfterCaptureFromMenu() {
App.Config.HideAfterCapture := !App.Config.HideAfterCapture
Menu, MainMenu, % (App.Config.HideAfterCapture ? "Check" : "UnCheck"), % App.Menu.MainHideAfterCapture
; Menu-only setting: it is not part of the settings dialog, so there is no
; cancel-snapshot to keep in sync. It only affects the next area capture and
; is persisted to ini by SaveSettings (on Apply/OK or on exit).
}
; When the settings window is open, update the cancel-restore snapshot so a menu
; toggle survives closing the window without confirmation (menu wins). Confirming
; the dialog re-snapshots from its own controls, so the dialog keeps priority.
SyncSettingsSnapshotFromMenu(Name, Value) {
if (WindowExistsByHwnd(App.Settings.WindowHwnd) && IsObject(App.Settings.Previous))
App.Settings.Previous[Name] := Value
}
SelectOutputDirectory() {
SelectionHwnd := App.Selection.Hwnd
Old_OutDirectory := App.Config.OutDirectory
SelectionWasVisible := WinExist("ahk_id " SelectionHwnd)
if (SelectionWasVisible)
ToggleSelectionWindow()
Gui, 2:+OwnDialogs
CurrentOutDirectory := App.Config.OutDirectory
FileSelectFolder, OutDir, *%CurrentOutDirectory%, 3, Выберите папку для вывода:
App.Config.OutDirectory := OutDir ? OutDir : App.Config.OutDirectory
if (App.Config.OutDirectory != Old_OutDirectory)
GuiControl, 2:, % App.Settings.OutDirectoryEditHwnd, % App.Config.OutDirectory
if (SelectionWasVisible && !WinExist("ahk_id " SelectionHwnd))
ToggleSelectionWindow()
}
IsRunOnWindowsStartEnabled() {
FileGetShortcut, % GetRunOnWindowsStartShortcutPath(), OutTarget,, OutArgs
return (OutTarget = A_ScriptFullPath && OutArgs = 1)
}
SetRunOnWindowsStart(Enable) {
ShortcutPath := GetRunOnWindowsStartShortcutPath()
if (Enable)
FileCreateShortcut, % A_ScriptFullPath, % ShortcutPath, % A_ScriptDir, 1
else
FileDelete, % ShortcutPath
}
GetRunOnWindowsStartShortcutPath() {
return A_Startup "\" RegExReplace(A_ScriptName, "(.*)\..*", "$1.lnk")
}
OpenOutputDirectory() {
Run, % App.Config.OutDirectory
}
UpdateResizePointerHover(Mode) {
if (Mode = "Cursors")
App.Selection.ResizeHandle := Cursors1()
else
App.Selection.ResizeHandle := Markers1()
}
GuiSize() {
MoveSelectionResizeMarkers(A_GuiWidth, A_GuiHeight)
}
CreateSelectionCoordinateWindows() {
Coordinates := App.Selection.Coordinates
FontOptions := "s" . Coordinates.FontSize . " q5 Bold cFFFFFF"
WindowOptions := "-Caption +AlwaysOnTop +ToolWindow +Owner1 +E0x08000020"
Gui, SelectionCoordinatesTop:New, % WindowOptions . " +hwndTopWindowHwnd"
Gui, SelectionCoordinatesTop:Color, 202020
Gui, SelectionCoordinatesTop:Margin, 0, 0
Gui, SelectionCoordinatesTop:Font, % FontOptions, % Coordinates.FontName
Gui, SelectionCoordinatesTop:Add, Text, x0 y0 w1 h1 BackgroundTrans hwndTopTextHwnd
Gui, SelectionCoordinatesBottom:New, % WindowOptions . " +hwndBottomWindowHwnd"
Gui, SelectionCoordinatesBottom:Color, 202020
Gui, SelectionCoordinatesBottom:Margin, 0, 0
Gui, SelectionCoordinatesBottom:Font, % FontOptions, % Coordinates.FontName
Gui, SelectionCoordinatesBottom:Add, Text, x0 y0 w1 h1 BackgroundTrans hwndBottomTextHwnd
SetWindowCornerPreference(TopWindowHwnd)
SetWindowCornerPreference(BottomWindowHwnd)
Coordinates.TopWindowHwnd := TopWindowHwnd
Coordinates.TopTextHwnd := TopTextHwnd
Coordinates.BottomWindowHwnd := BottomWindowHwnd
Coordinates.BottomTextHwnd := BottomTextHwnd
Gui, 1:Default
}
SetWindowCornerPreference(hwnd, Preference := 3) {
static DWMWA_WINDOW_CORNER_PREFERENCE := 33
return DllCall("dwmapi\DwmSetWindowAttribute", "Ptr", hwnd
, "UInt", DWMWA_WINDOW_CORNER_PREFERENCE
, "UInt*", Preference, "UInt", 4, "Int")
}
MeasureSelectionCoordinateText(ControlHwnd, Text) {
if (Text = "")
return {w: 0, h: 0}
hdc := DllCall("GetDC", "Ptr", ControlHwnd, "Ptr")
if !hdc
return {w: 0, h: 0}
hFont := DllCall("SendMessage", "Ptr", ControlHwnd, "UInt", 0x31
, "Ptr", 0, "Ptr", 0, "Ptr")
if hFont
hOldFont := DllCall("SelectObject", "Ptr", hdc, "Ptr", hFont, "Ptr")
VarSetCapacity(TextSize, 8, 0)
DllCall("gdi32\GetTextExtentPoint32W", "Ptr", hdc, "WStr", Text
, "Int", StrLen(Text), "Ptr", &TextSize)
if hOldFont
DllCall("SelectObject", "Ptr", hdc, "Ptr", hOldFont)
DllCall("ReleaseDC", "Ptr", ControlHwnd, "Ptr", hdc)
Scale := A_ScreenDPI / 96
return {w: Ceil(NumGet(TextSize, 0, "Int") / Scale) + 2
, h: Ceil(NumGet(TextSize, 4, "Int") / Scale) + 2}
}
UpdateSelectionCoordinateWindows() {
Coordinates := App.Selection.Coordinates
SelectionHwnd := App.Selection.Hwnd
if !IsObject(Coordinates) || !Coordinates.TopWindowHwnd || !Coordinates.BottomWindowHwnd
return
if !App.Config.ShowCoordinates {
HideSelectionCoordinateWindows()
return
}
if !DllCall("IsWindowVisible", "Ptr", SelectionHwnd) {
HideSelectionCoordinateWindows()
return
}
WinGetPos, SelectionXPhysical, SelectionYPhysical
, SelectionWidthPhysical, SelectionHeightPhysical, % "ahk_id " SelectionHwnd
if (SelectionWidthPhysical = "" || SelectionHeightPhysical = "")
return
TopText := SelectionXPhysical . ", " . SelectionYPhysical . " "
. SelectionWidthPhysical . "x" . SelectionHeightPhysical
BottomText := (SelectionXPhysical + SelectionWidthPhysical) . ", "
. (SelectionYPhysical + SelectionHeightPhysical)
TopTextMetrics := MeasureSelectionCoordinateText(Coordinates.TopTextHwnd, TopText)
BottomTextMetrics := MeasureSelectionCoordinateText(Coordinates.BottomTextHwnd, BottomText)
TopWidthLogical := TopTextMetrics.w + 2 * Coordinates.PaddingX
TopHeightLogical := TopTextMetrics.h + 2 * Coordinates.PaddingY
BottomWidthLogical := BottomTextMetrics.w + 2 * Coordinates.PaddingX
BottomHeightLogical := BottomTextMetrics.h + 2 * Coordinates.PaddingY
Scale := A_ScreenDPI / 96
GapPhysical := Round(Coordinates.Gap * Scale)
TopWidthPhysical := Round(TopWidthLogical * Scale)
TopHeightPhysical := Round(TopHeightLogical * Scale)
BottomWidthPhysical := Round(BottomWidthLogical * Scale)
BottomHeightPhysical := Round(BottomHeightLogical * Scale)
TopXPhysical := SelectionXPhysical
TopYPhysical := SelectionYPhysical - GapPhysical - TopHeightPhysical
BottomXPhysical := SelectionXPhysical + SelectionWidthPhysical - BottomWidthPhysical
BottomYPhysical := SelectionYPhysical + SelectionHeightPhysical + GapPhysical
TopLayout := {x: TopXPhysical, y: TopYPhysical
, w: TopWidthLogical, h: TopHeightLogical
, physicalW: TopWidthPhysical, physicalH: TopHeightPhysical
, textW: TopTextMetrics.w, textH: TopTextMetrics.h}
BottomLayout := {x: BottomXPhysical, y: BottomYPhysical
, w: BottomWidthLogical, h: BottomHeightLogical
, physicalW: BottomWidthPhysical, physicalH: BottomHeightPhysical
, textW: BottomTextMetrics.w, textH: BottomTextMetrics.h}
ShowSelectionCoordinateWindow("SelectionCoordinatesTop", Coordinates.TopTextHwnd
, TopText, TopLayout, SelectionCoordinateWindowFitsScreen(TopLayout))
ShowSelectionCoordinateWindow("SelectionCoordinatesBottom", Coordinates.BottomTextHwnd
, BottomText, BottomLayout, SelectionCoordinateWindowFitsScreen(BottomLayout))
}
ShowSelectionCoordinateWindow(GuiName, TextHwnd, Text, Layout, ShowWindow) {
Coordinates := App.Selection.Coordinates
GuiControl, % GuiName . ":", % TextHwnd, % Text
GuiControl, % GuiName . ":MoveDraw", % TextHwnd
, % "x" Coordinates.PaddingX " y" Coordinates.PaddingY
. " w" Layout.textW " h" Layout.textH
if ShowWindow {
; Gui Show принимает физические x/y и логические w/h.
Options := "NA x" Layout.x " y" Layout.y " w" Layout.w " h" Layout.h
Gui, % GuiName . ":Show", % Options
} else {
Gui, % GuiName . ":Hide"
}
}
SelectionCoordinateWindowFitsScreen(Layout) {
return Layout.x >= 0 && Layout.y >= 0
&& Layout.x + Layout.physicalW <= A_ScreenWidth
&& Layout.y + Layout.physicalH <= A_ScreenHeight
}
HideSelectionCoordinateWindows() {
Coordinates := App.Selection.Coordinates
if !IsObject(Coordinates) || !Coordinates.TopWindowHwnd || !Coordinates.BottomWindowHwnd
return
Gui, SelectionCoordinatesTop:Hide
Gui, SelectionCoordinatesBottom:Hide
}
IsSelectionCoordinateWindowHwnd(hwnd) {
Coordinates := App.Selection.Coordinates
return hwnd && IsObject(Coordinates)
&& (hwnd = Coordinates.TopWindowHwnd || hwnd = Coordinates.BottomWindowHwnd)
}
MoveSelectionResizeMarkers(Width, Height) {
GuiControl, Move, Static1, % "x" Width - 10 "y" Height - 10
GuiControl, Move, Static2, % "x0 y" Height - 10
GuiControl, Move, Static3, % "x0 y0"
GuiControl, Move, Static4, % "x" Width - 10 "y0"
GuiControl, Move, Static5, % "x" Width - 10 "y" (Height - 10)/2
GuiControl, Move, Static6, % "x" (Width - 10)/2 "y" Height - 10
GuiControl, Move, Static7, % "x0 y" (Height - 10)/2
GuiControl, Move, Static8, % "x" (Width - 10)/2 "y0"
}
GuiContextMenu() {
RestoreCursors()
Menu, MainMenu, Show
}
; Окно выделения в центр экрана
CenterSelectionWindow() {
SelectionHwnd := App.Selection.Hwnd
if WinExist("ahk_id " SelectionHwnd)
Melt(SelectionHwnd, App.Config.ARGB>>24, 0)
else {
Menu, Tray, Rename, % App.Menu.TrayShow, % App.Menu.TrayHide
SetResizePointerTimer(50)
}
Gui, 1:Show, % "x" (A_ScreenWidth - 200)//2 " y" (A_ScreenHeight - 200)//2 " h200 w200 Hide"
Melt(SelectionHwnd, App.Config.ARGB>>24, 1)
UpdateSelectionCoordinateWindows()
}
GuiClose() {
ToggleSelectionWindow()
}
GuiEscape() {
ToggleSelectionWindow()
}
HideShow() {
ToggleSelectionWindow()
}
ToggleSelectionWindow() {
SelectionHwnd := App.Selection.Hwnd
Exist := WinExist("ahk_id " SelectionHwnd)
Melt(SelectionHwnd, App.Config.ARGB>>24, !Exist)
Menu, Tray, Rename, % Exist ? App.Menu.TrayHide : App.Menu.TrayShow
, % Exist ? App.Menu.TrayShow : App.Menu.TrayHide
SetResizePointerTimer(Exist ? "Off" : 50)
( Exist && NormalizeResizePointersValue(App.Config.ResizePointers) = "Cursors" && RestoreCursors() )
}
; Keep the selection window hidden after an area capture (Hide_After_Capture).
; The window is already hidden by WinHide during the capture, so here we only sync
; the visible state: tray menu label, resize-pointer timer and cursors. Mirrors the
; hide branch of ToggleSelectionWindow without toggling the layered fade.
HideSelectionWindowAfterCapture() {
Menu, Tray, Rename, % App.Menu.TrayHide, % App.Menu.TrayShow
SetResizePointerTimer("Off")
( NormalizeResizePointersValue(App.Config.ResizePointers) = "Cursors" && RestoreCursors() )
}
CaptureAreaScreenshot() {
CoordMode, Pixel, Screen
MouseGetPos, mx, my
prev_color := 0
Loop {
PixelGetColor, cur_color, %mx%, %my%
if (cur_color = prev_color)
break
prev_color := cur_color
Sleep, 30
}
GetScreenshot("Area")
}
SetInterpolationModeFromMenu(MenuItemPos) {
Menu, Interpolation, UnCheck, % App.Menu.InterpolationItems[App.Config.InterpolationMode]
App.Config.InterpolationMode := MenuItemPos
Menu, Interpolation, Check, % App.Menu.InterpolationItems[App.Config.InterpolationMode]
}
FindDuplicateHotkey() {
Names := ScreenCatcherHotkeyNames()
Loop % Names.MaxIndex() {
Name1 := Names[A_Index]
Value1 := Hotkey_Value(Name1)
if !IsHotkeyEnabled(Value1)
continue
i := A_Index + 1
Loop % Names.MaxIndex() - A_Index {
Name2 := Names[i]
Value2 := Hotkey_Value(Name2)
if (IsHotkeyEnabled(Value2) && Hotkey_Equal(Value1, Value2))
return {Name: Name2, OtherName: Name1, Hwnd: Hotkey_ID(Name2), Value: Value2}
i++
}
}
return ""
}
ShowDuplicateHotkey(Duplicate) {
Labels := ScreenCatcherHotkeyLabels()
ActivateHotkeyControl(Duplicate.Name)
Hwnd := Duplicate.Hwnd
WinGetPos, X, Y, W, H, ahk_id %Hwnd%
Text := "Эта горячая клавиша уже назначена:`n" Labels[Duplicate.OtherName]
new ToolTip({ text: Text, x: X, y: Y + H + 8, TimeOut: -3500
, BackColor: 0x0055aa, TextColor: "white", FontSize: 10, FontName: "calibri" })
BlinkWindow(Hwnd)
}
ActivateHotkeyControl(Name) {
Index := ScreenCatcherHotkeyIndex(Name)
if !Index
return
SubTab := Index < 4 ? 1 : Index < 7 ? 2 : 3
GuiControl, 2:Choose, % App.Settings.TabHwnd, 4
Gui, 4:Show, NA
GuiControl, 4:Choose, % App.Settings.HotkeysSubTabHwnd, %SubTab%
Hwnd := Hotkey_ID(Name)
ControlFocus,, ahk_id %Hwnd%
Sleep, 50
}
BlinkWindow(Hwnd) {
Loop 6 {
DllCall("ShowWindowAsync", "Ptr", Hwnd, "Int", Mod(A_Index, 2) ? 0 : 4)
Sleep, 70
}
DllCall("ShowWindowAsync", "Ptr", Hwnd, "Int", 4)
}
SetScriptHotkeys(Enable, Values := "") {
if !IsObject(Values)
Values := GetScriptHotkeys()
Hotkey, IfWinActive
if IsHotkeyEnabled(Values.GetArea) {
if Enable {
obj := Func("GetScreenshot").Bind("Area")
Hotkey, % Values.GetArea, % obj, On
} else {
Hotkey, % Values.GetArea, Off
}
}
if IsHotkeyEnabled(Values.GetActiveWindow) {
if Enable {
obj := Func("GetScreenshot").Bind("ActiveWindow")
Hotkey, % Values.GetActiveWindow, % obj, On
} else {
Hotkey, % Values.GetActiveWindow, Off
}
}
if IsHotkeyEnabled(Values.GetScreen) {
if Enable {
obj := Func("GetScreenshot").Bind("Screen")
Hotkey, % Values.GetScreen, % obj, On
} else {
Hotkey, % Values.GetScreen, Off
}
}
if IsHotkeyEnabled(Values.ShowHideSelWindow) {
if Enable
Hotkey, % Values.ShowHideSelWindow, HideShow, On
else
Hotkey, % Values.ShowHideSelWindow, Off
}
if IsHotkeyEnabled(Values.SelWindowToCenter) {
if Enable
Hotkey, % Values.SelWindowToCenter, CenterSelectionWindow, On
else
Hotkey, % Values.SelWindowToCenter, Off
}
if IsHotkeyEnabled(Values.OpenOutputFolder) {
if Enable
Hotkey, % Values.OpenOutputFolder, OpenOutputDirectory, On
else
Hotkey, % Values.OpenOutputFolder, Off
}
if IsHotkeyEnabled(Values.SelectAreaOverlay) {
if Enable {
obj := Func("StartOverlaySelection").Bind("Arm")
Hotkey, % Values.SelectAreaOverlay, % obj, On
} else {
Hotkey, % Values.SelectAreaOverlay, Off
}
}
if IsHotkeyEnabled(Values.QuickSelectAreaOverlay) {
if Enable {
obj := Func("StartOverlaySelection").Bind("Quick")
Hotkey, % Values.QuickSelectAreaOverlay, % obj, On
} else {
Hotkey, % Values.QuickSelectAreaOverlay, Off
}
}
if IsHotkeyEnabled(Values.SelectPreview) {
Hotkey, if, WinExist("ScreenShot ahk_class AutoHotkeyGUI")
if Enable
Hotkey, % Values.SelectPreview, FindHighlight, On
else
Hotkey, % Values.SelectPreview, Off
}
Hotkey, if
}
SetResizeHotkeyState(State) {
Hotkey, IfWinActive
Hotkey, LButton, WinResize, %State%
Hotkey, if
}
Cursors1() {
static
SelectionHwnd := App.Selection.Hwnd
NearDistance := Round(10 * A_ScreenDPI / 96)
FarDistance := Round(20 * A_ScreenDPI / 96)
MouseGetPos, X_M, Y_M, ID_Win
for index, value in App.Windows {
if (value.Hwnd = ID_Win) {
if Cursor {
RestoreCursors()
SetResizeHotkeyState("Off")
Cursor := ""
}
return
}
}
WinGetPos, X, Y, W, H, ahk_id %SelectionHwnd%
XW := X + W, YH := Y + H
if ((X_M <= XW) && (X_M > XW - FarDistance) && (Y_M <= YH) && (Y_M > YH - NearDistance))
|| ((X_M <= XW) && (X_M > XW - NearDistance) && (Y_M <= YH) && (Y_M > YH - FarDistance))
Var := 1
else if ((X_M < X + FarDistance) && (X_M >= X) && (Y_M <= YH) && (Y_M > YH - NearDistance))
|| ((X_M < X + NearDistance) && (X_M >= X) && (Y_M <= YH) && (Y_M > YH - FarDistance))
Var := 2
else if ((X_M < X + FarDistance) && (X_M >= X) && (Y_M < Y + NearDistance) && (Y_M >= Y))
|| ((X_M < X + NearDistance) && (X_M >= X) && (Y_M < Y + FarDistance) && (Y_M >= Y))
Var := 3
else if ((X_M <= XW ) && (X_M > XW - FarDistance) && (Y_M < Y + NearDistance) && (Y_M >= Y))
|| ((X_M <= XW ) && (X_M > XW - NearDistance) && (Y_M < Y + FarDistance) && (Y_M >= Y))
Var := 4
else if (X_M <= XW) && (X_M > XW - NearDistance)
&& (Y_M <= YH - NearDistance) && (Y_M >= Y + NearDistance)
Var := 5
else if (X_M <= XW - NearDistance) && (X_M >= X + NearDistance)
&& (Y_M <= YH) && (Y_M > YH - NearDistance)
Var := 6
else if (X_M < X + NearDistance) && (X_M >= X)
&& (Y_M <= YH - NearDistance) && (Y_M >= Y + NearDistance)
Var := 7
else if (X_M <= XW - NearDistance) && (X_M >= X + NearDistance)
&& (Y_M < Y + NearDistance) && (Y_M >= Y)
Var := 8
else
Var := ""
if Var {
SetResizeHotkeyState("On")
if (Var = 1 || Var = 3) && (Cursor != "IDC_SIZENWSE")
RestoreCursors(), SetSystemCursor("IDC_SIZENWSE"), Cursor := "IDC_SIZENWSE"
if (Var = 2 || Var = 4) && (Cursor != "IDC_SIZENESW")
RestoreCursors(), SetSystemCursor("IDC_SIZENESW"), Cursor := "IDC_SIZENESW"
if (Var = 5 || Var = 7) && (Cursor != "IDC_SIZEWE")
RestoreCursors(), SetSystemCursor("IDC_SIZEWE"), Cursor := "IDC_SIZEWE"
if (Var = 6 || Var = 8) && (Cursor != "IDC_SIZENS")
RestoreCursors(), SetSystemCursor("IDC_SIZENS"), Cursor := "IDC_SIZENS"
} else {
SetResizeHotkeyState("Off")
RestoreCursors(), Cursor := ""
}
return Var
}
Markers1() {
SelectionHwnd := App.Selection.Hwnd
NearDistance := Round(10 * A_ScreenDPI / 96)
FarDistance := Round(20 * A_ScreenDPI / 96)
MouseGetPos, X_M, Y_M, ID_Win
for index, value in App.Windows {
if (value.Hwnd = ID_Win) {
SetResizeHotkeyState("Off")
Loop 8
GuiControl, Hide, static%a_index%
return
}
}
WinGetPos, X, Y, W, H, ahk_id %SelectionHwnd%
XW := X + W, YH := Y + H
if (X_M <= XW + FarDistance) && (X_M >= XW - NearDistance)
&& (Y_M <= YH + FarDistance) && (Y_M >= YH - NearDistance)
Var := 1
else if (X_M <= X + NearDistance) && (X_M >= X - FarDistance)
&& (Y_M <= YH + FarDistance) && (Y_M >= YH - NearDistance)
Var := 2
else if (X_M <= X + NearDistance) && (X_M >= X - FarDistance)
&& (Y_M <= Y + NearDistance) && (Y_M >= Y - FarDistance)
Var := 3
else if (X_M <= XW + FarDistance) && (X_M >= XW - NearDistance)
&& (Y_M <= Y + NearDistance) && (Y_M >= Y - FarDistance)
Var := 4
else if (X_M <= XW + FarDistance) && (X_M >= XW - NearDistance)
&& (Y_M < YH - NearDistance) && (Y_M > Y + NearDistance)
Var := 5
else if (X_M < XW - NearDistance) && (X_M > X + NearDistance)
&& (Y_M <= YH + FarDistance) && (Y_M >= YH - NearDistance)
Var := 6
else if (X_M <= X + NearDistance) && (X_M >= X - FarDistance)
&& (Y_M < YH - NearDistance) && (Y_M > Y + NearDistance)
Var := 7
else if (X_M < XW - NearDistance) && (X_M > X + NearDistance)
&& (Y_M <= Y + NearDistance) && (Y_M >= Y - FarDistance)
Var := 8
else Var := ""
if Var {
SetResizeHotkeyState("On")
GuiControl, Show, static%Var%
Loop 8 {
if (a_index != Var)
GuiControl, Hide, static%a_index%
}
} else {
SetResizeHotkeyState("Off")
Loop 8 {
GuiControl, Hide, static%a_index%
}
}
return Var
}
WinResize() {
SelectionHwnd := App.Selection.Hwnd
ResizeVar := App.Selection.ResizeHandle
SetResizePointerTimer("Off")
MouseGetPos, X_M_Old, Y_M_Old
WinGetPos, X, Y, W, H, ahk_id %SelectionHwnd%
Left := X, Top := Y, Right := X + W, Bottom := Y + H
MoveHorizontal := (ResizeVar = 1 || ResizeVar = 2 || ResizeVar = 3 || ResizeVar = 4
|| ResizeVar = 5 || ResizeVar = 7)
MoveVertical := (ResizeVar = 1 || ResizeVar = 2 || ResizeVar = 3 || ResizeVar = 4
|| ResizeVar = 6 || ResizeVar = 8)
HorizontalSide := (ResizeVar = 1 || ResizeVar = 4 || ResizeVar = 5) ? "Right" : "Left"
VerticalSide := (ResizeVar = 1 || ResizeVar = 2 || ResizeVar = 6) ? "Bottom" : "Top"
if MoveHorizontal {
AnchorX := HorizontalSide = "Right" ? Left : Right
StartEdgeX := HorizontalSide = "Right" ? Right : Left
}
if MoveVertical {
AnchorY := VerticalSide = "Bottom" ? Top : Bottom
StartEdgeY := VerticalSide = "Bottom" ? Bottom : Top
}
while GetKeyState("LButton", "P") {
MouseGetPos, X_M, Y_M
dX := X_M - X_M_Old, dY := Y_M - Y_M_Old
NewX := X, NewY := Y, NewW := W, NewH := H
if MoveHorizontal {
DraggedX := StartEdgeX + dX
if (DraggedX < AnchorX) {
NewX := DraggedX
NewW := AnchorX - DraggedX
NewHorizontalSide := "Left"
} else if (DraggedX > AnchorX) {
NewX := AnchorX
NewW := DraggedX - AnchorX
NewHorizontalSide := "Right"
} else {
NewX := HorizontalSide = "Left" ? AnchorX - 1 : AnchorX
NewW := 1
NewHorizontalSide := HorizontalSide
}
}
if MoveVertical {
DraggedY := StartEdgeY + dY
if (DraggedY < AnchorY) {
NewY := DraggedY
NewH := AnchorY - DraggedY
NewVerticalSide := "Top"
} else if (DraggedY > AnchorY) {
NewY := AnchorY
NewH := DraggedY - AnchorY
NewVerticalSide := "Bottom"
} else {
NewY := VerticalSide = "Top" ? AnchorY - 1 : AnchorY
NewH := 1
NewVerticalSide := VerticalSide
}
}
NewResizeVar := SelectionResizeHandleFromSides(MoveHorizontal ? NewHorizontalSide : ""
, MoveVertical ? NewVerticalSide : "")
if (NewResizeVar != ResizeVar) {
UpdateActiveSelectionResizePointer(ResizeVar, NewResizeVar)
ResizeVar := NewResizeVar
HorizontalSide := NewHorizontalSide
VerticalSide := NewVerticalSide
}
WinMove, ahk_id %SelectionHwnd%,, %NewX%, %NewY%, %NewW%, %NewH%
Sleep, 10
}
SetResizePointerTimer("On")
}
SelectionResizeHandleFromSides(HorizontalSide, VerticalSide) {
if (HorizontalSide = "Right")
return VerticalSide = "Bottom" ? 1 : VerticalSide = "Top" ? 4 : 5
if (HorizontalSide = "Left")
return VerticalSide = "Bottom" ? 2 : VerticalSide = "Top" ? 3 : 7
return VerticalSide = "Bottom" ? 6 : VerticalSide = "Top" ? 8 : ""
}
UpdateActiveSelectionResizePointer(OldHandle, NewHandle) {
App.Selection.ResizeHandle := NewHandle
if (NormalizeResizePointersValue(App.Config.ResizePointers) = "Markers") {
GuiControl, Hide, static%OldHandle%
GuiControl, Show, static%NewHandle%
return
}
if (NewHandle = 1 || NewHandle = 3)
CursorName := "IDC_SIZENWSE"
else if (NewHandle = 2 || NewHandle = 4)
CursorName := "IDC_SIZENESW"
else if (NewHandle = 5 || NewHandle = 7)
CursorName := "IDC_SIZEWE"
else
CursorName := "IDC_SIZENS"
RestoreCursors()
SetSystemCursor(CursorName)
}
IsSelectionWindowActive() {
SelectionHwnd := App.Selection.Hwnd
return (SelectionHwnd && WinActive("ahk_id " SelectionHwnd))
}
NudgeSelectionEdge(Edge, Delta) {
static MinSize := 1
SelectionHwnd := App.Selection.Hwnd
if !WinExist("ahk_id " SelectionHwnd)
return
WinGetPos, X, Y, W, H, ahk_id %SelectionHwnd%
if (Edge = "Left") {
if (W - Delta < MinSize)
return
WinMove, ahk_id %SelectionHwnd%,, X + Delta, Y, W - Delta, H
} else if (Edge = "Top") {
if (H - Delta < MinSize)
return
WinMove, ahk_id %SelectionHwnd%,, X, Y + Delta, W, H - Delta
} else if (Edge = "Right") {
if (W + Delta < MinSize)
return
WinMove, ahk_id %SelectionHwnd%,, X, Y, W + Delta, H
} else if (Edge = "Bottom") {
if (H + Delta < MinSize)
return
WinMove, ahk_id %SelectionHwnd%,, X, Y, W, H + Delta
}
}
NormalizeLoadedSettings() {
if !IsIntegerSetting(App.Config.ARGB)
App.Config.ARGB := 0x82FFC700
if !RegExMatch(App.Config.Output, "^(File|Clip|Imgbb)+$")
App.Config.Output := "File"
if !RegExMatch(App.Config.Ext, "^(png|jpg|bmp|tif|gif)$")
App.Config.Ext := "png"
if (!IsIntegerSetting(App.Config.JPEGQuality) || App.Config.JPEGQuality < 50 || App.Config.JPEGQuality > 100)
App.Config.JPEGQuality := 100
if (App.Config.OutDirectory = "" || App.Config.OutDirectory = "OutDirectory")
App.Config.OutDirectory := A_ScriptDir
if !IsBooleanSetting(App.Config.CaptureCursor)
App.Config.CaptureCursor := 0
if !IsBooleanSetting(App.Config.HideAfterCapture)
App.Config.HideAfterCapture := 0
if !IsBooleanSetting(App.Config.ShowCoordinates)
App.Config.ShowCoordinates := 1
if !IsBooleanSetting(App.Config.ShowPreview)
App.Config.ShowPreview := 1
if !IsBooleanSetting(App.Config.Notify)
App.Config.Notify := 1
App.Config.ResizePointers := NormalizeResizePointersValue(App.Config.ResizePointers)
if (!IsIntegerSetting(App.Config.InterpolationMode) || App.Config.InterpolationMode < 1 || App.Config.InterpolationMode > 8)
App.Config.InterpolationMode := 3
}
NormalizeResizePointersValue(Value) {
return Value = "Markers" ? "Markers" : "Cursors"
}
SetResizePointerTimer(State, Value := "") {
TimerName := NormalizeResizePointersValue(Value = "" ? App.Config.ResizePointers : Value)
SetTimer, %TimerName%, %State%
}
Cursors() {
UpdateResizePointerHover(A_ThisFunc)
}
Markers() {
UpdateResizePointerHover(A_ThisFunc)
}
IsIntegerSetting(Value) {
return RegExMatch(Value, "i)^\s*(?:0x[0-9a-f]+|\d+)\s*$")
}
IsBooleanSetting(Value) {
return Value = 0 || Value = 1
}
IniReadConfigSect(Section, params*) {
; Читает секцию Section ini-файла в App.Config
ConfigNames := [ "ARGB", "Output", "Ext", "JPEGQuality", "OutDirectory", "CaptureCursor"
, "HideAfterCapture", "ShowCoordinates", "ShowPreview", "Notify", "ResizePointers", "InterpolationMode" ]
IniReadObjectSect(Section, App.Config, ConfigNames, params*)
}
IniReadHotkeysSect(Section, params*) {
; Читает секцию Section ini-файла в App.Hotkeys.
if !IsObject(App.Hotkeys)
App.Hotkeys := {}
IniReadObjectSect(Section, App.Hotkeys, ScreenCatcherHotkeyNames(), params*)
}
IniReadObjectSect(Section, Target, AllowedNames, params*) {
; Читает секцию Section ini-файла в объект Target.
IniName := IniFilePath()
for index, param in params {
if Mod(index, 3) = 1
Key := param
else if Mod(index, 3) = 2
Name := param
else {
IniRead, Value, % IniName, % Section, % Key, % param
SetObjectValue(Target, AllowedNames, Name, Value)
}
}
}
SetObjectValue(Target, AllowedNames, Name, Value) {
for index, AllowedName in AllowedNames {
if (Name = AllowedName) {
Target[AllowedName] := Value
return
}
}
}
IniWriteSect(Section, params*) {
; Пишет секцию Section ini-файла в директории скрипта.
IniName := IniFilePath()
for index, param in params {
if Mod(index, 2)
Key := param
else
IniWrite, % param, % IniName, % Section, % Key
}
}
; Settings file next to the script. A per-computer file
; <ComputerName>_ScreenCatcher.ini is used when it exists: one synced script
; folder can serve several computers, each with its own settings. Otherwise
; the common ScreenCatcher.ini is used (and created on the first save).
IniFilePath() {
SplitPath, % A_ScriptFullPath,, OutDir,, OutNameNoExt
PerComputerPath := OutDir . "\" . A_ComputerName . "_" . OutNameNoExt . ".ini"
if FileExist(PerComputerPath)
return PerComputerPath
return OutDir . "\" . OutNameNoExt . ".ini"
}
; File name (without the folder) of the settings file in use, for messages
SettingsFileName() {
SplitPath, % IniFilePath(), FileName
return FileName
}
; Opts the script executable into the IE11 edge rendering mode used by the
; embedded WebBrowser control (help window). Without this MSHTML falls back to
; an old document mode and modern CSS/anchors behave inconsistently.
FixIE() {
static RegKey := "HKCU\Software\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION"
SplitPath, % (A_IsCompiled ? A_ScriptFullPath : A_AhkPath), ExeName
try {
RegRead, Current, % RegKey, % ExeName
if (Current != 11001)
RegWrite, REG_DWORD, % RegKey, % ExeName, 11001
}
}
Melt(hWnd, Trans, Appear, N = 20) {
WinShow, ahk_id %hWnd%
while (i := A_Index * N) < Trans {
WinSet, Transparent, % Appear ? i : Trans - i, ahk_id %hWnd%
Sleep, 10
}
if Appear
WinSet, Transparent, % Trans, ahk_id %hWnd%
else
WinHide, ahk_id %hWnd%
}
SetSystemCursor(IDC) {
static IDC_SIZENWSE := 32642, IDC_SIZENESW := 32643, IDC_SIZEWE := 32644
, IDC_SIZENS := 32645, IDC_ARROW := 32512
, sys_cursors := [32512,32513,32514,32516,32642,32643,32644,32645,32646,32648,32649,32650]
hCursor := DllCall("LoadCursor", "UInt", 0, "Int", %IDC%)
for k, v in sys_cursors {
hCopy := DllCall("CopyImage", "Ptr", hCursor, "UInt", 2, "Int", 0, "Int", 0, "UInt", 0)
DllCall("SetSystemCursor", "UInt", hCopy, "Int", v)
}
}
RestoreCursors() {
DllCall("SystemParametersInfo", "UInt", SPI_SETCURSORS:=0x57, "UInt", 0, "UInt", 0, "UInt", 0)
}
SetColorToControl(hwnd, Color) { ; окрашивает static-контрол со стилем SS_BITMAP = 0xE в цвет Color
WinGetPos,,, w, h, ahk_id %hwnd%
DllCall("gdiplus\GdipCreateSolidFill", "UInt", 0xFF000000|Color, "Ptr*", pBrush)
DllCall("gdiplus\GdipCreateBitmapFromScan0", "Int", w, "Int", h, "Int", 0, "Int", 0x26200A, "Ptr", 0, "Ptr*", pBitmap)
DllCall("gdiplus\GdipGetImageGraphicsContext", "Ptr", pBitmap, "Ptr*", G)
DllCall("gdiplus\GdipFillRectangle", "Ptr", G, "Ptr", pBrush, "Float", 0, "Float", 0, "Float", w, "Float", h)
DllCall("gdiplus\GdipCreateHBITMAPFromBitmap", "Ptr", pBitmap, "Ptr*", hBitmap, "Int", 0xFFFFFFFF)
SendMessage, STM_SETIMAGE := 0x172,, hBitmap,, ahk_id %hwnd%
DllCall("DeleteObject", "Ptr", ErrorLevel)
DllCall("gdiplus\GdipDeleteBrush", "Ptr", pBrush)
DllCall("gdiplus\GdipDeleteGraphics", "Ptr", G)
DllCall("gdiplus\GdipDisposeImage", "Ptr", pBitmap)
DllCall("DeleteObject", "Ptr", hBitmap)
}
DDLCreate(N) {
Loop % N
String .= A_Index-1 "|"
return SubStr(String, 1, -1)
}
WM_SELECTION_WINDOWPOSCHANGED(wParam, lParam, msg, hwnd) {
if (hwnd = App.Selection.Hwnd)
UpdateSelectionCoordinateWindows()
}
WM_LBUTTONDOWN(wParam, lParam, msg, hwnd) {
if IsOverlaySelectionHwnd(hwnd) || IsSelectionCoordinateWindowHwnd(hwnd)
return
if (A_Gui = 1 || A_Gui > 9) {
if (A_Gui > 9) {
App.Menu.CancelPreviewIntroHwnd := hwnd
HidePreviewHighlight()
; In drawing mode the left button draws instead of moving the preview
if IsPreviewInDrawMode(A_Gui) {
BeginPreviewDrag(A_Gui, hwnd, lParam)
return
}
}
PostMessage, WM_NCLBUTTONDOWN := 0xA1, HTCAPTION := 2,,, % "ahk_id " hwnd
}
else if (A_Gui = 2 && WhichPageOfTab(App.Settings.TabHwnd) = 4)
{
MouseGetPos,,,, Control
if InStr(Control, "ComboBox")
{
GuiControlGet, OutputVar, 3:Enabled, % Control
if OutputVar
return
else
GuiControl, 3:Focus, TextT
}
else
GuiControl, 3:Focus, TextT
}
}
WM_LBUTTONDBLCLK(wParam, lParam, msg, hwnd) {
if IsOverlaySelectionHwnd(hwnd) || IsSelectionCoordinateWindowHwnd(hwnd)
return
; GUI windows have CS_DBLCLKS, so a quick second click arrives here instead
; of WM_LBUTTONDOWN; in drawing mode it must start a new shape as well.
if IsPreviewInDrawMode(A_Gui) {
BeginPreviewDrag(A_Gui, hwnd, lParam)
return
}
(A_Gui = 1) && GetScreenshot("Area")
}
WM_RBUTTONDOWN(wParam, lParam, msg, hwnd) {
if IsOverlaySelectionHwnd(hwnd) || IsSelectionCoordinateWindowHwnd(hwnd)
return
if (A_Gui < 10 || A_Gui = "Imgbb")
return
; No menu while a shape is being dragged
if IsObject(App.Drawing.Drag)
return
App.Menu.CurrentPreviewGui := A_Gui
PreviewMenuName := App.Windows[A_Gui].Scale = 1 ? "ScreenShotMenu" : "ScreenShotMenu2"
SyncPreviewDrawMenu(PreviewMenuName, A_Gui)
Menu, % PreviewMenuName, Show
}
AHK_NOTIFYICON(wp, lp) {
static WM_LBUTTONDOWN := 0x201
(lp = WM_LBUTTONDOWN) && ToggleSelectionWindow()
}
WhichPageOfTab(SettingsTabHwnd) {
ControlGet, NTab, Tab,,, ahk_id %SettingsTabHwnd%
return NTab
}
GetControlFocus(NGui) {
GuiControlGet, Focus, %NGui%:Focus
return Focus
}
GetOverlaySelection() {
if !IsObject(App.Selection.Overlay) {
gap := 5
labelSpecs := [{style: {fontStyle: 1}
, provider: Func("OverlayTopLabelProvider").Bind(gap)}
, {style: {fontStyle: 1}
, provider: Func("OverlayBottomLabelProvider").Bind(gap)}]
armedStyle := {fontStyle: 1, offsetX: 12, offsetY: 12}
App.Selection.Overlay := new OverlaySelection(2, 0xFFAA00, labelSpecs, armedStyle)
Gui, 1:Default
}
return App.Selection.Overlay
}
StartOverlaySelection(Mode) {
Overlay := GetOverlaySelection()
if (Overlay.state != "idle" || Overlay.busy)
return
HideSelectionCoordinateWindows()
Callback := Func("CaptureOverlaySelection")
if (Mode = "Quick")
Overlay.Quick(Callback)
else
Overlay.Arm(Callback)
}
CaptureOverlaySelection(Rect) {
if (Rect.w < 1 || Rect.h < 1)
return
GetScreenshot("Area", Rect)
}
OverlayTopLabelProvider(Gap, Context) {
Rect := Context.r
return {text: Rect.x . ", " . Rect.y . " " . Rect.w . "x" . Rect.h
, ax: Rect.x
, ay: Rect.y - Context.t - Round(Gap * Context.scale)
, side: "top"}
}
OverlayBottomLabelProvider(Gap, Context) {
Rect := Context.r
return {text: (Rect.x + Rect.w) . ", " . (Rect.y + Rect.h)
, ax: Rect.x + Rect.w
, ay: Rect.y + Rect.h + Context.t + Round(Gap * Context.scale)
, side: "bottom"}
}
IsOverlaySelectionState(State) {
return IsObject(App.Selection.Overlay) && App.Selection.Overlay.state = State
}
BeginOverlaySelectionDrag() {
if IsObject(App.Selection.Overlay)
App.Selection.Overlay.BeginDrag()
}
CancelOverlaySelection() {
if IsObject(App.Selection.Overlay)
App.Selection.Overlay.Cancel()
}
FinishOverlaySelection() {
if IsObject(App.Selection.Overlay)
App.Selection.Overlay.Finish()
}
GetScreenshot(Area, SelectionRect := "") {
SelectionHwnd := App.Selection.Hwnd
SRCCOPY := 0x00CC0020, CAPTUREBLT := 0x40000000
Critical
HideSelectionCoordinateWindows()
if (Area = "Area") {
IfWinExist, ahk_id %SelectionHwnd%
{
Vis = 1
WinHide ; Melt(SelectionHwnd, App.Config.ARGB>>24, 0, 50)
}
if IsObject(SelectionRect) {
X := SelectionRect.x
Y := SelectionRect.y
W := SelectionRect.w
H := SelectionRect.h
} else {
DetectHiddenWindows, On
WinGetPos, X, Y, W, H, ahk_id %SelectionHwnd%
}
Rect := X "|" Y "|" W "|" H
pBitmap := BitmapFromScreen(Rect, App.Config.CaptureCursor, SRCCOPY|CAPTUREBLT)
if Vis
{
Sleep, 50
if (App.Config.HideAfterCapture)
HideSelectionWindowAfterCapture() ; keep it hidden and sync app state
else
WinShow ; Melt(SelectionHwnd, App.Config.ARGB>>24, 1, 50)
}
} else if (Area = "ActiveWindow") {
WinGet, hwnd, ID, A
if !GetVisibleWindowRect(hwnd, X, Y, W, H)
WinGetPos, X, Y, W, H, ahk_id %hwnd%
pBitmap := BitmapFromScreen(X "|" Y "|" W "|" H, App.Config.CaptureCursor, SRCCOPY|CAPTUREBLT)
} else {
X := Y := 0
W := A_ScreenWidth
H := A_ScreenHeight
pBitmap := BitmapFromScreen(0, App.Config.CaptureCursor, SRCCOPY|CAPTUREBLT)
}
UpdateSelectionCoordinateWindows()
Critical, Off ; capture is done; let the message queue flow for preview/notification
Time := A_Year "." A_MM "." A_DD "-" A_Hour "." A_Min "." A_Sec "." SubStr(A_MSec, 1, 1)
if (App.Config.ShowPreview) {
ShowPreview(pBitmap, Time, X, Y, W, H)
} else {
SaveScreenshot(pBitmap, Time)
}
}
BitmapFromHWND(hwnd) {
WinGetPos,,, Width, Height, ahk_id %hwnd%
hbm := CreateDIBSection(Width, Height)
hdc := DllCall("CreateCompatibleDC", "Ptr", 0)
obm := DllCall("SelectObject", "Ptr", hdc, "Ptr", hbm)
DllCall("PrintWindow", "Ptr", hwnd, "Ptr", hdc, "UInt", PW_RENDERFULLCONTENT := 2)
DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", "Ptr", hbm, "Ptr", 0, "Ptr*", pBitmap)
DllCall("SelectObject", "Ptr", hdc, "Ptr", obm)
DllCall("DeleteObject", "Ptr", hbm)
DllCall("DeleteDC", "Ptr", hdc)
return pBitmap
}
GetBitmapFromWindow(hwnd) {
WinGetPos,,, W, H, ahk_id %hwnd%
hWDC := DllCall("GetWindowDC", "Ptr", hwnd, "Ptr")
hdc := DllCall("CreateCompatibleDC", "Ptr", hWDC, "Ptr")
hbm := DllCall("CreateCompatibleBitmap", "Ptr", hWDC, "Int", W, "Int", H)
obm := DllCall("SelectObject", "Ptr", hdc, "Ptr", hbm)
DllCall("BitBlt", "Ptr", hdc, "Int", 0, "Int", 0, "Int", W, "Int", H, "Ptr", hWDC, "Int", 0, "Int", 0, "UInt", 0x00CC0020)
DllCall("ReleaseDC", "Ptr", hwnd, "Ptr", hWDC)
DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", "Ptr", hbm, "Ptr", 0, "Ptr*", pBitmap)
DllCall("SelectObject", "Ptr", hdc, "Ptr", obm)
DllCall("DeleteObject", "Ptr", hbm)
DllCall("DeleteDC", "Ptr", hdc)
return pBitmap
}
ShowPreview(pBitmap, Time, X, Y, W, H) {
static WS_EX_LAYERED := 0x80000, IntroOffsetLogical := 10
SelectionHwnd := App.Selection.Hwnd
while App.Windows[i := A_Index+9]
continue
Gui, %i%: -Caption +E%WS_EX_LAYERED% +LastFound +AlwaysOnTop +ToolWindow +Owner
WinGet, PreviewHwnd
Gui, %i%: Show, NA, ScreenShot
App.Windows[i] := Object("Hwnd", PreviewHwnd, "Time", Time, "pBM", pBitmap
, "Canvas", new PreviewCanvas(PreviewHwnd, pBitmap))
App.Windows[i].Canvas.Render(X, Y, W, H)
WinActivate, ahk_id %PreviewHwnd%
SetWinDelay, 10
Loop % IntroOffsetLogical {
if (App.Menu.CancelPreviewIntroHwnd = PreviewHwnd)
break
OffsetPhysical := Round(A_Index * A_ScreenDPI / 96)
WinMove, ahk_id %PreviewHwnd%,, X + OffsetPhysical, Y - OffsetPhysical
}
DetectHiddenWindows, Off
if !WinExist("ahk_id " SelectionHwnd)
ShowPreviewHighlight(PreviewHwnd)
if (App.Menu.CancelPreviewIntroHwnd = PreviewHwnd)
App.Menu.CancelPreviewIntroHwnd := ""
}
ShowPreviewHighlight(PreviewHwnd) {
Critical
if (App.Menu.CancelPreviewIntroHwnd = PreviewHwnd) {
Critical, Off
return
}
Highlight(PreviewHwnd)
Critical, Off
Sleep, 300
HidePreviewHighlight()
}
Highlight(TargetHwnd) {
HidePreviewHighlight()
WinActivate, ahk_id %TargetHwnd%
; WS_EX_LAYERED := 0x80000, WS_EX_TRANSPARENT := 0x20
Gui, 5:-Caption +E0x80020 +LastFound +AlwaysOnTop +ToolWindow +Owner
WinGet, HighlightHwnd
App.Menu.HighlightHwnd := HighlightHwnd
Gui, 5:Show, NA
WinGetPos, X, Y, W, H, ahk_id %TargetHwnd%
hbm := CreateDIBSection(W, H)
hdc := DllCall("CreateCompatibleDC", "Ptr", 0)
obm := DllCall("SelectObject", "Ptr", hdc, "Ptr", hbm)
DllCall("gdiplus\GdipCreateFromHDC", "Ptr", hdc, "Ptr*", G)
DllCall("gdiplus\GdipCreateSolidFill", "UInt", 0xffffaa00, "Ptr*", pBrush)
TH := 5 ; толщина линии подсветки
Points := "0,0|" W ",0|" W "," H "|0," H "|0," TH "|" TH ","
. TH "|" TH "," H - TH "|" W - TH "," H - TH "|" W - TH "," TH "|0," TH
FillPolygon(G, pBrush, Points)
DllCall("gdiplus\GdipDeleteBrush", "Ptr", pBrush)
UpdateLayeredWindow(HighlightHwnd, hdc, X, Y, W, H)
DllCall("SelectObject", "Ptr", hdc, "Ptr", obm)
DllCall("DeleteObject", "Ptr", hbm), DllCall("DeleteDC", "Ptr", hdc)
DllCall("gdiplus\GdipDeleteGraphics", "Ptr", G)
}
HidePreviewHighlight() {
HighlightHwnd := App.Menu.HighlightHwnd
if (HighlightHwnd && WinExist("ahk_id " HighlightHwnd))
Gui, 5:Destroy
App.Menu.HighlightHwnd := ""
}
FindHighlight() {
static CurrentScr
if !CurrentScr
CurrentScr := App.Windows.MaxIndex()
else {
while !App.Windows[CurrentScr := CurrentScr = 10 ? App.Windows.MaxIndex() : CurrentScr - 1]
continue
}
Highlight(App.Windows[CurrentScr].Hwnd)
KeyWait, Space
HidePreviewHighlight()
}
SaveScreenshot(pBitmap, OutFileName, OutputOverride := "") {
Output := OutputOverride = "" ? App.Config.Output : OutputOverride
OutDirectory := App.Config.OutDirectory
Ext := App.Config.Ext
JPEGQuality := App.Config.JPEGQuality
ImgbbSent := false
MissingImgbbClientID := false
if (File := InStr(Output, "File")) {
Critical
IfNotExist, % OutDirectory
{
FileCreateDir, % OutDirectory
if ErrorLevel {
File := ""
MsgBox, 48, Невозможно создать папку
, Невозможно создать папку вывода.`nОшибка %A_LastError%
}
}
if (Result := SaveBitmap(pBitmap, OutDirectory "\" OutFileName "." Ext, JPEGQuality)) {
File := ""
Errors := { 2: "Could not get a list of encoders on system"
, 3: "Could not find matching encoder for specified file format"
, 4: "Could not save file to disk" }
MsgBox, 48, Ошибка записи в файл, % Errors[-Result]
}
}
if Clip := InStr(Output, "Clip")
SetBitmapToClipboard(pBitmap)
if InStr(Output, "Imgbb") {
ClientID := EnsureImgbbClientId()
if (ClientID = "")
MissingImgbbClientID := true
else {
SendImageToImgbb(pBitmap, ClientID)
ImgbbSent := true
}
}
if (App.Config.Notify) {
if File && Clip && ImgbbSent
NotifyText := "Скриншот сохранён в файл,`nпомещён в буфер обмена`nи отправлен на imgbb.com"
else {
NotifyText := "Скриншот "
if File
NotifyText .= (NotifyText = "Скриншот " ? "" : "`nи ") . "сохранён в файл"
if Clip
NotifyText .= (NotifyText = "Скриншот " ? "" : "`nи ") . "помещён в буфер обмена"
if ImgbbSent
NotifyText .= (NotifyText = "Скриншот " ? "" : "`nи ") . "отправлен на imgbb.com"
if MissingImgbbClientID {
if (NotifyText = "Скриншот ")
NotifyText .= "не отправлен на Imgbb!`nВпишите ClientID в " SettingsFileName()
else
NotifyText .= "`nно не отправлен на Imgbb"
}
}
if (NotifyText = "Скриншот ")
NotifyText := MissingImgbbClientID
? "Скриншот не отправлен на Imgbb!`nВпишите ClientID в " SettingsFileName()
: "Скриншот не сохранён!`nУкажите в настройках во вкладке ""Вывод""`nвариант сохранения скриншота!"
new ToolTip({ text: NotifyText, FontSize: 14, FontName: "calibri", TrayTip: true
, TimeOut: -3500, BackColor: 0x0055aa, TextColor: "white"
, Margin: [10, 5, 10, 5] })
}
DllCall("gdiplus\GdipDisposeImage", "Ptr", pBitmap)
}
SendImageToImgbb(pBitmap, apiKey) {
Ext := App.Config.Ext
JPEGQuality := App.Config.JPEGQuality
buff := Ext
if ( (size := SaveBitmap(pBitmap, buff, JPEGQuality, 1)) < 0 ) {
Errors := { 2: "Could not get a list of encoders on system"
, 3: "Could not find matching encoder for specified file format"
, 4: "Не удалось сохранить битмап в буфер" }
MsgBox, 48, Ошибка записи в буфер, % Errors[-size]
return
}
strBase64 := EncodeDecodeURI(CryptBinaryToStringBASE64(&buff, size, 1))
http := ComObjCreate("WinHttp.WinHttpRequest.5.1")
http.open("POST", "https://api.imgbb.com/1/upload", true)
http.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
body := "key=" . apiKey . "&image=" . strBase64
http.send(body)
http.WaitForResponse()
if (http.status != 200)
throw "failed to upload image. Status: " . http.status
responsetext := http.responsetext
RegExMatch(responsetext, """url"":""(.*?)""", match)
link := StrReplace(match1, "\")
Gui, 5: Default
try Gui, Destroy
Gui, Font, s9
Gui, Add, Edit, % "w250 h" . (link ? 24 : 120), % link ? link : responsetext
Gui, Font
Gui, Add, Button, x+-80 y+7 w80 h24 gCopyResponse Default, Copy
GuiControl, Focus, Button1
Gui, Show,, Imgbb.com
VarSetCapacity(strBase64, 0), VarSetCapacity(buff, 0)
}
EncodeDecodeURI(str, encode := true, component := true) {
static document := "", JS := ""
if !document {
document := ComObjCreate("htmlfile")
document.write("<meta http-equiv=""X-UA-Compatible"" content=""IE=9"">")
JS := document.parentWindow
(document.documentMode < 9 && JS.execScript())
}
return JS[(encode ? "en" : "de") . "codeURI" . (component ? "Component" : "")](str)
}
CopyResponse() {
GuiControlGet, Clipboard, 5:, Edit1
Gui, 5: Destroy
}
WM_SHOWWINDOW(wp, lp, msg, hwnd) {
if (hwnd = App.Selection.Hwnd) {
if wp
UpdateSelectionCoordinateWindows()
else
HideSelectionCoordinateWindows()
return
}
if IsOverlaySelectionHwnd(hwnd) || IsSelectionCoordinateWindowHwnd(hwnd)
return
if (A_Gui < 10 || wp || A_Gui = "Imgbb") ; окно показывается — wp = true, скрывается — wp = false
return
; Leaving the preview (save, delete, Esc) also ends its drawing mode
ExitPreviewDrawMode(A_Gui)
Gui, %A_Gui%:Destroy
if IsObject(App.Windows[A_Gui].Canvas)
App.Windows[A_Gui].Canvas.Dispose()
DllCall("gdiplus\GdipDisposeImage", "Ptr", App.Windows[A_Gui].pBM)
App.Windows.Remove(A_Gui, "")
}
WM_COMMAND(info, wp, lp) {
static EN_SETFOCUS := 0x100, EN_KILLFOCUS := 0x200
notify := wp >> 16
if !(notify = EN_SETFOCUS || notify = EN_KILLFOCUS)
return
for k, v in info {
if (v = lp) {
( notify = EN_SETFOCUS && DllCall("HideCaret", "Ptr", v) )
SetStaticColor(v, notify = EN_SETFOCUS ? 0xFECC53 : 0xFFFFFF, 0)
}
}
}
WM_SETCURSOR(info, wp) {
static hCursor, OCR_NORMAL := 32512
( !hCursor && hCursor := LoadCursor(OCR_NORMAL) )
for k, v in info {
if (v = wp)
return DllCall("SetCursor", "Ptr", hCursor)
}
}
; Crosshair over the selection overlay and over previews in drawing mode.
; Only exact hwnd matches are handled; other windows keep their cursors.
WM_APP_SETCURSOR(wParam, lParam, msg, hwnd) {
static hCross := DllCall("LoadCursor", "Ptr", 0, "Ptr", 32515, "Ptr")
if !(IsOverlaySelectionHwnd(hwnd) || IsPreviewDrawHwnd(hwnd))
return
DllCall("SetCursor", "Ptr", hCross)
return true
}
IsOverlaySelectionHwnd(hwnd) {
return hwnd && IsObject(App.Selection.Overlay)
&& IsObject(App.Selection.Overlay.overlay)
&& hwnd = App.Selection.Overlay.overlay.hwnd
}
LoadCursor(cursorId) {
static IMAGE_CURSOR := 2, LR_DEFAULTSIZE := 0x40, LR_SHARED := 0x8000
return DllCall("LoadImage", "Ptr", 0
, "UInt", cursorId
, "UInt", IMAGE_CURSOR
, "Int", 0, "Int", 0
, "UInt", LR_DEFAULTSIZE|LR_SHARED, "Ptr")
}
WM_ESC() {
; In drawing mode Esc cancels the shape being drawn, otherwise leaves the
; mode. Only outside the mode does it close the preview.
if IsPreviewInDrawMode(A_Gui) {
if IsPreviewDragGui(A_Gui)
EndPreviewDrag(false)
else
ExitPreviewDrawMode(A_Gui)
return
}
Gui, %A_Gui%:Cancel
}
WM_WHEEL(wp, lp, msg, hwnd) {
static PrevTime = 0
Critical
App.Windows[A_Gui].Scale := 1 ; значит, размер скриншота изменён
pBitmap := App.Windows[A_Gui].pBM
GetImageDimensions(pBitmap, WidthBM, HeightBM)
RatioBM := WidthBM/HeightBM
SquareBM := WidthBM*HeightBM
WinGetPos, X, Y, W, H, A
DeltaW := Round(W/(!wp ? 10 : 11))
CtrlState := GetKeyState("Ctrl", "P")
DeltaW := !wp ? (CtrlState ? 1 : DeltaW) : -(CtrlState ? 1 : DeltaW)
ResultW := W + DeltaW
ResultH := Round(ResultW/RatioBM)
ResultX := X - (CtrlState ? 0 : Round(DeltaW/2))
ResultY := Y - (CtrlState ? 0 : Round((ResultH - H)/2))
SquareWin := ResultW*ResultH
if (!wp && SquareWin > 13000000) || (wp && SquareWin < 1000 && SquareWin < SquareBM) {
if (A_TickCount - PrevTime > 200) {
SoundBeep
PrevTime := A_TickCount
}
return
}
App.Windows[A_Gui].Canvas.Render(ResultX, ResultY, ResultW, ResultH)
}
GetImageDimensions(pBitmap, ByRef Width, ByRef Height) {
DllCall("gdiplus\GdipGetImageWidth", "Ptr", pBitmap, "UInt*", Width)
DllCall("gdiplus\GdipGetImageHeight", "Ptr", pBitmap, "UInt*", Height)
}
GetVisibleWindowRect(hwnd, ByRef X, ByRef Y, ByRef W, ByRef H) {
static DWMWA_EXTENDED_FRAME_BOUNDS := 9
VarSetCapacity(rect, 16, 0)
if DllCall("dwmapi\DwmGetWindowAttribute", "Ptr", hwnd, "UInt", DWMWA_EXTENDED_FRAME_BOUNDS
, "Ptr", &rect, "UInt", 16)
return false
left := NumGet(rect, 0, "Int")
top := NumGet(rect, 4, "Int")
right := NumGet(rect, 8, "Int")
bottom := NumGet(rect, 12, "Int")
if (right <= left || bottom <= top)
return false
X := left, Y := top, W := right - left, H := bottom - top
return true
}
FillPolygon(pGraphics, pBrush, Points, FillMode=0) {
StringSplit, Points, Points, |
VarSetCapacity(PointF, 8*Points0)
Loop, %Points0%
{
StringSplit, Coord, Points%A_Index%, `,
NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
}
return DllCall("gdiplus\GdipFillPolygon", "Ptr", pGraphics, "Ptr", pBrush, "Ptr", &PointF, "Int", Points0, "Int", FillMode)
}
DrawImage(pGraphics, pBitmap, dx="", dy="", dw="", dh="", sx="", sy="", sw="", sh="") {
if (sx = "" && sy = "" && sw = "" && sh = "") {
if (dx = "" && dy = "" && dw = "" && dh = "") {
sx := dx := 0, sy := dy := 0
GetImageDimensions(pBitmap, sw, sh)
dw := sw, dh := sh
} else {
sx := sy := 0
GetImageDimensions(pBitmap, sw, sh)
}
}
E := DllCall("gdiplus\GdipDrawImageRectRect", "Ptr", pGraphics, "Ptr", pBitmap, "Float", dx, "Float", dy, "Float", dw, "Float", dh
, "Float", sx, "Float", sy, "Float", sw, "Float", sh, "int", 2, "Ptr", 0, "Ptr", 0, "Ptr", 0)
return E
}
BitmapFromScreen(Screen, Cursor, Raster="") {
if (Screen = 0) {
Sysget, x, 76
Sysget, y, 77
Sysget, w, 78
Sysget, h, 79
} else {
StringSplit, S, Screen, |
x := S1, y := S2, w := S3, h := S4
}
chdc := DllCall("CreateCompatibleDC", "Ptr", 0, "Ptr")
VarSetCapacity(bi, 40, 0)
NumPut(w, bi, 4, "UInt"), NumPut(h, bi, 8, "UInt"), NumPut(40, bi, 0, "UInt"), NumPut(1, bi, 12, "UShort")
NumPut(0, bi, 16), NumPut(32, bi, 14, "UShort")
hbm := DllCall("CreateDIBSection", "Ptr" , chdc, "Ptr" , &bi, "UInt" , 0, "Ptr*", 0, "Ptr" , 0, "UInt" , 0, "Ptr")
obm := DllCall("SelectObject", "Ptr", chdc, "Ptr", hbm, "Ptr")
hhdc := DllCall("GetDC", "Ptr", 0, "Ptr")
DllCall("BitBlt", "Ptr", chdc, "Int", 0, "Int", 0, "Int", w, "Int", h, "Ptr", hhdc, "Int", x, "Int", y, "UInt", Raster)
DllCall("ReleaseDC", "Ptr", 0, "Ptr", hhdc)
( Cursor && CaptureCursor(chdc, x, y) )
DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", "Ptr", hbm, "Ptr", 0, "Ptr*", pBitmap)
DllCall("SelectObject", "Ptr", chdc, "Ptr", obm, "Ptr")
DllCall("DeleteObject", "Ptr", hbm)
DllCall("DeleteDC", "Ptr", hhdc)
DllCall("DeleteDC", "Ptr", chdc)
return pBitmap
}
CaptureCursor(hDC, x, y) {
VarSetCapacity(CURSORINFO, szCI := 4*2 + A_PtrSize + 8, 0)
NumPut(szCI, CURSORINFO)
DllCall("GetCursorInfo", "Ptr", &CURSORINFO)
bShow := NumGet(CURSORINFO, 4, "UInt")
hCursor := NumGet(CURSORINFO, 4*2)
xCursor := NumGet(CURSORINFO, 4*2 + A_PtrSize, "Int")
yCursor := NumGet(CURSORINFO, 4*2 + A_PtrSize + 4, "Int")
if bShow && hCursor := DllCall("CopyIcon", "Ptr", hCursor, "Ptr") {
VarSetCapacity(ICONINFO, 4*2 + A_PtrSize*3, 0)
DllCall("GetIconInfo", "Ptr", hCursor, "Ptr", &ICONINFO)
bIcon := NumGet(ICONINFO, "UInt")
xHotspot := NumGet(ICONINFO, 4, "UInt")
yHotspot := NumGet(ICONINFO, 4*2, "UInt")
hBMMask := NumGet(ICONINFO, 4*2 + A_PtrSize)
hBMColor := NumGet(ICONINFO, 4*2 + A_PtrSize*2)
DllCall("DrawIcon", "Ptr", hDC, "Int", xCursor - xHotspot - x, "Int", yCursor - yHotspot - y, "Ptr", hCursor)
DllCall("DestroyIcon", "Ptr", hCursor)
( hBMMask && DllCall("DeleteObject", "Ptr", hBMMask) )
( hBMColor && DllCall("DeleteObject", "Ptr", hBMColor) )
}
}
; Preview save handlers never pass the preview's own pBM to SaveScreenshot:
; SaveScreenshot disposes the bitmap it gets, and pBM is disposed again when
; the preview is hidden (WM_SHOWWINDOW). They always save a fresh composed copy.
ScreenShotMenuHandling() {
CurrentGui := App.Menu.CurrentPreviewGui
Time := App.Windows[CurrentGui].Time
if (A_ThisMenuItem = "Сохранить" || A_ThisMenuItem = "Сохранить в первоначальном размере")
SaveScreenshot(ComposePreviewBitmap(CurrentGui), Time)
else if (A_ThisMenuItem = "Сохранить в текущем размере")
SavePreviewCurrentSize(CurrentGui, Time)
Gui, %CurrentGui%:Cancel
}
PreviewSaveToMenuHandling() {
CurrentGui := App.Menu.CurrentPreviewGui
Time := App.Windows[CurrentGui].Time
Output := PreviewSaveToOutput(A_ThisMenuItem)
if (Output != "")
SaveScreenshot(ComposePreviewBitmap(CurrentGui), Time, Output)
Gui, %CurrentGui%:Cancel
}
PreviewSaveCurrentToMenuHandling() {
CurrentGui := App.Menu.CurrentPreviewGui
Time := App.Windows[CurrentGui].Time
Output := PreviewSaveToOutput(A_ThisMenuItem)
if (Output != "")
SavePreviewCurrentSize(CurrentGui, Time, Output)
Gui, %CurrentGui%:Cancel
}
; Returns a new bitmap at the original capture size built from the preview:
; a copy of the captured image with the shapes drawn on the preview.
; The pixel format of the capture is kept, so saved files do not change.
; The caller owns the result (SaveScreenshot disposes what it is given).
ComposePreviewBitmap(GuiNumber) {
pSource := App.Windows[GuiNumber].pBM
GetImageDimensions(pSource, WidthBM, HeightBM)
SourceFormat := 0, pComposed := 0
DllCall("gdiplus\GdipGetImagePixelFormat", "Ptr", pSource, "UInt*", SourceFormat)
DllCall("gdiplus\GdipCloneBitmapAreaI", "Int", 0, "Int", 0, "Int", WidthBM, "Int", HeightBM
, "UInt", SourceFormat, "Ptr", pSource, "Ptr*", pComposed)
Canvas := App.Windows[GuiNumber].Canvas
if (pComposed && IsObject(Canvas) && Canvas.CanClear()) { ; has visible shapes
pGraphics := 0
DllCall("gdiplus\GdipGetImageGraphicsContext", "Ptr", pComposed, "Ptr*", pGraphics)
DllCall("gdiplus\GdipSetSmoothingMode", "Ptr", pGraphics, "Int", 4) ; AntiAlias
Canvas.DrawShapes(pGraphics)
DllCall("gdiplus\GdipDeleteGraphics", "Ptr", pGraphics)
}
return pComposed
}
;********************************** Drawing on previews **********************************
; Drawing tools in menu order: id is stored in shapes, label is the menu item.
PreviewDrawTools() {
return [ {id: "free", label: "Свободная линия"}
, {id: "line", label: "Линия"}
, {id: "arrow", label: "Стрелка"}
, {id: "rect", label: "Прямоугольник"}
, {id: "ellipse", label: "Эллипс"}
, {id: "marker", label: "Маркер"} ]
}
; Colours offered for every tool (RGB). The marker keeps its own alpha.
PreviewDrawColors() {
return [ {label: "Красный", rgb: 0xFF0000}
, {label: "Оранжевый", rgb: 0xFF8C00}
, {label: "Жёлтый", rgb: 0xFFFF00}
, {label: "Зелёный", rgb: 0x00C000}
, {label: "Голубой", rgb: 0x00B0FF}
, {label: "Синий", rgb: 0x0040FF}
, {label: "Фиолетовый", rgb: 0xA020F0}
, {label: "Чёрный", rgb: 0x000000}
, {label: "Белый", rgb: 0xFFFFFF} ]
}
; Widths in screenshot pixels; the marker uses larger ones
PreviewDrawWidths(Tool) {
if (Tool = "marker")
return [8, 12, 18, 24, 32]
return [1, 2, 3, 5, 8, 12]
}
; Reads the [Drawing] section of the ini; written back by SaveSettings().
InitPreviewDrawing() {
IniPath := IniFilePath()
IniRead, ToolValue, % IniPath, Drawing, Tool, rect
IniRead, PenColorValue, % IniPath, Drawing, PenColor, 0xFFFF0000
IniRead, PenWidthValue, % IniPath, Drawing, PenWidth, 3
IniRead, MarkerColorValue, % IniPath, Drawing, MarkerColor, 0x66FFFF00
IniRead, MarkerWidthValue, % IniPath, Drawing, MarkerWidth, 18
; Current tool; pen and marker colours (ARGB) and widths in screenshot
; pixels. The marker has its own semi-transparent colour and width.
; Drag describes the shape being dragged: {Gui, Hwnd}, or "" when idle.
App.Drawing := {Tool: NormalizeDrawTool(ToolValue)
, Color: NormalizeDrawColor(PenColorValue, 0xFFFF0000)
, Width: NormalizeDrawWidth(PenWidthValue, 3)
, MarkerColor: NormalizeDrawColor(MarkerColorValue, 0x66FFFF00)
, MarkerWidth: NormalizeDrawWidth(MarkerWidthValue, 18)
, Drag: ""}
; Mouse handlers are registered only while a shape is being dragged
App.Drawing.OnMove := Func("PreviewDrawMouseMove")
App.Drawing.OnButtonUp := Func("PreviewDrawButtonUp")
App.Drawing.OnCaptureChanged := Func("PreviewDrawCaptureChanged")
}
NormalizeDrawTool(Value) {
for index, DrawTool in PreviewDrawTools() {
if (DrawTool.id = Value)
return DrawTool.id
}
return "rect"
}
; ARGB from the ini: decimal or 0x... integer with a non-zero alpha
NormalizeDrawColor(Value, DefaultValue) {
if !IsIntegerSetting(Value)
return DefaultValue
Value := Trim(Value) + 0
if (Value > 0xFFFFFFFF || !(Value >> 24))
return DefaultValue
return Value
}
NormalizeDrawWidth(Value, DefaultValue) {
if !IsIntegerSetting(Value)
return DefaultValue
Value := Trim(Value) + 0
return (Value >= 1 && Value <= 100) ? Value : DefaultValue
}
; The colour and width menus edit the marker's own pair when the marker is
; the current tool, otherwise the pen's pair shared by the other tools.
PreviewDrawCurrentColor() {
return App.Drawing.Tool = "marker" ? App.Drawing.MarkerColor : App.Drawing.Color
}
PreviewDrawCurrentWidth() {
return App.Drawing.Tool = "marker" ? App.Drawing.MarkerWidth : App.Drawing.Width
}
; Picking a colour also turns the drawing mode on, like picking a tool
PreviewDrawColorMenuHandling() {
Colors := PreviewDrawColors()
Rgb := Colors[A_ThisMenuItemPos].rgb
; Keep the alpha of the colour being replaced (the marker is semi-transparent)
if (App.Drawing.Tool = "marker")
App.Drawing.MarkerColor := (App.Drawing.MarkerColor & 0xFF000000) | Rgb
else
App.Drawing.Color := (App.Drawing.Color & 0xFF000000) | Rgb
EnterPreviewDrawMode(App.Menu.CurrentPreviewGui)
}
PreviewDrawWidthMenuHandling() {
Widths := PreviewDrawWidths(App.Drawing.Tool)
SetPreviewDrawWidth(Widths[A_ThisMenuItemPos])
EnterPreviewDrawMode(App.Menu.CurrentPreviewGui)
}
SetPreviewDrawWidth(Value) {
if (App.Drawing.Tool = "marker")
App.Drawing.MarkerWidth := Value
else
App.Drawing.Width := Value
}
; Tool menu item: name plus its hotkey (the digit of its position)
PreviewDrawToolItemName(Index, DrawTool) {
return DrawTool.label "`t" Index
}
; Hotkeys of the active preview (see the #if WinActive("ScreenShot ...") block):
; "Mode" - D toggles the drawing mode;
; "Tool", n - 1-6 pick the n-th tool of PreviewDrawTools();
; "Width", +1/-1 - ] and [ step the width through PreviewDrawWidths().
; Like the menu, picking a tool or a width also turns the drawing mode on.
PreviewDrawHotkey(Action, Value := "") {
GuiNumber := PreviewGuiFromHwnd(WinExist("A"))
if !GuiNumber
return
if (Action = "Mode") {
if IsPreviewInDrawMode(GuiNumber) {
ExitPreviewDrawMode(GuiNumber)
ShowPreviewDrawTip("Рисование выключено")
} else {
EnterPreviewDrawMode(GuiNumber)
ShowPreviewDrawTip("Рисование включено")
}
return
}
if (Action = "Tool") {
Tools := PreviewDrawTools()
if !IsObject(Tools[Value])
return
App.Drawing.Tool := Tools[Value].id
ShowPreviewDrawTip(Tools[Value].label)
} else if (Action = "Width") {
StepPreviewDrawWidth(Value)
ShowPreviewDrawTip("Толщина: " PreviewDrawCurrentWidth() " px")
}
EnterPreviewDrawMode(GuiNumber)
}
; Moves the current width to the next larger (Direction > 0) or smaller value
; of the tool's width list. A width that is not in the list (edited ini) moves
; to the nearest list value in that direction; at the end of the list nothing
; changes.
StepPreviewDrawWidth(Direction) {
Widths := PreviewDrawWidths(App.Drawing.Tool)
CurrentWidth := PreviewDrawCurrentWidth()
if (Direction > 0) {
for index, WidthValue in Widths {
if (WidthValue > CurrentWidth) {
SetPreviewDrawWidth(WidthValue)
return
}
}
} else {
Loop % Widths.Length() {
WidthValue := Widths[Widths.Length() - A_Index + 1]
if (WidthValue < CurrentWidth) {
SetPreviewDrawWidth(WidthValue)
return
}
}
}
}
; Short feedback for the drawing hotkeys (there is no toolbar to show the state)
ShowPreviewDrawTip(Text) {
ToolTip, % Text,,, 20
SetTimer, HidePreviewDrawTip, -1000
}
HidePreviewDrawTip() {
ToolTip,,,, 20
}
; The width list depends on the tool, so the submenu is rebuilt (with the
; current width checked) right before a preview menu is shown.
RebuildPreviewDrawWidthMenu() {
static Created := false
if Created
Menu, PreviewDrawWidthMenu, DeleteAll
Created := true
CurrentWidth := PreviewDrawCurrentWidth()
for index, WidthValue in PreviewDrawWidths(App.Drawing.Tool) {
ItemName := WidthValue " px"
Menu, PreviewDrawWidthMenu, Add, % ItemName, PreviewDrawWidthMenuHandling, +Radio
if (WidthValue = CurrentWidth)
Menu, PreviewDrawWidthMenu, Check, % ItemName
}
}
IsPreviewInDrawMode(GuiNumber) {
return IsObject(App.Windows[GuiNumber]) && App.Windows[GuiNumber].DrawMode
}
IsPreviewDrawHwnd(hwnd) {
GuiNumber := PreviewGuiFromHwnd(hwnd)
return GuiNumber && App.Windows[GuiNumber].DrawMode
}
; GUI number of the preview window hwnd, or 0 if hwnd is not a preview
PreviewGuiFromHwnd(hwnd) {
for GuiNumber, WindowData in App.Windows {
if (GuiNumber >= 10 && WindowData.Hwnd = hwnd)
return GuiNumber
}
return 0
}
; Undo and redo are hotkey-only (Ctrl+Z / Ctrl+Y); the menu has only "Clear"
PreviewClearMenuHandling() {
PreviewHistoryAction(App.Menu.CurrentPreviewGui, "Clear")
}
; Ctrl+Z / Ctrl+Y on the active preview
PreviewHistoryHotkey(Action) {
GuiNumber := PreviewGuiFromHwnd(WinExist("A"))
if GuiNumber
PreviewHistoryAction(GuiNumber, Action)
}
; Action: "Undo", "Redo" or "Clear". Ignored while a shape is being dragged.
PreviewHistoryAction(GuiNumber, Action) {
if IsPreviewDragGui(GuiNumber)
return
Canvas := App.Windows[GuiNumber].Canvas
if IsObject(Canvas)
Canvas[Action]()
}
IsPreviewDragGui(GuiNumber) {
return IsObject(App.Drawing.Drag) && App.Drawing.Drag.Gui = GuiNumber
}
PreviewDrawModeMenuHandling() {
CurrentGui := App.Menu.CurrentPreviewGui
if IsPreviewInDrawMode(CurrentGui)
ExitPreviewDrawMode(CurrentGui)
else
EnterPreviewDrawMode(CurrentGui)
}
; Picking a tool also turns the drawing mode on
PreviewDrawToolMenuHandling() {
Tools := PreviewDrawTools()
App.Drawing.Tool := Tools[A_ThisMenuItemPos].id
EnterPreviewDrawMode(App.Menu.CurrentPreviewGui)
}
; The preview menus are shared by all previews, so the checkmarks are set
; from the clicked preview right before the menu is shown.
SyncPreviewDrawMenu(MenuName, GuiNumber) {
Menu, % MenuName, % (IsPreviewInDrawMode(GuiNumber) ? "Check" : "UnCheck"), % App.Menu.PreviewDraw
for index, DrawTool in PreviewDrawTools()
Menu, PreviewDrawToolMenu, % (DrawTool.id = App.Drawing.Tool ? "Check" : "UnCheck")
, % PreviewDrawToolItemName(index, DrawTool)
CurrentRgb := PreviewDrawCurrentColor() & 0xFFFFFF
for index, DrawColor in PreviewDrawColors()
Menu, PreviewDrawColorMenu, % (DrawColor.rgb = CurrentRgb ? "Check" : "UnCheck"), % DrawColor.label
RebuildPreviewDrawWidthMenu()
Canvas := App.Windows[GuiNumber].Canvas
Menu, % MenuName, % (Canvas.CanClear() ? "Enable" : "Disable"), % App.Menu.PreviewClear
}
EnterPreviewDrawMode(GuiNumber) {
WindowData := App.Windows[GuiNumber]
if !IsObject(WindowData) || WindowData.DrawMode
return
WindowData.DrawMode := true
; Keep the render buffers between frames while drawing
WindowData.Canvas.keepBuffers := true
UpdatePreviewCursor(GuiNumber)
}
; Leaves the drawing mode. The shapes stay on the preview and are saved with it.
ExitPreviewDrawMode(GuiNumber) {
WindowData := App.Windows[GuiNumber]
if !IsObject(WindowData) || !WindowData.DrawMode
return
if IsPreviewDragGui(GuiNumber)
EndPreviewDrag(false)
WindowData.DrawMode := false
WindowData.Canvas.keepBuffers := false
WindowData.Canvas.ReleaseBuffers()
UpdatePreviewCursor(GuiNumber)
}
; WM_SETCURSOR only arrives with the next mouse move, so after the drawing mode
; changes the cursor is set right away when the mouse is over this preview.
UpdatePreviewCursor(GuiNumber) {
WindowData := App.Windows[GuiNumber]
if !IsObject(WindowData)
return
MouseGetPos,,, HwndUnderMouse
if (HwndUnderMouse != WindowData.Hwnd)
return
CursorId := WindowData.DrawMode ? 32515 : 32512 ; IDC_CROSS : IDC_ARROW
DllCall("SetCursor", "Ptr", DllCall("LoadCursor", "Ptr", 0, "Ptr", CursorId, "Ptr"))
}
BeginPreviewDrag(GuiNumber, hwnd, lParam) {
if IsObject(App.Drawing.Drag)
return
pt := PreviewClientPoint(lParam)
App.Windows[GuiNumber].Canvas.BeginShape(App.Drawing.Tool
, PreviewDrawCurrentColor(), PreviewDrawCurrentWidth(), pt.x, pt.y)
App.Drawing.Drag := {Gui: GuiNumber, Hwnd: hwnd}
OnMessage(0x200, App.Drawing.OnMove) ; WM_MOUSEMOVE
OnMessage(0x202, App.Drawing.OnButtonUp) ; WM_LBUTTONUP
OnMessage(0x215, App.Drawing.OnCaptureChanged) ; WM_CAPTURECHANGED
DllCall("SetCapture", "Ptr", hwnd)
}
; Ends the current drag: Commit keeps the shape, otherwise it is discarded.
EndPreviewDrag(Commit) {
Drag := App.Drawing.Drag
if !IsObject(Drag)
return
; Clear the state first: ReleaseCapture sends WM_CAPTURECHANGED synchronously
App.Drawing.Drag := ""
OnMessage(0x200, App.Drawing.OnMove, 0)
OnMessage(0x202, App.Drawing.OnButtonUp, 0)
OnMessage(0x215, App.Drawing.OnCaptureChanged, 0)
if (DllCall("GetCapture", "Ptr") = Drag.Hwnd)
DllCall("ReleaseCapture")
Canvas := App.Windows[Drag.Gui].Canvas
if !IsObject(Canvas)
return
if Commit
Canvas.CommitShape()
else
Canvas.CancelShape()
}
PreviewDrawMouseMove(wParam, lParam, msg, hwnd) {
Drag := App.Drawing.Drag
if (!IsObject(Drag) || hwnd != Drag.Hwnd)
return
pt := PreviewClientPoint(lParam)
App.Windows[Drag.Gui].Canvas.UpdateShape(pt.x, pt.y, GetKeyState("Shift", "P"))
}
PreviewDrawButtonUp(wParam, lParam, msg, hwnd) {
Drag := App.Drawing.Drag
if (!IsObject(Drag) || hwnd != Drag.Hwnd)
return
pt := PreviewClientPoint(lParam)
App.Windows[Drag.Gui].Canvas.UpdateShape(pt.x, pt.y, GetKeyState("Shift", "P"))
EndPreviewDrag(true)
return 0
}
; The capture was taken away (another window, Alt+Tab): keep what was drawn
PreviewDrawCaptureChanged(wParam, lParam, msg, hwnd) {
Drag := App.Drawing.Drag
if (!IsObject(Drag) || hwnd != Drag.Hwnd)
return
EndPreviewDrag(true)
}
; Client coordinates from a mouse message lParam (signed: with the mouse
; captured they can be outside the window).
PreviewClientPoint(lParam) {
x := lParam & 0xFFFF
y := (lParam >> 16) & 0xFFFF
if (x > 0x7FFF)
x -= 0x10000
if (y > 0x7FFF)
y -= 0x10000
return {x: x, y: y}
}
SavePreviewCurrentSize(CurrentGui, Time, OutputOverride := "") {
pSource := ComposePreviewBitmap(CurrentGui)
WinGetPos,,, W, H, % "ahk_id " App.Windows[CurrentGui].Hwnd
DllCall("gdiplus\GdipCreateBitmapFromScan0", "Int", W, "Int", H, "Int", 0, "Int", 0x26200A, "Ptr", 0, "Ptr*", pBM)
DllCall("gdiplus\GdipGetImageGraphicsContext", "Ptr", pBM, "Ptr*", G)
DllCall("gdiplus\GdipSetInterpolationMode", "Ptr", G, "Int", App.Config.InterpolationMode-1)
GetImageDimensions(pSource, WidthBM, HeightBM)
DrawImage(G, pSource, -Round(W/400), -Round(H/400)
, Ceil(W*1.005), Ceil(H*1.005), 0, 0, WidthBM, HeightBM)
DllCall("gdiplus\GdipDeleteGraphics", "Ptr", G)
DllCall("gdiplus\GdipDisposeImage", "Ptr", pSource)
SaveScreenshot(pBM, Time, OutputOverride)
}
PreviewSaveToOutput(MenuItem) {
if (MenuItem = "файл")
return "File"
if (MenuItem = "буфер обмена")
return "Clip"
if (MenuItem = "imgbb.com")
return "Imgbb"
return ""
}
SaveBitmap(pBitmap, ByRef info, Quality := 75, tobuff := "") {
if tobuff
Extension := info
else
SplitPath, info,,, Extension
if Extension not in BMP,DIB,RLE,JPG,JPEG,JPE,JFIF,GIF,TIF,TIFF,PNG
return -1
DllCall("gdiplus\GdipGetImageEncodersSize", "UInt*", nCount, "UInt*", nSize)
VarSetCapacity(ci, nSize)
DllCall("gdiplus\GdipGetImageEncoders", "UInt", nCount, "UInt", nSize, "Ptr", &ci)
if !(nCount && nSize)
return -2
Loop, % nCount {
sString := StrGet(NumGet(ci, (idx := (48+7*A_PtrSize)*(A_Index-1))+32+3*A_PtrSize), "UTF-16")
if !InStr(sString, "*." Extension)
continue
pCodec := &ci+idx
break
}
if !pCodec
return -3
if RegExMatch(Extension, "i)^J(PG|PEG|PE|FIF)$") && Quality != 75 {
DllCall("gdiplus\GdipGetEncoderParameterListSize", "Ptr", pBitmap, "Ptr", pCodec, "UInt*", nSize)
VarSetCapacity(EncoderParameters, nSize, 0)
DllCall("gdiplus\GdipGetEncoderParameterList", "Ptr", pBitmap, "Ptr", pCodec, "UInt", nSize, "Ptr", &EncoderParameters)
Loop, % NumGet(EncoderParameters, "UInt") {
elem := (24+A_PtrSize)*(A_Index-1) + 4 + (pad := A_PtrSize = 8 ? 4 : 0)
if (NumGet(EncoderParameters, elem+16, "UInt") = 1) && (NumGet(EncoderParameters, elem+20, "UInt") = 6) {
p := elem+&EncoderParameters-pad-4
NumPut(Quality, NumGet(NumPut(4, NumPut(1, p+0)+20, "UInt")), "UInt")
break
}
}
}
if !tobuff {
if A_IsUnicode
pOutput := &info
else {
VarSetCapacity(wOutput, StrPut(info, "UTF-16")*2, 0)
StrPut(info, &wOutput, "UTF-16")
pOutput := &wOutput
}
E := DllCall("gdiplus\GdipSaveImageToFile", "Ptr", pBitmap, "Ptr", pOutput, "Ptr", pCodec, "UInt", p ? p : 0)
}
else {
DllCall( "ole32\CreateStreamOnHGlobal", "UInt", 0, "Int", 1, "Ptr*", pStream )
if E := DllCall( "gdiplus\GdipSaveImageToStream", "Ptr", pBitmap, "Ptr", pStream, "Ptr", pCodec, "UInt", p ? p : 0 )
DllCall( NumGet( NumGet( 1*pStream ) + A_PtrSize*2 ), "Ptr", pStream )
else {
DllCall( "ole32\GetHGlobalFromStream", "Ptr", pStream, "Ptr*", hData )
pData := DllCall( "GlobalLock", "Ptr", hData )
nSize := DllCall( "GlobalSize", "Ptr", hData )
VarSetCapacity( info, 0), VarSetCapacity( info, nSize, 0 )
DllCall( "RtlMoveMemory", "Ptr", &info, "Ptr", pData, "UInt", nSize )
DllCall( "GlobalUnlock", "Ptr", hData )
DllCall( NumGet( NumGet( 1*pStream ) + A_PtrSize*2 ), "Ptr", pStream )
DllCall( "GlobalFree", "Ptr", hData )
}
}
return E ? -4 : tobuff ? nSize : 0
}
SetBitmapToClipboard(pBitmap) {
off1 := A_PtrSize = 8 ? 52 : 44, off2 := A_PtrSize = 8 ? 32 : 24
DllCall("gdiplus\GdipCreateHBITMAPFromBitmap", "Ptr", pBitmap, "Ptr*", hBitmap, "Int", 0xFFFFFFFF)
DllCall("GetObject", "Ptr", hBitmap, "int", VarSetCapacity(oi, A_PtrSize = 8 ? 104 : 84, 0), "Ptr", &oi)
hdib := DllCall("GlobalAlloc", "UInt", 2, "Ptr", 40+NumGet(oi, off1, "UInt"), "Ptr")
pdib := DllCall("GlobalLock", "Ptr", hdib, "Ptr")
DllCall("RtlMoveMemory", "Ptr", pdib, "Ptr", &oi+off2, "Ptr", 40)
DllCall("RtlMoveMemory", "Ptr", pdib+40, "Ptr", NumGet(oi, off2 - A_PtrSize, "Ptr"), "Ptr", NumGet(oi, off1, "UInt"))
DllCall("GlobalUnlock", "Ptr", hdib)
DllCall("DeleteObject", "Ptr", hBitmap)
DllCall("OpenClipboard", "Ptr", 0)
DllCall("EmptyClipboard")
DllCall("SetClipboardData", "UInt", 8, "Ptr", hdib)
DllCall("CloseClipboard")
}
CreateDIBSection(w, h, hdc="", bpp=32, ByRef ppvBits=0) {
hdc2 := hdc ? hdc : DllCall("GetDC", "Ptr", 0)
VarSetCapacity(bi, 40, 0)
NumPut(w, bi, 4, "uint")
NumPut(h, bi, 8, "uint")
NumPut(40, bi, 0, "uint")
NumPut(1, bi, 12, "ushort")
NumPut(0, bi, 16, "uInt")
NumPut(bpp, bi, 14, "ushort")
hbm := DllCall("CreateDIBSection", "Ptr", hdc2, "Ptr", &bi, "UInt", 0, "Ptr*", ppvBits, "Ptr", 0, "UInt", 0, "Ptr")
( !hdc && DllCall("ReleaseDC", "Ptr", 0, "Ptr", hdc2) )
return hbm
}
UpdateLayeredWindow(hwnd, hdc, x="", y="", w="", h="", Alpha=255) {
if ((x != "") && (y != ""))
VarSetCapacity(pt, 8), NumPut(x, pt, 0, "UInt"), NumPut(y, pt, 4, "UInt")
if (w = "") ||(h = "")
WinGetPos,,, w, h, ahk_id %hwnd%
return DllCall( "UpdateLayeredWindow", "Ptr", hwnd, "Ptr", 0, "Ptr", ((x = "") && (y = "")) ? 0 : &pt, "Int64*", w|h<<32
, "Ptr", hdc, "Int64*", 0, "UInt", 0, "UInt*", Alpha<<16|1<<24, "UInt", 2 )
}
GdipStartup() {
if !DllCall("GetModuleHandle", "Str", "gdiplus", "Ptr")
DllCall("LoadLibrary", "Str", "gdiplus")
VarSetCapacity(si, A_PtrSize = 8 ? 24 : 16, 0), si := Chr(1)
DllCall("gdiplus\GdiplusStartup", "Ptr*", pToken, "Ptr", &si, "Ptr", 0)
return pToken
}
GdipShutdown(pToken) {
DllCall("gdiplus\GdiplusShutdown", "Ptr", pToken)
if hModule := DllCall("GetModuleHandle", "Str", "gdiplus", "Ptr")
DllCall("FreeLibrary", "Ptr", hModule)
return 0
}
SetStaticColor(hStatic, b_color, f_color := 0) {
static arr := [], GWL_WNDPROC := -4
b_color := DllCall("Ws2_32\ntohl", "UInt", b_color << 8, "UInt")
f_color := DllCall("Ws2_32\ntohl", "UInt", f_color << 8, "UInt")
hGui := DllCall("GetParent", "Ptr", hStatic, "Ptr")
if !arr.HasKey(hGui) {
arr[hGui] := {}, arr[hGui].Statics := []
arr[hGui].ProcOld := DllCall("SetWindowLong" . (A_PtrSize = 8 ? "Ptr" : ""), "Ptr", hGui, "Int", GWL_WNDPROC
, "Ptr", RegisterCallback("WindowProc", "", 4, Object(arr[hGui])), "Ptr")
}
else if arr[hGui].Statics.HasKey(hStatic)
DllCall("DeleteObject", "Ptr", arr[hGui].Statics[hStatic].hBrush)
arr[hGui].Statics[hStatic] := { b_color: b_color, f_color: f_color
, hBrush: DllCall("CreateSolidBrush", "UInt", b_color, "Ptr") }
WinSet, Redraw,, ahk_id %hStatic%
}
WindowProc(hwnd, uMsg, wParam, lParam) {
Critical
static WM_CTLCOLORSTATIC := 0x138
obj := Object(A_EventInfo)
if (uMsg = WM_CTLCOLORSTATIC && k := obj.Statics[lParam]) {
DllCall("SetBkColor", "Ptr", wParam, "UInt", k.b_color)
DllCall("SetTextColor", "Ptr", wParam, "UInt", k.f_color)
return k.hBrush
}
return DllCall("CallWindowProc", "Ptr", obj.ProcOld, "Ptr", hwnd, "UInt", uMsg, "Ptr", wParam, "Ptr", lParam)
}
CryptBinaryToStringBASE64(pData, Bytes, NOCRLF = "") {
static CRYPT_STRING_BASE64 := 1, CRYPT_STRING_NOCRLF := 0x40000000
CRYPT := CRYPT_STRING_BASE64 | (NOCRLF ? CRYPT_STRING_NOCRLF : 0)
DllCall("Crypt32\CryptBinaryToString", "Ptr", pData, "UInt", Bytes, "UInt", CRYPT, "Ptr", 0, "UInt*", Chars)
VarSetCapacity(OutData, Chars * (A_IsUnicode ? 2 : 1))
DllCall("Crypt32\CryptBinaryToString", "Ptr", pData, "UInt", Bytes, "UInt", CRYPT, "Str", OutData, "UInt*", Chars)
return OutData
}
CreateIconFromBase64(StringBASE64, Size) {
DllCall("Crypt32.dll\CryptStringToBinary", "Ptr", &StringBase64
, "UInt", StrLen(StringBase64), "UInt", CRYPT_STRING_BASE64 := 1, "UInt", 0, "UInt*", Bytes, "UInt*", 0, "UInt*", 0)
VarSetCapacity(IconData, Bytes)
DllCall("Crypt32.dll\CryptStringToBinary", "Ptr", &StringBase64
, "UInt", StrLen(StringBase64), "UInt", CRYPT_STRING_BASE64, "Str", IconData, "UInt*", Bytes, "UInt*", 0, "UInt*", 0)
return DllCall("CreateIconFromResourceEx", "Ptr", &IconData + 4
, "UInt", NumGet(&IconData, "UInt"), "UInt", true, "UInt", 0x30000, "Int", Size, "Int", Size, "UInt", 0, "Ptr")
}
GetBase64String(Size) {
Icon16 =
(RTrim Join
aAQAACgAAAAQAAAAIAAAAAEAIAAAAAAAQAQAAAAAAAAAAAAAAAAAAAAAAAD///+3
////////////////////////////////////////////////////////////////
//////////////+3/////8H2/v865Pz/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/zLi/P+u9P7///////////8w4vz/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/H+D8////////////
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P///////////xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z///////////8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8////////////
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P///////////xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z///////////8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8////////////
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P///////////xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z///////////8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8////////////
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P///////////zDi/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8f4Pz////////////G9/7/Sub9/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P9A5Pz/tPT+//////////+3
////////////////////////////////////////////////////////////////
//////////////+3AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==
)
Icon32 =
(RTrim Join
qBAAACgAAAAgAAAAQAAAAAEAIAAAAAAAgBAAAAAAAAAAAAAAAAAAAAAAAAC9vr5avb6+5L2+vv+9vr7/vb6+/72+vv+9vr7/vb6+/72+vv+9vr7/vb6+/72+vv+9vr7/
vb6+/72+vv+9vr7/vb6+/72+vv+9vr7/vb6+/72+vv+9vr7/vb6+/72+vv+9vr7/vb6+/72+vv+9vr7/vb6+/72+vv+9vr7kvb6+Wr2+vvO9vr7/vb6+/72+vv+9vr7/
vb6+/72+vv+9vr7/vb6+/72+vv+9vr7/vb6+/72+vv+9vr7/vb6+/72+vv+9vr7/vb6+/72+vv+9vr7/vb6+/72+vv+9vr7/vb6+/72+vv+9vr7/vb6+/72+vv+9vr7/
vb6+/72+vv+9vr7zvb6+/72+vv+LyNH/Ldv1/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/y3b9f+LyNH/vb6+/72+vv+9vr7/vb6+/ybd+P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/ybd+P+9vr7/vb6+/72+vv+zwML/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/7PAwv+9vr7/vb6+/7PAwv8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/s8DC/72+vv+9vr7/s8DC/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P+zwML/vb6+/72+vv+zwML/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/7PAwv+9vr7/vb6+/7PAwv8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/s8DC/72+vv+9vr7/s8DC/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P+zwML/vb6+/72+vv+zwML/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/7PAwv+9vr7/vb6+/7PAwv8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/s8DC/72+vv+9vr7/s8DC/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P+zwML/vb6+/72+vv+zwML/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/7PAwv+9vr7/vb6+/7PAwv8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/s8DC/72+vv+9vr7/s8DC/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P+zwML/vb6+/72+vv+zwML/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/7PAwv+9vr7/vb6+/7PAwv8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/s8DC/72+vv+9vr7/s8DC/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P+zwML/vb6+/72+vv+zwML/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/7PAwv+9vr7/vb6+/7PAwv8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/s8DC/72+vv+9vr7/s8DC/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P+zwML/vb6+/72+vv+zwML/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/7PAwv+9vr7/vb6+/7PAwv8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/s8DC/72+vv+9vr7/s8DC/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P+zwML/vb6+/72+vv+zwML/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/7PAwv+9vr7/vb6+/7PAwv8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/s8DC/72+vv+9vr7/s8DC/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P+zwML/vb6+/72+vv+9vr7/Jt34/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/
Jt34/72+vv+9vr7/vb6+/72+vv+NyND/O9jw/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/
Gt/8/xrf/P8a3/z/Gt/8/xrf/P8a3/z/Gt/8/zvY8P+NyND/vb6+/72+vv+9vr72vb6+/72+vv+9vr7/vb6+/72+vv+9vr7/vb6+/72+vv+9vr7/vb6+/72+vv+9vr7/
vb6+/72+vv+9vr7/vb6+/72+vv+9vr7/vb6+/72+vv+9vr7/vb6+/72+vv+9vr7/vb6+/72+vv+9vr7/vb6+/72+vv+9vr7/vb6+9r2+vmC9vr7wvb6+/72+vv+9vr7/
vb6+/72+vv+9vr7/vb6+/72+vv+9vr7/vb6+/72+vv+9vr7/vb6+/72+vv+9vr7/vb6+/72+vv+9vr7/vb6+/72+vv+9vr7/vb6+/72+vv+9vr7/vb6+/72+vv+9vr7/
vb6+/72+vvC9vr5gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
)
return Icon%Size%
}
; Renders a screenshot preview into its layered window and keeps the shapes
; drawn on it. One instance per preview, stored in App.Windows[i].Canvas; the
; preview's pBM stays owned by the window (disposed in WM_SHOWWINDOW), the
; canvas only reads it.
;
; Shapes are stored in screenshot (bitmap) pixels, so they follow the preview
; when it is resized with the wheel and are saved at the original size. On
; screen they are drawn through a GDI+ world transform (window / bitmap size).
;
; Buffers are sized to the window in physical pixels:
; baked - the scaled capture plus committed shapes;
; frame - baked copy plus the shape being dragged (only while dragging).
; By default the buffers are released right after each render, so idle
; previews hold no extra memory; keepBuffers = true keeps them (drawing mode).
class PreviewCanvas {
__New(hwnd, pBitmap) {
this.hwnd := hwnd
this.pBitmap := pBitmap
GetImageDimensions(pBitmap, WidthBM, HeightBM)
this.bitmapW := WidthBM
this.bitmapH := HeightBM
this.keepBuffers := false
; Linear history: shapes and {type: "clear"} markers; only the shapes
; after the last marker are visible. Undo moves entries to redoStack.
this.shapes := []
this.redoStack := []
this.current := ""
this.w := 0
this.h := 0
this.baked := ""
this.frame := ""
}
; Draws the capture with its shapes scaled to w x h and shows it at screen
; position x, y. All values are physical pixels, as UpdateLayeredWindow expects.
Render(x, y, w, h) {
this.EnsureBaked(w, h)
this.Bake()
this.Present(x, y)
if !this.keepBuffers
this.ReleaseBuffers()
}
; Rebuilds the baked buffer for the current window size if it is missing
; (released outside the drawing mode) or the window size has changed.
Prepare() {
WinGetPos,,, w, h, % "ahk_id " this.hwnd
if (IsObject(this.baked) && this.w = w && this.h = h)
return
this.EnsureBaked(w, h)
this.Bake()
}
EnsureBaked(w, h) {
if (IsObject(this.baked) && this.w = w && this.h = h)
return
this.ReleaseBuffers()
this.baked := this.CreateBuffer(w, h)
this.w := w
this.h := h
}
Bake() {
G := this.baked.G
DllCall("gdiplus\GdipGraphicsClear", "Ptr", G, "UInt", 0)
; At the original size no resampling is needed, so keep GDI+'s default
; mode there; otherwise use the interpolation chosen in the menu.
if (this.w = this.bitmapW && this.h = this.bitmapH)
Mode := 0
else
Mode := App.Config.InterpolationMode - 1
DllCall("gdiplus\GdipSetInterpolationMode", "Ptr", G, "Int", Mode)
DrawImage(G, this.pBitmap, 0, 0, this.w, this.h, 0, 0, this.bitmapW, this.bitmapH)
this.DrawShapesScaled(G, this.VisibleShapes())
}
; Re-renders at the current window position and size (after history changes)
Refresh() {
WinGetPos, x, y, w, h, % "ahk_id " this.hwnd
if (w = "" || h = "")
return
this.Render(x, y, w, h)
}
; Puts the baked image on screen, with the shape being dragged on top.
; x, y: new window position, or "" to keep the current one.
Present(x := "", y := "") {
if !IsObject(this.baked)
return
hdc := this.baked.hdc
if IsObject(this.current) {
if !(IsObject(this.frame) && this.frame.w = this.w && this.frame.h = this.h) {
this.FreeBuffer(this.frame)
this.frame := this.CreateBuffer(this.w, this.h)
}
DllCall("BitBlt", "Ptr", this.frame.hdc, "Int", 0, "Int", 0, "Int", this.w, "Int", this.h
, "Ptr", this.baked.hdc, "Int", 0, "Int", 0, "UInt", 0x00CC0020) ; SRCCOPY
this.DrawShapesScaled(this.frame.G, [this.current])
hdc := this.frame.hdc
}
UpdateLayeredWindow(this.hwnd, hdc, x, y, this.w, this.h)
}
; --- shape being dragged; x, y are client coordinates of the window -----
BeginShape(tool, color, width, x, y) {
this.Prepare()
bx := this.ToBitmapX(x)
by := this.ToBitmapY(y)
if this.IsStroke(tool)
this.current := {type: tool, color: color, width: width
, points: [bx, by], lastX: x, lastY: y}
else
this.current := {type: tool, color: color, width: width
, x1: bx, y1: by, x2: bx, y2: by}
this.Present()
}
; constrain: Shift is held (see ConstrainEnd)
UpdateShape(x, y, constrain := false) {
shape := this.current
if !IsObject(shape)
return
if (constrain && shape.type = "marker") {
; Shift: a straight horizontal marker stroke from the start point
shape.points := [shape.points[1], shape.points[2], this.ToBitmapX(x), shape.points[2]]
shape.lastX := x
shape.lastY := y
} else if this.IsStroke(shape.type) {
; Skip points closer than 2 logical pixels on screen to the previous one
MinStep := Round(2 * A_ScreenDPI / 96)
if (Abs(x - shape.lastX) < MinStep && Abs(y - shape.lastY) < MinStep)
return
shape.points.Push(this.ToBitmapX(x), this.ToBitmapY(y))
shape.lastX := x
shape.lastY := y
} else {
x2 := this.ToBitmapX(x)
y2 := this.ToBitmapY(y)
if constrain
this.ConstrainEnd(shape, x2, y2)
shape.x2 := x2
shape.y2 := y2
}
this.Present()
}
; Shift: lines and arrows snap to multiples of 45 degrees, rectangles and
; ellipses become squares and circles. Works in bitmap coordinates.
ConstrainEnd(shape, ByRef x2, ByRef y2) {
dx := x2 - shape.x1
dy := y2 - shape.y1
sx := dx < 0 ? -1 : 1
sy := dy < 0 ? -1 : 1
if (shape.type = "line" || shape.type = "arrow") {
; tan(22.5 deg) = 0.4142: within 22.5 degrees of an axis snaps to it
if (Abs(dy) <= Abs(dx) * 0.4142) {
y2 := shape.y1
} else if (Abs(dx) <= Abs(dy) * 0.4142) {
x2 := shape.x1
} else {
d := (Abs(dx) + Abs(dy)) / 2
x2 := shape.x1 + sx * d
y2 := shape.y1 + sy * d
}
} else if (shape.type = "rect" || shape.type = "ellipse") {
d := Max(Abs(dx), Abs(dy))
x2 := shape.x1 + sx * d
y2 := shape.y1 + sy * d
}
}
CommitShape() {
shape := this.current
this.current := ""
if this.IsShapeValid(shape) {
this.shapes.Push(shape)
this.redoStack := []
if IsObject(this.baked)
this.DrawShapesScaled(this.baked.G, [shape])
}
this.Present()
}
CancelShape() {
this.current := ""
this.Present()
}
; --- history -------------------------------------------------------------
; Shapes after the last "clear" marker
VisibleShapes() {
First := 1
Loop % this.shapes.Length() {
if (this.shapes[A_Index].type = "clear")
First := A_Index + 1
}
Result := []
Loop % this.shapes.Length() - First + 1
Result.Push(this.shapes[First + A_Index - 1])
return Result
}
CanUndo() {
return this.shapes.Length() > 0
}
CanRedo() {
return this.redoStack.Length() > 0
}
CanClear() {
return this.VisibleShapes().Length() > 0
}
Undo() {
if (!this.CanUndo() || IsObject(this.current))
return
this.redoStack.Push(this.shapes.Pop())
this.Refresh()
}
Redo() {
if (!this.CanRedo() || IsObject(this.current))
return
this.shapes.Push(this.redoStack.Pop())
this.Refresh()
}
; Clearing is a history step too, so it can be undone
Clear() {
if (!this.CanClear() || IsObject(this.current))
return
this.shapes.Push({type: "clear"})
this.redoStack := []
this.Refresh()
}
IsShapeValid(shape) {
if !IsObject(shape)
return false
; Strokes need two different points (a Shift marker stroke may have
; its end right on the start point)
if this.IsStroke(shape.type)
return shape.points.Length() >= 4
&& (shape.points[1] != shape.points[3] || shape.points[2] != shape.points[4])
; Ignore accidental clicks: at least 2 screenshot pixels in size
dx := Abs(shape.x2 - shape.x1)
dy := Abs(shape.y2 - shape.y1)
if (shape.type = "line" || shape.type = "arrow")
return Max(dx, dy) >= 2
return dx >= 2 && dy >= 2
}
; Shapes made of a list of points rather than two corners
IsStroke(type) {
return type = "free" || type = "marker"
}
; Client coordinates (clamped to the window) -> bitmap coordinates
ToBitmapX(x) {
return Max(0, Min(x, this.w)) * this.bitmapW / this.w
}
ToBitmapY(y) {
return Max(0, Min(y, this.h)) * this.bitmapH / this.h
}
; --- drawing shapes ------------------------------------------------------
; Visible shapes in bitmap coordinates, without scaling (for saving).
DrawShapes(G) {
for index, shape in this.VisibleShapes()
this.DrawShape(G, shape)
}
; Shapes onto a window-sized buffer: bitmap coordinates scaled to the window.
DrawShapesScaled(G, shapeList) {
if !shapeList.Length()
return
DllCall("gdiplus\GdipScaleWorldTransform", "Ptr", G
, "Float", this.w / this.bitmapW, "Float", this.h / this.bitmapH, "Int", 0)
for index, shape in shapeList
this.DrawShape(G, shape)
DllCall("gdiplus\GdipResetWorldTransform", "Ptr", G)
}
DrawShape(G, shape) {
pPen := 0
; UnitWorld (0): the pen width scales together with the shape
DllCall("gdiplus\GdipCreatePen1", "UInt", shape.color, "Float", shape.width, "Int", 0, "Ptr*", pPen)
if !pPen
return
if (shape.type = "rect") {
DllCall("gdiplus\GdipDrawRectangle", "Ptr", G, "Ptr", pPen
, "Float", Min(shape.x1, shape.x2), "Float", Min(shape.y1, shape.y2)
, "Float", Abs(shape.x2 - shape.x1), "Float", Abs(shape.y2 - shape.y1))
} else if (shape.type = "ellipse") {
DllCall("gdiplus\GdipDrawEllipse", "Ptr", G, "Ptr", pPen
, "Float", Min(shape.x1, shape.x2), "Float", Min(shape.y1, shape.y2)
, "Float", Abs(shape.x2 - shape.x1), "Float", Abs(shape.y2 - shape.y1))
} else if (shape.type = "line") {
DllCall("gdiplus\GdipSetPenStartCap", "Ptr", pPen, "Int", 2) ; LineCapRound
DllCall("gdiplus\GdipSetPenEndCap", "Ptr", pPen, "Int", 2) ; LineCapRound
DllCall("gdiplus\GdipDrawLine", "Ptr", G, "Ptr", pPen
, "Float", shape.x1, "Float", shape.y1, "Float", shape.x2, "Float", shape.y2)
} else if (shape.type = "arrow") {
this.DrawArrow(G, pPen, shape)
} else if this.IsStroke(shape.type) {
; One DrawLines call for the whole stroke: GDI+ fills the widened
; outline once, so a semi-transparent marker does not get darker
; where the stroke crosses itself or where segments meet.
PointCount := shape.points.Length() // 2
VarSetCapacity(PointsF, 8 * PointCount, 0)
Loop % PointCount {
NumPut(shape.points[2 * A_Index - 1], PointsF, 8 * (A_Index - 1), "Float")
NumPut(shape.points[2 * A_Index], PointsF, 8 * (A_Index - 1) + 4, "Float")
}
; Round ends for the pen, flat ends for the marker
LineCap := (shape.type = "marker") ? 0 : 2 ; LineCapFlat : LineCapRound
DllCall("gdiplus\GdipSetPenStartCap", "Ptr", pPen, "Int", LineCap)
DllCall("gdiplus\GdipSetPenEndCap", "Ptr", pPen, "Int", LineCap)
DllCall("gdiplus\GdipSetPenLineJoin", "Ptr", pPen, "Int", 2) ; LineJoinRound
DllCall("gdiplus\GdipDrawLines", "Ptr", G, "Ptr", pPen, "Ptr", &PointsF, "Int", PointCount)
}
DllCall("gdiplus\GdipDeletePen", "Ptr", pPen)
}
; Arrow from (x1, y1) to (x2, y2). The head is a filled triangle and the
; shaft stops at its base, so the tip stays sharp at any pen width (a pen
; end cap would round it off). The head grows with the pen width and is
; shortened to the arrow length for very short arrows.
DrawArrow(G, pPen, shape) {
dx := shape.x2 - shape.x1
dy := shape.y2 - shape.y1
ArrowLen := Sqrt(dx * dx + dy * dy)
if (ArrowLen < 1)
return
HeadLen := Min(10 + 4 * shape.width, ArrowLen)
HalfWidth := HeadLen * 0.35 ; about 39 degrees at the tip
ux := dx / ArrowLen ; unit vector along the arrow
uy := dy / ArrowLen
BaseX := shape.x2 - ux * HeadLen ; centre of the head base
BaseY := shape.y2 - uy * HeadLen
; The shaft goes half a pen width into the head to hide the antialiased
; seam between them (the pen colours are opaque, so no darker overlap).
ShaftLen := ArrowLen - HeadLen + Min(shape.width / 2, HeadLen)
DllCall("gdiplus\GdipSetPenStartCap", "Ptr", pPen, "Int", 2) ; LineCapRound
DllCall("gdiplus\GdipSetPenEndCap", "Ptr", pPen, "Int", 0) ; LineCapFlat
DllCall("gdiplus\GdipDrawLine", "Ptr", G, "Ptr", pPen
, "Float", shape.x1, "Float", shape.y1
, "Float", shape.x1 + ux * ShaftLen, "Float", shape.y1 + uy * ShaftLen)
VarSetCapacity(HeadPoints, 24, 0)
NumPut(shape.x2, HeadPoints, 0, "Float")
NumPut(shape.y2, HeadPoints, 4, "Float")
NumPut(BaseX - uy * HalfWidth, HeadPoints, 8, "Float")
NumPut(BaseY + ux * HalfWidth, HeadPoints, 12, "Float")
NumPut(BaseX + uy * HalfWidth, HeadPoints, 16, "Float")
NumPut(BaseY - ux * HalfWidth, HeadPoints, 20, "Float")
pBrush := 0
DllCall("gdiplus\GdipCreateSolidFill", "UInt", shape.color, "Ptr*", pBrush)
DllCall("gdiplus\GdipFillPolygon", "Ptr", G, "Ptr", pBrush, "Ptr", &HeadPoints, "Int", 3, "Int", 0)
DllCall("gdiplus\GdipDeleteBrush", "Ptr", pBrush)
}
; --- buffers -------------------------------------------------------------
CreateBuffer(w, h) {
buf := {w: w, h: h}
buf.hbm := CreateDIBSection(w, h)
buf.hdc := DllCall("CreateCompatibleDC", "Ptr", 0, "Ptr")
buf.oldBm := DllCall("SelectObject", "Ptr", buf.hdc, "Ptr", buf.hbm, "Ptr")
pGraphics := 0
DllCall("gdiplus\GdipCreateFromHDC", "Ptr", buf.hdc, "Ptr*", pGraphics)
DllCall("gdiplus\GdipSetSmoothingMode", "Ptr", pGraphics, "Int", 4) ; AntiAlias, for shapes
buf.G := pGraphics
return buf
}
FreeBuffer(buf) {
if !IsObject(buf)
return
if (buf.G)
DllCall("gdiplus\GdipDeleteGraphics", "Ptr", buf.G)
if (buf.hdc) {
DllCall("SelectObject", "Ptr", buf.hdc, "Ptr", buf.oldBm)
DllCall("DeleteDC", "Ptr", buf.hdc)
}
if (buf.hbm)
DllCall("DeleteObject", "Ptr", buf.hbm)
}
ReleaseBuffers() {
this.FreeBuffer(this.baked)
this.FreeBuffer(this.frame)
this.baked := ""
this.frame := ""
this.w := 0
this.h := 0
}
Dispose() {
this.current := ""
this.ReleaseBuffers()
}
__Delete() {
this.Dispose()
}
}
; Persist and restore a GUI window's position (and size) across runs, DPI-safe.
; Position is stored as the window centre expressed as a fraction of the primary
; monitor work area; size is stored in logical (96-dpi) units. Physical geometry
; from WinGetPos/WinMove is converted through A_ScreenDPI, so a window saved at
; one display scale restores correctly at another.
;
; posOnly: persist/restore only the position (window centre), not the size.
; Use when the window size is content-driven and may differ between runs.
class SaveGuiCoordsLogical {
WM_MOVE := 0x3
WM_SIZE := 0x5
__New(hGui, iniPath := "", section := "Coords", posOnly := false) {
this.hGui := IsObject(hGui) ? hGui.hwnd : hGui
this.iniPath := iniPath = "" ? A_ScriptDir . "\coords_logical.ini" : iniPath
this.section := section
this.posOnly := posOnly
this.restoring := false
this.onMvSz := ObjBindMethod(this, "OnMoveSize")
this.tmrSave := ObjBindMethod(this, "Save")
OnMessage(this.WM_MOVE, this.onMvSz)
OnMessage(this.WM_SIZE, this.onMvSz)
}
__Delete() {
OnMessage(this.WM_MOVE, this.onMvSz, 0)
OnMessage(this.WM_SIZE, this.onMvSz, 0)
}
; --- message handlers ---------------------------------------------------
OnMoveSize(wp, lp, msg, hwnd) {
; Ignore move/size events caused by our own Restore.
if (this.restoring)
return
if (hwnd = this.hGui && DllCall("IsWindowVisible", "Ptr", this.hGui)) {
; SetTimer needs a simple variable holding the func object, not a
; member expression like this.tmrSave.
tmr := this.tmrSave
SetTimer, % tmr, -300
}
}
; --- unit / geometry helpers -------------------------------------------
Dpi() {
return A_ScreenDPI
}
WorkArea() {
SysGet, PrimaryMonitor, MonitorPrimary
SysGet, WA, MonitorWorkArea, %PrimaryMonitor%
return [WALeft, WATop, WARight, WABottom]
}
ClampAxis(pos, len, lo, hi) {
if (pos + len > hi)
pos := hi - len
if (pos < lo)
pos := lo ; oversized window pins to the low edge
return pos
}
; --- Save: physical geometry -> logical size + centre percentage --------
Save(p*) {
if (this.restoring)
return
if !DllCall("IsWindowVisible", "Ptr", this.hGui)
return
; Only persist geometry for a NORMAL window. A minimized window reports
; off-screen junk coords and a maximized one reports full-screen bounds;
; either would overwrite the last valid normal geometry in the .ini.
; Checked here (at timer fire time), not in OnMoveSize, because the -300ms
; debounce can fire after the window has already been minimized.
WinGet, MinMaxState, MinMax, % "ahk_id " this.hGui
if (MinMaxState != 0)
return
WinGetPos, x, y, w, h, % "ahk_id " this.hGui
wa := this.WorkArea()
workW := wa[3] - wa[1]
workH := wa[4] - wa[2]
if (workW <= 0 || workH <= 0 || w <= 0 || h <= 0)
return
; Position is always the window centre as a fraction of the work area.
xPct := (x + w / 2 - wa[1]) / workW
yPct := (y + h / 2 - wa[2]) / workH
IniWrite, % Round(xPct, 6), % this.iniPath, % this.section, xPct
IniWrite, % Round(yPct, 6), % this.iniPath, % this.section, yPct
; Size is stored only in full mode; in posOnly the size is content-driven.
if (!this.posOnly) {
dpi := this.Dpi()
IniWrite, % Round(w * 96 / dpi), % this.iniPath, % this.section, wLog
IniWrite, % Round(h * 96 / dpi), % this.iniPath, % this.section, hLog
}
}
; --- Restore: position (+ size in full mode), atomic, no jump -----------
DoRestore(p*) {
; Space defaults + Trim: IniRead with an empty default is ambiguous in v1.
IniRead, xPct, % this.iniPath, % this.section, xPct, %A_Space%
IniRead, yPct, % this.iniPath, % this.section, yPct, %A_Space%
xPct := Trim(xPct)
yPct := Trim(yPct)
if (xPct = "" || yPct = "")
return
wa := this.WorkArea()
workW := wa[3] - wa[1]
workH := wa[4] - wa[2]
if (workW <= 0 || workH <= 0)
return
this.restoring := true
; The window may still be hidden (geometry is restored before it is shown,
; to avoid a flicker). Hidden windows must be detectable or WinMove and
; WinGetPos would target nothing and silently do nothing.
prevDHW := A_DetectHiddenWindows
DetectHiddenWindows, On
if (this.posOnly) {
; Size stays content-driven: read the actual size, position only.
WinGetPos, , , wUse, hUse, % "ahk_id " this.hGui
} else {
IniRead, wLog, % this.iniPath, % this.section, wLog, %A_Space%
IniRead, hLog, % this.iniPath, % this.section, hLog, %A_Space%
wLog := Trim(wLog)
hLog := Trim(hLog)
if (wLog = "" || hLog = "") {
DetectHiddenWindows, %prevDHW%
this.restoring := false
return
}
; Use the REQUESTED size for centring and apply it atomically with the
; position below, so the first painted frame is already correct.
dpi := this.Dpi()
wUse := Round(wLog * dpi / 96)
hUse := Round(hLog * dpi / 96)
}
nx := Round(wa[1] + xPct * workW - wUse / 2)
ny := Round(wa[2] + yPct * workH - hUse / 2)
nx := this.ClampAxis(nx, wUse, wa[1], wa[3])
ny := this.ClampAxis(ny, hUse, wa[2], wa[4])
if (this.posOnly)
WinMove, % "ahk_id " this.hGui, , nx, ny ; position only
else
WinMove, % "ahk_id " this.hGui, , nx, ny, wUse, hUse ; position + size, atomic
DetectHiddenWindows, %prevDHW%
this.restoring := false
}
}
; Full-screen mouse selection overlay.
class OverlaySelection {
static WM_MOUSEMOVE := 0x0200
__New(thickness := 2, color := 0x00FF00, labelSpecs := "", armedStyle := "") {
this.scale := A_ScreenDPI / 96
this.overlay := new SelectionOverlayFrame(thickness, color, this.scale)
this.state := "idle"
this.busy := false
this.startX := 0
this.startY := 0
this.curX := 0
this.curY := 0
this.callback := ""
this.callbackTimer := ""
this.disposed := false
this.onMove := ObjBindMethod(this, "OnMouseMove")
this.labels := []
this.providers := []
specs := IsObject(labelSpecs) ? labelSpecs : OverlaySelection.DefaultSpecs()
for index, spec in specs {
style := spec.HasKey("style") ? spec.style : {}
this.labels.Push(new SelectionOverlayLabel(style, this.scale))
this.providers.Push(spec.provider)
}
if !IsObject(armedStyle)
armedStyle := {}
this.armedLabel := new SelectionOverlayLabel(armedStyle, this.scale)
this.armedOffsetX := armedStyle.HasKey("offsetX") ? armedStyle.offsetX : 12
this.armedOffsetY := armedStyle.HasKey("offsetY") ? armedStyle.offsetY : 12
}
DefaultSpecs() {
gap := 5
return [ {style: {}, provider: Func("OverlayTopLabelProvider").Bind(gap)}
, {style: {}, provider: Func("OverlayBottomLabelProvider").Bind(gap)} ]
}
Arm(callback, showArmedLabel := true) {
if (this.state != "idle" || this.busy)
return
this.callback := callback
this.overlay.ClearFrame()
this.overlay.Show()
this.state := "armed"
OnMessage(this.WM_MOUSEMOVE, this.onMove)
MouseGetPos, mx, my
this.curX := mx
this.curY := my
if showArmedLabel
this.UpdateArmed()
}
BeginDrag() {
if (this.state != "armed")
return
MouseGetPos, mx, my
this.startX := mx
this.startY := my
this.curX := mx
this.curY := my
this.overlay.ClearFrame()
this.state := "dragging"
this.Update()
}
Quick(callback) {
if (this.state != "idle" || this.busy)
return
this.Arm(callback, false)
this.BeginDrag()
if !GetKeyState("LButton", "P")
this.Finish()
}
Cancel() {
if (this.state != "armed" && this.state != "dragging")
return
OnMessage(this.WM_MOUSEMOVE, this.onMove, 0)
this.overlay.Hide()
this.state := "idle"
UpdateSelectionCoordinateWindows()
}
OnMouseMove(wParam, lParam, msg, hwnd) {
if (hwnd != this.overlay.hwnd)
return
pt := this.ClientPoint(lParam)
this.curX := pt.x
this.curY := pt.y
if (this.state = "dragging")
this.Update()
else if (this.state = "armed")
this.UpdateArmed()
}
ClientPoint(lParam) {
x := lParam & 0xFFFF
y := (lParam >> 16) & 0xFFFF
if (x > 0x7FFF)
x -= 0x10000
if (y > 0x7FFF)
y -= 0x10000
VarSetCapacity(pt, 8, 0)
NumPut(x, pt, 0, "Int")
NumPut(y, pt, 4, "Int")
DllCall("ClientToScreen", "Ptr", this.overlay.hwnd, "Ptr", &pt)
return {x: NumGet(pt, 0, "Int"), y: NumGet(pt, 4, "Int")}
}
Rect() {
x := Min(this.startX, this.curX)
y := Min(this.startY, this.curY)
w := Abs(this.curX - this.startX)
h := Abs(this.curY - this.startY)
return {x: x, y: y, w: w, h: h}
}
Update() {
r := this.Rect()
if !App.Config.ShowCoordinates {
this.overlay.Render(r, [])
return
}
ctx := {r: r, t: this.overlay.PhysT(), scale: this.scale}
for index, provider in this.providers {
spec := provider.Call(ctx)
this.labels[index].SetText(spec.text, spec.ax, spec.ay, spec.side)
}
this.overlay.Render(r, this.labels)
}
UpdateArmed() {
if !App.Config.ShowCoordinates
return
x := this.curX
y := this.curY
anchorX := x - Round(this.armedOffsetX * this.scale)
anchorY := y - Round(this.armedOffsetY * this.scale)
this.armedLabel.SetText(x . ", " . y, anchorX, anchorY, "topLeft")
this.overlay.RenderLabels([this.armedLabel])
}
Finish() {
if (this.state != "dragging")
return
this.state := "idle"
OnMessage(this.WM_MOUSEMOVE, this.onMove, 0)
this.overlay.Hide()
callback := this.callback
if IsObject(callback) {
this.busy := true
r := this.Rect()
this.callbackTimer := ObjBindMethod(this, "InvokeCallback", callback, r)
timer := this.callbackTimer
SetTimer, % timer, -1
}
}
InvokeCallback(callback, r) {
try callback.Call(r)
finally {
this.busy := false
this.callbackTimer := ""
UpdateSelectionCoordinateWindows()
}
}
Dispose() {
if (this.disposed)
return
this.disposed := true
if (this.state = "armed" || this.state = "dragging")
OnMessage(this.WM_MOUSEMOVE, this.onMove, 0)
if IsObject(this.callbackTimer) {
timer := this.callbackTimer
SetTimer, % timer, Delete
this.callbackTimer := ""
}
for index, label in this.labels
label.Dispose()
if IsObject(this.armedLabel)
this.armedLabel.Dispose()
if IsObject(this.overlay)
this.overlay.Dispose()
this.state := "idle"
}
__Delete() {
this.Dispose()
}
}
class SelectionOverlayFrame {
__New(thickness, color, scale := 1) {
this.t := thickness
this.scale := scale
this.color := 0xFF000000 | color
this.w := A_ScreenWidth
this.h := A_ScreenHeight
this.prev := ""
this.disposed := false
this.guiName := "SelectionOverlay"
Gui, % this.guiName . ":New", +AlwaysOnTop -Caption +ToolWindow -DPIScale +E0x80000 +hwndOverlayHwnd
this.hwnd := OverlayHwnd
this.hArrow := DllCall("LoadCursor", "Ptr", 0, "Ptr", 32512, "Ptr")
this.CreateBuffer()
}
CreateBuffer() {
this.hdcMem := DllCall("CreateCompatibleDC", "Ptr", 0, "Ptr")
VarSetCapacity(bi, 40, 0)
NumPut(40, bi, 0, "UInt")
NumPut(this.w, bi, 4, "Int")
NumPut(-this.h, bi, 8, "Int")
NumPut(1, bi, 12, "UShort")
NumPut(32, bi, 14, "UShort")
NumPut(0, bi, 16, "UInt")
this.hbm := DllCall("CreateDIBSection", "Ptr", this.hdcMem, "Ptr", &bi
, "UInt", 0, "Ptr*", pBits, "Ptr", 0, "UInt", 0, "Ptr")
this.pBits := pBits
this.oldBm := DllCall("SelectObject", "Ptr", this.hdcMem, "Ptr", this.hbm, "Ptr")
DllCall("gdiplus\GdipCreateBitmapFromScan0", "Int", this.w, "Int", this.h
, "Int", this.w * 4, "Int", 0xE200B, "Ptr", this.pBits, "Ptr*", pBitmap)
this.pBitmap := pBitmap
DllCall("gdiplus\GdipGetImageGraphicsContext", "Ptr", this.pBitmap, "Ptr*", pGraphics)
this.pGraphics := pGraphics
DllCall("gdiplus\GdipSetCompositingMode", "Ptr", this.pGraphics, "Int", 1)
DllCall("gdiplus\GdipSetTextRenderingHint", "Ptr", this.pGraphics, "Int", 4)
DllCall("gdiplus\GdipSetSmoothingMode", "Ptr", this.pGraphics, "Int", 3)
DllCall("gdiplus\GdipCreateSolidFill", "UInt", this.color, "Ptr*", pBrush)
this.pBrush := pBrush
DllCall("gdiplus\GdipCreateSolidFill", "UInt", 0x01000000, "Ptr*", pErase)
this.pErase := pErase
DllCall("gdiplus\GdipGraphicsClear", "Ptr", this.pGraphics, "UInt", 0x01000000)
}
Show() {
options := "NA x0 y0 w" . this.w . " h" . this.h
Gui, % this.guiName . ":Show", % options
}
Hide() {
if (this.disposed)
return
DllCall("gdiplus\GdipGraphicsClear", "Ptr", this.pGraphics, "UInt", 0x01000000)
this.prev := ""
this.Flush()
Gui, % this.guiName . ":Hide"
DllCall("SetCursor", "Ptr", this.hArrow)
}
ClearFrame() {
DllCall("gdiplus\GdipGraphicsClear", "Ptr", this.pGraphics, "UInt", 0x01000000)
this.prev := ""
this.Flush()
}
SetRect(x, y, w, h) {
cur := {x: x, y: y, w: w, h: h}
if IsObject(this.prev)
this.Strips(this.prev, this.pErase)
this.Strips(cur, this.pBrush)
this.prev := cur
this.Flush()
}
Render(rect, labels) {
for index, label in labels
label.Erase(this.pGraphics, this.pErase)
if IsObject(this.prev)
this.Strips(this.prev, this.pErase)
cur := {x: rect.x, y: rect.y, w: rect.w, h: rect.h}
this.Strips(cur, this.pBrush)
this.prev := cur
for index, label in labels
label.Draw(this.pGraphics, this.w, this.h)
this.Flush()
for index, label in labels
label.Commit()
}
RenderLabels(labels) {
for index, label in labels
label.Erase(this.pGraphics, this.pErase)
for index, label in labels
label.Draw(this.pGraphics, this.w, this.h)
this.Flush()
for index, label in labels
label.Commit()
}
PhysT() {
return Max(1, Round(this.t * this.scale))
}
Strips(r, brush) {
t := this.PhysT()
this.Fill(brush, r.x - t, r.y - t, r.w + 2 * t, t)
this.Fill(brush, r.x - t, r.y + r.h, r.w + 2 * t, t)
this.Fill(brush, r.x - t, r.y, t, r.h)
this.Fill(brush, r.x + r.w, r.y, t, r.h)
}
Fill(brush, x, y, w, h) {
if (w < 1 || h < 1)
return
DllCall("gdiplus\GdipFillRectangle", "Ptr", this.pGraphics
, "Ptr", brush, "Float", x, "Float", y, "Float", w, "Float", h)
}
Flush() {
VarSetCapacity(pt, 8, 0)
VarSetCapacity(sz, 8, 0)
NumPut(this.w, sz, 0, "Int")
NumPut(this.h, sz, 4, "Int")
VarSetCapacity(src, 8, 0)
VarSetCapacity(blend, 4, 0)
NumPut(255, blend, 2, "UChar")
NumPut(1, blend, 3, "UChar")
DllCall("UpdateLayeredWindow", "Ptr", this.hwnd, "Ptr", 0
, "Ptr", &pt, "Ptr", &sz, "Ptr", this.hdcMem, "Ptr", &src
, "UInt", 0, "Ptr", &blend, "UInt", 2)
}
Dispose() {
if (this.disposed)
return
this.disposed := true
if (this.pBrush)
DllCall("gdiplus\GdipDeleteBrush", "Ptr", this.pBrush)
if (this.pErase)
DllCall("gdiplus\GdipDeleteBrush", "Ptr", this.pErase)
if (this.pGraphics)
DllCall("gdiplus\GdipDeleteGraphics", "Ptr", this.pGraphics)
if (this.pBitmap)
DllCall("gdiplus\GdipDisposeImage", "Ptr", this.pBitmap)
if (this.hbm) {
DllCall("SelectObject", "Ptr", this.hdcMem, "Ptr", this.oldBm)
DllCall("DeleteObject", "Ptr", this.hbm)
}
if (this.hdcMem)
DllCall("DeleteDC", "Ptr", this.hdcMem)
if (this.hwnd && DllCall("IsWindow", "Ptr", this.hwnd))
Gui, % this.guiName . ":Destroy"
this.pBrush := 0
this.pErase := 0
this.pGraphics := 0
this.pBitmap := 0
this.hbm := 0
this.hdcMem := 0
this.hArrow := 0
this.hwnd := 0
}
__Delete() {
this.Dispose()
}
}
class SelectionOverlayLabel {
__New(style := "", scale := 1) {
if !IsObject(style)
style := {}
fontName := this.StyleValue(style, "fontName", "Segoe UI")
fontSize := this.StyleValue(style, "fontSize", 14) * scale
fontStyle := this.StyleValue(style, "fontStyle", 0)
textColor := this.StyleValue(style, "textColor", 0xFFFFFF)
backColor := this.StyleValue(style, "backColor", 0x202020)
this.padX := Round(this.StyleValue(style, "padX", 6) * scale)
this.padY := Round(this.StyleValue(style, "padY", 3) * scale)
this.radius := Round(this.StyleValue(style, "radius", 6) * scale)
this.text := ""
this.box := ""
this.eraseBox := ""
this.prevErase := ""
this.disposed := false
DllCall("gdiplus\GdipCreateFontFamilyFromName", "WStr", fontName
, "Ptr", 0, "Ptr*", family)
this.family := family
DllCall("gdiplus\GdipCreateFont", "Ptr", this.family, "Float", fontSize
, "Int", fontStyle, "Int", 2, "Ptr*", font)
this.font := font
DllCall("gdiplus\GdipCreateStringFormat", "Int", 0, "Int", 0, "Ptr*", fmt)
this.fmt := fmt
DllCall("gdiplus\GdipSetStringFormatAlign", "Ptr", this.fmt, "Int", 0)
DllCall("gdiplus\GdipSetStringFormatLineAlign", "Ptr", this.fmt, "Int", 1)
DllCall("gdiplus\GdipCreateSolidFill", "UInt", 0xFF000000 | textColor, "Ptr*", textBrush)
this.textBrush := textBrush
DllCall("gdiplus\GdipCreateSolidFill", "UInt", 0xFF000000 | backColor, "Ptr*", backBrush)
this.backBrush := backBrush
}
StyleValue(style, key, defaultValue) {
return style.HasKey(key) ? style[key] : defaultValue
}
SetText(text, anchorX, anchorY, side := "top") {
this.text := text
this.ax := anchorX
this.ay := anchorY
this.side := side
}
Measure(pGraphics) {
VarSetCapacity(layout, 16, 0)
NumPut(0, layout, 0, "Float")
NumPut(0, layout, 4, "Float")
NumPut(9999, layout, 8, "Float")
NumPut(9999, layout, 12, "Float")
VarSetCapacity(bounds, 16, 0)
DllCall("gdiplus\GdipMeasureString", "Ptr", pGraphics, "WStr", this.text
, "Int", -1, "Ptr", this.font, "Ptr", &layout, "Ptr", this.fmt
, "Ptr", &bounds, "Int*", chars, "Int*", lines)
return {w: NumGet(bounds, 8, "Float"), h: NumGet(bounds, 12, "Float")}
}
ComputeBox(pGraphics, screenW, screenH) {
metrics := this.Measure(pGraphics)
bw := Ceil(metrics.w) + this.padX * 2
bh := Ceil(metrics.h) + this.padY * 2
if (this.side = "top") {
bx := this.ax
by := this.ay - bh - 1
} else if (this.side = "bottom") {
bx := this.ax - bw
by := this.ay
} else if (this.side = "left") {
bx := this.ax - bw
by := this.ay - bh // 2
} else if (this.side = "right") {
bx := this.ax
by := this.ay - bh // 2
} else if (this.side = "topLeft") {
bx := this.ax - bw
by := this.ay - bh - 1
} else {
bx := this.ax - bw // 2
by := this.ay - bh // 2
}
bx := Max(0, Min(bx, screenW - bw))
by := Max(0, Min(by, screenH - bh))
return {x: bx, y: by, w: bw, h: bh}
}
Draw(pGraphics, screenW, screenH) {
if (this.text = "") {
this.box := ""
this.eraseBox := ""
return
}
box := this.ComputeBox(pGraphics, screenW, screenH)
this.box := box
ex := Max(0, box.x - 1)
ey := Max(0, box.y - 1)
er := Min(screenW, box.x + box.w + 1)
eb := Min(screenH, box.y + box.h + 1)
this.eraseBox := {x: ex, y: ey, w: er - ex, h: eb - ey}
DllCall("gdiplus\GdipSetCompositingMode", "Ptr", pGraphics, "Int", 0)
this.FillRoundRect(pGraphics, box.x, box.y, box.w, box.h, this.radius, this.backBrush)
VarSetCapacity(rect, 16, 0)
NumPut(box.x + this.padX, rect, 0, "Float")
NumPut(box.y, rect, 4, "Float")
NumPut(box.w, rect, 8, "Float")
NumPut(box.h, rect, 12, "Float")
DllCall("gdiplus\GdipDrawString", "Ptr", pGraphics, "WStr", this.text
, "Int", -1, "Ptr", this.font, "Ptr", &rect, "Ptr", this.fmt
, "Ptr", this.textBrush)
DllCall("gdiplus\GdipSetCompositingMode", "Ptr", pGraphics, "Int", 1)
}
FillRoundRect(pGraphics, x, y, w, h, radius, brush) {
radius := Min(radius, Min(w // 2, h // 2))
diameter := radius * 2
DllCall("gdiplus\GdipCreatePath", "Int", 0, "Ptr*", path)
if (radius > 0) {
DllCall("gdiplus\GdipAddPathArc", "Ptr", path, "Float", x
, "Float", y, "Float", diameter, "Float", diameter, "Float", 180, "Float", 90)
DllCall("gdiplus\GdipAddPathArc", "Ptr", path, "Float", x + w - diameter
, "Float", y, "Float", diameter, "Float", diameter, "Float", 270, "Float", 90)
DllCall("gdiplus\GdipAddPathArc", "Ptr", path, "Float", x + w - diameter
, "Float", y + h - diameter, "Float", diameter, "Float", diameter, "Float", 0, "Float", 90)
DllCall("gdiplus\GdipAddPathArc", "Ptr", path, "Float", x
, "Float", y + h - diameter, "Float", diameter, "Float", diameter, "Float", 90, "Float", 90)
DllCall("gdiplus\GdipClosePathFigure", "Ptr", path)
} else {
DllCall("gdiplus\GdipAddPathRectangle", "Ptr", path
, "Float", x, "Float", y, "Float", w, "Float", h)
}
DllCall("gdiplus\GdipSetSmoothingMode", "Ptr", pGraphics, "Int", 4)
DllCall("gdiplus\GdipFillPath", "Ptr", pGraphics, "Ptr", brush, "Ptr", path)
DllCall("gdiplus\GdipSetSmoothingMode", "Ptr", pGraphics, "Int", 3)
DllCall("gdiplus\GdipDeletePath", "Ptr", path)
}
Erase(pGraphics, eraseBrush) {
if !IsObject(this.prevErase)
return
box := this.prevErase
DllCall("gdiplus\GdipFillRectangle", "Ptr", pGraphics, "Ptr", eraseBrush
, "Float", box.x, "Float", box.y, "Float", box.w, "Float", box.h)
}
Commit() {
this.prevErase := this.eraseBox
}
Dispose() {
if (this.disposed)
return
this.disposed := true
if (this.textBrush)
DllCall("gdiplus\GdipDeleteBrush", "Ptr", this.textBrush)
if (this.backBrush)
DllCall("gdiplus\GdipDeleteBrush", "Ptr", this.backBrush)
if (this.fmt)
DllCall("gdiplus\GdipDeleteStringFormat", "Ptr", this.fmt)
if (this.font)
DllCall("gdiplus\GdipDeleteFont", "Ptr", this.font)
if (this.family)
DllCall("gdiplus\GdipDeleteFontFamily", "Ptr", this.family)
this.textBrush := 0
this.backBrush := 0
this.fmt := 0
this.font := 0
this.family := 0
}
__Delete() {
this.Dispose()
}
}
class ToolTip {
; Default options. Any option omitted by the caller falls back to the value here.
; Color options use "" to mean "leave the system default" (0 is a valid black).
DefaultOptions() {
return { text: "", title: "", icon: 0
, x: "", y: "", TimeOut: "", ShowNow: true
, FontName: "", FontSize: 0, FontStyle: ""
, BackColor: "", TextColor: "", Margin: ""
, BalloonTip: false, CloseButton: false
, transparent: true, RightBottom: false, TrayTip: false }
}
__New( options ) {
defaults := this.DefaultOptions()
for k, v in defaults
this[k] := options.HasKey(k) ? options[k] : v
this._CreateToolTip()
( this.ShowNow && this.Show(this.x, this.y, this.TimeOut) )
}
_CreateToolTip() {
static WS_POPUP := 0x80000000, WS_EX_TOPMOST := 8, WS_EX_TRANSPARENT := 0x20
, TTS_NOPREFIX := 2, TTS_ALWAYSTIP := 1, TTS_BALLOON := 0x40, TTS_CLOSE := 0x80
, TTF_TRACK := 0x20, TTF_ABSOLUTE := 0x80, szTI := A_PtrSize = 4 ? 48 : 72
VarSetCapacity(TOOLINFO, szTI, 0)
this.pTI := &TOOLINFO
NumPut(szTI, TOOLINFO)
(this.TrayTip && this.BalloonTip := true)
(this.CloseButton && this.transparent := false)
NumPut(TTF_TRACK|(this.BalloonTip ? 0 : TTF_ABSOLUTE), &TOOLINFO + 4)
this.hwnd := DllCall("CreateWindowEx", "UInt", WS_EX_TOPMOST|(this.transparent ? WS_EX_TRANSPARENT : 0)
, "Str", "tooltips_class32", "Str", ""
, "UInt", WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP | (this.CloseButton ? TTS_CLOSE : 0) | (this.BalloonTip ? TTS_BALLOON : 0)
, "Int", 0, "Int", 0, "Int", 0, "Int", 0, "Ptr", 0, "Ptr", 0, "Ptr", 0, "Ptr", 0)
if (this.FontName || this.FontSize || this.FontStyle)
this._SetFont()
if (this.TextColor != "" || this.BackColor != "")
this._SetColor()
this._SetInfo()
}
_SetFont() {
static WM_GETFONT := 0x31, mult := A_IsUnicode ? 2 : 1, szLF := 28 + 32 * mult
, LOGPIXELSY := 90, ANTIALIASED_QUALITY := 4
, styles := { bold: {value: 700, offset: 16, size: "Int"}
, italic: {value: 1, offset: 20, size: "Char"}
, underline: {value: 1, offset: 21, size: "Char"}
, strikeout: {value: 1, offset: 22, size: "Char"} }
hPrevFont := this._SendMessage(WM_GETFONT)
VarSetCapacity(LOGFONT, szLF, 0)
DllCall("GetObject", "Ptr", hPrevFont, "Int", szLF, "Ptr", &LOGFONT)
DllCall("DeleteObject", "Ptr", hPrevFont)
if this.FontSize {
hDC := DllCall("GetDC", "Ptr", this.hwnd, "Ptr")
picH := DllCall("GetDeviceCaps", "Ptr", hDC, "Int", LOGPIXELSY)
height := -DllCall("MulDiv", "Int", this.FontSize, "Int", picH, "Int", 72)
DllCall("ReleaseDC", "Ptr", this.hwnd, "Ptr", hDC)
NumPut(height, LOGFONT, "Int")
}
FontStyle := this.FontStyle
Loop, parse, FontStyle, %A_Space%
{
if obj := styles[A_LoopField]
NumPut(obj.value, &LOGFONT + obj.offset, obj.size)
}
(this.FontSize > 24 && NumPut(ANTIALIASED_QUALITY, &LOGFONT + 26, "Char"))
this.FontName && StrPut(this.FontName, &LOGFONT + 28, StrLen(this.FontName) * mult, A_IsUnicode ? "UTF-16" : "CP0")
this.hFont := DllCall("CreateFontIndirect", "Ptr", &LOGFONT, "Ptr")
}
_SetColor() {
static WM_USER := 0x400, TTM_SETTIPBKCOLOR := WM_USER + 19, TTM_SETTIPTEXTCOLOR := WM_USER + 20
VarSetCapacity(empty, 2, 0)
DllCall("UxTheme\SetWindowTheme", "Ptr", this.hwnd, "Ptr", 0, "Ptr", &empty)
( this.TextColor != "" && this._SendMessage(TTM_SETTIPTEXTCOLOR, this._GetColor(this.TextColor)) )
( this.BackColor != "" && this._SendMessage(TTM_SETTIPBKCOLOR, this._GetColor(this.BackColor)) )
}
_GetColor(color) {
static WS_CHILD := 0x40000000, WM_CTLCOLORSTATIC := 0x138
Gui, New, +hwndhGui +%WS_CHILD%
Gui, Color, % color + 0 = "" ? color : Format("{:x}", color)
Gui, Add, Text, hwndhText
hdc := DllCall("GetDC", "Ptr", hText, "Ptr")
SendMessage, WM_CTLCOLORSTATIC, hdc, hText,, ahk_id %hGui%
clr := DllCall("GetBkColor", "Ptr", hdc)
DllCall("ReleaseDC", "Ptr", hText, "Ptr", hdc)
Gui, Destroy
return clr
}
_SetInfo() {
static WM_USER := 0x400, TTM_SETMAXTIPWIDTH := WM_USER + 24
, TTM_ADDTOOL := WM_USER + (A_IsUnicode ? 50 : 4), WM_SETFONT := 0x30
this._SendMessage(WM_SETFONT, this.hFont, 1)
this._SendMessage(TTM_ADDTOOL, 0, this.pTI)
this.SetTitle(this.icon, this.title)
this._SendMessage(TTM_SETMAXTIPWIDTH, 0, A_ScreenWidth)
this._SetMargin()
this.SetText(this.text)
}
_SetMargin() {
static WM_USER := 0x400, TTM_SETMARGIN := WM_USER + 26
margin := this.Margin
if !(IsObject(margin) && margin.MaxIndex() = 4)
return
VarSetCapacity(RECT, 16, 0)
for i, offset in margin
NumPut(offset, &RECT + (i - 1) * 4, "Int")
this._SendMessage(TTM_SETMARGIN, 0, &RECT)
}
SetText(text) {
static WM_USER := 0x400, TTM_UPDATETIPTEXT := WM_USER + (A_IsUnicode ? 57 : 12)
NumPut(&text, this.pTI + (A_PtrSize = 4 ? 36 : 48))
this._SendMessage(TTM_UPDATETIPTEXT, 0, this.pTI)
}
SetTitle(icon := "", title := "") {
static WM_USER := 0x400, TTM_SETTITLE := WM_USER + (A_IsUnicode ? 33 : 32), TTM_UPDATE := WM_USER + 29
((icon || this.CloseButton) && title = "") && title := " "
this._SendMessage(TTM_SETTITLE, icon, &title)
(icon > 3 && DllCall("DestroyIcon", "Ptr", icon))
this._SendMessage(TTM_UPDATE)
}
Show(x := "", y := "", timeout := "") {
static WM_USER := 0x400, TTM_TRACKACTIVATE := WM_USER + 17, TTM_TRACKPOSITION := WM_USER + 18
SysGet, MonPrimary, MonitorPrimary
SysGet, Mon, MonitorWorkArea, %MonPrimary%
xTT := x, yTT := y
; TrayTip mode: anchor the balloon to the script's tray icon (one-shot)
if this.TrayTip {
this._GetTrayIconCoords(xTT, yTT)
; RightBottom mode: push beyond the work area so the post-activation
; clamp below pins the tip to the bottom-right corner, above the taskbar
} else if this.RightBottom {
xTT := MonRight, yTT := MonBottom
} else if (xTT = "" || yTT = "") {
CoordMode, Mouse
MouseGetPos, xm, ym
(xTT = "" && xTT := xm + 10)
(yTT = "" && yTT := ym + 10)
}
this._SendMessage(TTM_TRACKPOSITION, 0, xTT|(yTT<<16))
this._SendMessage(TTM_TRACKACTIVATE, 1, this.pTI)
if this.BalloonTip
xMax := MonRight, yMax := MonBottom
else {
WinGetPos,,, W, H, % "ahk_id" this.hwnd
xMax := MonRight - W - 10
yMax := MonBottom - H - 10
}
if (xTT > xMax || yTT > yMax) {
(xTT > xMax && xTT := xMax)
(yTT > yMax && yTT := yMax)
this._SendMessage(TTM_TRACKPOSITION, 0, xTT|(yTT<<16))
}
if timeout {
timer := this.timer
try SetTimer, % timer, Delete
this.timer := timer := ObjBindMethod(this, timeout > 0 ? "Hide" : "Destroy")
SetTimer % timer, % "-" . Abs(timeout)
}
}
Hide() {
static WM_USER := 0x400, TTM_TRACKACTIVATE := WM_USER + 17
this._SendMessage(TTM_TRACKACTIVATE, 0, this.pTI)
}
Destroy() {
this.__Delete()
this.SetCapacity(0)
this.base := ""
}
_SendMessage(msg, wp := 0, lp := 0) {
return DllCall("SendMessage", "Ptr", this.hwnd, "UInt", msg, "Ptr", wp, "Ptr", lp, "Ptr")
}
_GetTrayIconCoords(ByRef x, ByRef y) {
static AHK_NOTIFYICON := 0x404, szNII := 16 + 3 * A_PtrSize
; Modern, Win11-safe way: ask the shell for the icon's screen rect directly.
VarSetCapacity(NII, szNII, 0)
NumPut(szNII, NII, 0, "UInt")
NumPut(A_ScriptHwnd, NII, A_PtrSize, "Ptr")
NumPut(AHK_NOTIFYICON, NII, A_PtrSize * 2, "UInt")
VarSetCapacity(RECT, 16, 0)
if (DllCall("Shell32\Shell_NotifyIconGetRect", "Ptr", &NII, "Ptr", &RECT, "UInt") = 0) {
xL := NumGet(RECT, 0, "Int"), yT := NumGet(RECT, 4, "Int")
xR := NumGet(RECT, 8, "Int")
x := (xL + xR) // 2 ; balloon anchors its tail at this point
y := yT
} else {
; Fallback: aim at the tray notification area as a whole.
for k, v in ["TrayNotifyWnd", "SysPager", "ToolbarWindow32"]
hTray := DllCall("FindWindowEx", "Ptr", k = 1 ? WinExist("ahk_class Shell_TrayWnd") : hTray, "Ptr", 0, "Str", v, "UInt", 0, "Ptr")
WinGetPos, xTray, yTray, wTray,, % "ahk_id" hTray
x := xTray + wTray // 2, y := yTray
}
}
__Delete() {
(this.hFont && DllCall("DeleteObject", "Ptr", this.hFont))
(this.Icon > 3 && DllCall("DestroyIcon", "Ptr", this.Icon))
DllCall("DestroyWindow", "Ptr", this.hwnd)
}
}
;*************************************************************** HotKeys ***************************************************************
; Автор - serzh82saratov
; E-Mail: serzh82saratov@mail.ru
; Описание - http://forum.script-coding.com/viewtopic.php?id=8343
Hotkey_Register(Controls*) {
static IsStart
for k, v in Controls
{
Hotkey_ID(v[2], v[1]), Hotkey_ID(v[1], v[2])
Hotkey_Options(v[2], v[3] = "" ? "K" : v[3])
Hotkey_Value(v[2], Hotkey_Value(v[1]))
PostMessage, 0x00CF, 1, , , % "ahk_id" v[2] ; EM_SETREADONLY
if RegExMatch(v[3], "i)G(\d+)", g)
Hotkey_Group("Set", v[1], g1)
}
if IsStart
return Hotkey_IsRegFocus()
#HotkeyInterval 0
Hotkey_SetWinEventHook(0x8005, 0x8005, 0, RegisterCallback("Hotkey_EventFocus", "F"), 0, 0, 0) ; EVENT_OBJECT_FOCUS := 0x8005
Hotkey_InitHotkeys(), Hotkey_IsRegFocus(), IsStart := 1
}
Hotkey_Main(Param1, Param2 = "") {
static OnlyMods, ControlHandle, Hotkey, KeyName, K := {}
, Prefix := {"LAlt":"<!","LCtrl":"<^","LShift":"<+","LWin":"<#"
,"RAlt":">!","RCtrl":">^","RShift":">+","RWin":">#"
,"Alt":"!","Ctrl":"^","Shift":"+","Win":"#"}
, EngSym := {"sc2":"1","sc3":"2","sc4":"3","sc5":"4","sc6":"5","sc7":"6"
,"sc8":"7","sc9":"8","scA":"9","scB":"0","scC":"-","scD":"="
,"sc10":"Q","sc11":"W","sc12":"E","sc13":"R","sc14":"T","sc15":"Y"
,"sc16":"U","sc17":"I","sc18":"O","sc19":"P","sc1A":"[","sc1B":"]"
,"sc1E":"A","sc1F":"S","sc20":"D","sc21":"F","sc22":"G","sc23":"H"
,"sc24":"J","sc25":"K","sc26":"L","sc27":"`;","sc28":"'","sc29":"``"
,"sc2B":"\","sc2C":"Z","sc2D":"X","sc2E":"C","sc2F":"V","sc30":"B"
,"sc31":"N","sc32":"M","sc33":",","sc34":".","sc35":"/"}
if Param1 = GetMod
return K.MLCtrl K.MRCtrl K.MLAlt K.MRAlt K.MLShift K.MRShift K.MLWin K.MRWin K.MCtrl K.MAlt K.MShift K.MWin
if Param2
{
if OnlyMods
{
SendMessage, 0xC, 0, "" Hotkey_Arr("Empty"), , ahk_id %ControlHandle%
OnlyMods := 0, K := {}
}
ControlHandle := Param2
Hotkey_Arr("Hook", Hotkey_Options(ControlHandle))
PostMessage, 0x00B1, -1, -1, , ahk_id %ControlHandle% ; EM_SETSEL
}
else if Hotkey_Arr("Hook")
{
Hotkey_Arr("Hook", 0), K := {}
if OnlyMods
SendMessage, 0xC, 0, "" Hotkey_Arr("Empty"), , ahk_id %ControlHandle%
SetTimer, Hotkey_IsRegFocus, -200
}
return
Hotkey_Mods:
if InStr(Hotkey_Arr("Hook"), "S")
GoTo Hotkey_View
IsMod := InStr(Hotkey_Arr("Hook"), "D") ? A_ThisHotkey : SubStr(A_ThisHotkey, 2)
if (K["M" IsMod] != "")
return
K["M" IsMod] := IsMod "+", K["P" IsMod] := Prefix[IsMod]
GoTo Hotkey_ViewMod
Hotkey_ModsUp:
if InStr(Hotkey_Arr("Hook"), "S")
return
IsMod := InStr(Hotkey_Arr("Hook"), "D") ? SubStr(A_ThisHotkey, 1, -3) : SubStr(A_ThisHotkey, 2, -3)
K["M" IsMod] := "", K["P" IsMod] := ""
if (Hotkey != "")
return
Hotkey_ViewMod:
Hotkey := "", OnlyMods := 1, Hotkey_Value(Hotkey_ID(ControlHandle), K.Prefix Hotkey), Hotkey_Value(ControlHandle, K.Prefix Hotkey)
K.Mods := K.MLCtrl K.MRCtrl K.MLAlt K.MRAlt K.MLShift K.MRShift K.MLWin K.MRWin K.MCtrl K.MAlt K.MShift K.MWin
Text := K.Mods = "" ? Hotkey_Arr("Empty") : K.Mods
SendMessage, 0xC, 0, &Text, , ahk_id %ControlHandle%
return
Hotkey_ViewNum:
if InStr(Hotkey_Arr("Hook"), "N")
KeyName := Hotkey := GetKeyName(A_ThisHotkey)
else
KeyName := GetKeyName(A_ThisHotkey), Hotkey := Format("sc{:x}", GetKeySC(A_ThisHotkey))
GoTo, Hotkey_Put
Hotkey_ViewSC:
KeyName := Hotkey_Arr("OnlyEngSym") ? EngSym[A_ThisHotkey] : Format("{:U}", GetKeyName(A_ThisHotkey))
Hotkey := A_ThisHotkey
GoTo, Hotkey_Put
Hotkey_View:
if (A_ThisHotkey = "Backspace")
GoTo, Hotkey_Clear
if Hotkey_IsMouseInput(A_ThisHotkey)
Hotkey_SyncPhysicalModifiers(K)
KeyName := Hotkey := A_ThisHotkey
Hotkey_Put:
OnlyMods := 0
K.Prefix := K.PLCtrl K.PRCtrl K.PLAlt K.PRAlt K.PLShift K.PRShift K.PLWin K.PRWin K.PCtrl K.PAlt K.PShift K.PWin
Hotkey_Value(Hotkey_ID(ControlHandle), K.Prefix Hotkey), Hotkey_Value(ControlHandle, K.Prefix Hotkey)
K.Mods := K.MLCtrl K.MRCtrl K.MLAlt K.MRAlt K.MLShift K.MRShift K.MLWin K.MRWin K.MCtrl K.MAlt K.MShift K.MWin
Text := K.Mods KeyName = "" ? Hotkey_Arr("Empty") : K.Mods KeyName
SendMessage, 0xC, 0, &Text, , ahk_id %ControlHandle%
if Hotkey_Group("Get", Hotkey_ID(ControlHandle)) && Hotkey_Group("SaveCheck", ControlHandle)
SetTimer, Hotkey_Group, -70
return
Hotkey_Clear:
OnlyMods := 0, K := {}
Hotkey_Value(Hotkey_ID(ControlHandle), " "), Hotkey_Value(ControlHandle, " ")
Text := Hotkey_Arr("Empty")
SendMessage, 0xC, 0, &Text, , ahk_id %ControlHandle%
if Hotkey_Group("Get", Hotkey_ID(ControlHandle)) && Hotkey_Group("SaveCheck", ControlHandle)
SetTimer, Hotkey_Group, -70
return
}
Hotkey_InitHotkeys() {
static nmMods := "LAlt|RAlt|LCtrl|RCtrl|LShift|RShift|LWin|RWin"
, nmMouse := "MButton|WheelDown|WheelUp|WheelRight|WheelLeft|XButton1|XButton2"
, scSymb := "2|3|4|5|6|7|8|9|A|B|C|D|10|11|12|13|14|15|16|17|18|19|1A|1B|"
. "1E|1F|20|21|22|23|24|25|26|27|28|29|2B|2C|2D|2E|2F|30|31|32|33|34|35"
; , scNumSymb := "53|52|4F|50|51|4B|4C|4D|47|48|49"
, scOther := "1|E|F|1C|37|39|3A|3B|3C|3D|3E|3F|40|41|42|43|44|45|46|4A|4E|54|57|58|63|64|65|"
. "66|67|68|69|6A|6B|6C|6D|6E|76|11C|135|147|148|149|14B|14D|14F|150|151|152|153|15D"
, vkNum := "2E|6E|60|2D|61|23|62|28|63|22|64|25|65|C|66|27|67|24|68|26|69"
, vkOther := "3|13|5F|A6|A7|A8|A9|AA|AB|AC|AD|AE|AF|B0|B1|B2|B3|B4|B5|B6|B7"
S_BatchLines := A_BatchLines
SetBatchLines, -1
#IF Hotkey_IsRegControl()
#IF Hotkey_Hook("K")
#IF Hotkey_Hook("M")
#IF Hotkey_Hook("L") && Hotkey_HasKeyboardModifier()
#IF Hotkey_Hook("R") && Hotkey_HasKeyboardModifier()
#IF Hotkey_Hook("J") && !Hotkey_Main("GetMod")
#IF Hotkey_Arr("Hook") && !Hotkey_Hook("K")
#IF
Hotkey, IF, Hotkey_Hook("M")
Loop, Parse, nmMouse, |
Hotkey, % A_LoopField, Hotkey_View
Hotkey, IF, Hotkey_Hook("K")
Loop, Parse, nmMods, |
{
Hotkey, % A_LoopField, Hotkey_Mods
Hotkey, % A_LoopField " Up", Hotkey_ModsUp
}
Loop, Parse, scSymb, |
Hotkey, % "sc" A_LoopField, Hotkey_ViewSC
Loop, Parse, scOther, |
Hotkey, % GetKeyName("sc" A_LoopField), Hotkey_View
Loop, Parse, vkNum, |
Hotkey, % "vk" A_LoopField, Hotkey_ViewNum
Loop, Parse, vkOther, |
Hotkey, % GetKeyName("vk" A_LoopField), Hotkey_View
Hotkey, IF, Hotkey_Hook("L") && Hotkey_HasKeyboardModifier()
Hotkey, LButton, Hotkey_View
Hotkey, IF, Hotkey_Hook("R") && Hotkey_HasKeyboardModifier()
Hotkey, RButton, Hotkey_View
S_FormatInteger := A_FormatInteger
SetFormat, IntegerFast, D
Hotkey, IF, Hotkey_Hook("J") && !Hotkey_Main("GetMod")
Loop, 128
Hotkey % Ceil(A_Index / 32) "Joy" Mod(A_Index - 1, 32) + 1, Hotkey_View
SetFormat, IntegerFast, %S_FormatInteger%
Hotkey, IF, Hotkey_IsRegControl()
Hotkey, RButton, Hotkey_RButton
Hotkey, RButton Up, Hotkey_Return
Hotkey, IF, Hotkey_Arr("Hook") && !Hotkey_Hook("K")
Hotkey, AppsKey Up, Hotkey_Return
Hotkey, +F10, Hotkey_Return
Hotkey, IF
SetBatchLines, %S_BatchLines%
return
Hotkey_RButton:
Click
Hotkey_Return:
return
}
Hotkey_IsRegControl() {
MouseGetPos,,,, Control, 2
return Hotkey_ID(Control) != ""
}
Hotkey_IsMouseInput(Key) {
static MouseInputs := "|LButton|RButton|MButton|WheelDown|WheelUp|WheelRight|WheelLeft|XButton1|XButton2|"
return InStr(MouseInputs, "|" Key "|")
}
Hotkey_HasKeyboardModifier() {
return GetKeyState("Ctrl", "P") || GetKeyState("Shift", "P")
|| GetKeyState("Alt", "P") || GetKeyState("LWin", "P")
|| GetKeyState("RWin", "P")
}
Hotkey_SyncPhysicalModifiers(K) {
static Modifiers := { LCtrl: "<^", RCtrl: ">^", LAlt: "<!", RAlt: ">!"
, LShift: "<+", RShift: ">+", LWin: "<#", RWin: ">#" }
for Name, Prefix in Modifiers {
IsDown := GetKeyState(Name, "P")
K["M" Name] := IsDown ? Name "+" : ""
K["P" Name] := IsDown ? Prefix : ""
}
K.MCtrl := K.MAlt := K.MShift := K.MWin := ""
K.PCtrl := K.PAlt := K.PShift := K.PWin := ""
}
Hotkey_IsRegFocus() {
ControlGetFocus, ControlNN, A
ControlGet, hFocus, Hwnd, , %ControlNN%, A
Hotkey_ID(hFocus) != "" ? Hotkey_Main("Control", hFocus) : 0
}
Hotkey_EventFocus(hWinEventHook, event, hwnd) {
Hotkey_ID(hwnd) != "" ? Hotkey_Main("Control", hwnd) : Hotkey_Main("Control")
}
Hotkey_SetWinEventHook(eventMin, eventMax, hmodWinEventProc, lpfnWinEventProc, idProcess, idThread, dwFlags) {
return DllCall("SetWinEventHook" , "UInt", eventMin, "UInt", eventMax, "Ptr", hmodWinEventProc
, "Ptr", lpfnWinEventProc, "UInt", idProcess, "UInt", idThread, "UInt", dwFlags, "Ptr")
}
; -------------------------------------- Save and get --------------------------------------
Hotkey_Arr(P*) {
static Arr := {"Empty":"Нет"}
return P.MaxIndex() = 1 ? Arr[P[1]] : (Arr[P[1]] := P[2])
}
Hotkey_ID(P*) {
static Arr := {}
return P.MaxIndex() = 1 ? Arr[P[1]] : P.MaxIndex() = 2 ? (Arr[P[1]] := P[2]) : Arr.Delete(P[1])
}
Hotkey_Value(P*) {
static Arr := {}
return P.MaxIndex() = 1 ? Arr[P[1]] : P.MaxIndex() = 2 ? (Arr[P[1]] := P[2]) : Arr.Delete(P[1])
}
Hotkey_Options(P*) {
static Arr := {}
return P.MaxIndex() = 1 ? Arr[P[1]] : P.MaxIndex() = 2 ? (Arr[P[1]] := P[2]) : Arr.Delete(P[1])
}
Hotkey_ChangeOption(ID, Option) {
(ID + 0 = "") ? (Hwnd := Hotkey_ID(ID), Name := ID) : (Hwnd := ID, Name := Hotkey_ID(ID))
if RegExMatch(Hotkey_Options(Hwnd), "i)G(\d+)", g)
Hotkey_Group("Delete", Name)
if RegExMatch(Option, "i)G(\d+)", g)
Hotkey_Group("Set", Name, g1)
return Hotkey_Options(Hwnd, Option)
}
Hotkey_Hook(Option) {
return Hotkey_Arr("Hook") && !!InStr(Hotkey_Arr("Hook"), Option)
}
Hotkey_Delete(ID, Destroy = 0) {
(ID + 0 = "") ? (Hwnd := Hotkey_ID(ID), Name := ID) : (Hwnd := ID, Name := Hotkey_ID(ID))
Hotkey_Group("Delete", Name)
Hotkey_ID(Hwnd, "", 1), Hotkey_ID(Name, "", 1)
Hotkey_Value(Hwnd, "", 1), Hotkey_Value(Name, "", 1)
Hotkey_Options(Hwnd, "", 1)
ControlGetFocus, ControlNN, A
ControlGet, hFocus, Hwnd, , %ControlNN%, A
(hFocus = Hwnd ? Hotkey_Main("Control") : 0)
if Destroy
DllCall("DestroyWindow", "Ptr", Hwnd)
else
PostMessage, 0x00CF, 0, , , % "ahk_id" Hwnd ; EM_SETREADONLY
return Hwnd
}
Hotkey_Set(Name, Value = "") {
Text := Hotkey_HKToStr(Value)
SendMessage, 0xC, 0, &Text, , % "ahk_id" Hotkey_ID(Name)
return Text, Hotkey_Value(Name, Value), Hotkey_Value(Hotkey_ID(Name), Value)
}
Hotkey_Read(Name, Section = "", FilePath = "") {
HK := Hotkey_IniRead(Name, Section, FilePath), Hotkey_Value(Name, HK)
return Hotkey_HKToStr(HK)
}
Hotkey_IniPath(Path = "") {
return Path = "" ? Hotkey_Arr("IniPath") : Hotkey_Arr("IniPath", Path)
}
Hotkey_IniSection(Section = "") {
return Section = "" ? Hotkey_Arr("IniSection") : Hotkey_Arr("IniSection", Section)
}
Hotkey_IniRead(Name, Section = "", FilePath = "") {
IniRead, Data, % FilePath = "" ? Hotkey_IniPath() : FilePath, % Section = "" ? Hotkey_IniSection() : Section, % Name, % A_Space
return Data
}
Hotkey_IniWrite(ID, Section = "", FilePath = "") {
Key := (ID + 0 = "") ? ID : Hotkey_ID(ID)
if (Key != "")
IniWrite, % Hotkey_Value(ID), % FilePath = "" ? Hotkey_IniPath() : FilePath, % Section = "" ? Hotkey_IniSection() : Section, % Key
}
; -------------------------------------- Group --------------------------------------
Hotkey_Group(Key = "", p1 = "", p2 = "") {
static NG := {}, GN := [], Blink := [], SaveCheck := [], i := 0
if (Key = "") {
for k, Name in SaveCheck {
if ((Value := Hotkey_Value(Name)) != "") {
(f := Hotkey_Arr("GroupEvents")) != "" && (r := {}, r.names := [])
for m, n in GN[NG[Name]] {
if (n != Name && Hotkey_Equal(Value, Hotkey_Value(n))) {
Hotkey_Set(Name)
(f != "") && (r.names.Push(n), r.this := Name, r.value := Value, r.group := NG[Name])
if !DllCall("IsWindowVisible", "Ptr", Hotkey_ID(n))
continue
DllCall("ShowWindowAsync", "Ptr", Hotkey_ID(n), "Int", 0)
Blink[Hotkey_ID(n)] := 1, i := 3
SetTimer, Hotkey_BlinkControl, -50
}
}
}
SaveCheck.Delete(k)
}
(f != "") && (r.this != "") && %f%(r)
}
else if (Key = "Set")
NG[p1] := p2, IsObject(GN[p2]) ? GN[p2].Push(p1) : GN[p2] := [p1]
else if (Key = "SaveCheck")
return 1, SaveCheck[p1] := Hotkey_ID(p1)
else if (Key = "Get")
return NG[p1] != ""
else if (Key = "CheckAll") {
for k, v in GN {
for k, n in v {
if ((Value := Hotkey_Value(n)) != "") {
for k, m in v {
if (n != m && Hotkey_Equal(Value, Hotkey_Value(m)))
Hotkey_Set(m)
}
}
}
}
}
else if (Key = "Delete") {
for k, v in GN[NG[p1]] {
if (v = p1) {
GN[NG[p1]].RemoveAt(k)
break
}
}
NG.Delete(p1)
}
return
Hotkey_BlinkControl:
for k in Blink
DllCall("ShowWindowAsync", "Ptr", k, "Int", Mod(i, 2) ? 4 : 0)
if (--i > 0) || !(Blink := [])
SetTimer, Hotkey_BlinkControl, -50
return
}
Hotkey_Equal(HK1, HK2) {
if (HK2 = "")
return 0
if (HK1 = HK2)
return 1
if !(HK1 ~= "S)[\^\+!#]") || !(HK2 ~= "S)[\^\+!#]")
return 0
if (HK1 ~= "S)[<>]") && (HK2 ~= "S)[<>]")
return 0
return (Hotkey_ModsSub(HK1) = Hotkey_ModsSub(HK2))
}
Hotkey_ModsSub(Value) {
if !(Value ~= "[<>]")
return Value
Value := StrReplace(Value, "<")
Value := StrReplace(Value, ">")
Value := StrReplace(Value, "^^", "^", , 1)
Value := StrReplace(Value, "!!", "!", , 1)
Value := StrReplace(Value, "++", "+", , 1)
return StrReplace(Value, "##", "#", , 1)
}
; -------------------------------------- Format --------------------------------------
; http://forum.script-coding.com/viewtopic.php?pid=105023#p105023
Hotkey_HKToStr(HK) {
static LRPrefix := [["<^","LCtrl"],[">^","RCtrl"],["<!","LAlt"],[">!","RAlt"]
,["<+","LShift"],[">+","RShift"],["<#","LWin"],[">#","RWin"]]
, Prefix := [["^","Ctrl"],["!","Alt"],["+","Shift"],["#","Win"]]
, EngSym := {"sc2":"1","sc3":"2","sc4":"3","sc5":"4","sc6":"5","sc7":"6"
,"sc8":"7","sc9":"8","scA":"9","scB":"0","scC":"-","scD":"="
,"sc10":"Q","sc11":"W","sc12":"E","sc13":"R","sc14":"T","sc15":"Y"
,"sc16":"U","sc17":"I","sc18":"O","sc19":"P","sc1A":"[","sc1B":"]"
,"sc1E":"A","sc1F":"S","sc20":"D","sc21":"F","sc22":"G","sc23":"H"
,"sc24":"J","sc25":"K","sc26":"L","sc27":"`;","sc28":"'","sc29":"``"
,"sc2B":"\","sc2C":"Z","sc2D":"X","sc2E":"C","sc2F":"V","sc30":"B"
,"sc31":"N","sc32":"M","sc33":",","sc34":".","sc35":"/"
,"vk31":"1","vk32":"2","vk33":"3","vk34":"4","vk35":"5","vk36":"6"
,"vk37":"7","vk38":"8","vk39":"9","vk30":"0","vkBD":"-","vkBB":"="
,"vk51":"Q","vk57":"W","vk45":"E","vk52":"R","vk54":"T","vk59":"Y"
,"vk55":"U","vk49":"I","vk4F":"O","vk50":"P","vkDB":"[","vkDD":"]"
,"vk41":"A","vk53":"S","vk44":"D","vk46":"F","vk47":"G","vk48":"H"
,"vk4A":"J","vk4B":"K","vk4C":"L","vkBA":"`;","vkDE":"'","vkC0":"``"
,"vkDC":"\","vk5A":"Z","vk58":"X","vk43":"C","vk56":"V","vk42":"B"
,"vk4E":"N","vk4D":"M","vkBC":",","vkBE":".","vkBF":"/"}
RegExMatch(HK, "S)^\s*([~\*\$\^\+!#<>]*)\{?(.*?)}?\s*$", K)
if (K2 = "")
return "" Hotkey_Arr("Empty")
if (InStr("|" K2, "|sc") || InStr("|" K2, "|vk"))
K2 := Hotkey_Arr("OnlyEngSym") && EngSym.HasKey(K2) ? EngSym[K2] : GetKeyName(K2)
if (K1 != "")
for I, V in K1 ~= "[<>]" ? LRPrefix : Prefix
K1 := StrReplace(K1, V[1], "", R), R && (M .= V[2] "+")
return M . (StrLen(K2) = 1 ? Format("{:U}", K2) : K2)
}
Hotkey_HKToSend(HK, Section = "", FilePath = "") {
static LRPrefix := [["<^","LCtrl"],[">^","RCtrl"],["<!","LAlt"],[">!","RAlt"]
,["<+","LShift"],[">+","RShift"],["<#","LWin"],[">#","RWin"]]
, Prefix := [["^","LCtrl"],["!","LAlt"],["+","LShift"],["#","LWin"]]
if (HK = "")
return
if (Section != "")
IniRead, HK, % FilePath = "" ? Hotkey_IniPath() : FilePath, % Section, % HK, % A_Space
RegExMatch(HK, "S)^\s*([~\*\$\^\+!#<>]*)\{?(.*?)}?\s*$", K)
if (K1 != "") {
for I, V in K1 ~= "[<>]" ? LRPrefix : Prefix {
K1 := StrReplace(K1, V[1], "", R)
, R ? (M1 .= "{" V[2] " Down}", M2 .= "{" V[2] " Up}") : 0
}
}
return M1 . "{" K2 "}" . M2
}
#if WinExist("ScreenShot ahk_class AutoHotkeyGUI")
#if
#if IsOverlaySelectionState("armed")
LButton:: BeginOverlaySelectionDrag()
RButton:: CancelOverlaySelection()
Esc:: CancelOverlaySelection()
#if
#if IsOverlaySelectionState("dragging")
*LButton Up:: FinishOverlaySelection()
RButton:: CancelOverlaySelection()
Esc:: CancelOverlaySelection()
#if
#if IsSelectionWindowActive()
^WheelUp:: NudgeSelectionEdge("Left" , -1)
^WheelDown:: NudgeSelectionEdge("Left" , 1)
+WheelUp:: NudgeSelectionEdge("Top" , -1)
+WheelDown:: NudgeSelectionEdge("Top" , 1)
!WheelUp:: NudgeSelectionEdge("Right" , 1)
!WheelDown:: NudgeSelectionEdge("Right" , -1)
#WheelUp:: NudgeSelectionEdge("Bottom", -1)
#WheelDown:: NudgeSelectionEdge("Bottom", 1)
; Precise edge positioning without a mouse: same modifiers, arrow keys along the edge axis
^Left:: NudgeSelectionEdge("Left" , -1)
^Right:: NudgeSelectionEdge("Left" , 1)
+Up:: NudgeSelectionEdge("Top" , -1)
+Down:: NudgeSelectionEdge("Top" , 1)
!Right:: NudgeSelectionEdge("Right" , 1)
!Left:: NudgeSelectionEdge("Right" , -1)
#Up:: NudgeSelectionEdge("Bottom", -1)
#Down:: NudgeSelectionEdge("Bottom", 1)
#if
#if WinActive("ScreenShot ahk_class AutoHotkeyGUI")
; Symbol keys here MUST be given by scan code: the hotkey edit control library
; (Hotkey_InitHotkeys, run when the settings window is first opened) registers
; scan-code hotkeys sc2..sc35 under #IF Hotkey_Hook("K"). A scan-code hotkey
; takes precedence over a VK/character hotkey for the same key, so "1::" or
; "^z::" would silently stop firing until reload. Same scan code = variants of
; one hotkey, and this #if variant fires. Scan codes are also layout-independent.
^sc2C:: PreviewHistoryHotkey("Undo") ; Ctrl+Z
^sc15:: PreviewHistoryHotkey("Redo") ; Ctrl+Y
^+sc2C:: PreviewHistoryHotkey("Redo") ; Ctrl+Shift+Z
; Drawing: D toggles the mode, 1-6 pick a tool, [ and ] step the width.
sc20:: PreviewDrawHotkey("Mode") ; D
sc2:: PreviewDrawHotkey("Tool", 1) ; 1
sc3:: PreviewDrawHotkey("Tool", 2) ; 2
sc4:: PreviewDrawHotkey("Tool", 3) ; 3
sc5:: PreviewDrawHotkey("Tool", 4) ; 4
sc6:: PreviewDrawHotkey("Tool", 5) ; 5
sc7:: PreviewDrawHotkey("Tool", 6) ; 6
sc1A:: PreviewDrawHotkey("Width", -1) ; [
sc1B:: PreviewDrawHotkey("Width", 1) ; ]
Esc:: PostMessage, Esc,,,, A
*WheelDown::
*WheelUp:: PostMessage, Wheel, A_ThisHotkey = "*WheelUp" ? 0 : 1,,, A
#if
#if IsHelpWindowActive()
; By scan code, see the note in the preview block above
^sc1E:: HelpBrowserExecWB(17) ; Ctrl+A, OLECMDID_SELECTALL
^sc2E:: HelpBrowserExecWB(12) ; Ctrl+C, OLECMDID_COPY
; Ctrl+Home/End and PgUp/PgDn are left to the WebBrowser control for now; add
; explicit handlers here only if the control does not scroll them out of the box.
#if
Сохраните скрипт в кодировке UTF-8 с BOM, (иначе получите кракозябры вместо кириллицы).
Если кто-нибудь захочет задать вопрос по работе скрипта или сообщить о замеченных багах — прошу писать в эту тему.

