ioa747 Posted 12 hours ago Posted 12 hours ago (edited) hybrid GUI (killing boredom) Flat_GUI.au3 expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <GUIConstants.au3> #include <WinAPISysWin.au3> #include <WinAPIGdi.au3> ; Flat_GUI.au3 Global $Bar _MakeGui() ;--------------------------------------------------------------------------------------- Func _MakeGui() Local $hGUI = GUICreate("Flat GUI", 400, 200, -1, -1, $WS_POPUP) Local $sExtras = "Do_This, Do_That, -, DarkSlateGray, DimGray, SteelBlue, DarkSlateBlue, DarkViolet" $Bar = _MakeBar($hGUI, $sExtras, 0x42414D, 0xC8C8C8, 0x999999) GUISetBkColor($Bar.GUI_BkColor, $hGUI) GUISetState(@SW_SHOW, $hGUI) Local $iMsg While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE, $Bar.PowerButton ConsoleWrite("$Bar.PowerButton" & @CRLF) ExitLoop Case $Bar.Save ConsoleWrite("$Bar.Save" & @CRLF) Case $Bar.Settings ConsoleWrite("$Bar.Settings" & @CRLF) Case $Bar.Pinned ConsoleWrite("$Bar.Pinned" & @CRLF) $Bar.TopMost = Not $Bar.TopMost WinSetOnTop($hGUI, "", $Bar.TopMost) If $Bar.TopMost Then _ToolTip(" ", Default, Default, "Wnd Pinned on Top", 1) Else _ToolTip(" ", Default, Default, "Wnd UnPinned from Top", 3) EndIf Case $Bar.Minimize ConsoleWrite("$Bar.Minimize" & @CRLF) GUISetState(@SW_MINIMIZE) Case $Bar.GlobalNavButton ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MouseClick("right") Case $Bar.ctx_Do_This ConsoleWrite("$Bar.ctx_Do_This" & @CRLF) Case $Bar.ctx_Do_That ConsoleWrite("$Bar.ctx_Do_That" & @CRLF) Case $Bar.ctx_DarkSlateGray ConsoleWrite("$Bar.ctx_DarkSlateGray" & @CRLF) _UpdateTheme(0x42414D) ;Dark slate gray Case $Bar.ctx_DimGray ConsoleWrite("$Bar.ctx_DimGray" & @CRLF) _UpdateTheme(0x4A5D68) ;Dim gray Case $Bar.ctx_SteelBlue ConsoleWrite("$Bar.ctx_SteelBlue" & @CRLF) _UpdateTheme(0x388692) ;Steel blue Case $Bar.ctx_DarkSlateBlue ConsoleWrite("$Bar.ctx_DarkSlateBlue" & @CRLF) _UpdateTheme(0x385385) ;Dark slate blue Case $Bar.ctx_DarkViolet ConsoleWrite("$Bar.ctx_DarkViolet" & @CRLF) _UpdateTheme(0xB200FF) ;Dark violet Case $Bar.ctx_About ConsoleWrite("$Bar.ctx_About" & @CRLF) MsgBox($MB_SYSTEMMODAL, "About", "Flat GUI version 0.0.1", 5, $hGUI) Case Else ;If $iMsg > 1 Then ConsoleWrite("$iMsg=" & $iMsg & @CRLF) EndSwitch _CheckHover($hGUI) WEnd GUIDelete($hGUI) EndFunc ;==>_MakeGui ;--------------------------------------------------------------------------------------- Func _MakeBar($hGUI, $ctx_list = "", $iBkColor = 0x42414D, $iTxtColor = 0xC8C8C8, $iGUIBkColor = 0x999999) Local $Btn[][] = [[59136, "GlobalNavButton"] _ , [0xE74E, "Save"] _ , [0xF8B0, "Settings"] _ , [0xE840, "Pinned"] _ , [0xE70D, "Minimize"] _ , [0xE7E8, "PowerButton"]] Local $aCsz = WinGetClientSize($hGUI) Local $m[] $m.TxtColor = $iTxtColor $m.BkColor = $iBkColor $m.GUI_BkColor = $iGUIBkColor $m.TopMost = 0 $m.Bar_Cnt = UBound($Btn) $m.Bar_H = 24 $m.Bar_W = $m.Bar_Cnt * $m.Bar_H $m.Bar_Y = 2 $m.Bar_X = $aCsz[0] - $m.Bar_W - $m.Bar_Y $m.Bar_Dummy = GUICtrlCreateButton("", 0, 0, 1, 1) $m.Bar_Title = " " & WinGetTitle($hGUI) $m.Bar_idTitle = GUICtrlCreateLabel($m.Bar_Title, $m.Bar_Y, $m.Bar_Y, $m.Bar_X - ($m.Bar_Y * 2), $m.Bar_H, $BS_FLAT, $GUI_WS_EX_PARENTDRAG) GUICtrlSetFont(-1, 12, 600, Default, "Segoe UI") GUICtrlSetColor(-1, $iTxtColor) GUICtrlSetBkColor(-1, $iBkColor) Local $mCtrl[] For $i = 0 To $m.Bar_Cnt - 1 $m[$Btn[$i][1]] = GUICtrlCreateButton(ChrW($Btn[$i][0]), $i * $m.Bar_H + $m.Bar_X, $m.Bar_Y, $m.Bar_H, $m.Bar_H) $mCtrl["ID_" & $m[$Btn[$i][1]]] = $Btn[$i][1] GUICtrlSetColor(-1, $iTxtColor) GUICtrlSetBkColor(-1, $iBkColor) GUICtrlSetFont(-1, 12, 600, Default, "Segoe Fluent Icons") Next $m["Ctrl"] = $mCtrl ; Creating the Context Menu (adding to GlobalNavButton) $m.ctx = GUICtrlCreateContextMenu($m.GlobalNavButton) ; List combination: Extra items + Separator + Basic items Local $sFinalList = $ctx_list If $sFinalList <> "" Then $sFinalList &= ",-," $sFinalList &= "About" ; defaul entry Local $aItems = StringSplit($sFinalList, ",") Local $sName For $i = 1 To $aItems[0] $sName = StringReplace(StringStripWS($aItems[$i], 3), " ", "_") If $sName = "-" Then GUICtrlCreateMenuItem("", $m.ctx) ; Create a separator line Else $m["ctx_" & $sName] = GUICtrlCreateMenuItem($sName, $m.ctx) EndIf Next Return $m EndFunc ;==>_MakeBar ;--------------------------------------------------------------------------------------- Func _ToolTip($sText, $iX = Default, $iY = Default, $sTitle = "", $iIcon = 0, $iTimeout = 1500, $iOptions = 0) AdlibUnRegister("_ToolTipKiller") ; This prevents the previous timer from closing the new tooltip. ToolTip($sText, $iX, $iY, $sTitle, $iIcon, $iOptions) AdlibRegister("_ToolTipKiller", $iTimeout) EndFunc ;==>_ToolTip ;--------------------------------------------------------------------------------------- Func _ToolTipKiller() ToolTip("") ; Hide the tooltip AdlibUnRegister("_ToolTipKiller") ; unregister itself. EndFunc ;==>_ToolTipKiller ;--------------------------------------------------------------------------------------- Func On_Hover($idControl, $bHoover) Local $xCollor If $bHoover Then $xCollor = ($Bar.Ctrl["ID_" & $idControl] = "PowerButton" ? 0xFF0000 : $Bar.TxtColor) GUICtrlSetColor($idControl, $Bar.BkColor) GUICtrlSetBkColor($idControl, $xCollor) Else $xCollor = (($Bar.Ctrl["ID_" & $idControl] = "Pinned" And $Bar.TopMost) ? 0x00B4FF : $Bar.TxtColor) GUICtrlSetColor($idControl, $xCollor) GUICtrlSetBkColor($idControl, $Bar.BkColor) EndIf EndFunc ;==>On_Hover ;--------------------------------------------------------------------------------------- Func _CheckHover($hGUI) Local Static $iLastBtnID = 0, $iLastWndState = 0 Local $aCursor = GUIGetCursorInfo($hGUI) If $iLastWndState <> WinActive($hGUI) Then $iLastWndState = WinActive($hGUI) GUICtrlSetColor($Bar.Bar_idTitle, ($iLastWndState = 0 ? $Bar.GUI_BkColor : $Bar.TxtColor)) EndIf ; If Not Not $iLastWndState Then Return If Not IsArray($aCursor) Then Return Local $iCurrentID = $aCursor[4] If $iCurrentID = $iLastBtnID Then Return If $iLastBtnID <> 0 Then On_Hover($iLastBtnID, False) $iLastBtnID = 0 _ToolTipKiller() EndIf If $iCurrentID <> 0 Then Local $sBtnText = GUICtrlRead($iCurrentID) ; Check if it is an icon If StringLen($sBtnText) = 1 Then On_Hover($iCurrentID, True) $iLastBtnID = $iCurrentID _ToolTip($Bar.Ctrl["ID_" & $iCurrentID]) EndIf EndIf EndFunc ;==>_CheckHover ;--------------------------------------------------------------------------------------- Func _UpdateTheme($iNewColor) $Bar.BkColor = $iNewColor GUICtrlSetState($Bar.Bar_Dummy, $GUI_FOCUS) ; move focus to Dummy GUICtrlSetBkColor($Bar.Bar_idTitle, $iNewColor) ; Force a hover check to redraw buttons Local $aKeys = MapKeys($Bar.Ctrl) For $vKey In $aKeys On_Hover(Int(StringTrimLeft($vKey, 3)), False) Next EndFunc ;==>_UpdateTheme ;--------------------------------------------------------------------------------------- Edited 7 hours ago by ioa747 mLipok and argumentum 2 I know that I know nothing
ioa747 Posted 11 hours ago Author Posted 11 hours ago (edited) and some extras for easy selection SegoeFluentIconsUI.au3 expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <GUIConstants.au3> #include <WinAPIGdi.au3> #include <File.au3> #include <GUIScrollbars_Ex.au3> ; https://www.autoitscript.com/forum/topic/113723-scrollbars-made-easy-new-version-27-jan-22/ ; SegoeFluentIconsUI.au3 Global $sButtonFont = "Segoe Fluent Icons" Global $aMaterialIcons = MaterialIcons() Global $aBtn[$aMaterialIcons[0][0] + 1] = [$aMaterialIcons[0][0]] Global $hGUI ; grid 25 x ?? Global $iCol = 25, $iRow = Ceiling($aMaterialIcons[0][0] / $iCol) ConsoleWrite("$iCol=" & $iCol & ", $iRow=" & $iRow & @CRLF) Global $iW = 32, $iH = 32, $iSpace = 5, $iHeader = 5, $iHeight = 820 _Main() Func _Main() $hGUI = GUICreate($sButtonFont, $iCol * $iW + 4 * $iSpace, $iHeight, 700, 50) GUISetBkColor(0x999999) Local $hSubGUI = _Make_SubForm() _GUIScrollbars_Generate($hSubGUI, 0, $iRow * $iH + 15) ; _Rich_GUI If Not WinExists("_Rich_GUI") Then ShellExecute(@AutoItExe, '"' & @ScriptDir & '\_Rich_GUI.au3"') Local $hRich_Wnd = WinWait("_Rich_GUI", "", 5) If Not $hRich_Wnd Then Exit ConsoleWrite("! Not found _Rich_GUI" & @CRLF) Local $hRichInp_Font = ControlGetHandle($hRich_Wnd, "", "Edit1") Local $hRichInp_Data = ControlGetHandle($hRich_Wnd, "", "Edit2") Local $hRichBtn_Update = ControlGetHandle($hRich_Wnd, "", "Button1") GUISwitch($hGUI) GUISetState(@SW_SHOW, $hGUI) Local $iMsg While WinExists($hRich_Wnd) $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE ExitLoop Case 3 To 2 + $aMaterialIcons[0][0] Local $id = $iMsg - 2 Local $sData = ChrW($aMaterialIcons[$id][0]) & ', [' & $aMaterialIcons[$id][0] & ', "' & $aMaterialIcons[$id][1] & '"] _' ControlSetText($hRich_Wnd, "", $hRichInp_Font, $sButtonFont) ControlSetText($hRich_Wnd, "", $hRichInp_Data, $sData) ControlClick($hRich_Wnd, "", $hRichBtn_Update) EndSwitch _CheckHover($hGUI) WEnd GUIDelete($hGUI) EndFunc ;==>_Main ;--------------------------------------------------------------------------------------- Func _Make_SubForm() Local $iCnt = 0 Local $iX = $iSpace, $iY = $iSpace Local $hSubGUI = GUICreate("SubGUI", $iCol * $iW + 2 * $iSpace, $iHeight - 2 * $iSpace - $iHeader, $iSpace, $iHeader, _ BitOR($WS_CHILD, $WS_CLIPCHILDREN), $WS_EX_COMPOSITED, $hGUI) GUISetBkColor(0x999999) ; grid 25 x ?? For $ir = 1 To $iRow For $ic = 1 To $iCol $iCnt += 1 If $iCnt > $aBtn[0] Then ExitLoop 2 $aBtn[$iCnt] = GUICtrlCreateButton(ChrW($aMaterialIcons[$iCnt][0]), $iX, $iY, $iW, $iH) GUICtrlSetFont(-1, 18, Default, Default, $sButtonFont) GUICtrlSetColor(-1, 0xC8C8C8) GUICtrlSetBkColor(-1, 0x42414D) $iX += $iW Next $iX = $iSpace $iY += $iH Next GUISetState(@SW_SHOW) Return $hSubGUI EndFunc ;==>_Make_SubForm ;--------------------------------------------------------------------------------------- Func _CheckHover($hGUI) Local Static $iLastBtnID = 0 Local $aCursor = GUIGetCursorInfo($hGUI) If Not IsArray($aCursor) Or Not WinActive($hGUI) Then Return Local $iCurrentID = $aCursor[4] If $iCurrentID = $iLastBtnID Then Return If $iLastBtnID <> 0 Then On_Hover($iLastBtnID, False) $iLastBtnID = 0 _ToolTipKiller() EndIf If $iCurrentID <> 0 Then Local $sBtnText = GUICtrlRead($iCurrentID) ; Check if it is an icon If StringLen($sBtnText) = 1 Then On_Hover($iCurrentID, True) $iLastBtnID = $iCurrentID _ToolTip($aMaterialIcons[$iCurrentID - 2][1]) EndIf EndIf EndFunc ;==>_CheckHover ;--------------------------------------------------------------------------------------- Func On_Hover($idControl, $bHoover) If $bHoover Then GUICtrlSetColor($idControl, 0x42414D) GUICtrlSetBkColor($idControl, 0xC8C8C8) Else GUICtrlSetColor($idControl, 0xC8C8C8) GUICtrlSetBkColor($idControl, 0x42414D) EndIf EndFunc ;==>On_Hover ;--------------------------------------------------------------------------------------- Func MaterialIcons() Local $aArray = FileReadToArray(@ScriptDir & "\Segoe Fluent Icons.codepoints") Local $iLineCount = @extended If @error Then MsgBox($MB_SYSTEMMODAL, "", "There was an error reading the file. @error: " & @error) Else Local $aFont[$iLineCount + 1][2] $aFont[0][0] = $iLineCount ConsoleWrite("$iLineCount=" & $iLineCount & @CRLF) Local $aTxtPart For $i = 0 To $iLineCount - 1 ; Loop through the array. UBound($aArray) can also be used. $aTxtPart = StringSplit($aArray[$i], " ") If $aTxtPart[0] <> 2 Then ContinueLoop $aFont[$i + 1][1] = $aTxtPart[1] $aFont[$i + 1][0] = "0x" & $aTxtPart[2] Next Return $aFont EndIf EndFunc ;==>MaterialIcons ;--------------------------------------------------------------------------------------- Func _ToolTip($sText, $iX = Default, $iY = Default, $sTitle = "", $iIcon = 0, $iTimeout = 2000, $iOptions = 0) AdlibUnRegister("_ToolTipKiller") ; This prevents the previous timer from closing the new tooltip. ToolTip($sText, $iX, $iY, $sTitle, $iIcon, $iOptions) AdlibRegister("_ToolTipKiller", $iTimeout) EndFunc ;==>_ToolTip ;-------------------------------------------------------------------------------------------- Func _ToolTipKiller() ToolTip("") ; Hide the tooltip AdlibUnRegister("_ToolTipKiller") ; unregister itself. EndFunc ;==>_ToolTipKiller ;-------------------------------------------------------------------------------------------- _Rich_GUI.au3 expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <GUIConstantsEx.au3> #include <GuiRichEdit.au3> #include <WindowsStylesConstants.au3> ; _Rich_GUI.au3 Global $g_idLbl_Msg, $g_hRichEdit Example() Func Example() Local $hGui, $iMsg, $idBtn_Update, $idInp_Font, $idInp_Data, $idBtn_copy Local $iW = 600, $iH = 820 $hGui = GUICreate("_Rich_GUI", $iW, $iH, 50, 50) GUISetBkColor(0x999999) $g_hRichEdit = _GUICtrlRichEdit_Create($hGui, "", 10, 10, $iW - 20, $iH - 60, _ BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL), 0) _GUICtrlRichEdit_SetBkColor($g_hRichEdit, _WinAPI_SwitchColor(0x42414D)) $idBtn_Update = GUICtrlCreateButton("Next", $iW - 90, $iH - 40, 80, 30) GUICtrlSetState(-1, $GUI_HIDE) $idInp_Font = GUICtrlCreateInput("Times New Roman", 10, $iH - 40, 80, 20) GUICtrlSetState(-1, $GUI_HIDE) $idInp_Data = GUICtrlCreateInput("This is a test.", 100, $iH - 40, 80, 20) GUICtrlSetState(-1, $GUI_HIDE) $idBtn_copy = GUICtrlCreateButton("Copy Selection", $iW - 130, $iH - 40, 120, 30) GUISetState(@SW_SHOW) ; Constants for the EM_SETLANGOPTIONS message Local Const $WM_USER = 0x0400 Local Const $EM_SETLANGOPTIONS = $WM_USER + 120 Local Const $IMF_AUTOFONT = 0x0002 ; Read the current options Local $iOptions = _SendMessage($g_hRichEdit, $WM_USER + 121) ; EM_GETLANGOPTIONS ; Remove IMF_AUTOFONT (0x02) so that the font does NOT change on its own _SendMessage($g_hRichEdit, $EM_SETLANGOPTIONS, 0, BitAND($iOptions, BitNOT($IMF_AUTOFONT))) While True $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE _GUICtrlRichEdit_Destroy($g_hRichEdit) ; needed unless script crashes ; GUIDelete() ; is OK too Exit Case $idBtn_copy _GUICtrlRichEdit_Copy($g_hRichEdit) Case $idBtn_Update ; 1. Go to the end Local $iLen = _GUICtrlRichEdit_GetTextLength($g_hRichEdit, True, True) _GUICtrlRichEdit_SetSel($g_hRichEdit, $iLen, $iLen) ; 2. SET THE FONT IN THE SPACE (Before the text is entered) Local $sFontName = GUICtrlRead($idInp_Font) _GUICtrlRichEdit_SetFont($g_hRichEdit, 12, $sFontName, 2) _GUICtrlRichEdit_SetCharColor($g_hRichEdit, _WinAPI_SwitchColor(0xC8C8C8)) ; 3. ENTER THE TEXT ; Use InsertText - it will automatically get the font we set in step 2 Local $sNewText = GUICtrlRead($idInp_Data) & @CRLF _GUICtrlRichEdit_InsertText($g_hRichEdit, $sNewText) ; 4. Move to the end for next time Local $iFinalLen = _GUICtrlRichEdit_GetTextLength($g_hRichEdit, True, True) _GUICtrlRichEdit_SetSel($g_hRichEdit, $iFinalLen, $iFinalLen) _GUICtrlRichEdit_ScrollToCaret($g_hRichEdit) EndSwitch WEnd EndFunc ;==>Example ;--------------------------------------------------------------------------------------- Segoe Fluent Icons.codepoints Please, every comment is appreciated! leave your comments and experiences here! Thank you very much Edited 7 hours ago by ioa747 WildByDesign and argumentum 2 I know that I know nothing
argumentum Posted 8 hours ago Posted 8 hours ago 3 hours ago, ioa747 said: #include <GUIScrollbars_Ex.au3> ; https://www.autoitscript.com/forum/topic/113723-scrollbars-made-easy-new-version-27-jan-22/ Nice looking ioa747 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
WildByDesign Posted 40 minutes ago Posted 40 minutes ago @ioa747 This is nice and unique. I always appreciate it when you share interesting and unique things like this. I am a big fan of using the Segoe Fluent Icons in GUIs because they scale well and look good. I do have a suggestion for anyone who uses them: My suggestion is to ensure that "Segoe Fluent Icons" exist first, whether checking physical SegoeIcons.ttf in Windows Font folder or some other API check. Segoe Fluent Icons is on every Windows 11 install by default. However, Windows 10 users do not have it by default. So I always check that Segoe Fluent Icons exists, and if not, fall back to using Segoe MDL2 Assets which would cover Windows 10 users. The unicode for the individual fonts is the same between both font sets since they are intended to be interchangeable. By the way, as much as I dislike UWP apps, I do highly recommend Character Map UWP from the Windows Store for working with fonts. I hate UWP apps in general but there is nothing really like that program.
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