zoukankan      html  css  js  c++  java
  • show tooltip on control

    http://www.borngeek.com/coding/dialog/control_tooltips.html

    Adding Tooltips to Dialog Controls

    Back to the Coding Article Index

    Enabling Tooltips

    Enabling tooltips on dialog controls can be extremely useful, especially when a large number of controls are used. In this scenario, they could be used to describe what a particular control does, as well as any corresponding shortcut keys. Adding this feature is a relatively simple procedure. First we need to enable the tooltips by calling the following line of code in our OnInitDialog() method:

    EnableToolTips(TRUE);

    This function simply enables the tooltip control in our dialog window. We now need to add the following line of code to the message map in our dialog class. Note that the text OnToolTip in the code below is the name of the method that will be associated with this message. Feel free to change the name of this method if you like. For the purposes of this article, we will stick with using OnToolTip as the method name.

    ON_NOTIFY_EX(TTN_NEEDTEXT, 0, OnToolTip)

    Handling the Tooltips

    Next, add the OnToolTip() method declaration to the dialog class header file:

    afx_msg BOOL OnToolTip(UINT id, NMHDR* pTTTStruct, LRESULT* pResult);

    After we have declared this method, we need to add its code to the dialog class CPP file. The definition for this method is shown below:

    BOOL CYourDlg::OnToolTip(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)
    {
    pTTT->lpszText = MAKEINTRESOURCE(nID);
    pTTT->hinst = AfxGetResourceHandle();
    return(TRUE);
    }
    }
    return(FALSE);
    }
    

    Now that our code is in place, we need to add the tooltip strings to the string table resource. In the resource editor, open the string table (insert a new one if your project doesn't already have a string table). Now add one string for each control that you want to show a tooltip. Each string's value should be set to the text that you want to appear in the tooltip. Most importantly, each string's ID should be set to the same ID of the corresponding control.

  • 相关阅读:
    D3D中的Alpha颜色混合(1)
    最小的MFC程序
    命名空间规则【内部】
    能登陆QQ,打不开网页
    .net重要的开源组件[更新中]
    validateRequest="false"属性及xss攻击
    RSS介绍
    Virtual、Override和New关键字的使用
    SQL语句精妙集合
    绝好的软件集合
  • 原文地址:https://www.cnblogs.com/cy163/p/556073.html
Copyright © 2011-2022 走看看