编辑框添加灰色提示字(html+VC)

  Html中添加灰色提示字,使用属性placeholder即可!

  <input type="text" placeholder="要显示的文字">  

  

  但是,VC++实现这样的效果比较困难,但是可以借助ToolTipCtrl实现类似的效果:

  1、对话框头文件中声明成员变量:CToolTipCtrl   m_ToolTip;

       2、对话框OnInitDialog中加入:

  m_ToolTip.Create(this);
  m_ToolTip.AddTool(GetDlgItem(IDC_EDIT_HTTP_URL), _T("http:// or https://"));
  m_ToolTip.AddTool(GetDlgItem(IDC_EDIT_HTTP_PARAMETER), _T("{\"a\":\"1\",\"b\":\"2\"}"));
  m_ToolTip.AddTool(GetDlgItem(IDC_EDIT_HTTP_FREQUENCY), _T("1-60"));
  m_ToolTip.SetMaxTipWidth(300);
  m_ToolTip.Activate(TRUE);

  3、重写PreTranslateMessage:

  BOOL CXXDlg::PreTranslateMessage(MSG* pMsg)
  {
    ASSERT(pMsg != NULL);
    if (pMsg->message == WM_MOUSEMOVE ||
      pMsg->message == WM_LBUTTONDOWN ||
      pMsg->message == WM_LBUTTONUP)
    {
      m_ToolTip.RelayEvent(pMsg);
    }

    return CDialog::PreTranslateMessage(pMsg);
  }

  

扫描二维码关注公众号,回复: 1454042 查看本文章

猜你喜欢

转载自www.cnblogs.com/MakeView660/p/9134494.html