Hướng dẫn thực hành Lập trình C trên Windows - Thêm Tooltip cho các Control trong Visual C++ 6.0

Đểchèn một record vào bảng, chúng ta sửdụng hàm sau:

void CUseListCtrlDlg::InsertStudent(CString Code, CString Name,

COleDateTime Birthday, BOOL IsMale, CString Addr)

{

 static unsigned int index = 0;

CString Temp;

 // Chèn thêm một record ởdòng thứindex

m_StdList.InsertItem(index,Code);

// Ghi dữliệu vào cột thứ0 với nội dung trong biến Code ởdòng thứindex

pdf4 trang | Chuyên mục: Visual C++ | Chia sẻ: dkS00TYs | Lượt xem: 1694 | Lượt tải: 1download
Tóm tắt nội dung Hướng dẫn thực hành Lập trình C trên Windows - Thêm Tooltip cho các Control trong Visual C++ 6.0, để xem tài liệu hoàn chỉnh bạn click vào nút "TẢI VỀ" ở trên
Thêm ToolTip cho các control trong 
VISUAL C++ 6.0 
Văn Chí Nam, Nguyễn Đức Hoàng Hạ 
Khoa Công nghệ Thông tin, trường ĐH KHTN TP.HCM 
vcnam@fit.hcmuns.edu.vn, ndhha@fit.hcmuns.edu.vn 
Phiên bản cập nhật ngày 15/05/2005 
Tooltip là một dòng đơn chú thích hiện ra bên cạnh control khi chuột di chuyển 
phía trên "khu vực" của đối tượng. Tooltip thường được dùng như là một ghi chú hướng 
dẫn người sử dụng chức năng của đối tượng đang hướng đến. 
MFC hỗ trợ một lớp để thực hiện công việc này. Đó là lớp CToolTipCtrl. 
GIỚI THIỆU VỀ CTOOLTIPCTRL 
Các chức năng cuả lớp này chúng ta có thể tìm hiểu thêm ở MSDN, ở đây tôi chỉ 
ghi lại tóm tắt các hàm có thể dùng của 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. 
SetMaxTipWidth Sets the maximum width for a tool tip window. 
GetTipBkColor Retrieves the background color in a tool tip window. 
SetTipBkColor Sets the background color in a tool tip window. 
GetTipTextColor Retrieves the text color in a tool tip window. 
SetTipTextColor Sets the text color in a tool tip window. 
Activate Activates and deactivates the tool tip control. 
AddTool Registers a tool with the tool tip control. 
DelTool Removes a tool from the tool tip control. 
HitTest Tests a point to determine whether it is within the bounding rectangle of 
the given tool and, if so, retrieves information about the tool. 
RelayEvent Passes a mouse message to a tool tip control for processing. 
SetToolRect Sets a new bounding rectangle for a tool. 
UpdateTipText Sets the tool tip text for a tool. 
Update Forces the current tool to be redrawn. 
Pop Removes a displayed tool tip window from view. 
THÊM TOOLTIP CHO MỘT CONTROL 
Trong phần này, tôi chỉ trình bày việc thêm tooltip cho đối tượng trên dialog 
(dialog - based) bởi vì việc thêm tooltip cho các đối tượng trong chế độ Document - View 
có thể được thực hiện thông qua String Resource. 
Các bước thực hiện : 
- Bước 1 : Thêm vào trong lớp của Dialog (C…Dlg) một con trỏ kiểu 
CToolTipCtrl : 
CToolTipCtrl* m_pToolTip; 
- Bước 2: Trong hàm OnInitDialog(), thêm vào các dòng lệnh sau : 
m_pToolTip = new CToolTipCtrl; 
//Khai báo con trỏ kiểu CWnd để dùng trong việc thêm tooltip cho đối tượng 
CWnd* pWnd; 
//cấp bộ nhớ thành công 
if (m_pToolTip) 
 { 
 //Khởi tạo con trỏ Tooltip 
 if (!m_pToolTip->Create(this)) 
 { 
 MessageBox("Khong the tao ToolTip"); 
 OnOK(); 
 } 
/* 
Nếu muốn thêm tooltip cho đối tượng IDOK thìlấy con trỏ pWnd từ IDOK 
*/ 
 pWnd = GetDlgItem(IDOK); 
 CRect rect; 
 //Lấy hình chữ nhật bao quanh IDOK 
 pWnd->GetClientRect(rect); 
 /*Thêm vào đối tượng tooltip một tool mới*/ 
 /* Tham số thứ nhất : con trỏ chỉ đến đối tượng cần thêm tooltip 
 Tham số thứ hai : Chuỗi thể hiện trong tooltip 
 Tham số thứ ba : Hình chữ nhật bao quanh tooltip 
 Tham số thứ tư : Số hiệu cuả tool trong tooltip control (IDTool) 
 */ 
 m_pToolTip->AddTool(pWnd,"Bam vao day de 
thoat",rect,1); 
 } 
- Bước 3 : Thêm vào lớp CTamDlg hàm PreTranslateMessage, hàm này có tác 
dụng xử lý thông điệp trước khi gửi đến cửa sổ. Thông điệp phải được đưa đến cho tooltip 
control trước. Dùng hàm RelayEvent cuả CToolTipCtrl để làm công việc xử lý thông điệp 
cho tooltip. 
BOOL CToolTipDlg::PreTranslateMessage(MSG* pMsg) 
{ 
 if (m_pToolTip!=NULL) 
 { 
 m_pToolTip->RelayEvent(pMsg); 
 } 
 return CDialog::PreTranslateMessage(pMsg); 
} 
Hình ảnh minh họa khi chạy đoạn chương trình trên 

File đính kèm:

  • pdfHướng dẫn thực hành Lập trình C trên Windows - Thêm Tooltip cho các Control trong Visual C++ 6.0.pdf
Tài liệu liên quan