0

I need to delete tooltip window created for controls that will be deleted while the main window stays around. I came up with what is below, but it doesn't find any TOOLTIPS_CLASS windows. Any reason why?

TIA!!

  for (HWND hwndtip=NULL; (hwndtip=FindWindowEx(hwnd, hwndtip, TOOLTIPS_CLASS, NULL))!=NULL;) {
    // check if it has the control id we want
    TOOLINFO toolinfo ={ 0 };
    toolinfo.cbSize = sizeof(toolinfo);
    toolinfo.hwnd = hwnd;
    toolinfo.uFlags = TTF_IDISHWND;
    toolinfo.uId = (UINT_PTR)hwndctl;
    if (SendMessage(hwndtip, TTM_GETTOOLINFO, 0, (LPARAM)&toolinfo)) {
      // found tooltip to delete
      DestroyWindow(hwndtip);
      result=TRUE;
      break;
    }
  }
user3161924
  • 1,849
  • 18
  • 33
  • Tooltip windows are usually (always?) children of the desktop, so that they can float over other windows. – Jonathan Potter Jul 03 '19 at 07:32
  • Yes, Tooltips are always children of the Desktop and can be found with _EnumThreadWindows_ – Castorix Jul 03 '19 at 08:49
  • `FindWindowEx(NULL, NULL, TOOLTIPS_CLASS, NULL);` – Drake Wu Jul 03 '19 at 09:14
  • That's interesting since when I create the tooltip window the parent window is set as the dialog/window that owns the control. But okay, I'll search all from desktop. Thanks. – user3161924 Jul 03 '19 at 16:00
  • Well, I changed the code to use NULL as the parent window and left the rest the same. That caused outlook 2010 to end abnormally and restart it self, same with mouse and keyboard center. So something is weird? I put in a (unacceptable) delay in the loop and they don't crash? – user3161924 Jul 03 '19 at 16:41
  • It's actually hit or miss. Another one that is crashing is Windows Task Manager (I have it up to watch GDI counts). The crash is happening on the `SendMessage(hwndtip, TTM_GETTOOLINFO, 0, (LPARAM)&toolinfo)`. I had one of them I sent to MS via the option to report. So I guess this is unreliable on Windows (This is Win7 Pro x64). Is there any other way to find the tool tip to delete? Anyway I can tell I own the window before sending off the TTM_GETTOOLINFO to it? – user3161924 Jul 03 '19 at 19:59
  • https://stackoverflow.com/questions/7512080/get-tooltips-text-from-c-sharp-with-pinvoke – Raymond Chen Jul 04 '19 at 03:50
  • is there any problem naming the window and using the name (provided it's unique)? I think I looked at UI Automation for Win32 at some point and it looked like it had its own manual when I just needed to do something "simple". – user3161924 Jul 04 '19 at 06:44

1 Answers1

0

Okay, I found a way that doesn't crash other things via sending the TTM_GETTOOLINFO to each tooltip window found. Basically, give your created tooltip window a name. Example, _T("MINE!!") Then to find it:

for (HWND hwndtip=NULL; (hwndtip=FindWindowEx(NULL, hwndtip, TOOLTIPS_CLASS, _T("MINE!!")))!=NULL;) {
    // check if it has the control id we want
    TOOLINFO toolinfo ={ 0 };
    toolinfo.cbSize = sizeof(toolinfo);
    toolinfo.hwnd = hwnd;
    toolinfo.uFlags = TTF_IDISHWND;
    toolinfo.uId = (UINT_PTR)hwndctl;
    if (SendMessage(hwndtip, TTM_GETTOOLINFO, 0, (LPARAM)&toolinfo)) {
      // found tooltip to delete
      DestroyWindow(hwndtip);
      result=TRUE;
      break;
    }
  }
user3161924
  • 1,849
  • 18
  • 33