-
Jan 17th, 2022, 02:55 PM
#1
[RESOLVED] Tooltips on Popup Menus
I've been down this "dead end" road at least once before, maybe twice.
I just finished writing a nice subclassing procedure that tells me when a popup menu's item goes "hot" and when it's no longer "hot". (Hot = mouse is hovering over popup menu's item).
And then, I tried to put a ToolTip balloon onto that popup menu's item. But, no matter what I do, the ToolTip won't come up. I use this exact same ToolTip procedure in many other places and it works just fine. Here's a line out of the ToolTip procedure:
Code:
hWndTT = CreateWindowExW(WS_EX_TOOLWINDOW Or WS_EX_TOPMOST, StrPtr(TOOLTIPS_CLASS), 0&, lWinStyle, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0&, 0&, App.hInstance, 0&)
Here's my theory. Both a Popup menu and a Tooltip balloon are both sort of special things. When the user clicks off of them (another application or not), they self-destroy. So, I'm thinking that Windows allows only one of these things at a time. Therefore, the fact that my Popup menu is already up, that's freezing out the Tooltip balloon.
I've Googled and can't find any documentation for this theory, but I can't think of another explanation.
Anybody have any confirmation of this, or maybe an idea of something else I might try?
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Jan 17th, 2022, 03:01 PM
#2
Re: Tooltips on Popup Menus
You know? I have managed to get ToolTips on the pulldown items of a ComboBox. And that's also two self-destroying windows on top of each other.
Hmm, so, I'm gonna keep working on this thing a bit longer.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Jan 17th, 2022, 03:24 PM
#3
Re: Tooltips on Popup Menus
-
Jan 17th, 2022, 03:31 PM
#4
Re: Tooltips on Popup Menus
Ok, I've figured out what I'm doing wrong. I used hMenu for the hWnd. So, I need to turn hMenu into hWnd, and then try it.
I've found GetMenu, but I don't see an inverse function for this. And I'm not exactly sure that's the answer anyway. I've tried the hWnd of the form with the menus, and also the hWnd of the form which calls PopupMenu (which isn't the same form). But neither of those works. I need the hWnd of the actual window that's got the menu items on it, and I'm just not sure if that's hMenu or not.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Jan 17th, 2022, 03:53 PM
#5
Re: Tooltips on Popup Menus
Ok, I haven't figured out what I'm doing wrong. I can't find anything to "convert" a hMenu into a hWnd, other than to get the window to which the menu is attached. And, since these are PopupMenu menus, I guess they're attached to the form that called them. In fact, I explicitly placed a Me.PopupMenu on them. But, Me.hWnd still doesn't work for the ToolTip.
Grrr.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Jan 17th, 2022, 04:29 PM
#6
Re: Tooltips on Popup Menus
Crud, I found the following...
Code:
Dim hPopupHWnd As Long
hPopupHWnd = FindWindow("#32768", 0)
...and then used that hPopupHWnd in my TOOLINFO structure, but still no go.
Just as an FYI, here's the TOOLINFO structure I'm using:
Code:
Private Type TOOLINFO
lSize As Long
lFlags As Long
hWnd As Long
lId As Long
'
'lpRect As RECT
Left As Long
Top As Long
Right As Long ' This is +1 (right - left = width)
Bottom As Long ' This is +1 (bottom - top = height)
'
hInstance As Long
lpStr As String
lParam As Long
End Type
Whatever hWnd I pass in, I plug it into both .hWnd and .lId. In fact, here's all my TOOLINFO setup:
Code:
' Setup our tooltip info structure.
ti.lFlags = TTF_SUBCLASS Or TTF_IDISHWND
If bCentered Then ti.lFlags = ti.lFlags Or TTF_CENTERTIP
' Set the hwnd prop to our parent control's hwnd.
ti.hWnd = ParentHwnd
ti.lId = ParentHwnd
ti.hInstance = App.hInstance
ti.lpStr = TipText
ti.lSize = LenB(ti)
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Jan 17th, 2022, 07:19 PM
#7
Re: Tooltips on Popup Menus
I don't know...
I've tried all combinations of "#32768" class, the form that called PopupMenu, and the form that defines the menus ... as the parent for the ToolTip.
I've tried sending a TTM_ACTIVATE message.
I've tried using GWL_STYLE and WS_VISIBLE, forcing it to be visible, and it actually reports as visible.
I've tried all combinations of TTF_SUBCLASS, TTF_TRACK, & TTF_TRANSPARENT ... always specifying TTF_IDISHWND.
IDK, occasionally I break it for regular operations, but I've never once gotten it to work on a PopupMenu.
It's definitely calling my CreateToolTip procedure because I've got all kinds of Debug.Print statements in it, and that's where I'm doing all the testing.
I'm sure it's something trivial I'm missing, but I can't figure it out.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Jan 17th, 2022, 07:32 PM
#8
Re: Tooltips on Popup Menus
I'm starting to think I was correct to begin with. Both ToolTips and Popups us that #32768 class. I'm thinking that Windows only allows one of those at any one time.
But that gives me an idea. I'll just develop my own Popup form that looks like a context menu. That way, I know I can get tooltips on the items.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Jan 18th, 2022, 12:30 AM
#9
Re: Tooltips on Popup Menus
You can position the tooltip by x,y right?
You just need to get the selected menu item, then use GetMenuItemRect.
One of the examples jdc2000 linked did it that way:
Code:
void SetToolTipPosition(HMENU hMenu, UINT nItemID)
49 {
50 RECT rt = {0,0,0,0};
51
52 // find Item Rectangle and position
53 for(int nItem = 0; nItem < ::GetMenuItemCount(hMenu); nItem++) {
54 UINT cmd = ::GetMenuItemID(hMenu, nItem);
55 if(cmd == nItemID) {
56 ::GetMenuItemRect(m_hParent, hMenu, nItem, &rt);
57 }
58 }
59
60
61 // move position
62 ::SendMessage(m_hToolTip, TTM_TRACKPOSITION, 0,
63 (LPARAM)MAKELPARAM(rt.right + 10, rt.top + 2));
64 // make it top most
65 ::SetWindowPos(m_hToolTip, HWND_TOPMOST ,0,0,0,0, SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOMOVE);
Those GetMenu___s are all APIs you can call from VB.
-
Jan 22nd, 2022, 12:32 PM
#10
Re: Tooltips on Popup Menus
I rolled my own, found here. I'm calling this one resolved.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|