davezub Posted January 20, 2009 Share Posted January 20, 2009 So I'm venturing in the world of Autoit GUI for the first time - most of stuff is CLI utilities. Pretty slick. So I have my GUI looking pretty good and it works so I think a status bar would be nice. I have everything working well, however, I was wondering if there is a way to change the font style/color of the Status Bar Text? I've tried GUICtrlSetFont and GUISetFont with no luck. Thanks. Link to comment Share on other sites More sharing options...
rasim Posted January 21, 2009 Share Posted January 21, 2009 Example: #include <GuiConstantsEx.au3> #include <GuiStatusBar.au3> #include <WindowsConstants.au3> #include <FontConstants.au3> #include <WinAPI.au3> Global $hFont Dim $aParts[3] = [100, 250] Dim $aPartsText[2] = ["System info", "Current directory"] $hGUI = GUICreate("Statusbar custom font demo", 400, 300) $hStatus = _GUICtrlStatusBar_Create($hGUI, $aParts, $aPartsText) _GUICtrlStatusBar_SetFont($hStatus, 16, 800, 2 + 4, "Tahoma") GUISetState() Do Until GUIGetMsg() = $GUI_EVENT_CLOSE _WinAPI_DeleteObject($hFont) Func _GUICtrlStatusBar_SetFont($hWnd, $iHeight = 15, $iWeight = 400, $iFontAtrributes = 0, $sFontName = "Arial") $hFont = _WinAPI_CreateFont($iHeight, 0, 0, 0, $iWeight, BitAND($iFontAtrributes, 2), BitAND($iFontAtrributes, 4), _ BitAND($iFontAtrributes, 8), $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, _ $DEFAULT_QUALITY, 0, $sFontName) _SendMessage($hWnd, $WM_SETFONT, $hFont, 1) EndFunc ;==>_GUICtrlStatusBar_SetFont Parsix and mLipok 2 Link to comment Share on other sites More sharing options...
Zedna Posted January 21, 2009 Share Posted January 21, 2009 @rasim _GUICtrlStatusBar_SetFont() is absolutely great. It should be added to standard includes. Resources UDF Â ResourcesEx UDF Â AutoIt Forum Search Link to comment Share on other sites More sharing options...
davezub Posted January 21, 2009 Author Share Posted January 21, 2009 Rasim, Beautiful - Thanks. As Zedna said this would be a great addition. Link to comment Share on other sites More sharing options...
rasim Posted January 22, 2009 Share Posted January 22, 2009 @ZednaThanks @davezubGlad to help Link to comment Share on other sites More sharing options...
rover Posted January 22, 2009 Share Posted January 22, 2009 (edited) statusbar text colour is a bit more problematic as it requires ownerdrawing and more codethis example is a modified version of Rasim's demo with ownerdraw code added for statusbar part text and background colourCheersto whom it may concern: please refrain from posting this code in the example scripts forum without author attribution.Edit Hi Rasim expandcollapse popup;to whom it may concern: please refrain from posting this code in the example scripts forum with no attribution to the author. ;Author: rover ;Ownerdrawn StatusBar text font and colour demo ;set text colour and font for StatusBar parts ;modified version of demo by Rasim for setting StatusBar font ;http://www.autoitscript.com/forum/index.php?showtopic=88063 #include <GUIConstantsEX.au3> #include <Constants.au3> #include <WindowsConstants.au3> #include <GuiStatusBar.au3> #include <FontConstants.au3> #include <WinAPI.au3> Opt('MustDeclareVars', 1) Global $hFont Global $aParts[3] = [125, 250] Global $aPartsText[2] = ["RED on Transparent", "BLUE on Transparent"] Global $hGUI = GUICreate("Statusbar custom font and colour demo", 400, 300) GUISetBkColor(0xE0FFFF) Global $hStatus = _GUICtrlStatusBar_Create($hGUI) _GUICtrlStatusBar_SetParts($hStatus, $aParts) ; add text and color to struct called in WM_DRAWITEM message handler Global $tPart0 = _GUICtrlStatusBar_SetColor($hStatus, $aPartsText[0], 0, 0xFF0000); Red on transparent background Global $tPart1 = _GUICtrlStatusBar_SetColor($hStatus, $aPartsText[1], 1, 0x0C0DC0); Blue on transparent background ;_GUICtrlStatusBar_SetText($hStatus, "", 0, $SBT_OWNERDRAW); text not set when ownerdrawn ;_GUICtrlStatusBar_SetText($hStatus, "", 1, $SBT_OWNERDRAW) _GUICtrlStatusBar_SetText($hStatus, "Not ownerdrawn", 2) _GUICtrlStatusBar_SetFont($hStatus, 16, 800, 0, "Comic Sans MS") GUIRegisterMsg($WM_DRAWITEM, "_WM_DRAWITEM") GUISetState() Sleep(3000) ;you can use the above _GUICtrlStatusBar_SetText() lines and set text and colour in the message handler ;or use _GUICtrlStatusBar_SetColor() to change text, text colour and part background colour more easily Local $iCnt = 0 Do $iCnt +=1 $tPart0 = _GUICtrlStatusBar_SetColor($hStatus, "GOLD on BLACK", 0, 0xFFD700, 0) $tPart1 = _GUICtrlStatusBar_SetColor($hStatus, "BLUE on GOLD", 1, 0x0C0DC0, 0xFFD700) Sleep(500) $tPart0 = _GUICtrlStatusBar_SetColor($hStatus, $aPartsText[0], 0, 0xFF0000) $tPart1 = _GUICtrlStatusBar_SetColor($hStatus, $aPartsText[1], 1, 0x0C0DC0) Sleep(500) Until $iCnt = 5 Do Until GUIGetMsg() = $GUI_EVENT_CLOSE _WinAPI_DeleteObject($hFont) Func _GUICtrlStatusBar_SetFont($hWnd, $iHeight = 15, $iWeight = 400, $iFontAtrributes = 0, $sFontName = "Arial") ;Author: Rasim $hFont = _WinAPI_CreateFont($iHeight, 0, 0, 0, $iWeight, BitAND($iFontAtrributes, 2), BitAND($iFontAtrributes, 4), _ BitAND($iFontAtrributes, 8), $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, _ $DEFAULT_QUALITY, 0, $sFontName) _SendMessage($hWnd, $WM_SETFONT, $hFont, 1) EndFunc ;==>_GUICtrlStatusBar_SetFont Func _WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam) #forceref $hWnd, $Msg, $wParam, $lParam Local $tagDRAWITEMSTRUCT = DllStructCreate("uint cType;uint cID;uint itmID;" & _ "uint itmAction;uint itmState;hwnd hItm;hwnd hDC;int itmRect[4];dword itmData", $lParam) Local $hItm = DllStructGetData($tagDRAWITEMSTRUCT, "hItm"); retrieve statusbar handle Switch _WinAPI_GetClassName($hItm);an example of how message handler does not have to rely on having global variable for statusbar in advance ;Switch $hItm Case "msctls_statusbar32" ;Case $hStatus Local $hDC = DllStructGetData($tagDRAWITEMSTRUCT, "hDC") ; device context for statusbar for color and/or font Local $iID = DllStructGetData($tagDRAWITEMSTRUCT, "itmID"); statusbar part number ; get 32-bit value in itmData when text has SBT_OWNERDRAW drawing type - pointer to struct with text and color Local $pParam = DllStructGetData($tagDRAWITEMSTRUCT, "itmData") Local $tParam = DllStructCreate("wchar[512];dword;dword;dword", $pParam) ; create RECT structure from itmRect byte array for part metrics Local $tRECT = DllStructCreate("int Left;int Top;int Right;int Bottom") ; metrics not same as non-ownerdrawn part for some reason, so 1 added for alignment DllStructSetData($tRECT, "Left", DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 1)+1) DllStructSetData($tRECT, "Top", DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 2)+1) DllStructSetData($tRECT, "Right", DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 3)) DllStructSetData($tRECT, "Bottom", DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 4)) _WinAPI_SetBkMode($hDC, $TRANSPARENT); otherwise text background set to 0xFFFFFF _WinAPI_SetTextColor($hDC, DllStructGetData($tParam, 2)); set part text colour from struct If Not DllStructGetData($tParam, 4) Then; check if background should be transparent Local $iBkColor = DllStructGetData($tParam, 3), $hStatusDC, $hBrushBk $hStatusDC = _WinAPI_GetDC($hItm) $hBrushBk = _WinAPI_CreateSolidBrush($iBkColor) _WinAPI_FillRect($hStatusDC, DllStructGetPtr($tRect), $hBrushBk) _WinAPI_DeleteObject($hBrushBk) _WinAPI_ReleaseDC($hItm, $hStatusDC) EndIf ; draw text to DC (can also use gdi32 TextOutW and ExtTextOut API's) _WinAPI_DrawText($hDC, DllStructGetData($tParam, 1), $tRect, $DT_LEFT) EndSwitch Return $GUI_RUNDEFMSG EndFunc Func _GUICtrlStatusBar_SetColor($hWnd, $sText = "", $iPart = 0, $iColor = 0, $iBkColor = -1) ;Author: rover - modified ownerdraw version of _GUICtrlStatusBar_SetText() from GuiStatusBar.au3 ;Includes RGB2BGR() - Author: Siao - http://www.autoitscript.com/forum/index.php?s=&showtopic=57161&view=findpost&p=433593 ;sets itmData element of statusbar DRAWITEMSTRUCT with pointer to struct with text and colour for part number If $Debug_SB Then _GUICtrlStatusBar_ValidateClassName($hWnd) Local $ret, $tStruct, $pStruct, $iBuffer ; In Microsoft Windows XP and earlier, the text for each part is limited to 127 characters. ; This limitation has been removed in Windows Vista. ; set sufficiently large buffer for use with Vista (can exceed XP limit of 128 chars) $tStruct = DllStructCreate("wchar Text[512];dword Color;dword BkColor;dword Trans") Switch $iBkColor Case -1 DllStructSetData($tStruct, "Trans", 1) Case Else $iBkColor = BitAND(BitShift(String(Binary($iBkColor)), 8), 0xFFFFFF) DllStructSetData($tStruct, "Trans", 0) DllStructSetData($tStruct, "BkColor", $iBkColor) EndSwitch $iColor = BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF); From RGB2BGR() Author: Siao DllStructSetData($tStruct, "Text", $sText) DllStructSetData($tStruct, "Color", $iColor) $pStruct = DllStructGetPtr($tStruct) If _GUICtrlStatusBar_IsSimple($hWnd) Then $iPart = $SB_SIMPLEID ;FOR INTERNAL STATUSBARS ONLY If _WinAPI_InProcess($hWnd, $__ghSBLastWnd) Then $ret = _SendMessage($hWnd, $SB_SETTEXTW, BitOR($iPart, $SBT_OWNERDRAW), $pStruct, 0, "wparam", "ptr") Return $tStruct; returns struct to global variable EndIf Return 0 EndFunc ;==>_GUICtrlStatusBar_SetColor Edited January 22, 2009 by rover Parsix and mLipok 2 I see fascists... Link to comment Share on other sites More sharing options...
rasim Posted January 22, 2009 Share Posted January 22, 2009 statusbar text colour is a bit more problematic as it requires ownerdrawing and more codethis example is a modified version of Rasim's demo with ownerdraw code added for statusbar part text and background colourHi!Great work my friend! Thank you for sharing! Link to comment Share on other sites More sharing options...
rover Posted January 22, 2009 Share Posted January 22, 2009 Hi!Great work my friend! Thank you for sharing! Hey Rasim!thanksand Happy New Year read the UDF sticky, get the template software and submit _GUICtrlStatusBar_SetFont() to Gary!I could not get _GUICtrlStatusBar_SetBkColor() to work even with XPStyle UDF to turn off themes (Valuater posted on this).made a version of _GUICtrlStatusBar_SetColor() with option to set fonts per StatusBar part to compliment your default font UDF.perhaps when I clean the code up a bit I'll post to the examples forum.be seeing you I see fascists... Link to comment Share on other sites More sharing options...
rasim Posted January 22, 2009 Share Posted January 22, 2009 perhaps when I clean the code up a bit I'll post to the examples forum.Ok, in waiting... Link to comment Share on other sites More sharing options...
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