MFC Silder 滑动条

滑动添加当前值提示信息和显示当前值

1.在.h文件添加TTN_NEEDTEXT的消息函数

 afx_msg BOOL OnToolTipNotify(UINT id,NMHDR*pNMHDR,LRESULT * pResult);

#pragma once
#include "MyString.h"
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "afxcmn.h"
// CHoughCirclesDlg dialog

class CHoughCirclesDlg : public CDialogEx
{
    DECLARE_DYNAMIC(CHoughCirclesDlg)

public:
    CHoughCirclesDlg(CWnd* pParent = NULL);   // standard constructor
    virtual ~CHoughCirclesDlg();

// Dialog Data
    enum { IDD = IDD_DIALOG_HoughCircles };

protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

    DECLARE_MESSAGE_MAP()
public:
    afx_msg void OnBnClickedButtonHoughcircles();
    void HoughDetection(const cv::Mat& src_gray, const cv::Mat& src_display, int cannyThreshold, int accumulatorThreshold);
    CSliderCtrl m_canny_threshold;
    CSliderCtrl m_accumulator_threshold;

    afx_msg BOOL OnToolTipNotify(UINT id,NMHDR*pNMHDR,LRESULT * pResult);

    virtual BOOL OnInitDialog();
    afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
};

 

2.在cpp文件的消息映射中加入以下代码

 ON_NOTIFY_EX(TTN_NEEDTEXT, 0, &CHoughCirclesDlg::OnToolTipNotify) 

 

BEGIN_MESSAGE_MAP(CHoughCirclesDlg, CDialogEx)
    ON_BN_CLICKED(IDC_BUTTON_HoughCircles, &CHoughCirclesDlg::OnBnClickedButtonHoughcircles)
    ON_NOTIFY_EX(TTN_NEEDTEXT, 0, &CHoughCirclesDlg::OnToolTipNotify)
    
    ON_WM_HSCROLL()
END_MESSAGE_MAP()

 

3.在OnInitDialog()中,开启这个功能

 EnableToolTips(); 

 

BOOL CHoughCirclesDlg::OnInitDialog()
{

    CDialogEx::OnInitDialog();
    // TODO:  Add extra initialization here

    m_canny_threshold.SetRange(1,250);
    m_accumulator_threshold.SetRange(1,200);

    m_canny_threshold.SetTicFreq(10);
    m_accumulator_threshold.SetTicFreq(10);

    //开启滑动条提示信息
    EnableToolTips();  
    

    return TRUE;  // return TRUE unless you set the focus to a control
    // EXCEPTION: OCX Property Pages should return FALSE
}

4.

 

void CHoughCirclesDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
    // TODO: Add your message handler code here and/or call default
    if (pScrollBar == (CScrollBar*)GetDlgItem(IDC_SLIDER_Canny_Threshold))        
    {

      //把所调的阈值显示在label上
        CString canny_threshold;
        canny_threshold.Format(_T("%d"), m_canny_threshold.GetPos());
        GetDlgItem(IDC_STATIC_Canny_Threshold_Value)->SetWindowText(canny_threshold);

    }
    CDialogEx::OnHScroll(nSBCode, nPos, pScrollBar);
}

 

 

BOOL CHoughCirclesDlg::OnToolTipNotify(UINT id, NMHDR * pNMHDR, LRESULT * pResult)
{
    TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;
    UINT nID =pNMHDR->idFrom;
    if (pTTT->uFlags & TTF_IDISHWND)
    {
        // idFrom is actually the HWND of the tool
        nID = ::GetDlgCtrlID((HWND)nID);
        if(nID)
        {
            //  这里就是你要显示的Tooltips,可以根据需要来定制
            CString strToolTips;
            strToolTips.Format(_T("总共500帧,当前是第%d帧"), m_canny_threshold.GetPos());
            _tcscpy(pTTT->lpszText,strToolTips);
            pTTT->hinst = NULL;
            return(TRUE);
        }
    }

    return(FALSE);
}

 

posted @ 2014-12-18 17:05  ike_li  阅读(339)  评论(0)    收藏  举报