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.

  • 相关阅读:
    在集群环境中使用 EhCache 缓存系统|RMI 集群模式
    oracle中的针对该库的表
    oracle:触发器,自治事务 trigger
    PL/SQL中查询某的时间段内所有执行的sql
    金额input框控制只能小数点后有两位的有效数字
    JS判断键盘上的上下左右键
    MySQL按照汉字的拼音排序
    JAVA经典总结
    普通for循环遍历LinkedList弊端
    EASYUI 1.4版 combobox firefox 下不支持中文检索的问题
  • 原文地址:https://www.cnblogs.com/cy163/p/556073.html
Copyright © 2011-2022 走看看