The Study of Programming Windows with MFC--Slider,Spin,ToolTip

1.Slider

   CSliderCtrl m_wndSlider;

   //  m_wndSlider.Create(this);   //when and where is it used?

   m_wndSlider.SetRange(0,8);

   m_wndSlider.SetPos(4);

   m_wndSlider.SetTic(2);

   m_wndSlider.SetTic(4);

   m_wndSlider.SetTic(6);

   m_wndSlider.SetSelection (3, 7);

 

CSliderCtrl provides more than two dozen functions you can use to operate on slider controls. Other useful member functions include SetPageSize, which sets the number of units the thumb moves when the channel is clicked with the mouse or when Page Up or Page Down is pressed; GetTic, GetTicPos, GetTicArray, and GetNumTicks, which return information about tick marks; and ClearSel, which removes a selection range. See the MFC documentation for more information regarding these and other CSliderCtrl function members.

 

 

 

 

2.Spin Button

   EDITTEXT    IDC_EDIT, 60, 80, 40, 14, ES_AUTOHSCROLL
   CONTROL     "", IDC_SPIN, "msctls_updown32", UDS_SETBUDDYINT ¦ UDS_AUTOBUDDY ¦ UDS_ALIGNRIGHT, 0, 0, 0, 0

   // m_wndSpinBtn.Create  when and where is it used?

 

   CSpinButtonCtrl  m_wndSpinBtn;

   m_wndSpinBtn.SetBase(16);  // display hexadecimal numbers

   UDACCEL uda[4];
   uda[0].nSec = 0;
   uda[0].nInc = 1;
   uda[1].nSec = 2;
   uda[1].nInc = 2;
   uda[2].nSec = 4;
   uda[2].nInc = 10;
   uda[3].nSec = 8;
   uda[3].nInc = 100;
   pSpinButton->SetAccel (4, uda);

   You set a spin button control's range and position with CSpinButtonCtrl::SetRange and CSpinButtonCtrl::SetPos

 

   UDACCEL* puda = new UDACCEL[nCount];
   pSpinButton->GetAccel (nCount, puda);
   // Do something with the array.
   delete[] puda;

 

 

 

3.ToolTip

   CToolTipCtrl m_ctlTt;

   m_ctlTT.Create (this);
   m_ctlTT.AddTool (pWnd, _T ("This is a window"), NULL, 0);
   m_ctlTT.AddTool (pWnd, _T ("This is a rectangle"),CRect (32, 32, 64, 64), IDT_RECTANGLE);

 

   class CMyToolTipCtrl : public CToolTipCtrl
   {
    public:
       BOOL AddWindowTool (CWnd* pWnd, LPCTSTR pszText);
       BOOL AddRectTool (CWnd* pWnd, LPCTSTR pszText,   LPCRECT pRect, UINT nIDTool);
   };

BOOL CMyToolTipCtrl::AddWindowTool (CWnd* pWnd, LPCTSTR pszText)
{
    TOOLINFO ti;
    ti.cbSize = sizeof (TOOLINFO);
    ti.uFlags = TTF_IDISHWND ¦ TTF_SUBCLASS;
    ti.hwnd = pWnd->GetParent ()->GetSafeHwnd ();
    ti.uId = (UINT) pWnd->GetSafeHwnd ();
    ti.hinst = AfxGetInstanceHandle ();
    ti.lpszText = (LPTSTR) pszText;

    return (BOOL) SendMessage (TTM_ADDTOOL, 0, (LPARAM) &ti);
}

BOOL CMyToolTipCtrl::AddRectTool (CWnd* pWnd, LPCTSTR pszText,
    LPCRECT lpRect, UINT nIDTool)
{
    TOOLINFO ti;
    ti.cbSize = sizeof (TOOLINFO);
    ti.uFlags = TTF_SUBCLASS;
    ti.hwnd = pWnd->GetSafeHwnd ();
    ti.uId = nIDTool;
    ti.hinst = AfxGetInstanceHandle ();
    ti.lpszText = (LPTSTR) pszText;
    ::CopyRect (&ti.rect, lpRect);

    return (BOOL) SendMessage (TTM_ADDTOOL, 0, (LPARAM) &ti);
}

 

    m_ctlTT.AddWindowTool (GetDlgItem (IDC_SLIDER), MAKEINTRESOURCE (IDS_SLIDER));
    m_ctlTT.AddWindowTool (GetDlgItem (IDC_EDITHORZ),MAKEINTRESOURCE (IDS_EDITHORZ));
    m_ctlTT.AddWindowTool (GetDlgItem (IDC_EDITVERT),MAKEINTRESOURCE (IDS_EDITVERT));


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

风水月

从心底相信自己是成功的第一步

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值