PDA

Показать полную графическую версию : [решено] Какс делать "красивые вкладки", аналог GUICtrlCreateTab


Centrinar
13-07-2010, 22:17
Есть GUICtrlCreateTab, все замечательно, НО там не льзя "НОРМАЛЬНО" поменять цвет самой вклаки или сделать ее более оптикаемой. Есть ли другие варианты создания вкладок?

Creat0R
13-07-2010, 22:30
Нужно ручками рисовать табы, задача не из простых...

Creat0R
14-07-2010, 19:59
Нужно ручками рисовать табы »
Вот пример как это делается:

#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <GUIConstantsEx.au3>
#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <WindowsConstants.au3>
#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <GUITab.au3>

Global (http://www.autoitscript.com/autoit3/docs/keywords.htm#Global) Const (http://www.autoitscript.com/autoit3/docs/keywords.htm#Const) $ODT_TAB = 101
Global (http://www.autoitscript.com/autoit3/docs/keywords.htm#Global) Const (http://www.autoitscript.com/autoit3/docs/keywords.htm#Const) $ODS_SELECTED = 0x0001
Global (http://www.autoitscript.com/autoit3/docs/keywords.htm#Global) Const (http://www.autoitscript.com/autoit3/docs/keywords.htm#Const) $ODA_DRAWENTIRE = 0x1
Global (http://www.autoitscript.com/autoit3/docs/keywords.htm#Global) Const (http://www.autoitscript.com/autoit3/docs/keywords.htm#Const) $ODS_FOCUS = 0x0010

$hGUI = GUICreate (http://www.autoitscript.com/autoit3/docs/functions/GUICreate.htm)("Draw Tab", 300, 200)

$hTab = GUICtrlCreateTab (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateTab.htm)(10, 10, 280, 180, $TCS_OWNERDRAWFIXED)

$TabItem_1 = GUICtrlCreateTabItem (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateTabItem.htm)("TabItem 1")
GUICtrlCreateLabel (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateLabel.htm)("", 10, 33, 277, 155)
GUICtrlSetBkColor (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetBkColor.htm)(-1, 0xDDAA11)
GUICtrlSetState (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetState.htm)(-1, $GUI_DISABLE)

$TabItem_2 = GUICtrlCreateTabItem (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateTabItem.htm)("TabItem 2")
GUICtrlCreateLabel (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateLabel.htm)("", 10, 33, 277, 155)
GUICtrlSetBkColor (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetBkColor.htm)(-1, 0x99BBEE)
GUICtrlSetState (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetState.htm)(-1, $GUI_DISABLE)

GUICtrlCreateTabItem (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateTabItem.htm)("")

GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)()

GUIRegisterMsg (http://www.autoitscript.com/autoit3/docs/functions/GUIRegisterMsg.htm)($WM_DRAWITEM, "WM_DRAWITEM")

_GUICtrlTab_SetCurSel (http://dundats.mvps.org/help/html/libfunctions/_guictrltab_setcursel.htm)($hTab, 1)
_GUICtrlTab_SetCurSel (http://dundats.mvps.org/help/html/libfunctions/_guictrltab_setcursel.htm)($hTab, 0)

Do (http://www.autoitscript.com/autoit3/docs/keywords.htm#Do)
Until (http://www.autoitscript.com/autoit3/docs/keywords.htm#Until) GUIGetMsg (http://www.autoitscript.com/autoit3/docs/functions/GUIGetMsg.htm)() = -3

Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $DRAWITEMSTRUCT

$DRAWITEMSTRUCT = DllStructCreate (http://www.autoitscript.com/autoit3/docs/functions/DllStructCreate.htm)("uint cType;uint cID;uint itmID;uint itmAction;uint itmState;hwnd hItm;hwnd hDC;dword itmRect[4];dword itmData", $lParam)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($DRAWITEMSTRUCT, "cType") <> $ODT_TAB Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) $GUI_RUNDEFMSG

Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $cID = DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($DRAWITEMSTRUCT, "cID")
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $itmID = DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($DRAWITEMSTRUCT, "itmID")
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $itmAction = DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($DRAWITEMSTRUCT, "itmAction")
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $itmState = DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($DRAWITEMSTRUCT, "itmState")
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $hItm = DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($DRAWITEMSTRUCT, "hItm")
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $hDC = DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($DRAWITEMSTRUCT, "hDC")

If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $itmAction <> $ODA_DRAWENTIRE Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) $GUI_RUNDEFMSG

Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $iTextColor, $itmText

Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) $itmID
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) 0
$iBrushColor = 0x11AADD
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) 1
$iBrushColor = 0xEEBB99
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)

DLLCall (http://www.autoitscript.com/autoit3/docs/functions/DllCall.htm)("gdi32.dll","int","SetBkMode", "hwnd", $hDC, "int", 1)

Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $iBrush = DLLCall (http://www.autoitscript.com/autoit3/docs/functions/DllCall.htm)("gdi32.dll","hwnd","CreateSolidBrush", "int", $iBrushColor)
$iBrush = $iBrush[0]

Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $iBrushOld = _WinAPI_SelectObject (http://dundats.mvps.org/help/html/libfunctions/_winapi_selectobject.htm)($hDC, $iBrush)

DLLCall (http://www.autoitscript.com/autoit3/docs/functions/DllCall.htm)("user32.dll","int","FillRect", "hwnd", $hDC, "ptr", DllStructGetPtr (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetPtr.htm)($DRAWITEMSTRUCT, "itmRect"), "hwnd", $iBrush)

Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $tBuffer = DllStructCreate (http://www.autoitscript.com/autoit3/docs/functions/DllStructCreate.htm)("char[256]")
DllStructSetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructSetData.htm)($tBuffer, 1, "Item" & $itmID)
$itmText = DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($tBuffer, 1)

DllStructSetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructSetData.htm)($DRAWITEMSTRUCT, "itmRect", DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($DRAWITEMSTRUCT, "itmRect", 1) + 10, 1)
DllStructSetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructSetData.htm)($DRAWITEMSTRUCT, "itmRect", DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($DRAWITEMSTRUCT, "itmRect", 2) + 5, 2)

DllCall (http://www.autoitscript.com/autoit3/docs/functions/DllCall.htm)("user32.dll", "int", "DrawText", "hwnd", $hDC, "str", $itmText, "int", StringLen (http://www.autoitscript.com/autoit3/docs/functions/StringLen.htm)($itmText), _
"ptr", DllStructGetPtr (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetPtr.htm)($DRAWITEMSTRUCT, "itmRect"), "int", $DT_LEFT)

_WinAPI_SelectObject (http://dundats.mvps.org/help/html/libfunctions/_winapi_selectobject.htm)($hDC, $iBrushOld)
_WinAPI_DeleteObject (http://dundats.mvps.org/help/html/libfunctions/_winapi_deleteobject.htm)($iBrush)

Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) $GUI_RUNDEFMSG
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)

в аттаче более сложный пример (с использованием UDF OwnTab.au3).

Anarasius
31-07-2010, 23:21
а через Button это возможно воплатить?

Creat0R
31-07-2010, 23:45
через Button это возможно воплатить? »
Что именно?

Anarasius
31-07-2010, 23:52
Создание табов через Button. Вот тут мы делали табы: http://forum.oszone.net/thread-175101-2.html а можноли вместо них просто создать Buttons и стиль будет легче менять

Creat0R
01-08-2010, 00:37
Создание табов через Button »
А в чём проблема?

Creat0R
01-08-2010, 01:00
Вот так можно:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUITab.au3>

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

Global $aBrushColor[3] = [2, 0xDDAA11, 0x99BBEE]
Global $aTabItem[3] = [2]

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

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

$aTabItem[1] = GUICtrlCreateTabItem(" Item 1")
GUICtrlCreateLabel("", 10, 33, 277, 135)
GUICtrlSetBkColor(-1, $aBrushColor[1])
GUICtrlSetState(-1, $GUI_DISABLE)

$aTabItem[2] = GUICtrlCreateTabItem(" Item 2")
GUICtrlCreateLabel("", 10, 33, 277, 135)
GUICtrlSetBkColor(-1, $aBrushColor[2])
GUICtrlSetState(-1, $GUI_DISABLE)

GUICtrlCreateTabItem("")

$nButton = GUICtrlCreateButton("Create Tab", 10, 175, 60, 20)

GUISetState()

GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM")

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

While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
Case $nButton
$aBrushColor[0] += 1
ReDim $aBrushColor[$aBrushColor[0]+1]

While _ColorIsDarkShade($aBrushColor[$aBrushColor[0]])
$aBrushColor[$aBrushColor[0]] = _ColorGetRandomColor()
WEnd

$aTabItem[0] += 1
ReDim $aTabItem[$aTabItem[0]+1]
$aTabItem[$aTabItem[0]] = GUICtrlCreateTabItem(" Item " & $aTabItem[0])
GUICtrlCreateLabel("", 10, 33, 277, 135)
GUICtrlSetBkColor(-1, $aBrushColor[$aBrushColor[0]])
GUICtrlSetState(-1, $GUI_DISABLE)

GUICtrlSetState($aTabItem[$aTabItem[0]], $GUI_SHOW)
EndSwitch
WEnd

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, $iBrushColor = _ColorSwitchRGBBGR($aBrushColor[$itmID+1])

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

Func _ColorGetRandomColor()
Return "0x" & Hex(Random(1, 255, 1) & Random(1, 255, 1) & Random(1, 255, 1), 6)
EndFunc

Func _ColorIsDarkShade($nColor)
Local $i_Red = BitAND(BitShift($nColor, 16), 0xFF)
Local $i_Green = BitAND(BitShift($nColor, 8), 0xFF)
Local $i_Blue = BitAND($nColor, 0xFF)

Local $iMidle_Color_Val = Int(765 / 2) ;765 is the total of 255 + 255 + 255

Return (($i_Red + $i_Green + $i_Blue) < $iMidle_Color_Val)
EndFunc

Func _ColorSwitchRGBBGR($iColor)
Local $iMask = BitXOR(BitAND($iColor, 0xFF), ($iColor / 0x10000))
Return "0x" & Hex(BitXOR($iColor, ($iMask * 0x10001)), 6)
EndFunc

Centrinar
08-08-2010, 01:16
А как поменять цвет заголовков Табов?

Creat0R
08-08-2010, 01:49
как поменять цвет заголовков Табов? »
Это показано в примере выше.

Centrinar
09-08-2010, 00:24
не цвет фона а цвет текста-названия таба




© OSzone.net 2001-2012