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.
Value Description
TCHT_NOWHERE The position is not over a tab.位置不在一个标签上
TCHT_ONITEM The 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_ONITEMICON The position is over a tab's icon.鼠标在标签的图标上面图标
TCHT_ONITEMLABEL The 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;
    }

}


你可能感兴趣的:(image,struct,insert,structure)