1
votes

I created a MFC ActiveX Control, and within it I created a child dialog that will be used in the .NET environment. Within the dialog, I have a button and I put a tooltip when you hover your mouse, it should display the tooltip. For some reason, when I am using the dialog in the .NET environment, it won't work.

I created an MFC Dialog Application and performed the same thing and it works fine, but not through ActiveX when it is put in the C# .NET environment.

This is my code:

MainDialog.h

CToolTipCtrl m_tooltip;






MainDialog.cpp

CButton *PlayButton = (CButton*)GetDlgItem(IDC_PLAY_BUTTON);

m_tooltip.Create(this);
m_tooltip.AddTool(PlayButton, L"Play");
m_tooltip.Activate(TRUE);

BOOL OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult)
 {
  MSG msg;
  msg.wParam = wParam;
  msg.lParam = lParam;
  msg.message = message;
  msg.hwnd = m_hWnd;
  GetCursorPos(&msg.pt);

  // Tooltips notification.
  FilterToolTipMessage(&msg);

  return CWnd::OnWndMsg(message, wParam, lParam, pResult);
 } 

I first used PreTranslateMessage but I read on http://forum.codejock.com/forum_posts.asp?TID=1361&title=task-panel-tooltips-in-activex-control

here that it doesn't work with MFC but this code displayed above does but it doesn't work for me.

Any help is appreciated!

1

1 Answers

0
votes

I don't know if this is exactly what you are needing. In my MFC dialogs where I want tooltips, I first add this to my header:

using ToolTipMap = std::map<UINT, UINT>;

Then, I add this function (which is called in OnInitDialog):

void COptionsDlg::InitToolTips()
{
    int         i = 0;
    CString     strText = _T("");
    ToolTipMap  mapToolTips;

    mapToolTips.emplace(IDC_COMBO_WATCHTOWER_DAY, IDS_COMBO_WATCHTOWER_DAY);
    mapToolTips.emplace(IDC_COMBO_SCHOOL_DAY, IDS_COMBO_SCHOOL_DAY);
    mapToolTips.emplace(IDC_EDIT_DATE_FORMAT, IDS_EDIT_DATE_FORMAT);
    mapToolTips.emplace(IDC_CHECK_USE_CUSTOM_DATE, IDS_CHECK_USE_CUSTOM_DATE);
    mapToolTips.emplace(IDC_CHECK_PLATFORM, IDS_CHECK_PLATFORM);
    mapToolTips.emplace(IDC_CHECK_PLATFORM_MIKE, IDS_CHECK_PLATFORM_MIKE);
    mapToolTips.emplace(IDC_COMBO_NUM_MIKE_USERS, IDS_COMBO_NUM_MIKE_USERS);
    mapToolTips.emplace(IDC_COMBO_NUM_SOUND_USERS, IDS_COMBO_NUM_SOUND_USERS);
    mapToolTips.emplace(IDC_COMBO_NUM_ATTEND, IDS_COMBO_NUM_ATTEND);
    mapToolTips.emplace(IDC_BUTTON_HELP, IDS_BUTTON_HELP);
    mapToolTips.emplace(IDC_COMBO_REPORT_MODE, IDS_COMBO_REPORT_MODE);
    mapToolTips.emplace(IDC_COMBO_WEEKLY_DAY, IDS_COMBO_WEEKLY_DAY);

    for (auto& kv : mapToolTips) 
    {
        strText.LoadString(kv.second);

        m_tooltip[i].Create(this, TTS_BALLOON);
        m_tooltip[i].Activate(DisplayToolTips());
        m_tooltip[i].AddTool(GetDlgItem(kv.first), strText);

        i++;
    }
}

The above function creates a tooltip control for each element where I need a tooltip to show and associates it with a STRINGTABLE entry.

Finally, I have the PreTranslateMessage you referred to, but I do it like this:

BOOL COptionsDlg::PreTranslateMessage(MSG* pMsg)
{
    for(int i = 0; i < NUM_OPTION_TOOLTIPS; i++ )
            m_tooltip[i].RelayEvent(pMsg);

    return CDialog::PreTranslateMessage(pMsg);  // CG: This was added by the ToolTips component.
}

Way back in Visual C++ 6 there used to be a component gallery and you could insert tooltip support to any dialog class. Those were the days!

I don't know if the above fits within your context of an MFC ActiveX Control though.