0

I was trying to Manually Set Focus border to Tabs selected using SetCurSel() API. But While doing so i also wanted to set the Keyboard Focus(Dotted Border Focus around the Tab as shown in Picture). All I could achieve is Tab selection using SetCurSel().

Focus Border Applied to Tab Control when in Keyboard Focus In my project I don't want the TCN_SELCHANGING to be send, that's why I'm using SetCurSel() instead of SetCurFocus() which will invoke TCN_SELCHANGING or TCN_SELCHANGE notification message.

Currently in my code I am overriding LBUTTON down message to take control of Tab Selection and and I would call SetCurSel() from there.

LRESULT TabEx::WindowProc( UINT uMsg_i, WPARAM wParam_i, LPARAM lParam_i )
{
    switch( uMsg_i )
    {
        case WM_LBUTTONDOWN :
        {
            switch( wParam_i )
            {
                case MK_LBUTTON:
                {
                    int nIndex = GetCurSel( );
                    if()// Logic To determine Which Tab to Select
                    {
                            // Decide to Select nIndex th Tab
                            SetCurSel( nIndex );
                            SendSelChangeNotification( TCN_SELCHANGE );
                            retrun true;
                    
                    }
                    
                    break;
                }
            }
        break;
        }
        .
        .
        .
        .
    }
    .
    .
                            
}

The issue with the above code is it will change the tab selection but No Focus in changed. I cannot use SetCurFocus() here since I don't want to interfere with TCN_SELCHANGING. Is there any direct Message call or function call to Set the Focus to a specific Tab?

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
  • *"I was trying to Manually Set Focus border to Tabs selected using `SetCurSel()` API."* - Why? What *problem* are you trying to solve? Are you sure that this isn't an [XY Problem](https://xyproblem.info)? – IInspectable May 23 '21 at 11:28
  • Anyway, the function is unsurprisingly called [DrawFocusRect](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-drawfocusrect). Using it properly is far more involved than it looks. – IInspectable May 23 '21 at 11:41
  • My intent was to remove the offset [offset space](https://imgur.com/a/mFTH7zE) that is found to left of first Tab in Tab Control. I was able to remove that by drawing custom Tab and modifying the Tab Width using Deflate rectangle. I was successful in removing that offset GUI wise but the API's GetCurSel() and HitTest() returned Tab Indices without accounting for the offset i just removed. @IInspectable – Jishnu Jayakumar May 23 '21 at 12:26

0 Answers0