Jump to content

Recommended Posts

Posted

Hi all,

I was trying the example from this link in regards to creating tabs with a color behind the tabs themselves. While Yashied's code works great to achieve this, the controls on the tabs seem to be hidden until the mouse cursor hovers over them. What am I missing in order to show the controls on the tabs?

#include <Constants.au3>
#include <GuiTab.au3>
#include <TabConstants.au3>
#include <WinAPIEx.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

Global Const $PRF_CLIENT = 0x04

Global $hTab, $hDll, $pDll, $hProc

GUICreate('MyGUI', 300, 300)
GUISetBkColor(0xAACCFF)
GUICtrlCreateTab(20, 20, 262, 261, $TCS_FOCUSONBUTTONDOWN)
$hTab = GUICtrlGetHandle(-1)
GUICtrlCreateTabItem('Tab 1')
GUICtrlCreateButton("Hi", 50, 50, 80); <<<<< Hidden until mouse hovers over it...but why??
GUICtrlCreateTabItem('Tab 2')
GUICtrlCreateTabItem('Tab 3')
GUICtrlCreateTabItem('')

$hDll = DllCallbackRegister('_WinProc', 'ptr', 'hwnd;uint;wparam;lparam')
$pDll = DllCallbackGetPtr($hDll)
$hProc = _WinAPI_SetWindowLong($hTab, $GWL_WNDPROC, $pDll)

OnAutoItExitRegister('AutoItExit')

GUISetState()

Do
Until GUIGetMsg() = -3

Func _CreateClipRgn($hWnd)
    Local $tRect
    Local $Count = _GUICtrlTab_GetItemCount($hWnd)
    Local $Sel = _GUICtrlTab_GetCurSel($hWnd)
    Local $hRgn = _WinAPI_CreateRectRgn(0, 0, 0, 0)
    Local $hTmp, $Ht

    For $i = 0 To $Count - 1
        $tRect = _GUICtrlTab_GetItemRectEx($hWnd, $i)
        If $i = $Sel Then
            $hTmp = _WinAPI_CreateRectRgn(DllStructGetData($tRect, 1) - 2, DllStructGetData($tRect, 2) - 2, DllStructGetData($tRect, 3) + 2, DllStructGetData($tRect, 4))
            $Ht = DllStructGetData($tRect, 4) - DllStructGetData($tRect, 2) + 2
        Else
            If $i = $Count - 1 Then
                $hTmp = _WinAPI_CreateRectRgn(DllStructGetData($tRect, 1), DllStructGetData($tRect, 2), DllStructGetData($tRect, 3) - 2, DllStructGetData($tRect, 4))
            Else
                $hTmp = _WinAPI_CreateRectRgn(DllStructGetData($tRect, 1), DllStructGetData($tRect, 2), DllStructGetData($tRect, 3), DllStructGetData($tRect, 4))
            EndIf
        EndIf
        _WinAPI_CombineRgn($hRgn, $hRgn, $hTmp, $RGN_OR)
        _WinAPI_DeleteObject($hTmp)
    Next
    $tRect = _WinAPI_GetClientRect($hWnd)
    $hTmp = _WinAPI_CreateRectRgn(DllStructGetData($tRect, 1), DllStructGetData($tRect, 2) + $Ht, DllStructGetData($tRect, 3) - 2, DllStructGetData($tRect, 4) - 1)
    _WinAPI_CombineRgn($hRgn, $hRgn, $hTmp, $RGN_OR)
    _WinAPI_DeleteObject($hTmp)
    Return $hRgn
EndFunc   ;==>_CreateClipRgn

Func _WinProc($hWnd, $iMsg, $wParam, $lParam)
    If _WinAPI_IsThemeActive() Then
        Switch $iMsg
            Case $WM_ERASEBKGND
                Local $hRgn = _CreateClipRgn($hWnd)
                Local $hPrev = _WinAPI_GetClipRgn($wParam)
                Local $hBrush = _WinAPI_CreateSolidBrush(0xFFCCAA)
                Local $tRect = _WinAPI_GetClientRect($hWnd)
                _WinAPI_ExtSelectClipRgn($wParam, $hRgn, $RGN_DIFF)
                _WinAPI_FillRect($wParam, DllStructGetPtr($tRect), $hBrush)
                _WinAPI_SelectClipRgn($wParam, $hPrev)
                _WinAPI_DeleteObject($hBrush)
                _WinAPI_DeleteObject($hRgn)
                Return 1
            Case $WM_PAINT
                Local $tPaint
                Local $hDC = _WinAPI_BeginPaint($hWnd, $tPaint)
                Local $hRgn = _CreateClipRgn($hWnd)
                _WinAPI_ExtSelectClipRgn($hDC, $hRgn, $RGN_AND)
                _WinAPI_CallWindowProc($hProc, $hWnd, $WM_PRINTCLIENT, $hDC, $PRF_CLIENT)
                _WinAPI_DeleteObject($hRgn)
                _WinAPI_EndPaint($hWnd, $tPaint)
                Return 0
        EndSwitch
    EndIf
    Return _WinAPI_CallWindowProc($hProc, $hWnd, $iMsg, $wParam, $lParam)
EndFunc   ;==>_WinProc

Func AutoItExit()
    _WinAPI_SetWindowLong($hTab, $GWL_WNDPROC, $hProc)
    DllCallbackFree($hDll)
EndFunc   ;==>AutoItExit

 

Posted

This is an old and well known issue. Just replace

Return _WinAPI_CallWindowProc($hProc, $hWnd, $iMsg, $wParam, $lParam)

with

Return DllCall("user32.dll", "lresult", "CallWindowProc", "ptr", $hProc, "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam)[0]

 

Posted

Hey LarsJ, I've replaced the line as you suggest, but the "Hi" button in my reproducer is still hidden until I hover over it. Also, when I click the other tabs in the example, the button control is hidden again.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...