Jump to content
Sign in to follow this  
58fly

Consult the painting from a Tab problem!

Recommended Posts

58fly

Hi, hello ~ I am a beginner, English is not good, is to use translation softwaretranslation into English, to find the answer, I hope you can understand, thank you!
According to the above example, I just try to increase in the width of the lab
           Global $WinWidth = 800, $WinHeight = 600, $TabWidth = 60, $TabHeight = 50,$Tabcount = 5
Modify Global $WinWidth = 800, $WinHeight = 600, $TabWidth = 150, $TabHeight = 50, $Tabcount = 5
That button response is very slow, seeking a solution!
 

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <FontConstants.au3>
#include <WinAPIEx.au3>
#include <TabConstants.au3>
#include <GuiTab.au3>
#include <Constants.au3>
 
Global $hGUI, $GUIMsg
 
Global $TabHover = False, $TABActiveID = 0, $TabHoverID = -1, $Count = 0
Global $WinWidth = 600, $WinHeight = 400, $TabWidth = 60, $TabHeight = 50, $Tabcount = 5
 
Global $hTABCallback = DllCallbackRegister("My_TABProc", "int", "hWnd;uint;wparam;lparam")
Global $tTABCallback = DllCallbackGetPtr($hTABCallback)
 
$hGUI = GUICreate("TAB", $WinWidth, $WinHeight)
$tab = GUICtrlCreateTab(0, 0, $WinWidth, $WinHeight, BitOR($TCS_FIXEDWIDTH, $TCS_OWNERDRAWFIXED, $TCS_MULTILINE))
GUICtrlSetStyle(-1, $TCS_VERTICAL)
$tabHwnd = GUICtrlGetHandle(-1)
_GUICtrlTab_SetItemSize($tab, $TabWidth, $TabHeight)
 
GUICtrlCreateTabItem("Star")
GUICtrlCreateEdit("The first EDIT", 130, 60, 300, 220, 0x00C0)
GUICtrlCreateButton("OK", 450, 150, 60, 40)
 
GUICtrlCreateTabItem("Sec")
GUICtrlCreateLabel("Sec", 130, 80)
GUICtrlCreateCombo("", 130, 150, 60, 120)
GUICtrlSetData(-1, "Trids|CyberSlug|Larry|Jon|Tylo", "Jon")
GUICtrlCreateButton("setup", 280, 150, 50, 20)
 
GUICtrlCreateTabItem("Tid")
GUICtrlCreateLabel("The Third", 130, 80)
 
GUICtrlCreateTabItem("Four")
GUICtrlCreateButton("four", 130, 80)
GUICtrlCreateTabItem("Five")
GUICtrlCreateButton("Five", 130, 80)
GUICtrlCreateTabItem("")
 
$hdisplayDC = _WinAPI_CreateDC()

$MyhImage = _WinAPI_LoadImage(0, @ScriptDir & "\LOFFICE.bmp", $IMAGE_BITMAP, 0, 0, $LR_LOADFROMFILE)
$hBmpDC = _WinAPI_CreateCompatibleDC($hdisplayDC)
$hBmpSv = _WinAPI_SelectObject($hBmpDC, $MyhImage)
_WinAPI_DeleteObject($MyhImage)

$hTempDC = _WinAPI_CreateCompatibleDC($hdisplayDC)
$hTempImage = _WinAPI_CreateCompatibleBitmap($hdisplayDC, $TabWidth, $TabHeight * $Tabcount)
$hTempSv = _WinAPI_SelectObject($hTempDC, $hTempImage)
_WinAPI_DeleteObject($hTempImage)
_WinAPI_DeleteDC($hdisplayDC)
 
Global $TABCallProc = _WinAPI_SetWindowLong(GUICtrlGetHandle($tab), -4, $tTABCallback)
GUISetState()
 
While 1
        $GUIMsg = GUIGetMsg()
        Switch $GUIMsg
                Case $GUI_EVENT_CLOSE
                        _myexitfunc()
        EndSwitch
WEnd

Func _myexitfunc()
        _WinAPI_SetWindowLong(GUICtrlGetHandle($tab), -4, $TABCallProc)
        DllCallbackFree($hTABCallback)
        ;删除DC
        _WinAPI_SelectObject($hBmpDC, $hBmpSv)
        _WinAPI_DeleteDC($hBmpDC)
        _WinAPI_SelectObject($hTempDC, $hTempSv)
        _WinAPI_DeleteDC($hTempDC)
        Exit
EndFunc   ;==>_myexitfunc
 
Func My_TABProc($hWnd, $Msg, $wParam, $lParam)
        Switch $Msg
                Case $WM_MOUSEMOVE
                        If Not $TabHover Then;
                                $TabHover = True
                                _WinAPI_TrackMouseEvent($hWnd, 0x00000002)
                        EndIf
                        $mx = _WinAPI_LoWord($lParam)
                        $my = _WinAPI_HiWord($lParam)
                        onMouseMove($hWnd, $mx, $my)
                        Return 0
                Case 0x2A3;WM_MOUSELEAVE
                        $TabHover = False
                        $TabHoverID = -1
                        RedrawAllTAB()
                        Return 0
                Case $WM_ERASEBKGND
                        _JiuGongDraw($wParam, 0, 0, $WinWidth, $WinHeight, $hBmpDC, 25, 20, 2, 1, 0, 0, 0, 0)
                        _JiuGongDraw($wParam, 0, 0, $TabWidth, $WinHeight, $hBmpDC, 0, 26, 27, 1, 0, 0, 1, 0)
                        Return 0
                Case $WM_LBUTTONDOWN
                        $mx = _WinAPI_LoWord($lParam)
                        $my = _WinAPI_HiWord($lParam)
                        onMouseDown($hWnd, $mx, $my)
                        Return _WinAPI_CallWindowProc($TABCallProc, $hWnd, $Msg, $wParam, $lParam)
                Case $WM_PAINT
                        If $Count = 0 Then
                                Local $tPAINTSTRUCT, $hDC
                                $Count += 1
                                $hDC = _WinAPI_BeginPaint($hWnd, $tPAINTSTRUCT)
                                RedrawAllTAB()
                                _WinAPI_EndPaint($hWnd, $tPAINTSTRUCT)
                                $Count -= 1
                                Return 0
                        EndIf
        EndSwitch
        Return _WinAPI_CallWindowProc($TABCallProc, $hWnd, $Msg, $wParam, $lParam)
EndFunc   ;==>My_TABProc
 
Func onMouseMove($hWnd, $mx, $my)
        If $mx <= $TabWidth Then
                $Idx = Int($my / $TabHeight)
                If $Idx >= 0 And $Idx <= $Tabcount - 1 Then
                        If $Idx <> $TabHoverID Then
                                $TabHoverID = $Idx
                                RedrawAllTAB()
                        EndIf
                Else
                        If $TabHoverID <> -1 Then
                                $TabHoverID = -1
                                RedrawAllTAB()
                        EndIf
                EndIf
        Else
                If $TabHoverID >= 0 Then
                        $TabHoverID = -1
                        RedrawAllTAB()
                EndIf
        EndIf
EndFunc   ;==>onMouseMove
 
Func onMouseDown($hWnd, $mx, $my)
        If $mx <= $TabWidth Then
                $Idx = Int($my / $TabHeight)
                If $Idx >= 0 And $Idx <= $Tabcount - 1 Then
                        $TABActiveID = $Idx
                EndIf
        EndIf
EndFunc   ;==>onMouseDown
 
Func RedrawAllTAB()
        For $i = 0 To $Tabcount - 1
                If $i = $TabHoverID Then
                        $stata = 1
                Else
                        $stata = 0
                EndIf
                DrawTAB($hTempDC, $i, $stata, 0, $i * $TabHeight, $TabWidth, $TabHeight)
        Next
        $hDC = _WinAPI_GetDC($tabHwnd)
        _WinAPI_BitBlt($hDC, 0, 0, $TabWidth, $TabHeight * $Tabcount, $hTempDC, 0, 0, $SRCCOPY)
        _WinAPI_ReleaseDC($tabHwnd, $hDC)
EndFunc   ;==>RedrawAllTAB
 
Func DrawTAB($hDC, $nTabID, $TabState, $nLeft, $nTop, $nRight, $nBottom)
    
        If $nTabID = $TABActiveID Then
                _JiuGongDraw($hDC, $nLeft, $nTop, $nRight, $nBottom, $hBmpDC, 0, 13 - $TabState * 13, 27, 13, 5, 6, 2, 6)
        Else
                If $TabState = 0 Then
                        _JiuGongDraw($hDC, $nLeft, $nTop, $nRight, $nBottom, $hBmpDC, 0, 26, 27, 1, 0, 0, 1, 0)
                Else
                        _JiuGongDraw($hDC, $nLeft, $nTop, $nRight, $nBottom, $hBmpDC, 0, 26, 27, 13, 5, 6, 2, 6)
                EndIf
        EndIf
        
        $tRECT = DllStructCreate($tagRect)
        DllStructSetData($tRECT, "Left", $nLeft)
        DllStructSetData($tRECT, "Top", $nTop)
        DllStructSetData($tRECT, "Right", $nRight)
        DllStructSetData($tRECT, "Bottom", $nBottom + $nTop)
        _WinAPI_SetBkMode($hDC, $TRANSPARENT)
        $hFont = _WinAPI_CreateFont(14, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, _
                        $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Arial')
        $hOldFont = _WinAPI_SelectObject($hDC, $hFont)
        _WinAPI_DrawText($hDC, _GUICtrlTab_GetItemText($tab, $nTabID), $tRECT, BitOR($DT_CENTER, $DT_VCENTER, $DT_SINGLELINE))
        _WinAPI_SelectObject($hDC, $hOldFont)
        _WinAPI_DeleteObject($hFont)
        Return 1
EndFunc   ;==>DrawTAB
 

Func _JiuGongDraw($hDC, $dstX, $dstY, $dstWidth, $dstHeight, $hSrcDC, $SrcX, $SrcY, $srcWidth, $srcHeight, $gX1 = 0, $gY1 = 0, $gX2 = 0, $gY2 = 0)
        If $dstWidth = 0 Or $dstHeight = 0 Or $srcWidth = 0 Or $srcHeight = 0 Then Return
        Local $hmenDC = _WinAPI_CreateCompatibleDC($hDC)
        Local $hSource = _WinAPI_CreateCompatibleBitmap($hDC, $dstWidth, $dstHeight)
        Local $hSv = _WinAPI_SelectObject($hmenDC, $hSource)
        If $gX1 <= 0 And $gX2 <= 0 And $gY1 <= 0 And $gY2 <= 0 Then
                _WinApi_StretchBlt($hmenDC, 0, 0, $dstWidth, $dstHeight, $hSrcDC, $SrcX + $gX1, $SrcY + $gY1, $srcWidth - $gX2, $srcHeight - $gY2, $SRCCOPY)
        Else
                If $gX1 > 0 And $gY1 > 0 Then 
                        _WinAPI_BitBlt($hmenDC, 0, 0, $gX1, $gY1, $hSrcDC, $SrcX, $SrcY, $SRCCOPY)
                EndIf
                If $gX2 > 0 And $gY1 > 0 Then 
                        _WinAPI_BitBlt($hmenDC, $dstWidth - $gX2, 0, $gX2, $gY1, $hSrcDC, $SrcX + $srcWidth - $gX2, $SrcY, $SRCCOPY)
                EndIf
                If $gX1 > 0 And $gY2 > 0 Then 
                        _WinAPI_BitBlt($hmenDC, 0, $dstHeight - $gY2, $gX1, $gY2, $hSrcDC, $SrcX, $SrcY + $srcHeight - $gY2, $SRCCOPY)
                EndIf
                If $gX2 > 0 And $gY2 > 0 Then ;
                        _WinAPI_BitBlt($hmenDC, $dstWidth - $gX2, $dstHeight - $gY2, $gX2, $gY2, $hSrcDC, $SrcX + $srcWidth - $gX2, $SrcY + $srcHeight - $gY2, $SRCCOPY)
                EndIf
                If $gX1 > 0 Then 
                        _WinApi_StretchBlt($hmenDC, 0, $gY1, $gX1, $dstHeight - $gY1 - $gY2, $hSrcDC, $SrcX, $SrcY + $gY1, $gX1, $srcHeight - $gY1 - $gY2, $SRCCOPY)
                EndIf
                If $gX2 > 0 Then 
                        _WinApi_StretchBlt($hmenDC, $dstWidth - $gX2, $gY1, $gX2, $dstHeight - $gY1 - $gY2, $hSrcDC, $SrcX + $srcWidth - $gX2, $SrcY + $gY1, $gX2, $srcHeight - $gY1 - $gY2, $SRCCOPY)
                EndIf
                If $gY1 > 0 Then 
                        _WinApi_StretchBlt($hmenDC, $gX1, 0, $dstWidth - $gX1 - $gX2, $gY1, $hSrcDC, $SrcX + $gX1, $SrcY, $srcWidth - $gX1 - $gX2, $gY1, $SRCCOPY)
                EndIf
                If $gY2 > 0 Then 
                        _WinApi_StretchBlt($hmenDC, $gX1, $dstHeight - $gY2, $dstWidth - $gX1 - $gX2, $gY2, $hSrcDC, $SrcX + $gX1, $SrcY + $srcHeight - $gY2, $srcWidth - $gX1 - $gX2, $gY2, $SRCCOPY)
                EndIf
               
                _WinApi_StretchBlt($hmenDC, $gX1, $gY1, $dstWidth - $gX1 - $gX2, $dstHeight - $gY1 - $gY2, $hSrcDC, $SrcX + $gX1, $SrcY + $gY1, $srcWidth - $gX1 - $gX2, $srcHeight - $gY1 - $gY2, $SRCCOPY)
        EndIf
        _WinAPI_BitBlt($hDC, $dstX, $dstY, $dstWidth, $dstHeight, $hmenDC, 0, 0, $SRCCOPY)
        _WinAPI_SelectObject($hmenDC, $hSv)
        _WinAPI_DeleteObject($hSource)
        _WinAPI_DeleteDC($hmenDC)
EndFunc   ;==>_JiuGongDraw
 
Func _WinAPI_CreateDC()
        Local $aResult = DllCall("gdi32.dll", "handle", "CreateDC", "str", "DISPLAY", "str", "", "str", "", "ptr", 0)
        If @error Then Return SetError(@error, @extended, 0)
        Return $aResult[0]
EndFunc   ;==>_WinAPI_CreateDC

post-84939-0-24253100-1394033290_thumb.p

Share this post


Link to post
Share on other sites
FireFox

Hi,

Everything is working fine for me except the tab button for the "Five" which is not displaying the hover image and it's not clickable.

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×