#region ToolTip Hook
private static bool _dropNextHelpCall; // Flag to tell if the next message from AutoCAD to display it's own help should be ignored
private static string _currentTooltip; // If not null, this is the HelpTopic of the currently open tooltip. If null, no tooltip is displaying.
//// ReSharper disable InconsistentNaming
#pragma warning disable 1591
public enum WndMsg
{
WM_ACAD_HELP = 0x4D,
WM_KEYDOWN = 0x100,
}
public enum WndKey
{
VK_F1 = 0x70,
}
#pragma warning restore 1591
//// ReSharper restore InconsistentNaming
private void AutoCadMessageHandler(object sender, PreTranslateMessageEventArgs e)
{
if (e.Message.message == (int)WndMsg.WM_KEYDOWN)
{
if ((int)e.Message.wParam == (int)WndKey.VK_F1)
{
// F1 pressed
if (_currentTooltip != null && _currentTooltip.Length > 8 && _currentTooltip.StartsWith("https://modplus.org/"))
{
// Another implementation could be to look up the help topic in an index file matching it to URLs.
_dropNextHelpCall = true; // Even though we don't forward this F1 keypress, AutoCAD sends a message to itself to open the AutoCAD help file
object nomutt = AcApp.GetSystemVariable("NOMUTT");
string cmd = $"._BROWSER {_currentTooltip} _NOMUTT {nomutt} ";
AcApp.SetSystemVariable("NOMUTT", 1);
AcApp.DocumentManager.MdiActiveDocument.SendStringToExecute(cmd, true, false, false);
e.Handled = true;
}
}
}
else if (e.Message.message == (int)WndMsg.WM_ACAD_HELP && _dropNextHelpCall)
{
// Seems this is the message AutoCAD generates itself to open the help file. Drop this if help was called from a ribbon tooltip.
_dropNextHelpCall = false; // Reset state of help calls
e.Handled = true; // Stop this message from being passed on to AutoCAD
}
}
// AutoCAD event handlers to detect if a tooltip is open or not
private static void ComponentManager_ToolTipOpened(object sender, EventArgs e)
{
Autodesk.Internal.Windows.ToolTip tt = sender as Autodesk.Internal.Windows.ToolTip;
if (tt == null)
return;
Autodesk.Windows.RibbonToolTip rtt = tt.Content as Autodesk.Windows.RibbonToolTip;
if (rtt == null)
_currentTooltip = tt.HelpTopic;
else
_currentTooltip = rtt.HelpTopic;
}
private static void ComponentManager_ToolTipClosed(object sender, EventArgs e)
{
_currentTooltip = null;
}
#endregion