Author: Zhu Jincan
Source: http://www.cnblogs.com/clever101
Generally, toolbar buttons are generated through configuration, and the button prompts can also be saved in the configuration file. However, there is not much information on how to dynamically add this prompt. The Microsoft official website provides an article on how to display the tooltip.Article:
How to call laterEnabletooltipsDisplay tooltip
I have tried it.ProgramAdd a prompt dynamically on the toolbar. I noticed that the derived class of cformview is used in this article. Using this class actually requires a dialog box resource. In fact, I guess this method is more suitable for adding a prompt to the control in the dialog box. What I want to achieve now is to dynamically Add a prompt to the toolbar of the single-document program.
One effective method I found is to reloadWindowprocFunction, and then process the corresponding message. Specifically
1.Add the lresult function to the cmainframe class Windowproc(Uint Message,Wparam Wparam,Lparam Lparam);
2.Add the following to the CPP file:Code:
Lresult cmainframe: windowproc (uint message, wparam, lparam)
{
// Todo: Add dedicated code and/or call the base class here
Switch (Message)
{
Case Wm_notify:
Switch (Lpnmhdr) lparam) -> Code)
{
Case Ttn_getdispinfo:
{
Lptooltiptext lpttt;
Lpttt = (Lptooltiptext) lparam;
Lpttt -> Hinst = AfxGetInstanceHandle ();
Int ID = Lpttt -> HDR. idfrom;
Switch (ID) // The ID here is the ID of the toolbar button
{
Case Sys_command_begin:
Lpttt -> Lpsztext = Text ( " Add button " );
Break ;
Case Sys_command_begin + 1 :
Lpttt -> Lpsztext = Text ( " Tag button " );
Break ;
Case Sys_command_begin + 2 :
Lpttt -> Lpsztext = Text ( " Comment button " );
Break ;
Case Sys_command_begin + 3 :
Lpttt -> Lpsztext = Text ( " Conversion button " );
Break ;
Case Sys_command_begin + 4 :
Lpttt -> Lpsztext = Text ( " Delete button " );
Break ;
Case Sys_command_begin + 5 :
Lpttt -> Lpsztext = Text ( " Exit button " );
Break ;
Default :
Break ;
}
}
Default :
Break ;
}
Break ;
Default :
Break ;
}
Return Cframewnd: windowproc (message, wparam, lparam );
}