2011/05/27

[vc6]Button物件顯示Tip

1. 開啟MFC專案後,點選 project-> add   to   project-> component   and   controls-> 選擇 C:\Program Files\Microsoft Visual Studio\COMMON\MSDev98\Gallery\Visual C++ Components-> ToolTip   Support
,然後按Insert,即可將此物件插入本專案。
2. 插入後,在OnInitDialog()內會自動產生一段代碼
<code>

// CG: The following block was added by the ToolTips component.
{
// Create the ToolTip control.
m_tooltip.Create(this);
m_tooltip.Activate(TRUE);

// TODO: Use one of the following forms to add controls:
// m_tooltip.AddTool(GetDlgItem(IDC_<name>), <string-table-id>);
// m_tooltip.AddTool(GetDlgItem(IDC_<name>), "<text>");
}

</code>
假設你要的功能是當滑鼠游標移到"確定"按鈕上能顯示"我確定!"的Tip時,請將預設的
// m_tooltip.AddTool(GetDlgItem(IDC_<name>), "<text>");
修改為
m_tooltip.AddTool(GetDlgItem(IDOK),   "我確定! ");
就算大功告成了~

ps1. m_tooltip.AddTool不一定要在InitialDialog中才能做,如果你有手動創建CButton類,也可以在創建完成後,再替button物件增加tip。
ps2. m_tooltip.AddTool 可以針對同一個ItemID新增不只一次的Tip,但是畫面只會顯示最後一次所設定的tip內容。

以上~

沒有留言:

張貼留言