找回密码
 加入
搜索
查看: 4087|回复: 11

[AU3基础] GUICtrlCreateTabItem不能设置样式吗?也不能更改字体大小?

  [复制链接]
发表于 2011-5-12 12:23:18 | 显示全部楼层 |阅读模式
N天没解决的事情,希望大家帮忙想想。
发表于 2011-5-12 12:32:55 | 显示全部楼层
改是可以改,不过相当麻烦,蛋蛋见过,可能要涉及gdi的东西,不过也许有人有好的方法
发表于 2011-5-12 14:04:44 | 显示全部楼层
另类的办法.
#Include <Constants.au3>
#Include <GUIConstantsEx.au3>
#Include <StaticConstants.au3>
#Include <TabConstants.au3>
#Include <WindowsConstants.au3>

Dim $Pic[5]

GUICreate('MyGUI', 705, 369)
GUISetBkColor(0xFFFFFF)
GUICtrlCreatePic('img_bg.bmp', 0, 0, 705, 369)
GUICtrlSetState(-1, $GUI_DISABLE)

For $i = 0 To 4
        $Pic[$i] = GUICtrlCreatePic(@ScriptDir & '\img_black.bmp', 10, 24 + 50 * $i, 162, 49)
        GUICtrlCreateLabel('Tabsheet' & $i, 21, 40 + 50 * $i, 140, 18, $SS_CENTER)
        GUICtrlSetFont(-1, 11, 400, 0, 'Tahoma')
        GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
        GUICtrlSetcolor(-1, 0xFFFFFF)
Next

$Tab = GUICtrlCreateTab(172 + 4, 10 + 4, 523 - 8, 349 - 8)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlCreateTabItem('Tabsheet0')
GUICtrlCreateEdit('', 190, 28, 487, 313)
GUICtrlCreateTabItem('Tabsheet1')
GUICtrlCreateButton('OK', 398, 319, 70, 23)
GUICtrlCreateTabItem('Tabsheet2')
GUICtrlCreateTabItem('Tabsheet3')
GUICtrlCreateTabItem('Tabsheet4')
GUICtrlCreateTabItem('')

GUISetState()

$Item = -1
$Over = -1

While 1
        $Info = GUIGetCursorInfo()
        If @error Then
                If $Over <> -1 Then
                        GUICtrlSetImage($Pic[$Over], @ScriptDir & '\img_black.bmp')
                EndIf
                $Over = -1
        Else
                $Index = _Index($Info[4])
                If $Index <> $Over Then
                        If $Over <> -1 Then
                                GUICtrlSetImage($Pic[$Over], @ScriptDir & '\img_black.bmp')
                        EndIf
                        If ($Index <> -1) And ($Index <> $Item) Then
                                GUICtrlSetImage($Pic[$Index], @ScriptDir & '\img_over.bmp')
                                $Over = $Index
                        Else
                                $Over = -1
                        EndIf
                EndIf
        EndIf
        $Msg = GUIGetMsg()
        If $Item = -1 Then
                $Msg = $Pic[0]
                $Item = 1
        EndIf
        Switch $Msg
                Case 0
                        ContinueLoop
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Pic[0] To $Pic[UBound($Pic) - 1]
                        If $Msg <> $Pic[$Item] Then
                                GUICtrlSetImage($Pic[$Item], @ScriptDir & '\img_black.bmp')
                                GUICtrlSetcolor($Pic[$Item] + 1, 0xFFFFFF)
                                GUICtrlSetImage($Msg, @ScriptDir & '\img_white.bmp')
                                GUICtrlSetcolor($Msg + 1, 0x313A42)
                                $Item = _Index($Msg)
                                GUICtrlSendMsg($Tab, $TCM_SETCURFOCUS, $Item, 0)
                                $Over = -1
                        EndIf
        EndSwitch
WEnd

Func _Index($CtrlID)
        For $i = 0 To UBound($Pic) - 1
                If ($CtrlID = $Pic[$i]) Or ($CtrlID = $Pic[$i] + 1) Then
                        Return $i
                EndIf
        Next
        Return -1
EndFunc   ;==>_Index







本帖子中包含更多资源

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

×
 楼主| 发表于 2011-5-12 22:21:39 | 显示全部楼层
非常感谢,但是确定是麻烦了,那很多代码都要从整了。希望其它高人有更好的方法。
发表于 2011-5-13 08:37:24 | 显示全部楼层
看看,学习下
发表于 2011-5-13 19:06:05 | 显示全部楼层
再试试这个:
#include <GuiConstantsEx.au3>
#include <GuiTab.au3>
#include <StaticConstants.au3>

Global $aTabColours[4] = [0xFFC0C0, 0xC0FFC0, 0xC0C0FF, 0xC0C0C0]
Global $hGUI = GUICreate ("Test", 400,300)
GUISetBkColor (0)
Global $hColourTab = GUICtrlCreateLabel("", 0, 0, 1, 1, BitOR($SS_NOTIFY, $SS_CENTER, $SS_SUNKEN))
Global $hTab = GUICtrlCreateTab(5, 5,390, 290)
Global $hTab_Handle = GUICtrlGetHandle($hTab)
For $i = 0 To 3
    GUICtrlCreateTabItem ("Tab item - " & $i)
    _GUICtrlTab_SetBkColor($hGUI, $hTab, $aTabColours[$i])
    GUICtrlCreateTabItem ("")
Next

_GUICtrlTab_SetCurSel($hTab_Handle,0)
_GUICtrlTab_SetCurFocus($hTab_Handle,0)
TabEvent()

GUISetState ()

While 1
    Switch GUIGetMsg ()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hTab
            TabEvent()
    EndSwitch
WEnd

Func TabEvent()
    Local $iTab_X = 5, $iTab_Y = 5, $iTab_Margin = 1
    Local $iTab_Index = GUICtrlRead($hTab)
    Local $aTab_Coord = _GUICtrlTab_GetItemRect($hTab_Handle, $iTab_Index)
    Local $sTab_Text = _GUICtrlTab_GetItemText($hTab_Handle, $iTab_Index)
    GUICtrlSetPos($hColourTab, $iTab_X + $aTab_Coord[0] + $iTab_Margin, $iTab_Y + $aTab_Coord[1] + $iTab_Margin + 1, $aTab_Coord[2] - $aTab_Coord[0] - ($iTab_Margin * 2), $aTab_Coord[3] - $aTab_Coord[1] - ($iTab_Margin * 2) + 5)
    GUICtrlSetData($hColourTab, $sTab_Text)
    GUICtrlsetBkColor ($hColourTab,$aTabColours[$iTab_Index] )
    _GUICtrlTab_SetCurFocus($hTab_Handle,$iTab_Index)
EndFunc

Func _GUICtrlTab_SetBkColor($hWnd, $hSysTab32, $sBkColor)
    Local $aTabPos = ControlGetPos($hWnd, "", $hSysTab32)
    Local $aTab_Rect = _GUICtrlTab_GetItemRect($hSysTab32, -1)
    GUICtrlCreateLabel("", $aTabPos[0] + 2, $aTabPos[1] + $aTab_Rect[3] + 4, $aTabPos[2] - 6, $aTabPos[3] - $aTab_Rect[3] - 7)
    GUICtrlSetBkColor(-1, $sBkColor)
    GUICtrlSetState(-1, $GUI_DISABLE)
EndFunc   ;==>_GUICtrlTab_SetBkColor
发表于 2011-5-13 19:28:44 | 显示全部楼层
这下应该可以了,重绘下:
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiTab.au3>
#Include <FontConstants.au3>
#Include <WinAPI.au3>

Global Const $ODT_TAB = 101
Global Const $ODS_SELECTED          = 0x0001
Global Const $ODA_DRAWENTIRE = 0x1

Global Const $ODS_FOCUS             = 0x0010
Global $Font1 = _WinAPI_CreateFont(20, 0, 0, 0, $FW_BOLD)
Global $Font2 = _WinAPI_CreateFont(16, 0, 0, 0, $FW_NORMAL, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, "Impact")


$hGUI = GUICreate("Draw Tab", 300, 200)

$hTab = GUICtrlCreateTab(10, 10, 280, 180, $TCS_OWNERDRAWFIXED)

$TabItem_1 = GUICtrlCreateTabItem("TabItem 1")
GUICtrlCreateLabel("", 10, 33, 277, 155)
GUICtrlSetBkColor(-1, 0xDDAA11)
GUICtrlSetState(-1, $GUI_DISABLE)

$TabItem_2 = GUICtrlCreateTabItem("TabItem 2")
GUICtrlCreateLabel("", 10, 33, 277, 155)
GUICtrlSetBkColor(-1, 0x99BBEE)
GUICtrlSetState(-1, $GUI_DISABLE)

GUICtrlCreateTabItem("")

GUISetState()

GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM")

_GUICtrlTab_SetCurSel($hTab, 1)
_GUICtrlTab_SetCurSel($hTab, 0)

Do
Until GUIGetMsg() = -3

Func WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam)
    Local $DRAWITEMSTRUCT
    
    $DRAWITEMSTRUCT = DllStructCreate("uint cType;uint cID;uint itmID;uint itmAction;uint itmState;" & _
                                  "hwnd hItm;hwnd hDC;dword itmRect[4];dword itmData", $lParam)
    
    If DllStructGetData($DRAWITEMSTRUCT, "cType") <> $ODT_TAB Then Return $GUI_RUNDEFMSG
    
    Local $cID = DllStructGetData($DRAWITEMSTRUCT, "cID")
    Local $itmID = DllStructGetData($DRAWITEMSTRUCT, "itmID")
    Local $itmAction = DllStructGetData($DRAWITEMSTRUCT, "itmAction")
    Local $itmState = DllStructGetData($DRAWITEMSTRUCT, "itmState")
    Local $hItm = DllStructGetData($DRAWITEMSTRUCT, "hItm")
    Local $hDC = DllStructGetData($DRAWITEMSTRUCT, "hDC")
    
    If $itmAction <> $ODA_DRAWENTIRE Then Return $GUI_RUNDEFMSG
    
    Local $iTextColor, $itmText
    
    Switch $itmID
        Case 0
            $iBrushColor = 0x11AADD
                        _WinAPI_SelectObject($hDC, $Font1)
        Case 1
            $iBrushColor = 0xEEBB99
                        _WinAPI_SelectObject($hDC, $Font2)
    EndSwitch
    
    DLLCall("gdi32.dll","int","SetBkMode", "hwnd", $hDC, "int", 1)
    
    Local $iBrush = DLLCall("gdi32.dll","hwnd","CreateSolidBrush", "int", $iBrushColor)
    $iBrush = $iBrush[0]
    
    Local $iBrushOld = _WinAPI_SelectObject($hDC, $iBrush)
    
    DLLCall("user32.dll","int","FillRect", "hwnd", $hDC, "ptr", DllStructGetPtr($DRAWITEMSTRUCT, "itmRect"), "hwnd", $iBrush)
    
    Local $tBuffer = DllStructCreate("char[256]")
    DllStructSetData($tBuffer, 1, "Item" & $itmID)
    $itmText = DllStructGetData($tBuffer, 1)

    DllStructSetData($DRAWITEMSTRUCT, "itmRect", DllStructGetData($DRAWITEMSTRUCT, "itmRect", 1) + 10, 1)
    DllStructSetData($DRAWITEMSTRUCT, "itmRect", DllStructGetData($DRAWITEMSTRUCT, "itmRect", 2) + 5, 2)
    
    DllCall("user32.dll", "int", "DrawText", "hwnd", $hDC, "str", $itmText, "int", StringLen($itmText), _
            "ptr", DllStructGetPtr($DRAWITEMSTRUCT, "itmRect"), "int", $DT_LEFT)
    
    _WinAPI_SelectObject($hDC, $iBrushOld)
    _WinAPI_DeleteObject($iBrush)
    
    Return $GUI_RUNDEFMSG
EndFunc
发表于 2011-5-13 21:33:14 | 显示全部楼层
回复 7# 3mile


    三笑的技术突飞猛进呀,恭喜恭喜

评分

参与人数 1金钱 +10 收起 理由
3mile + 10 向你学习

查看全部评分

发表于 2011-5-14 00:43:44 | 显示全部楼层
果然是高手,太强大了,学习了!
发表于 2011-5-14 00:59:06 | 显示全部楼层
回复 7# 3mile

三笑,借着这个话题给你出个题目想想看,点击选项卡变色(应该能明白意思吧,突出显示选中的选项卡)
发表于 2011-5-16 21:09:23 | 显示全部楼层
回复  3mile

三笑,借着这个话题给你出个题目想想看,点击选项卡变色(应该能明白意思吧,突出显示选中的 ...
netegg 发表于 2011-5-14 00:59

蛋蛋兄出题了吗,我试下能做出来不?
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiTab.au3>
#include <FontConstants.au3>
#include <WinAPI.au3>

Global Const $ODT_TAB = 101
Global Const $ODS_SELECTED = 0x0001
Global Const $ODA_DRAWENTIRE = 0x1
Global Const $ODA_SELECT = 0x2
Global $iListBkColor = 0x0000CC
Global $iListSelColor = 0xFF00EE
Global $iDllGDI = DllOpen("gdi32.dll")
Global $iDllUSER32 = DllOpen("user32.dll")

Global Const $ODS_FOCUS = 0x0010
Global $Font1 = _WinAPI_CreateFont(16, 0, 0, 0, $FW_NORMAL)
Global $Font2 = _WinAPI_CreateFont(18, 0, 0, 0, $FW_HEAVY , False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, "Impact")


$hGUI = GUICreate("Draw Tab", 300, 200)

$hTab = GUICtrlCreateTab(10, 10, 280, 180, $TCS_OWNERDRAWFIXED)

$TabItem_1 = GUICtrlCreateTabItem("TabItem 1")
;GUICtrlCreateLabel("", 10, 33, 277, 155)
;GUICtrlSetBkColor(-1, 0xDDAA11)
;GUICtrlSetState(-1, $GUI_DISABLE)

$TabItem_2 = GUICtrlCreateTabItem("TabItem 2")
;GUICtrlCreateLabel("", 10, 33, 277, 155)
;GUICtrlSetBkColor(-1, 0x99BBEE)
;GUICtrlSetState(-1, $GUI_DISABLE)

GUICtrlCreateTabItem("")

GUISetState()

GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM")

_GUICtrlTab_SetCurSel($hTab, 1)
_GUICtrlTab_SetCurSel($hTab, 0)

Do
Until GUIGetMsg() = -3

Func WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam)
        Local $DRAWITEMSTRUCT

        $DRAWITEMSTRUCT = DllStructCreate("uint cType;uint cID;uint itmID;uint itmAction;uint itmState;" & _
                        "hwnd hItm;hwnd hDC;dword itmRect[4];dword itmData", $lParam)

        If DllStructGetData($DRAWITEMSTRUCT, "cType") <> $ODT_TAB Then Return $GUI_RUNDEFMSG

        Local $cID = DllStructGetData($DRAWITEMSTRUCT, "cID")
        Local $itmID = DllStructGetData($DRAWITEMSTRUCT, "itmID")
        Local $itmAction = DllStructGetData($DRAWITEMSTRUCT, "itmAction")
        Local $itmState = DllStructGetData($DRAWITEMSTRUCT, "itmState")
        Local $hItm = DllStructGetData($DRAWITEMSTRUCT, "hItm")
        Local $hDC = DllStructGetData($DRAWITEMSTRUCT, "hDC")
        Switch $itmAction
                Case $ODA_DRAWENTIRE, $ODA_SELECT
                        ;If $itmAction <> $ODA_DRAWENTIRE Then Return $GUI_RUNDEFMSG
                        If $itmState = $ODS_SELECTED Then
                                Local $iTextColor, $itmText
                                                $iBrushColor=0xDDAA11
                                                _WinAPI_SelectObject($hDC, $Font2)
;~                                 Switch $itmID
;~                                         Case 0
;~                                                 $iBrushColor = 0x11AADD
;~                                                 _WinAPI_SelectObject($hDC, $Font1)
;~                                         Case 1
;~                                                 $iBrushColor = 0xEEBB99
;~                                                 _WinAPI_SelectObject($hDC, $Font2)
;~                                 EndSwitch
                                        _WinAPI_SetTextColor($hDC, 0x0000FF)
                                        _WinAPI_SetBkColor($hDC, 0x000000)

                                DllCall("gdi32.dll", "int", "SetBkMode", "hwnd", $hDC, "int", 1)

                                Local $iBrush = DllCall("gdi32.dll", "hwnd", "CreateSolidBrush", "int", $iBrushColor)
                                $iBrush = $iBrush[0]

                                Local $iBrushOld = _WinAPI_SelectObject($hDC, $iBrush)

                                DllCall("user32.dll", "int", "FillRect", "hwnd", $hDC, "ptr", DllStructGetPtr($DRAWITEMSTRUCT, "itmRect"), "hwnd", $iBrush)

                                Local $tBuffer = DllStructCreate("char[256]")
                                DllStructSetData($tBuffer, 1, "Item" & $itmID)
                                $itmText = DllStructGetData($tBuffer, 1)

                                DllStructSetData($DRAWITEMSTRUCT, "itmRect", DllStructGetData($DRAWITEMSTRUCT, "itmRect", 1) + 10, 1)
                                DllStructSetData($DRAWITEMSTRUCT, "itmRect", DllStructGetData($DRAWITEMSTRUCT, "itmRect", 2) + 5, 2)

                                DllCall("user32.dll", "int", "DrawText", "hwnd", $hDC, "str", $itmText, "int", StringLen($itmText), _
                                                "ptr", DllStructGetPtr($DRAWITEMSTRUCT, "itmRect"), "int", $DT_LEFT)

                                _WinAPI_SelectObject($hDC, $iBrushOld)
                                _WinAPI_DeleteObject($iBrush)
                        Else
                                Local $iTextColor, $itmText

                                $iBrushColor=0xFFEEEE
                                DllCall("gdi32.dll", "int", "SetBkMode", "hwnd", $hDC, "int", 1)

                                Local $iBrush = DllCall("gdi32.dll", "hwnd", "CreateSolidBrush", "int", $iBrushColor)
                                $iBrush = $iBrush[0]

                                Local $iBrushOld = _WinAPI_SelectObject($hDC, $iBrush)

                                DllCall("user32.dll", "int", "FillRect", "hwnd", $hDC, "ptr", DllStructGetPtr($DRAWITEMSTRUCT, "itmRect"), "hwnd", $iBrush)

                                Local $tBuffer = DllStructCreate("char[256]")
                                DllStructSetData($tBuffer, 1, "Item" & $itmID)
                                $itmText = DllStructGetData($tBuffer, 1)

                                DllStructSetData($DRAWITEMSTRUCT, "itmRect", DllStructGetData($DRAWITEMSTRUCT, "itmRect", 1) + 10, 1)
                                DllStructSetData($DRAWITEMSTRUCT, "itmRect", DllStructGetData($DRAWITEMSTRUCT, "itmRect", 2) + 5, 2)

                                DllCall("user32.dll", "int", "DrawText", "hwnd", $hDC, "str", $itmText, "int", StringLen($itmText), _
                                                "ptr", DllStructGetPtr($DRAWITEMSTRUCT, "itmRect"), "int", $DT_LEFT)

                                _WinAPI_SelectObject($hDC, $iBrushOld)
                                _WinAPI_DeleteObject($iBrush)
                        EndIf
        EndSwitch
        Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_DRAWITEM

Func RGB2BGR($iColor)
        Return BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF)
EndFunc   ;==>RGB2BGR
发表于 2011-5-16 22:50:20 | 显示全部楼层
回复 11# 3mile


    大赞,不错
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-12-23 12:18 , Processed in 0.220625 second(s), 28 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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