找回密码
 加入
搜索
查看: 4347|回复: 4

[GUI管理] StatusBar上的字体颜色能调吗?

  [复制链接]
发表于 2011-2-3 12:25:31 | 显示全部楼层 |阅读模式
$StatusBar1 = _GUICtrlStatusBar_Create($Form1)
_GUICtrlStatusBar_SetMinHeight($StatusBar1, 49)
GUICtrlSetFont(-1, 18, 800, 0, "楷体_GB2312")
GUICtrlSetColor(-1, 0x0000FF)
控件本身没有这个选项,这个是我从input那复制的,但是不好使,有经验的说下
发表于 2011-2-3 13:09:30 | 显示全部楼层
假的!
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 400, 300)
$Graphic1 = GUICtrlCreateGraphic(0, 270, 400, 5)
GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, 5)
GUICtrlSetGraphic(-1, $GUI_GR_LINE, 400, 5)
$Label1 = GUICtrlCreateLabel("嘿嘿!这个算吗?", 10, 280, 150, 17)
GUICtrlSetColor(-1, 0xFF0000)
GUISetState()

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3
                        Exit

        EndSwitch
WEnd
发表于 2011-2-3 14:44:09 | 显示全部楼层
本帖最后由 netegg 于 2011-2-3 14:53 编辑

原文地址
#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)

Global $tPart0 = _GUICtrlStatusBar_SetColor($hStatus, $aPartsText[0], 0, 0xFF0000)
Global $tPart1 = _GUICtrlStatusBar_SetColor($hStatus, $aPartsText[1], 1, 0x0C0DC0)
_GUICtrlStatusBar_SetText($hStatus, "Not ownerdrawn", 2)

_GUICtrlStatusBar_SetFont($hStatus, 16, 800, 0, "Comic Sans MS")

GUIRegisterMsg($WM_DRAWITEM, "_WM_DRAWITEM")
GUISetState()

$tPart0 = _GUICtrlStatusBar_SetColor($hStatus, $aPartsText[0], 0, 0xFF0000)
$tPart1 = _GUICtrlStatusBar_SetColor($hStatus, $aPartsText[1], 1, 0x0C0DC0)

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

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)
                Case "msctls_statusbar32"
                        Local $hDC = DllStructGetData($tagDRAWITEMSTRUCT, "hDC")
                        Local $iID = DllStructGetData($tagDRAWITEMSTRUCT, "itmID")
                        Local $pParam = DllStructGetData($tagDRAWITEMSTRUCT, "itmData")
                        Local $tParam = DllStructCreate("wchar[512];dword;dword;dword", $pParam)
                        Local $tRECT = DllStructCreate("int Left;int Top;int Right;int Bottom")
                        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)
                        _WinAPI_SetTextColor($hDC, DllStructGetData($tParam, 2))
                        If Not DllStructGetData($tParam, 4) Then
                                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
                        _WinAPI_DrawText($hDC, DllStructGetData($tParam, 1), $tRECT, $DT_LEFT)
        EndSwitch
        Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_DRAWITEM

Func _GUICtrlStatusBar_SetColor($hWnd, $sText = "", $iPart = 0, $iColor = 0, $iBkColor = -1)
        Local $ret, $tStruct, $pStruct, $iBuffer
        $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)
        DllStructSetData($tStruct, "Text", $sText)
        DllStructSetData($tStruct, "Color", $iColor)
        $pStruct = DllStructGetPtr($tStruct)
        If _GUICtrlStatusBar_IsSimple($hWnd) Then $iPart = $SB_SIMPLEID
        If _WinAPI_InProcess($hWnd, $__ghSBLastWnd) Then
                $ret = _SendMessage($hWnd, $SB_SetTEXTW, BitOR($iPart, $SBT_OWNERDRAW), $pStruct, 0, "wparam", "ptr")
                Return $tStruct
        EndIf
        Return 0
EndFunc   ;==>_GUICtrlStatusBar_SetColor

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×

评分

参与人数 1金钱 +100 收起 理由
水木子 + 100 哈哈!真的!

查看全部评分

 楼主| 发表于 2011-2-3 21:20:09 | 显示全部楼层
万分感激!
水木子,鼬哥哥,写写你哦
同样感激三楼
我发了不少很傻的问题,都得到了回答 我感觉我的帖子对新人都有很大的帮助,嘿嘿
发表于 2011-2-4 16:44:08 | 显示全部楼层
这个好像很不错哦..
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-12-23 16:32 , Processed in 0.138485 second(s), 28 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表