English 中文(简体)
如何用 NM_CLICK 控制 Syslink 控制处理 NM_CLICK
原标题:How to handle NM_CLICK for Syslink control

做了相当多的研究, 试图找出如何让它正常运转。 我读到, 如果您过滤 WM_ NOTIFY - & gt; NM_ CLICK, 它将会抓住连接系统的实际点击事件 。 麻烦在于它会抓住事件, 尽管它会陷入无休止的循环中, 几秒钟后你就会看到 数百 个浏览器窗口或者链接打开了 。

Steps 采取了 :

  1. Create Syslink on dialog
  2. Add title to Syslink control link and change IDD to IDC_LINK1
  3. NM_CLICK 事件过滤器 WM_NOTIFY

       case WM_NOTIFY:
      //case NM_CLICK:
      switch(LOWORD(wParam))
      {
          case NM_CLICK:
             switch(LOWORD(wParam))
         {
                 case IDC_LINK1:
                     // Standard ShellExecute with added check for IsLinkCtrl to make sure its the right kind of control.
                     OpenLink(hWndDlg, LOWORD(wParam));            
             break;
         }
         break;
      }
      break;
    

我想,我真正的问题是,我如何正确做到这一点?我看不到任何好的例子来说明Syslink是如何被正确过滤的,以将链接作为URL执行的。

最佳回答

我找到了一个成功的方法来让它工作而不进入循环。 信息循环似乎不断在循环中读取, 如果您不使用正确的结构过滤, 它会掉入无限的循环中。 这对我有效。 如果您有更好的输入, 请使用所有手段来做添加 。

正确的步骤。

  1. Create WM_NOTIFY Message filter event.
  2. Create Switch statement using NMHDR to parse the code for NM_CLICK.
  3. Check wParam to identify correct control being clicked.
  4. Execute link with ShellExecute.

使用了以下代码。

       case WM_NOTIFY:
           //NMHDR* pHeader = (NMHDR*)lParam;
           //NMLINK* pNMLink = (NMLINK*)lParam;
           //LITEM iItem = pNMLink->item;
           switch(((NMHDR *)lParam)->code)
           {
               case NM_CLICK:
               { // Included to avoid "case" skip statements.
                   times++;

                   NMLINK* pNMLink = (NMLINK*)lParam;
                   LITEM iItem = pNMLink->item;
                   // Custom OutputDebugString
                   winapi::Output("NM_CLICK: Fired %d time%s!
", times, (times <= 1) ? L"" : L"s");
#ifdef DEBUG
                   assert(iItem.szID);
                   MessageBox(NULL, (LPCWSTR)lParam, L"Assert", MB_OK|MB_ICONINFORMATION);
#endif
                   if(wParam == IDC_LINK1)
                   {
                       winapi::Output("Success!");
                       OpenLink(hWndDlg, LOWORD(wParam));
                   }

note :如果依赖包含 HTML 属性( link 或这里) 的链接喂养 Shellexecuceut URL 路径, 请使用 NMLINK 结构 。

问题回答

Just to clarify, I do not think you are using managed C++, there for I am not sure why you are referring to a NM_CLICK notificaton code as an event. Besides, you do not have to catch anything, you are not handling any exceptions, you are just handling a WM_NOTIFY message.

Anyway, I am not sure why you experience this particular behavior since I do not see what you do outside of the code snippet but I know what is causing it. In our code snippet you use wParam to determine a notification code and this is incorrect. This control does not use wParam. To determine notification code you should do the following:

    NMHDR* pHeader = (NMHDR*)lParam;

    switch (pHeader->code)

< 加固 > p Header- & gt; code 持有您应该使用的通知代码值, 而 < 坚固 > pheader- gt; hwndFrom 是被单击的控件的控件控件 。

Furthermore, you using LOWORD(wParam) again and pass it as the parameter to function call. You are not showing what you do in this function but I can conclude that the code is also not correct. The same lParam is a pointer to the NMLINK structure. First member of this structure is mentioned above NMHDR, the next member is LITEM structure that should be used to determine what the URL is.

    NMLINK* pNMLink = (NMLINK*)lParam;
    LITEM iItem = pNMLink->item;

item.szUrl 是您在呼叫 ShellExercute 调用时应该使用的 URL 。

两者中

  1. 您的 OpenLink 函数导致另一个消息( 最有可能) 发送, 或

  2. 这不是唯一一个调用 OpenLink 的代码,

  3. 您不是来自 WM_NOTIFY ,而是来自上述案件的倒转,或者

  4. 您虽然已经处理过,但还是为信件拨打 DefWindowProc

尝试

  break; // make sure there s no fall-through here
  case NM_CLICK:
     switch(LOWORD(wParam))
     {
         case IDC_LINK1:
             // Standard ShellExecute with added check for IsLinkCtrl to make sure its the right kind of control.
             OpenLink(hWndDlg, LOWORD(wParam));            
             return TRUE; // handled, don t pass to DefWindowProc
     }
     break;




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签