Dan_555 Posted November 26, 2024 Author Posted November 26, 2024 (edited) Clipboard_Monitoring (the newest is at the bottom of this post:) Playing with my previous code I've added a few buttons to it, along with clipboard monitoring found in the Help File. The button 0 contains a copy of the last screenshot, it will be green if it contains a picture. The buttons 1 to x have following functions: If they are red, left click will store the screenshot into it, and they will get a cyan color. Clicking on the cyan button with the left mouse click will display the stored image. Right click will delete the image from it and the button will become red again. The images are stored in memory, and when the program is closed, they will be deleted. The window is resizable and the image will adapt to the size. expandcollapse popup#NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile_x64=..\..\..\!MyApps\ClipboardMonitor\ClipBoard-ImageMonitoring.exe #AutoIt3Wrapper_UseX64=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ;modified code from https://www.autoitscript.com/forum/topic/57053-updating-a-picture-control-without-a-file/?do=findComment&comment=514735 ;#include <ScreenCapture.au3> #include <SendMessage.au3> #include <Clipboard.au3> #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WinAPIHObj.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <String.au3> #include <ListBoxConstants.au3> #include <StructureConstants.au3> #include <StaticConstants.au3> Opt("GUIResizeMode", BitOR($GUI_DOCKSIZE, $Gui_DOCKLEFT)) Opt("TrayMenuMode", 1) Opt("TrayAutoPause", 0) ;Check if @scriptdir has a \, add it if not $tmp = "\" If StringRight(@ScriptDir, 1) = "\" Then $tmp = "" Global $iniFile = @ScriptDir & $tmp & "im_config.ini" ;Prepare the ini file Global $Foldername = @ScriptDir & $tmp & "IMG_" ;Prepare the Folder names Global $FNMax = 2 $tmp = "" Global $aFmt[][] = [["PNG", 0], ["JPG", 0], ["BMP", 0], ["GIF", 0], ["TIFF", 0]] Global $DefaultMenuTypeFMT = IniRead($iniFile, "setting", "MenuFormatType", 0) Global $aSaveSet[10][2] Global $DefaultMenuSaveSet = IniRead($iniFile, "setting", "MenuSaveSetNr", 0) Global $btnmax = IniRead($iniFile, "setting", "NumberOfButtons", 30) if $btnmax<2 then $btnmax=2 Global $CBTN[$btnmax][2] Global $displayinfo = IniRead($iniFile, "setting", "DisplayInfo", 1) ;0 = in the title, 1 = in the menue Global $hGUI = GUICreate("Clipboard Monitor", 450, 290, -1, -1, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX), $WS_EX_ACCEPTFILES) $idMenuFile = GUICtrlCreateMenu("File") $idMenuOpenFolder = GUICtrlCreateMenuItem("Open Folder in File Explorer", $idMenuFile) GUICtrlCreateMenuItem("", $idMenuFile) $idMenuSave = GUICtrlCreateMenuItem("Save Images", $idMenuFile) GUICtrlCreateMenuItem("", $idMenuFile) $idMenuExit = GUICtrlCreateMenuItem("Exit", $idMenuFile) $idMenuOptions = GUICtrlCreateMenu("Options") For $x = 0 To UBound($aFmt) - 1 $aFmt[$x][1] = GUICtrlCreateMenuItem($aFmt[$x][0], $idMenuOptions, $idMenuSave, 1) If $x = $DefaultMenuTypeFMT Then GUICtrlSetState(-1, $gui_checked) Next GUICtrlCreateMenuItem("", $idMenuOptions) $idMenuClearButtons = GUICtrlCreateMenuItem("Clear Buttons", $idMenuOptions) GUICtrlCreateMenuItem("", $idMenuOptions) $idMenuGuiOnTop = GUICtrlCreateMenuItem("Keep Gui on TOP", $idMenuOptions) $idMenuSet = GUICtrlCreateMenu("Image Set") For $x = 0 To UBound($aSaveSet) - 1 $tmp = _StringRepeat("0", $FNMax - StringLen($x)) & $x $aSaveSet[$x][0] = $tmp $tmp = "" If FileExists($Foldername & $aSaveSet[$x][0] & "\") = 0 Then $tmp = " (New)" $aSaveSet[$x][1] = GUICtrlCreateMenuItem($aSaveSet[$x][0] & $tmp, $idMenuSet, -1, 1) If $x = $DefaultMenuSaveSet Then GUICtrlSetState(-1, $gui_checked) Next $tmp = "" $mDummymenu = GUICtrlCreateMenu("this menu control will be deleted") $idMenuAbout = GUICtrlCreateMenuItem("About", -1,-1,1) GUICtrlDelete($mDummymenu) ; <====================== ;Create Buttons For $x = 0 To ($btnmax - 1) $CBTN[$x][0] = GUICtrlCreateButton($x, 1 + ($x * 21), 1, 21, 25) GUICtrlSetBkColor(-1, "0xFF7070") Next GUICtrlSetTip($CBTN[0][0], "A Copy of the last captured Image") $hListBox = GUICtrlCreateList("", 1, 30, 80, 222, BitOR($LBS_NOTIFY, $WS_VSCROLL, $WS_BORDER)) GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKBOTTOM, $GUI_DOCKWIDTH)) $hWndListBox = GUICtrlGetHandle($hListBox) Local $idLabel = GUICtrlCreateLabel(@CRLF & @crlf & @CRLF & @CRLF & @crlf & @CRLF & @CRLF & "Drag and Drop files here", 85, 30, 360, 214, BitOr($WS_BORDER,$SS_SUNKEN,$SS_CENTER)) GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKBOTTOM, $GUI_DOCKBORDERS)) GUICtrlSetState($idLabel, $GUI_DROPACCEPTED) GUISetState() If IniRead($iniFile, "setting", "WinOnTop", 0) = 1 Then GUICtrlSetState($idMenuGuiOnTop, $GUI_CHECKED) WinSetOnTop($hGUI, "", 1) WinActivate($hGUI) EndIf Global $hImage Local $anmsg ;~ If Not _ClipBoard_IsFormatAvailable($CF_BITMAP) Then ;~ Send("{printscreen}") ;~ EndIf Global $g_hNext = _ClipBoard_SetViewer($hGUI) GUIRegisterMsg($WM_CHANGECBCHAIN, "WM_CHANGECBCHAIN") GUIRegisterMsg($WM_DRAWCLIPBOARD, "WM_DRAWCLIPBOARD") _GDIPlus_Startup() ClipDrawBitmap() PopulateListBox($DefaultMenuSaveSet) UpdateTitle() GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") $sLastSel = "" $fAction = 0 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_DROPPED ; If the value of @GUI_DropId is $idLabel, then set the label of the dragged file. If @GUI_DropId = $idLabel Then LoadDroppedImage(@GUI_DragFile) Case $idMenuAbout $tmp="Options saved/read to/from the ini file::" & @crlf & @crlf & "[setting]" & @crlf & "WinOnTop=0" & @crlf & "MenuFormatType=0" & @crlf & "MenuSaveSetNr=0" & @crlf & "NumberOfButtons=30" & @crlf & "DisplayInfo=1" $WPos = WinGetPos($hGUI) MsgBoxButton("Info: ", $tmp, "Ok", 200, 150, $WPos[0] + 130, $WPos[1] + 50, 2) $WPos = "" $tmp="" Case $idMenuGuiOnTop If BitAND(GUICtrlRead($idMenuGuiOnTop), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState($idMenuGuiOnTop, $GUI_UNCHECKED) WinSetOnTop($hGUI, "", 0) IniWrite($iniFile, "setting", "WinOnTop", 0) Else GUICtrlSetState($idMenuGuiOnTop, $GUI_CHECKED) WinSetOnTop($hGUI, "", 1) WinActivate($hGUI) IniWrite($iniFile, "setting", "WinOnTop", 1) EndIf Case $idMenuClearButtons $WPos = WinGetPos($hGUI) $iMsgBoxAnswer = MsgBoxButton("Warning ! ", " Do you really want to clear all buttons?", "Yes|No", 200, 80, $WPos[0] + 130, $WPos[1] + 50, 2) If $iMsgBoxAnswer = 1 Then ;Yes For $x = 1 To ($btnmax - 1) _GDIPlus_ImageDispose($CBTN[$x][1]) $CBTN[$x][1] = 0 GUICtrlSetBkColor($CBTN[$x][0], "0xFF7070") Next EndIf $WPos = "" Case $idMenuOpenFolder $tmp = $Foldername & $aSaveSet[$DefaultMenuSaveSet][0] & "\" If FileExists($tmp) Then ShellExecute($tmp) $tmp = "" Case $idMenuSave SaveImages($DefaultMenuSaveSet, $DefaultMenuTypeFMT) PopulateListBox($DefaultMenuSaveSet) Case $GUI_EVENT_CLOSE, $idMenuExit $WPos = WinGetPos($hGUI) $iMsgBoxAnswer = MsgBoxButton("Warning ! ", " Do you really want to end the program ?", "Yes|No", 200, 80, $WPos[0] + 130, $WPos[1] + 50, 2) If $iMsgBoxAnswer = 1 Then ;Yes _GDIPlus_ImageDispose($hImage) For $x = 0 To ($btnmax - 1) _GDIPlus_ImageDispose($CBTN[$x][1]) Next _GDIPlus_Shutdown() ; Shut down clipboard viewer _ClipBoard_ChangeChain($hGUI, $g_hNext) Exit EndIf $WPos = "" Case $GUI_EVENT_RESIZED, $GUI_EVENT_RESTORE, $GUI_EVENT_MAXIMIZE ReDrawBitmap() Case $GUI_EVENT_SECONDARYUP $anmsg = GUIGetCursorInfo($hGUI) If IsArray($anmsg) Then For $x = 0 To ($btnmax - 1) If $x > 0 Then If $anmsg[4] = $CBTN[$x][0] Then If $CBTN[$x][1] > 0 Then _GDIPlus_ImageDispose($CBTN[$x][1]) GUICtrlSetBkColor($CBTN[$x][0], "0xFF7070") $CBTN[$x][1] = 0 EndIf EndIf EndIf Next EndIf $anmsg = "" Case Else If $nMsg > 0 Then ;Loop through the Buttons For $x = 0 To ($btnmax - 1) If $nMsg = $CBTN[$x][0] Then If $x > 0 Then If $CBTN[$x][1] = 0 And $hImage > 0 Then $CBTN[$x][1] = _GDIPlus_ImageClone($hImage) GUICtrlSetBkColor($CBTN[$x][0], "0x70FFFF") EndIf EndIf If $CBTN[$x][1] > 0 Then _GDIPlus_ImageDispose($hImage) $hImage = _GDIPlus_ImageClone($CBTN[$x][1]) EndIf ReDrawBitmap() EndIf Next ;Loop throgh the Set menu For $x = 0 To (UBound($aSaveSet) - 1) If $nMsg = $aSaveSet[$x][1] Then $DefaultMenuSaveSet = $x PopulateListBox($x) UpdateTitle() IniWrite($iniFile, "setting", "MenuSaveSetNr", $DefaultMenuSaveSet) EndIf Next ;Loop throgh Option menu For $x = 0 To (UBound($aFmt) - 1) If $nMsg = $aFmt[$x][1] Then $DefaultMenuTypeFMT = $x UpdateTitle() IniWrite($iniFile, "setting", "MenuFormatType", $DefaultMenuTypeFMT) EndIf Next EndIf EndSwitch If GUICtrlRead($hListBox) <> $sLastSel Then ;Code by melba23 - autoit forum $sLastSel = GUICtrlRead($hListBox) Sleep(150) If $fAction = 1 Then ;Listbox Double Click LoadImage($sLastSel, $DefaultMenuSaveSet) Else ;Listbox Single Click LoadImage($sLastSel, $DefaultMenuSaveSet) EndIf $fAction = 0 Else If $fAction = 1 Then ;Listbox Double Click LoadImage($sLastSel, $DefaultMenuSaveSet) $fAction = 0 EndIf EndIf WEnd Func UpdateTitle() if $displayinfo=1 Then GUICtrlSetData ($idMenuAbout," ( " & $aFmt[$DefaultMenuTypeFMT][0] & " ) / ( " & $aSaveSet[$DefaultMenuSaveSet][0] & " )") Else WinSetTitle($hGUI, "", "Clipboard Monitor (" & $aFmt[$DefaultMenuTypeFMT][0] & ") / ( " & $aSaveSet[$DefaultMenuSaveSet][0] & " )") EndIf EndFunc ;==>UpdateTitle Func LoadImage($FNa, $Nr) Local $tmp1 = $aSaveSet[$Nr][0] Local $tmpF = $Foldername & $tmp1 & "\" & $FNa Local $tmpH = 0 If FileExists($tmpF) Then $tmpH = _GDIPlus_ImageLoadFromFile($tmpF) If $tmpH > 0 Then If $hImage > 0 Then _GDIPlus_ImageDispose($hImage) $hImage = _GDIPlus_ImageClone($tmpH) _GDIPlus_ImageDispose($tmpH) ReDrawBitmap() EndIf EndIf EndFunc ;==>LoadImage Func LoadDroppedImage($Filename) If FileExists($Filename) Then $tmpH = _GDIPlus_ImageLoadFromFile($Filename) If $tmpH > 0 Then If $hImage > 0 Then _GDIPlus_ImageDispose($hImage) $hImage = _GDIPlus_ImageClone($tmpH) _GDIPlus_ImageDispose($tmpH) ReDrawBitmap() EndIf EndIf EndFunc ;==>LoadDroppedImage Func PopulateListBox($Nr = 0) Local $tmp = $aFmt[1][0] Local $tmp1 = $aSaveSet[$Nr][0] Local $tmpF = $Foldername & $tmp1 & "\" Local $tmpFN = "", $tmpFNa = "" Local $tmpfiles Local $x, $y Local $tmpBox = "" GUICtrlSetData($hListBox, $tmpBox) For $y = 0 To UBound($aFmt) - 1 $tmp = $aFmt[$y][0] For $x = 0 To $btnmax - 1 $tmpFNa = _StringRepeat("0", 2 - StringLen($x)) & $x & "." & $tmp $tmpFN = $tmpF & $tmpFNa If FileExists($tmpFN) Then $tmpBox = $tmpBox & $tmpFNa & "|" EndIf Next Next GUICtrlSetData($hListBox, $tmpBox) EndFunc ;==>PopulateListBox Func SaveImages($Nr = 0, $typ = 0) Local $tmp = $aFmt[$typ][0] Local $tmp1 = $aSaveSet[$Nr][0] Local $tmpF = $Foldername & $tmp1 & "\" Local $tmpFN = "" Local $tmpfiles If FileExists($tmpF) = 0 Then DirCreate($tmpF) $tmpexist = 0 For $x = 1 To UBound($CBTN) - 1 $tmpFNa = _StringRepeat("0", 2 - StringLen($x)) & $x & "." & $tmp $tmpFN = $tmpF & $tmpFNa If FileExists($tmpFN) And $CBTN[$x][1] > 0 Then $tmpexist = $tmpexist + 1 $tmpfiles = $tmpfiles & $tmpFNa & @CRLF EndIf Next If $tmpexist > 0 Then $WPos = WinGetPos($hGUI) If MsgBoxButton("Warning: File(s) exist", "Following files may be deleted from:" & @CRLF & $tmpF & @CRLF & @CRLF & $tmpfiles & "Do you wish to continue ?", "Yes|No", 220, 100, $WPos[0] + 130, $WPos[1] + 50, 2) = 1 Then $tmpexist = 0 EndIf If $tmpexist = 0 Then For $x = 1 To UBound($CBTN) - 1 $tmpFN = $tmpF & _StringRepeat("0", 2 - StringLen($x)) & $x & "." & $tmp If $CBTN[$x][1] > 0 Then _GDIPlus_ImageSaveToFile($CBTN[$x][1], $tmpFN) Next EndIf EndFunc ;==>SaveImages Func ReDrawBitmap() $WPos = WinGetPos($hGUI) $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) _GDIPlus_DrawImagePoints($hGraphics, $hImage, 85, 30, $WPos[2] - 20, 30, 85, $WPos[3] - 62) _GDIPlus_GraphicsDispose($hGraphics) EndFunc ;==>ReDrawBitmap Func ClipDrawBitmap() Local $WPos, $hBitmap, $hGraphics $WPos = WinGetPos($hGUI) _ClipBoard_Open($hGUI) $hBitmap = _ClipBoard_GetDataEx($CF_BITMAP) _ClipBoard_Close() If $hBitmap > 0 Then If $hImage > 0 Then _GDIPlus_ImageDispose($hImage) If $CBTN[0][1] > 0 Then _GDIPlus_ImageDispose($CBTN[0][1]) $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap) $CBTN[0][1] = _GDIPlus_ImageClone($hImage) GUICtrlSetBkColor($CBTN[0][0], "0x00FF00") _WinAPI_DeleteObject($hBitmap) ReDrawBitmap() EndIf EndFunc ;==>ClipDrawBitmap ; Handle $WM_CHANGECBCHAIN messages Func WM_CHANGECBCHAIN($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg ; If the next window is closing, repair the chain If $wParam = $g_hNext Then $g_hNext = $lParam ; Otherwise pass the message to the next viewer ElseIf $g_hNext <> 0 Then _SendMessage($g_hNext, $WM_CHANGECBCHAIN, $wParam, $lParam, 0, "hwnd", "hwnd") EndIf EndFunc ;==>WM_CHANGECBCHAIN ; Handle $WM_DRAWCLIPBOARD messages Func WM_DRAWCLIPBOARD($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg ; Display any image from clipboard ClipDrawBitmap() ; Pass the message to the next viewer If $g_hNext <> 0 Then _SendMessage($g_hNext, $WM_DRAWCLIPBOARD, $wParam, $lParam) EndFunc ;==>WM_DRAWCLIPBOARD Func MsgBoxButton($title = "MsgBox", $txt = "", $buttons = "Ok|Cancel", $width = 250, $height = 100, $xpos = -1, $ypos = -1, $defbtn = 1) ;By Dan_555 ;Displays a custom message box with variable number of buttons ;$title = Title text, $txt=info text ;$buttons = Add any number of buttons needed by entering their names. Buttons are separated by | E.g. 'yes|no' will create two buttons. Button numbers start from 1 ;$Width, $height minimum of 250,100. Height is expanded by the amount of buttons. ;Button width is dependant on the Gui-Width ;$defbtn sets a button to act as default button - Acted upon return Local $hParentGui = WinGetHandle("", "") GUISetState(@SW_DISABLE, $hParentGui) Local $nMsg Local $btnnr = -1 If StringLeft($buttons, 1) <> "|" Then $buttons = "|" & $buttons If StringRight($buttons, 1) <> "|" Then $buttons = $buttons & "|" Local $a_btn = _StringBetween($buttons, "|", "|") If @error = 0 Then For $x = UBound($a_btn) - 1 To 0 Step -1 If $a_btn[$x] = "" Then _ArrayDelete($a_btn, $x) Next Else ;Error creating button array Local $a_btn[] = ["ok"] EndIf If $height < (UBound($a_btn)) * 20 Then $height = (UBound($a_btn)) * 20 If $width < 250 Then $width = 250 If $height < 100 Then $height = 100 Local $ahBtn[UBound($a_btn)] Local $hMsgBoxGui = GUICreate($title, $width, $height, $xpos, $ypos, BitOR($WS_DLGFRAME, $WS_BORDER, $WS_VISIBLE), BitOR($WS_EX_TOPMOST, $WS_EX_APPWINDOW), $hParentGui) Local $hMsgBoxEdi = GUICtrlCreateEdit($txt, 0, 0, 195, $height, BitOR($WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY)) ;Local $hMsgBoxEdi = GUICtrlCreateEdit($txt, 0, 0, 195, $height, BitOR($WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_READONLY)) ;Local $hMsgBoxEdi = GUICtrlCreateLabel($txt, 2, 2, 195, $height-4,$SS_SUNKEN) Local $xs = $height - (20 * (UBound($a_btn) - 1)) - 20 For $x = 0 To UBound($a_btn) - 1 $deftyp = -1 If $defbtn = $x + 1 Then $deftyp = $BS_DEFPUSHBUTTON $ahBtn[$x] = GUICtrlCreateButton($a_btn[$x], 198, $xs + ($x * 20), $width - 199, 20, $deftyp) ;~ $ahBtn[$x] = GUICtrlCreateButton($a_btn[$x], 198, (UBound($a_btn)-1 = 0) ? (($height/2)-10)+($x * 20) : (($height/UBound($a_btn))-20)+($x * 20) , $width-199, 20,$deftyp) Next GUISetState(@SW_SHOW) Do $nMsg = GUIGetMsg() If $nMsg > 0 Then For $x = 0 To UBound($ahBtn) - 1 If $nMsg = $ahBtn[$x] Then $btnnr = $x + 1 Next EndIf Until $btnnr > -1 GUIDelete($hMsgBoxGui) GUISetState(@SW_ENABLE, $hParentGui) WinActivate($hParentGui) Return $btnnr EndFunc ;==>MsgBoxButton Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) ;code from https://www.autoitscript.com/forum/topic/119058-how-to-set-a-handler-function-for-listbox-double-click-action/?do=findComment&comment=827814 #forceref $hWnd, $iMsg Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = $lParam $iCode = BitShift($wParam, 16) ; Hi Word Switch $hWndFrom Case $hWndListBox Switch $iCode Case $LBN_DBLCLK ; Sent when the user double-clicks a string in a list box $fAction = 1 EndSwitch EndSwitch EndFunc ;==>WM_COMMAND Edit: 27.11.2024 : Added the missing _ClipBoard_ChangeChain($hGUI, $g_hNext) before exiting the script. Edit #2: Added a custom Message box when exiting the program. Edit #3; Added some menus and a Listbox. You can open the Folder of a set (if it exists). Save all the images which are in the button, into the set folder. You can choose a filetype (png,jpg,bmp,gif,tiff) under which the files will be saved). You can choose a set number (will display the set name and "(new)" if the folder does not exists). Listbox will display the files from the set, the filenames will be added 1-29 for each filetype. (double)Clicking on the filename in the listbox will display the image. Edit #4: Because why not: Just after posting the last update i thought to add loading and diplaying files with Drag&Drop ... You can drag and drop one image file from the explorer into the area where the pictures are usually displayed. Edit #5: Probably the last one for today: Added a menu item (under options) to clear all buttons. Edit 30.11.2024: Added Exit, Keep Gui on top and an "about" menue. Gui on top, Image Set and Image type are saved to the ini and reloaded upon starting. Number of buttons can be changed in the ini file (min 2). The "Image save Format" and "Folder set number" display "(png) / ( 00 )" as default into the about menu, but can be changed to be displayed in the Window title. Edit 3.12.2024: Iv set up the buttons into an extra, scrollable window. For it i had to use the functions from "GUIScrollbars_Ex.au3" (look in the sourcecode for where to get it). Added a menu "Bugfix". Sometime if the program is running too long, it may stop capturing the clipboard. (haven't identified the exact cause, yet). If it happens, this would (in theory) re register the window as clipboard viewer. (p.s. In theory means that i haven't tested it, yet) Here is the sourcecode: expandcollapse popup#NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile_x64=..\..\..\!MyApps\ClipboardMonitor\ClipBoard-ImageMonitoring.exe #AutoIt3Wrapper_UseX64=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ;modified code from https://www.autoitscript.com/forum/topic/57053-updating-a-picture-control-without-a-file/?do=findComment&comment=514735 ;#include <ScreenCapture.au3> #include <SendMessage.au3> #include <Clipboard.au3> #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WinAPIHObj.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <String.au3> #include <ListBoxConstants.au3> #include <StructureConstants.au3> #include <StaticConstants.au3> #include "GUIScrollbars_Ex.au3" ;https : / / www.autoitscript.com / forum / topic / 113723 - scrollbars - made - easy - new - version - 27 - jan - 22 / #include "GUIScrollbars_Size.au3" ;https : / / www.autoitscript.com / forum / topic / 113723 - scrollbars - made - easy - new - version - 27 - jan - 22 / Opt("GUIResizeMode", BitOR($GUI_DOCKSIZE, $Gui_DOCKLEFT)) Opt("TrayMenuMode", 1) Opt("TrayAutoPause", 0) ;Check if @scriptdir has a \, add it if not $tmp = "\" If StringRight(@ScriptDir, 1) = "\" Then $tmp = "" Global $iniFile = @ScriptDir & $tmp & "ClipBoard-ImageMonitor.ini" ;Prepare the ini file Global $Foldername = @ScriptDir & $tmp & "IMG_" ;Prepare the Folder names Global $FNMax = 2 $tmp = "" Global $aFmt[][] = [["PNG", 0], ["JPG", 0], ["BMP", 0], ["GIF", 0], ["TIFF", 0]] Global $DefaultMenuTypeFMT = IniRead($iniFile, "setting", "MenuFormatType", 0) Global $aSaveSet[10][2] Global $DefaultMenuSaveSet = IniRead($iniFile, "setting", "MenuSaveSetNr", 0) Global $btnmax = IniRead($iniFile, "setting", "NumberOfButtons", 50) If $btnmax < 2 Then $btnmax = 2 Global $CBTN[$btnmax][2] Global $displayinfo = IniRead($iniFile, "setting", "DisplayInfo", 1) ;0 = in the title, 1 = in the menue If $displayinfo < 0 Or $displayinfo > 1 Then $displayinfo = 0 Global $hGUI = GUICreate("Clipboard Monitor", 450, 320, -1, -1, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX), $WS_EX_ACCEPTFILES) $idMenuFile = GUICtrlCreateMenu("File") $idMenuOpenFolder = GUICtrlCreateMenuItem("Open Folder in File Explorer", $idMenuFile) GUICtrlCreateMenuItem("", $idMenuFile) $idMenuSave = GUICtrlCreateMenuItem("Save Images", $idMenuFile) GUICtrlCreateMenuItem("", $idMenuFile) $idMenuExit = GUICtrlCreateMenuItem("Exit", $idMenuFile) $idMenuOptions = GUICtrlCreateMenu("Options") For $x = 0 To UBound($aFmt) - 1 $aFmt[$x][1] = GUICtrlCreateMenuItem($aFmt[$x][0], $idMenuOptions, $idMenuSave, 1) If $x = $DefaultMenuTypeFMT Then GUICtrlSetState(-1, $gui_checked) Next GUICtrlCreateMenuItem("", $idMenuOptions) $idMenuClearButtons = GUICtrlCreateMenuItem("Clear Buttons", $idMenuOptions) GUICtrlCreateMenuItem("", $idMenuOptions) $idMenuGuiOnTop = GUICtrlCreateMenuItem("Gui on TOP", $idMenuOptions) GUICtrlCreateMenuItem("", $idMenuOptions) $idBugFixMenuMain = GUICtrlCreateMenu("Bugfix", $idMenuOptions) $idBugFixMenu = GUICtrlCreateMenuItem("Reassign as viewer", $idBugFixMenuMain) $idMenuSet = GUICtrlCreateMenu("Image Set") For $x = 0 To UBound($aSaveSet) - 1 $tmp = _StringRepeat("0", $FNMax - StringLen($x)) & $x $aSaveSet[$x][0] = $tmp $tmp = "" If FileExists($Foldername & $aSaveSet[$x][0] & "\") = 0 Then $tmp = " (New)" $aSaveSet[$x][1] = GUICtrlCreateMenuItem($aSaveSet[$x][0] & $tmp, $idMenuSet, -1, 1) If $x = $DefaultMenuSaveSet Then GUICtrlSetState(-1, $gui_checked) Next $tmp = "" $mDummymenu = GUICtrlCreateMenu("this menu control will be deleted") $idMenuAbout = GUICtrlCreateMenuItem("About", -1, -1, 1) GUICtrlDelete($mDummymenu) ; <====================== ;Create a child window which will get the scrollbar Local $hChild = GUICreate("Scroll area", 628, 48, 0, 0, $WS_POPUP, $WS_EX_MDICHILD, $hGUI) GUISwitch($hChild) ;Create Buttons For $x = 0 To ($btnmax - 1) $CBTN[$x][0] = GUICtrlCreateButton($x, 1 + ($x * 21), 1, 21, 25) GUICtrlSetBkColor(-1, "0xFF7070") Next GUICtrlSetTip($CBTN[0][0], "A Copy of the last captured Image") $WPos = WinGetPos($hGUI) WinMove($hChild, "", $WPos[0] + 13, $WPos[1] + 54, $WPos[2] - 24, 54) $WPos = "" _GUIScrollbars_Generate($hChild, (($btnmax) * 21), 30) GUISetState(@SW_SHOW, $hChild) GUISwitch($hGUI) $hListBox = GUICtrlCreateList("", 1, 60, 80, 222, BitOR($LBS_NOTIFY, $WS_VSCROLL, $WS_BORDER)) GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKBOTTOM, $GUI_DOCKWIDTH)) $hWndListBox = GUICtrlGetHandle($hListBox) Local $idLabel = GUICtrlCreateLabel(@CRLF & @CRLF & @CRLF & @CRLF & @CRLF & @CRLF & @CRLF & "Drag and Drop files here", 85, 60, 360, 214, BitOR($WS_BORDER, $SS_SUNKEN, $SS_CENTER)) GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKBOTTOM, $GUI_DOCKBORDERS)) GUICtrlSetState($idLabel, $GUI_DROPACCEPTED) GUISetState() If IniRead($iniFile, "setting", "WinOnTop", 0) = 1 Then GUICtrlSetState($idMenuGuiOnTop, $GUI_CHECKED) WinSetOnTop($hGUI, "", 1) WinActivate($hGUI) EndIf Global $hImage Local $anmsg ;~ If Not _ClipBoard_IsFormatAvailable($CF_BITMAP) Then ;~ Send("{printscreen}") ;~ EndIf Global $g_hNext = _ClipBoard_SetViewer($hGUI) GUIRegisterMsg($WM_CHANGECBCHAIN, "WM_CHANGECBCHAIN") GUIRegisterMsg($WM_DRAWCLIPBOARD, "WM_DRAWCLIPBOARD") _GDIPlus_Startup() ClipDrawBitmap() PopulateListBox($DefaultMenuSaveSet) UpdateTitle() GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") $sLastSel = "" $fAction = 0 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_DROPPED ; If the value of @GUI_DropId is $idLabel, then set the label of the dragged file. If @GUI_DropId = $idLabel Then LoadDroppedImage(@GUI_DragFile) Case $idBugFixMenu Bugfix() Case $idMenuAbout $tmp = "Options saved/read to/from the ini file:" & @CRLF & @CRLF & "[setting]" & @CRLF & "WinOnTop=0" & @CRLF & "MenuFormatType=0" & @CRLF & "MenuSaveSetNr=0" & @CRLF & "NumberOfButtons=50" & @CRLF & "DisplayInfo=1" $WPos = WinGetPos($hGUI) MsgBoxButton("Info: ", $tmp, "Ok", 200, 150, $WPos[0] + 130, $WPos[1] + 50, 2) $WPos = "" $tmp = "" Case $idMenuGuiOnTop If BitAND(GUICtrlRead($idMenuGuiOnTop), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState($idMenuGuiOnTop, $GUI_UNCHECKED) WinSetOnTop($hGUI, "", 0) IniWrite($iniFile, "setting", "WinOnTop", 0) Else GUICtrlSetState($idMenuGuiOnTop, $GUI_CHECKED) WinSetOnTop($hGUI, "", 1) WinActivate($hGUI) IniWrite($iniFile, "setting", "WinOnTop", 1) EndIf Case $idMenuClearButtons $WPos = WinGetPos($hGUI) $iMsgBoxAnswer = MsgBoxButton("Warning ! ", " Do you really want to clear all buttons?", "Yes|No", 200, 80, $WPos[0] + 130, $WPos[1] + 50, 2) If $iMsgBoxAnswer = 1 Then ;Yes For $x = 1 To ($btnmax - 1) _GDIPlus_ImageDispose($CBTN[$x][1]) $CBTN[$x][1] = 0 GUICtrlSetBkColor($CBTN[$x][0], "0xFF7070") Next EndIf $WPos = "" Case $idMenuOpenFolder $tmp = $Foldername & $aSaveSet[$DefaultMenuSaveSet][0] & "\" If FileExists($tmp) Then ShellExecute($tmp) $tmp = "" Case $idMenuSave SaveImages($DefaultMenuSaveSet, $DefaultMenuTypeFMT) PopulateListBox($DefaultMenuSaveSet) Case $GUI_EVENT_CLOSE, $idMenuExit $WPos = WinGetPos($hGUI) $iMsgBoxAnswer = MsgBoxButton("Warning ! ", " Do you really want to end the program ?", "Yes|No", 200, 80, $WPos[0] + 130, $WPos[1] + 50, 2) If $iMsgBoxAnswer = 1 Then ;Yes _GDIPlus_ImageDispose($hImage) For $x = 0 To ($btnmax - 1) _GDIPlus_ImageDispose($CBTN[$x][1]) Next _GDIPlus_Shutdown() ; Shut down clipboard viewer _ClipBoard_ChangeChain($hGUI, $g_hNext) Exit EndIf $WPos = "" Case $GUI_EVENT_RESIZED, $GUI_EVENT_RESTORE, $GUI_EVENT_MAXIMIZE _GUIScrollBars_SetScrollInfoPos($hChild, $SB_Horz, 0) $WPos = WinGetPos($hGUI) WinMove($hChild, "", $WPos[0] + 13, $WPos[1] + 54, $WPos[2] - 24, 54) $WPos = "" _GUIScrollbars_Generate($hChild, (($btnmax) * 21), 30) ;_GUIScrollbars_Restore($hChild, False, True) Sleep(20) ReDrawBitmap() Case $GUI_EVENT_SECONDARYUP $anmsg = GUIGetCursorInfo($hChild) If IsArray($anmsg) Then For $x = 0 To ($btnmax - 1) If $x > 0 Then If $anmsg[4] = $CBTN[$x][0] Then If $CBTN[$x][1] > 0 Then _GDIPlus_ImageDispose($CBTN[$x][1]) GUICtrlSetBkColor($CBTN[$x][0], "0xFF7070") $CBTN[$x][1] = 0 EndIf EndIf EndIf Next EndIf $anmsg = "" Case Else If $nMsg > 0 Then ;Loop through the Buttons For $x = 0 To ($btnmax - 1) If $nMsg = $CBTN[$x][0] Then If $x > 0 Then If $CBTN[$x][1] = 0 And $hImage > 0 Then $CBTN[$x][1] = _GDIPlus_ImageClone($hImage) GUICtrlSetBkColor($CBTN[$x][0], "0x70FFFF") EndIf EndIf If $CBTN[$x][1] > 0 Then _GDIPlus_ImageDispose($hImage) $hImage = _GDIPlus_ImageClone($CBTN[$x][1]) EndIf ReDrawBitmap() EndIf Next ;Loop throgh the Set menu For $x = 0 To (UBound($aSaveSet) - 1) If $nMsg = $aSaveSet[$x][1] Then $DefaultMenuSaveSet = $x PopulateListBox($x) UpdateTitle() IniWrite($iniFile, "setting", "MenuSaveSetNr", $DefaultMenuSaveSet) EndIf Next ;Loop throgh Option menu For $x = 0 To (UBound($aFmt) - 1) If $nMsg = $aFmt[$x][1] Then $DefaultMenuTypeFMT = $x UpdateTitle() IniWrite($iniFile, "setting", "MenuFormatType", $DefaultMenuTypeFMT) EndIf Next EndIf EndSwitch If GUICtrlRead($hListBox) <> $sLastSel Then ;Code by melba23 - autoit forum $sLastSel = GUICtrlRead($hListBox) Sleep(150) If $fAction = 1 Then ;Listbox Double Click LoadImage($sLastSel, $DefaultMenuSaveSet) Else ;Listbox Single Click LoadImage($sLastSel, $DefaultMenuSaveSet) EndIf $fAction = 0 Else If $fAction = 1 Then ;Listbox Double Click LoadImage($sLastSel, $DefaultMenuSaveSet) $fAction = 0 EndIf EndIf _GUIScrollbars_EventMonitor() WEnd Func Bugfix() _ClipBoard_ChangeChain($hGUI, $g_hNext) $g_hNext = _ClipBoard_SetViewer($hGUI) GUIRegisterMsg($WM_CHANGECBCHAIN, "WM_CHANGECBCHAIN") GUIRegisterMsg($WM_DRAWCLIPBOARD, "WM_DRAWCLIPBOARD") EndFunc ;==>Bugfix Func UpdateTitle() If $displayinfo = 1 Then GUICtrlSetData($idMenuAbout, " ( " & $aFmt[$DefaultMenuTypeFMT][0] & " ) / ( " & $aSaveSet[$DefaultMenuSaveSet][0] & " )") Else WinSetTitle($hGUI, "", "Clipboard Monitor (" & $aFmt[$DefaultMenuTypeFMT][0] & ") / ( " & $aSaveSet[$DefaultMenuSaveSet][0] & " )") EndIf EndFunc ;==>UpdateTitle Func LoadImage($FNa, $Nr) Local $tmp1 = $aSaveSet[$Nr][0] Local $tmpF = $Foldername & $tmp1 & "\" & $FNa Local $tmpH = 0 If FileExists($tmpF) Then $tmpH = _GDIPlus_ImageLoadFromFile($tmpF) If $tmpH > 0 Then If $hImage > 0 Then _GDIPlus_ImageDispose($hImage) $hImage = _GDIPlus_ImageClone($tmpH) _GDIPlus_ImageDispose($tmpH) ReDrawBitmap() EndIf EndIf EndFunc ;==>LoadImage Func LoadDroppedImage($Filename) If FileExists($Filename) Then $tmpH = _GDIPlus_ImageLoadFromFile($Filename) If $tmpH > 0 Then If $hImage > 0 Then _GDIPlus_ImageDispose($hImage) $hImage = _GDIPlus_ImageClone($tmpH) _GDIPlus_ImageDispose($tmpH) ReDrawBitmap() EndIf EndIf EndFunc ;==>LoadDroppedImage Func PopulateListBox($Nr = 0) Local $tmp = $aFmt[1][0] Local $tmp1 = $aSaveSet[$Nr][0] Local $tmpF = $Foldername & $tmp1 & "\" Local $tmpFN = "", $tmpFNa = "" Local $tmpfiles Local $x, $y Local $tmpBox = "" GUICtrlSetData($hListBox, $tmpBox) For $y = 0 To UBound($aFmt) - 1 $tmp = $aFmt[$y][0] For $x = 0 To $btnmax - 1 $tmpFNa = _StringRepeat("0", 2 - StringLen($x)) & $x & "." & $tmp $tmpFN = $tmpF & $tmpFNa If FileExists($tmpFN) Then $tmpBox = $tmpBox & $tmpFNa & "|" EndIf Next Next GUICtrlSetData($hListBox, $tmpBox) EndFunc ;==>PopulateListBox Func SaveImages($Nr = 0, $typ = 0) Local $tmp = $aFmt[$typ][0] Local $tmp1 = $aSaveSet[$Nr][0] Local $tmpF = $Foldername & $tmp1 & "\" Local $tmpFN = "" Local $tmpfiles If FileExists($tmpF) = 0 Then DirCreate($tmpF) $tmpexist = 0 For $x = 1 To UBound($CBTN) - 1 $tmpFNa = _StringRepeat("0", 2 - StringLen($x)) & $x & "." & $tmp $tmpFN = $tmpF & $tmpFNa If FileExists($tmpFN) And $CBTN[$x][1] > 0 Then $tmpexist = $tmpexist + 1 $tmpfiles = $tmpfiles & $tmpFNa & @CRLF EndIf Next If $tmpexist > 0 Then $WPos = WinGetPos($hGUI) If MsgBoxButton("Warning: File(s) exist", "Following files may be deleted from:" & @CRLF & $tmpF & @CRLF & @CRLF & $tmpfiles & "Do you wish to continue ?", "Yes|No", 220, 100, $WPos[0] + 130, $WPos[1] + 50, 2) = 1 Then $tmpexist = 0 EndIf If $tmpexist = 0 Then For $x = 1 To UBound($CBTN) - 1 $tmpFN = $tmpF & _StringRepeat("0", 2 - StringLen($x)) & $x & "." & $tmp If $CBTN[$x][1] > 0 Then _GDIPlus_ImageSaveToFile($CBTN[$x][1], $tmpFN) Next EndIf EndFunc ;==>SaveImages Func ReDrawBitmap() $WPos = WinGetPos($hGUI) $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) _GDIPlus_DrawImagePoints($hGraphics, $hImage, 85, 60, $WPos[2] - 20, 60, 85, $WPos[3] - 62) _GDIPlus_GraphicsDispose($hGraphics) EndFunc ;==>ReDrawBitmap Func ClipDrawBitmap() Local $WPos, $hBitmap, $hGraphics $WPos = WinGetPos($hGUI) _ClipBoard_Open($hGUI) $hBitmap = _ClipBoard_GetDataEx($CF_BITMAP) _ClipBoard_Close() If $hBitmap > 0 Then If $hImage > 0 Then _GDIPlus_ImageDispose($hImage) If $CBTN[0][1] > 0 Then _GDIPlus_ImageDispose($CBTN[0][1]) $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap) $CBTN[0][1] = _GDIPlus_ImageClone($hImage) GUICtrlSetBkColor($CBTN[0][0], "0x00FF00") _WinAPI_DeleteObject($hBitmap) ReDrawBitmap() EndIf EndFunc ;==>ClipDrawBitmap ; Handle $WM_CHANGECBCHAIN messages Func WM_CHANGECBCHAIN($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg ; If the next window is closing, repair the chain If $wParam = $g_hNext Then $g_hNext = $lParam ; Otherwise pass the message to the next viewer ElseIf $g_hNext <> 0 Then _SendMessage($g_hNext, $WM_CHANGECBCHAIN, $wParam, $lParam, 0, "hwnd", "hwnd") EndIf EndFunc ;==>WM_CHANGECBCHAIN ; Handle $WM_DRAWCLIPBOARD messages Func WM_DRAWCLIPBOARD($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg ; Display any image from clipboard ClipDrawBitmap() ; Pass the message to the next viewer If $g_hNext <> 0 Then _SendMessage($g_hNext, $WM_DRAWCLIPBOARD, $wParam, $lParam) EndFunc ;==>WM_DRAWCLIPBOARD Func MsgBoxButton($title = "MsgBox", $txt = "", $buttons = "Ok|Cancel", $width = 250, $height = 100, $xpos = -1, $ypos = -1, $defbtn = 1) ;By Dan_555 ;Displays a custom message box with variable number of buttons ;$title = Title text, $txt=info text ;$buttons = Add any number of buttons needed by entering their names. Buttons are separated by | E.g. 'yes|no' will create two buttons. Button numbers start from 1 ;$Width, $height minimum of 250,100. Height is expanded by the amount of buttons. ;Button width is dependant on the Gui-Width ;$defbtn sets a button to act as default button - Acted upon return Local $hParentGui = WinGetHandle("", "") GUISetState(@SW_DISABLE, $hParentGui) Local $nMsg Local $btnnr = -1 If StringLeft($buttons, 1) <> "|" Then $buttons = "|" & $buttons If StringRight($buttons, 1) <> "|" Then $buttons = $buttons & "|" Local $a_btn = _StringBetween($buttons, "|", "|") If @error = 0 Then For $x = UBound($a_btn) - 1 To 0 Step -1 If $a_btn[$x] = "" Then _ArrayDelete($a_btn, $x) Next Else ;Error creating button array Local $a_btn[] = ["ok"] EndIf If $height < (UBound($a_btn)) * 20 Then $height = (UBound($a_btn)) * 20 If $width < 250 Then $width = 250 If $height < 100 Then $height = 100 Local $ahBtn[UBound($a_btn)] Local $hMsgBoxGui = GUICreate($title, $width, $height, $xpos, $ypos, BitOR($WS_DLGFRAME, $WS_BORDER, $WS_VISIBLE), BitOR($WS_EX_TOPMOST, $WS_EX_APPWINDOW), $hParentGui) Local $hMsgBoxEdi = GUICtrlCreateEdit($txt, 0, 0, 195, $height, BitOR($WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY)) ;Local $hMsgBoxEdi = GUICtrlCreateEdit($txt, 0, 0, 195, $height, BitOR($WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_READONLY)) ;Local $hMsgBoxEdi = GUICtrlCreateLabel($txt, 2, 2, 195, $height-4,$SS_SUNKEN) Local $xs = $height - (20 * (UBound($a_btn) - 1)) - 20 For $x = 0 To UBound($a_btn) - 1 $deftyp = -1 If $defbtn = $x + 1 Then $deftyp = $BS_DEFPUSHBUTTON $ahBtn[$x] = GUICtrlCreateButton($a_btn[$x], 198, $xs + ($x * 20), $width - 199, 20, $deftyp) ;~ $ahBtn[$x] = GUICtrlCreateButton($a_btn[$x], 198, (UBound($a_btn)-1 = 0) ? (($height/2)-10)+($x * 20) : (($height/UBound($a_btn))-20)+($x * 20) , $width-199, 20,$deftyp) Next GUISetState(@SW_SHOW) Do $nMsg = GUIGetMsg() If $nMsg > 0 Then For $x = 0 To UBound($ahBtn) - 1 If $nMsg = $ahBtn[$x] Then $btnnr = $x + 1 Next EndIf Until $btnnr > -1 GUIDelete($hMsgBoxGui) GUISetState(@SW_ENABLE, $hParentGui) WinActivate($hParentGui) Return $btnnr EndFunc ;==>MsgBoxButton Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) ;code from https://www.autoitscript.com/forum/topic/119058-how-to-set-a-handler-function-for-listbox-double-click-action/?do=findComment&comment=827814 #forceref $hWnd, $iMsg Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = $lParam $iCode = BitShift($wParam, 16) ; Hi Word Switch $hWndFrom Case $hWndListBox Switch $iCode Case $LBN_DBLCLK ; Sent when the user double-clicks a string in a list box $fAction = 1 EndSwitch EndSwitch EndFunc ;==>WM_COMMAND Edited December 3, 2024 by Dan_555 Some of my script sourcecode
Dan_555 Posted December 10, 2024 Author Posted December 10, 2024 (edited) This is a mix of few scripts found here on the forum. What does it do ? - It is a Font Preview App. It has a Big Label, Normal Label, Edit box, Input box, Resizable Input box and a Big Button. - All of these are filled with a text. The script takes a list of fonts (although there are some missing like Terminal ... which you can type in the font name box) and applies the font with the settings to the above controls - On The Fly. You can see the result immediately. The Input box on the bottom right side holds the AutoIt ready command. If you click on the "Remember font", this setting will be saved (and added to the edit box above it). You can copy the text from the edit box, but conveniently, this app will Copy all the "Remembered" font commands and copy it to the clipboard. (There should be no duplicate entries) expandcollapse popup;modified version of this script: https://www.autoitscript.com/forum/topic/52677-font-selector/?do=findComment&comment=398585 ;mixed with (and modified) https://www.autoitscript.com/forum/topic/202989-enumerating-fonts/?do=findComment&comment=1458177 #include <Array.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <FontConstants.au3> #include <WinAPIGdi.au3> #include <GuiEdit.au3> $hGui = GUICreate("Font", 640, 252, 0, 0, $WS_SYSMENU + $WS_MAXIMIZEBOX + $WS_MINIMIZEBOX + $WS_THICKFRAME) Global $aWeight[][] = [["$FW_DONTCARE", 0], ["$FW_THIN", 100], ["$FW_EXTRALIGHT", 200], ["$FW_LIGHT", 300], ["$FW_NORMAL", 400], ["$FW_MEDIUM", 500], ["$FW_SEMIBOLD", 600], ["$FW_BOLD", 700], ["$FW_EXTRABOLD", 800], ["$FW_HEAVY", 900]] Opt("GUIResizeMode", 1) $fontlist = _FontGetList(0) _ArrayDelete($fontlist, 0) $aEnumFont = EnumFontTree() For $i = 1 To UBound($aEnumFont) - 1 _ArrayAdd($fontlist, $aEnumFont[$i]) Next $aEnumFont="" ;Free the Array $fontlist = _ArrayUnique($fontlist) _ArrayDelete($fontlist, 0) _ArraySort($fontlist) $fontselect = GUICtrlCreateCombo("Arial", 0, 200, 215, 20) For $i = 0 To UBound($fontlist) - 1 GUICtrlSetData($fontselect, $fontlist[$i], "Arial") Next $fontlist="" ;Free the Array $fontsize = GUICtrlCreateCombo("2", 216, 200, 45, 20) GUICtrlSetData($fontsize, "4|5|6.5|7|7.5|8|8.5|9|9.5|10|10.5|11|11.5|12|12.5|14|14.5|16|16.5|18|18.5|20|20.5|22|22.5|24|24|26|28|30|32|36|48|72", "10") $fontstyle = GUICtrlCreateCombo("Normal", 262, 200, 75, 20) GUICtrlSetData($fontstyle, "Italic|Underline|Strike", "Normal") $weight = GUICtrlCreateCombo("", 233, 179, 103, 20) $setfont = GUICtrlCreateButton("Test Font123", 233, 0, 103, 45) $edit = GUICtrlCreateEdit("", 339, 0, 300, 193) $label = GUICtrlCreateLabel("", 0, 0, 230, 193) $input = GUICtrlCreateInput("Font Test123", 233, 46, 103, 45) $inputSmall = GUICtrlCreateInput("Font Test123", 233, 93, 103, 20) GUICtrlSetResizing(-1, $GUI_DOCKSIZE) $labelSmall = GUICtrlCreateLabel("Font Test123", 233, 117, 103, 20) GUICtrlSetResizing(-1, $GUI_DOCKSIZE) $usefont = GUICtrlCreateButton("Remember font", 233, 150, 103, 22) GUICtrlSetTip($usefont, "Adds the definition into a variable and to the edit box! " & @CRLF & "The variable will be copied into clipboard at the end of the program", "Info:") $output = GUICtrlCreateInput("", 340, 200, 298, 20) GUICtrlSetBkColor($label, 0xff00ff) GUISetState() $tmp = "" $tmp = $tmp & "ABCDEFGHIJLKMNOPQRSTUVWYYZ" $tmp = $tmp & "ÜÄÖßüäöß" & @CRLF $tmp = $tmp & "abcdefghijlkmnopqrstuvwyyz" & @CRLF $tmp = $tmp & "1234567890!§$%&/()=?`|_-,<>|@^" & @CRLF $tmp = $tmp & "******************************" & @CRLF $tmp = $tmp & "* * * *" & @CRLF $tmp = $tmp & "* *" & @CRLF $tmp = $tmp & "******************************" & @CRLF For $x = 1 To 255 $tmp1 = "" If Mod($x, 30) = 1 Then $tmp1 = @CRLF $tmp = $tmp & Chr($x) & $tmp1 Next GUICtrlSetData($label, $tmp & @CRLF) GUICtrlSetData($edit, $tmp & @CRLF) $tmp = "" $tmp1 = "" For $x = 0 To UBound($aWeight) - 1 $tmp1 = "|" If $x = UBound($aWeight) - 1 Then $tmp1 = "" $tmp = $tmp & $aWeight[$x][0] & $tmp1 Next GUICtrlSetData($weight, $tmp, $aWeight[4][0]) Local $diffFSize = -1, $diffSel, $diffAttr, $diffWe, $changed = 0 Local $ClipboardText[0] Do $msg3 = GUIGetMsg() If $diffFSize <> GUICtrlRead($fontsize) Then $changed = 1 If $diffSel <> GUICtrlRead($fontselect) Then $changed = 1 If $diffAttr <> GUICtrlRead($fontstyle) Then $changed = 1 If $diffWe <> GUICtrlRead($weight) Then $changed = 1 If $changed = 1 Then If GUICtrlRead($fontstyle) = "Normal" Then $attribute = 0 ElseIf GUICtrlRead($fontstyle) = "Italic" Then $attribute = 2 ElseIf GUICtrlRead($fontstyle) = "Underline" Then $attribute = 4 ElseIf GUICtrlRead($fontstyle) = "Strike" Then $attribute = 8 EndIf $diffFSize = GUICtrlRead($fontsize) $diffSel = GUICtrlRead($fontselect) $diffAttr = GUICtrlRead($fontstyle) $diffWe = GUICtrlRead($weight) $tmp = "" For $x = 0 To UBound($aWeight) - 1 If $aWeight[$x][0] = $diffWe Then $tmp = $aWeight[$x][1] ExitLoop EndIf Next GUICtrlSetFont($edit, $diffFSize, $tmp, $attribute, $diffSel) GUICtrlSetFont($setfont, $diffFSize, $tmp, $attribute, $diffSel) GUICtrlSetFont($label, $diffFSize, $tmp, $attribute, $diffSel) GUICtrlSetFont($input, $diffFSize, $tmp, $attribute, $diffSel) GUICtrlSetFont($inputSmall, $diffFSize, $tmp, $attribute, $diffSel) GUICtrlSetFont($labelSmall, $diffFSize, $tmp, $attribute, $diffSel) GUICtrlSetData($output, "GuiCtrlSetFont ($id," & $diffFSize & "," & $diffWe & "," & $attribute & "," & $diffSel & ")") $changed = 0 EndIf If $msg3 = $usefont Then $tmp = GUICtrlRead($output) _ArrayAdd($ClipboardText, $tmp) _GUICtrlEdit_AppendText($edit, $tmp & @CRLF) EndIf Until $msg3 = $GUI_EVENT_CLOSE If IsArray($ClipboardText) And UBound($ClipboardText) > 0 Then $ClipboardText = _ArrayUnique($ClipboardText) _ArrayDelete($ClipboardText, 0) _ArrayToClip($ClipboardText, @CRLF) EndIf GUIDelete($hGui) Exit ;=============================================================================== ; Function Name: _FontGetList() ; Description: Returns an array with a list of all fonts currently installed on the system. ; Parameter(s): $i_opt - An Integer, 0 or 1. 0 will create a 1D array with font names only. ; 1 will create a 2d array with font names in the first column, font file names in the second ; Requirement(s): None ; Return Value(s): 1D-2D Array = [0] or [0][0] Contains total number of fonts. ; Author(s): Simucal <simucal@gmail.com> ; Revision: 20060501A ; ;=============================================================================== Func _FontGetList($i_opt = 0) Dim $a_FontNames[1], $a_FontNamesFiles[1][1], $i = 1 If @OSType = "WIN32_NT" Then $regkey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" If @OSType = "WIN32_WINDOWS" Then $regkey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Fonts" While 1 $s_temp = RegEnumVal($regkey, $i) If @error <> 0 Then ExitLoop $s_temp2 = RegRead($regkey, $s_temp) $s_temp = StringRegExpReplace($s_temp, "\s\(.*?\)(\s*)?", "") If $i_opt = 0 Then ReDim $a_FontNames[($i + 1)] $a_FontNames[$i] = $s_temp ElseIf $i_opt = 1 Then ReDim $a_FontNames[($i + 1)] $a_FontNames[$i] = $s_temp & "|" & $s_temp2 EndIf $i = $i + 1 WEnd If $i_opt = 0 Then _ArraySort($a_FontNames) $a_FontNames[0] = (UBound($a_FontNames) - 1) Return ($a_FontNames) ElseIf $i_opt = 1 Then _ArraySort($a_FontNames) ; Sort with font names and files as a single array For $i = 1 To (UBound($a_FontNames) - 1) ; then split it up into 2D, so they will be alphabatized together. $s_fontsplit = StringSplit($a_FontNames[$i], "|") If IsArray($s_fontsplit) = 1 Then ReDim $a_FontNamesFiles[($i + 1)][2] $a_FontNamesFiles[$i][0] = $s_fontsplit[1] $a_FontNamesFiles[$i][1] = $s_fontsplit[2] EndIf Next $a_FontNamesFiles[0][0] = (UBound($a_FontNamesFiles) - 1) Return ($a_FontNamesFiles) EndIf EndFunc ;==>_FontGetList Func EnumFontTree() Local $font_list = _WinAPI_EnumFontFamilies(0, "", "", -1, "@*", True) _ArraySort($font_list, 0, 1, 0, 0) Local $font_tree[1] $i = 1 While ($i <= $font_list[0][0]) $tmp = $font_list[$i][0] _ArrayAdd($font_tree, $tmp) $i = $i + 1 WEnd Return $font_tree EndFunc ;==>EnumFontTree Edited December 10, 2024 by Dan_555 Minor fixes. argumentum 1 Some of my script sourcecode
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now