Thêm ToolTip cho các control trong
VISUAL C++ 6.0
Vn Chí Nam, Nguyn c Hoàng H
Khoa Công ngh Thông tin, trng H KHTN TP.HCM
[email protected], [email protected]
Phiên bn cp nht ngày 15/05/2005
Tooltip là mt dòng đn chú thích hin ra bên cnh control khi chut di chuyn
phía trên "khu vc" ca đi tng. Tooltip thng đc dùng nh là mt ghi chú hng
dn ngi s dng chc nng ca đi tng đang hng đn.
MFC h tr mt lp đ thc hin công vic này. ó là lp CToolTipCtrl.
GII THIU V CTOOLTIPCTRL
Các chc nng cu lp này chúng ta có th tìm hiu thêm MSDN, đây tôi ch
ghi li tóm tt các hàm có th dùng ca CToolTipCtrl :
Create Creates a tool tip control and attaches it to a CToolTipCtrl object.
GetText Retrieves the text that a tool tip control maintains for a tool.
GetToolInfo Retrieves the information that a tool tip control maintains about a
tool.
SetToolInfo Sets the information that a tool tip maintains for a tool.
GetToolCount Retrieves a count of the tools maintained by a tool tip control.
GetDelayTime Retrieves the initial, pop-up, and reshow durations currently set for
a tool tip control.
SetDelayTime Sets the initial, pop-up, and reshow durations for a tool tip control.
GetMargin Retrieves the top, left, bottom, and right margins set for a tool tip
window.
SetMargin Sets the top, left, bottom, and right margins for a tool tip window.
GetMaxTipWidth Retrieves the maximum width for a tool tip window.
{
//Khi to con tr Tooltip
if (!m_pToolTip->Create(this))
{
MessageBox("Khong the tao ToolTip");
OnOK();
}
/*
Nu mun thêm tooltip cho đi tng IDOK thìly con tr pWnd t IDOK
*/
pWnd = GetDlgItem(IDOK);
CRect rect;
//Ly hình ch nht bao quanh IDOK
pWnd->GetClientRect(rect);
/*Thêm vào đi tng tooltip mt tool mi*/
/* Tham s th nht : con tr ch đn đi tng cn thêm tooltip
Tham s th hai : Chui th hin trong tooltip
Tham s th ba : Hình ch nht bao quanh tooltip
Tham s th t : S hiu cu tool trong tooltip control (IDTool)
*/
m_pToolTip->AddTool(pWnd,"Bam vao day de
thoat",rect,1);
}
- Bc 3 : Thêm vào lp CTamDlg hàm PreTranslateMessage, hàm này có tác
dng x lý thông đip trc khi gi đn ca s. Thông đip phi đc đa đn cho tooltip
control trc. Dùng hàm RelayEvent cu CToolTipCtrl đ làm công vic x lý thông đip
cho tooltip.