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.

  • 相关阅读:
    MQ 2035(MQRC_NOT_AUTHORIZED)
    C# 构造函数中调用虚方法的问题
    Oracle bug 使用max或min函数into到一个char类型报字符缓冲区太小的错误
    windows2003 64位 iis6.0 运行32位web应用程序
    .NET安装和配置Oracle数据访问组件(ODAC)
    WMS函数组:10.创建采购订单
    报表:BOM展开程序
    WMS函数组:9.交货单过帐3(BDC)
    WMS函数组: 7.交货单行项目除
    WMS函数组:1.检查ZPB2是否存在
  • 原文地址:https://www.cnblogs.com/cy163/p/556073.html
Copyright © 2011-2022 走看看