0

このMSDN コード例では:

// Description:
//   Creates a tooltip for an item in a dialog box. 
// Parameters:
//   idTool - identifier of an dialog box item.
//   nDlg - window handle of the dialog box.
//   pszText - string to use as the tooltip text.
// Returns:
//   The handle to the tooltip.
//
HWND CreateToolTip(int toolID, HWND hDlg, PTSTR pszText)
{
    if (!toolID || !hDlg || !pszText)
    {
        return FALSE;
    }
    // Get the window of the tool.
    HWND hwndTool = GetDlgItem(hDlg, toolID);
    
    // Create the tooltip. g_hInst is the global instance handle.
    HWND hwndTip = CreateWindowEx(NULL, TOOLTIPS_CLASS, NULL,
                              WS_POPUP |TTS_ALWAYSTIP | TTS_BALLOON,
                              CW_USEDEFAULT, CW_USEDEFAULT,
                              CW_USEDEFAULT, CW_USEDEFAULT,
                              hDlg, NULL, 
                              g_hInst, NULL);
    
   if (!hwndTool || !hwndTip)
   {
       return (HWND)NULL;
   }                              
                              
    // Associate the tooltip with the tool.
    TOOLINFO toolInfo = { 0 };
    toolInfo.cbSize = sizeof(toolInfo);
    toolInfo.hwnd = hDlg;                          // first HWND
    toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
    toolInfo.uId = (UINT_PTR)hwndTool;             // second HWND
    toolInfo.lpszText = pszText;
    SendMessage(hwndTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo);

    return hwndTip;
}

操作を 2 つの HWND ハンドルに関連付けTTM_ADDTOOLます。1 つは Dialogbox(hDlg) で、もう 1 つはダイアログ ボックス内のコントロールです。試してみたところtoolInfo.hwnd = hDlg;、toolID コントロールにマウスを置いたときに、コメントアウトしてもツールチップが表示されることがわかりました。

では、2 つの HWND ハンドルを渡す意味は何ですか? それは必須ですか、それとも他の場合に役立ちますか?

4

2 に答える 2

2

lpszTextフィールドを LPSTR_TEXTCALLBACKに設定すると、TOOLINFO 構造体のhwndも使用されます。ツールチップにテキストが必要な場合、WM_NOTIFY メッセージを介してそのhwndにTTN_GETDISPINFO通知が送信されます。そのメッセージの LPARAM は、ツール ヒントのテキストを設定するために使用できるNMTTDISPINFO構造体へのポインターになります。ツールチップのテキストを変更する必要がある場合に適しています。

于 2015-11-14T14:15:53.183 に答える