TCM_HITTEST TCHITTESTINFO 笔记

看notepad++的源代码,其中用到了这个消息,于是查了一下

TCM_HITTEST 

This message determines which tab, if any, is at a specified screen position. You can send this message explicitly or by using theTabCtrl_HitTest macro.

TCM_HITTEST wParam = 0; 
  lParam = (LPARAM)(TC_HITTESTINFO FAR *) pinfo;

return Values

The index of the tab indicates success. –1 indicates that no tab is at the specified position.



This structure contains information about a hit test.

typedef struct _TCHITTESTINFO { 
  POINT pt; 
  UINT flags; 
} TCHITTESTINFO; 
Members
pt
Position to hit test, in client coordinates.
flags
Receives the results of a hit test. The tab control sets this member to one of the following values.
ValueDescription
TCHT_NOWHEREThe position is not over a tab.位置不在一个标签上
TCHT_ONITEMThe position is over a tab but not over its icon or its text. For owner-drawn tab controls, this value is specified if the position is anywhere over a tab.
在一个标签上
TCHT_ONITEMICONThe position is over a tab's icon.鼠标在标签的图标上面图标
TCHT_ONITEMLABELThe position is over a tab's text.标签文本

TCHT_ONITEM is a bitwise-OR operation on TCHT_ONITEMICON and TCHT_ONITEMLABEL.

这句的意思是  TCHT_ONITEM == TCHT_ONITEMICON ||TCHT_ONITEMLABEL. 

在头文件里可以找到这个定义

#define TCHT_ONITEM    (TCHT_ONITEMICON|TCHT_ONITEMLABEL)

    TCHITTESTINFO hitinfo;
    hitinfo.pt.x = point.x;
    hitinfo.pt.y = point.y;

    // Find the destination tab...
    int nTab = ::SendMessage(_hSelf, TCM_HITTEST, 0, (LPARAM)&hitinfo);
检测当前的鼠标位置在标签的什么地方



下面贴出notepad++的部分源码

void TabBar::exchangeItemData(POINT point)
{
    TCHITTESTINFO hitinfo;
    hitinfo.pt.x = point.x;
    hitinfo.pt.y = point.y;

    // Find the destination tab...
    int nTab = ::SendMessage(_hSelf, TCM_HITTEST, 0, (LPARAM)&hitinfo);
//    if(hitinfo.flags == TCHT_NOWHERE)
//    {
//        MessageBox(0,"TCHT_NOWHERE",0,0);
//    }
     if(hitinfo.flags &TCHT_ONITEM)
    {
         MessageBox(0,"TCHT_ONITEM",0,0);

    }
    else if(hitinfo.flags &TCHT_ONITEMICON)
    {
                MessageBox(0,"TCHT_ONITEMICON",0,0);

    }
//    else if(hitinfo.flags ==TCHT_ONITEMLABEL)
//    {
//                   MessageBox(0,"TCHT_ONITEMLABEL",0,0);
//    }
//    else if(hitinfo.flags ==TCHT_ONITEM)
//    {
//           MessageBox(0,"TCHT_ONITEM",0,0);
//    }
    // The position is over a tab.
    if (hitinfo.flags != TCHT_NOWHERE)
    {

        _isDraggingInside = true;

        if (nTab != _nTabDragged)
        {
            //1. set to focus
            ::SendMessage(_hSelf, TCM_SETCURSEL, nTab, 0);

            //2. shift their data, and insert the source
            TCITEM itemData_nDraggedTab, itemData_shift;
            itemData_nDraggedTab.mask = itemData_shift.mask = TCIF_IMAGE | TCIF_TEXT;
            char str1[256];
            char str2[256];

            itemData_nDraggedTab.pszText = str1;
            itemData_nDraggedTab.cchTextMax = (sizeof(str1));

            itemData_shift.pszText = str2;
            itemData_shift.cchTextMax = (sizeof(str2));

            ::SendMessage(_hSelf, TCM_GETITEM, _nTabDragged, reinterpret_cast<LPARAM>(&itemData_nDraggedTab));

            if (_nTabDragged > nTab)
            {
                for (int i = _nTabDragged ; i > nTab ; i--)
                {
                    ::SendMessage(_hSelf, TCM_GETITEM, i-1, reinterpret_cast<LPARAM>(&itemData_shift));
                    ::SendMessage(_hSelf, TCM_SETITEM, i, reinterpret_cast<LPARAM>(&itemData_shift));
                }
            }
            else
            {
                for (int i = _nTabDragged ; i < nTab ; i++)
                {
                    ::SendMessage(_hSelf, TCM_GETITEM, i+1, reinterpret_cast<LPARAM>(&itemData_shift));
                    ::SendMessage(_hSelf, TCM_SETITEM, i, reinterpret_cast<LPARAM>(&itemData_shift));
                }
            }
            //
            ::SendMessage(_hSelf, TCM_SETITEM, nTab, reinterpret_cast<LPARAM>(&itemData_nDraggedTab));

            //3. update the current index
            _nTabDragged = nTab;

        }
    }
    else
    {
        //::SetCursor(::LoadCursor(_hInst, MAKEINTRESOURCE(IDC_DRAG_TAB)));
        _isDraggingInside = false;
    }

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值