回复 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
|