After Mr. TLama have answered my last question (How to trap the TTN_LINKCLICK notification?) one point went unanswered because it was not asked :)
How to identify each link I clicked on the balloon, if there are more than one link?
I want to be able to include more than one link in the balloon and to respond to clicks differently.
The notification has no parameters, so you don't know which link was clicked. The moral: If you need more than one link, consider a more versatile interface than a tool tip, such as a toast notification or a dialog box.
Finally I managed to solve this problem and YES, it is possible to get information from the link that was clicked in the ToolTip!
There really isn't any official documentation talking about it, which is a big mistake by Microsoft. I believe that anyone who works with Windows from the beginning already knew the answer, however either these people are dead or they simply have more important problems than helping people solve this type of problem which YES, it's ridiculously simple to solve. Let's explain...
The help regarding the WM_NOTIFY message says the following about its lParam parameter:
A pointer to an NMHDR structure that contains the notification code and additional information. For some notification messages, this parameter points to a larger structure that has the NMHDR structure as its first member.
The most important part of the text above is that some notification messages point to larger structures whose first member is an NMHDR. Reading this I thought "Hmm, is there any message for clicked links in general context?" So I googled for "wm_notify link click" and the first result came up with the answer: NM_CLICK
NM_CLICK is a notification message, sent via WM_NOTIFY to a control's parent window when the user clicks a link with the left mouse button. The link referred to here is a SysLink Control, for which there is extensive documentation on MSDN. It makes perfect sense that when using the TTF_PARSELINKS flag, the text inside the ToolTip that is a link is converted into a SysLink Control.
Also on the NM_CLICK documentation page, the NMLINK structure is mentioned, which contains additional information about the notification. When looking at the documentation about NMLINK I realized that its first member is an NMHDR and its second member is a LITEM, a structure that contains information about the link.
It is clear from now on that what the WM_NOTIFY message carries when it comes to a TTN_LINKCLICK, is actually an NMLINK structure, which contains the default first member (NMHDR) and the second member which contains everything we need to know about the clicked link. (LITEM).
Now, with this information, it is super easy to get information from the link that was clicked. The example below contains only Pascal (Delphi) pseudocode and is a method that handles WM_NOTIFY messages in the window that was informed in the hwnd member of TOOLINFO
procedure TFormPrincipal.HandleNotifyMessages(var AMessage: TWMNotify);
var
Link: TNMLink;
begin
if Assigned(AMessage.NMHdr) and (AMessage.NMHdr.code = TTN_LINKCLICK) then
begin
Link := PNMLink(AMessage.NMHdr)^;
Application.MessageBox(PChar('O link clicado tem href="' + Link.item.szUrl + '" e id="' + Link.item.szID + '"'),'Sou foda!',MB_ICONINFORMATION);
end;
end;
The final result follows:
When clicking on one of the links the message is displayed
The text included in the ToolTip was as follows:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus tincidunt
accumsan ex, et congue sem aliquam eget. Mauris ut arcu condimentum, tristique
mauris quis, consequat urna. Morbi id molestie erat. Sed egestas est elit. In a
faucibus lorem. Nam laoreet tincidunt risus ac tincidunt. Vivamus condimentum ex
id nulla porttitor. Isso é um link: <a href="xyz">oi oi oi</a> e isso é <a
href="soufoda">outro link</a>. Este é mais <a href="http://www.example.com"
id="iddestelink">um link</a> e outro <a href="x" id="idolink">link</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With