question

mohamadfraihat-2670 avatar image
0 Votes"
mohamadfraihat-2670 asked SongZhu-MSFT commented

How to get url of hyperlink in outlook 2019 when open the hyperlink. Using setwindowshookEx with WH_CALLWNDPROCRET OR WH_CALLWNDPROC

The below is part of the code in callback of WH_CALLWNDPROCRET OR WH_CALLWNDPROC as per my under standing about RichEdit control but I never catch the WM_NOTIFY, but EM_GETTEXTEX it is work fine and return the mail subject (caption of RichEdit). thes RichEdit class name is RichEdit20WPT.

 if (cwprStruct->message == WM_NOTIFY)
     {
         writetofile("WM_NOTIFY RetProc:", f1);
         switch (((LPNMHDR)cwprStruct->lParam)->code)
         {
         case EN_LINK:
             writetofile("EN_LINK:", f1);
             break;
         case NM_CLICK:
             writetofile("NM_CLICK:", f1);
             break;
         case NM_RETURN:
             writetofile("NM_RETURN:", f1);
             break;
         case NM_RCLICK:
             writetofile("NM_RCLICK:", f1);
             break;
         case NM_SETFOCUS:
             writetofile("NM_SETFOCUS:", f1);
             break;
         }
         writetofile(to_string(((LPNMHDR)cwprStruct-lParam)->code), f1);
     }
     if (cwprStruct->message == EM_GETTEXTEX)
     {
         isURL = true;
         writetofile("EM_GETTEXTEX:", f1);
         number = GetClassName(cwprStruct->hwnd, clsName_v, 256);
         writetofile(clsName_v, number, f1);// return RichEdit20WPT
    
         writetofile("Subject:", f1);
         if (cwprStruct->lParam)
         {
             size_t   i;
             char* subject = (char*)malloc(BUFFER_SIZE);
             wcstombs_s(&i, subject, (size_t)BUFFER_SIZE, (LPWSTR)cwprStruct->lParam, (size_t)BUFFER_SIZE);
             writetofile(subject, i - 1, f1);
         }
     }


windows-apic++
· 8
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


Did you take into account that EM_GETTEXTEX is sent to control, while WM_NOTIFY is sent to its parent?

0 Votes 0 ·

Actually, I am not getting the WM_NOTIFY when I click on the hyperlink. In addition, I am receiving EM_GETTEXTEX which returns the caption in (cwprStruct->lParam).
Do u have any suggestion which massage name should I capture to get the URL from the hyperlink.

0 Votes 0 ·
Viorel-1 avatar image Viorel-1 mohamadfraihat-2670 ·

Use “Microsoft Spy++” (included in Visual Studio) and “Inspect” (from Windows Kits) to analyse the windows and the messages that are sent to controls and parents.

Maybe also consider some other approaches, like Add-ins for Outlook.

0 Votes 0 ·
Show more comments

Outlook does not always use the standard windows controls. You can see this from the class name RichEdit20WPT. You are assuming that these controls behave identically to the documented standard controls and in my experience this is not always the case.

I suggest you test your code by hooking an application window (such as the one used by Wordpad) that hosts a standard rich edit control. In my own quick and dirty test using Wordpad the parent window of the rich edit control did receive WM_NOTIFY messages for EN_LINK when the mouse moved over a hyperlink.

If your code is successful with Wordpad that would confirm that the control used by Outlook does use non-standard behaviors.

0 Votes 0 ·

0 Answers