2

我正在用 Win32 编写一个许可协议对话框,我很困惑。像往常一样,我希望在 Richedit 控件的滚动条的滑块到达底部时启用“接受/不接受”按钮,但我找不到获得该事件通知的方法。我最早能够了解它是当用户释放鼠标左键时。

有没有办法做到这一点?

这是我到目前为止所尝试的:

  • WM_VSCROLLWM_LBUTTONUP在 Richedit 的 wndproc 中
  • EN_MSGFILTERdlgproc 中的通知(是的,正在设置过滤器掩码)
  • WM_VSCROLLWM_LBUTTONUP在 dlgproc 中。
  • EN_VSCROLLdlgproc 中的通知

我非常绝望,我尝试进行轮询,但这也不起作用,因为当鼠标按钮在滑块上按下时,定时器消息显然停止到达。我都试过了:

  • dlgproc 中的计时器回调(轮询)
  • Richedit 的 wndproc 中的计时器回调(轮询)
4

4 回答 4

1

您需要对编辑框进行子类化并将消息截获到编辑框本身。这是 MSDN 上关于子类化控件的文章

编辑:一些代码来演示启用按钮的滚动条:

#include <windows.h>
#include <richedit.h>

LRESULT __stdcall RichEditSubclass
(
  HWND window,
  UINT message,
  WPARAM w_param,
  LPARAM l_param
)
{
  HWND
    parent = reinterpret_cast <HWND> (GetWindowLong (window, GWL_HWNDPARENT));

  WNDPROC
    proc = reinterpret_cast <WNDPROC> (GetWindowLong (parent, GWL_USERDATA));

  switch (message)
  {
  case WM_VSCROLL:
    {
      SCROLLINFO
        scroll_info = 
        {
          sizeof scroll_info,
          SIF_ALL
        };

      GetScrollInfo (window, SB_VERT, &scroll_info);

      if (scroll_info.nPos + static_cast <int> (scroll_info.nPage) >= scroll_info.nMax ||
          scroll_info.nTrackPos + static_cast <int> (scroll_info.nPage) >= scroll_info.nMax)
      {
        HWND
          button = reinterpret_cast <HWND> (GetWindowLong (parent, 0));

        EnableWindow (button, TRUE);
      }
    }
    break;
  }

  return CallWindowProc (proc, window, message, w_param, l_param);
}

LRESULT __stdcall ApplicationWindowProc
(
  HWND window,
  UINT message,
  WPARAM w_param,
  LPARAM l_param
)
{
  bool
    use_default_proc = false;

  LRESULT
    result = 0;

  switch (message)
  {
  case WM_CREATE:
    {
      CREATESTRUCT
        *creation_data = reinterpret_cast <CREATESTRUCT *> (l_param);

      RECT
        client;

      GetClientRect (window, &client);

      HWND
        child = CreateWindow (RICHEDIT_CLASS,
                              TEXT ("The\nQuick\nBrown\nFox\nJumped\nOver\nThe\nLazy\nDog\nThe\nQuick\nBrown\nFox\nJumped\nOver\nThe\nLazy\nDog"),
                              WS_CHILD | WS_VISIBLE | ES_MULTILINE | ES_AUTOVSCROLL | WS_VSCROLL | ES_DISABLENOSCROLL,
                              0, 0, client.right, client.bottom - 30,
                              window,
                              0,
                              creation_data->hInstance,
                              0);

      SetWindowLong (window, GWL_USERDATA, GetWindowLong (child, GWL_WNDPROC));
      SetWindowLong (child, GWL_WNDPROC, reinterpret_cast <LONG> (RichEditSubclass));
      SetWindowLong (child, GWL_ID, 0);

      child = CreateWindow (TEXT ("BUTTON"), TEXT ("Go Ahead!"), WS_CHILD | WS_VISIBLE | WS_DISABLED, 0, client.bottom - 30, client.right, 30, window, 0, creation_data->hInstance, 0);

      SetWindowLong (window, 0, reinterpret_cast <LONG> (child));
      SetWindowLong (child, GWL_ID, 1);
    }
    break;

  case WM_COMMAND:
    if (HIWORD (w_param) == BN_CLICKED && LOWORD (w_param) == 1)
    {
      DestroyWindow (window);
    }
    break;

  default:
    use_default_proc = true;
    break;
  }

  return use_default_proc ? DefWindowProc (window, message, w_param, l_param) : result;
}

int __stdcall WinMain
(
  HINSTANCE instance,
  HINSTANCE unused,
  LPSTR command_line,
  int show
)
{
  LoadLibrary (TEXT ("riched20.dll"));

  WNDCLASS
    window_class = 
    {
      0,
      ApplicationWindowProc,
      0,
      4,
      instance,
      0,
      LoadCursor (0, IDC_ARROW),
      reinterpret_cast <HBRUSH> (COLOR_BACKGROUND + 1),
      0,
      TEXT ("ApplicationWindowClass")
    };

  RegisterClass (&window_class);

  HWND
    window = CreateWindow (TEXT ("ApplicationWindowClass"),
                           TEXT ("Application"),
                           WS_VISIBLE | WS_OVERLAPPED | WS_SYSMENU,
                           CW_USEDEFAULT,
                           CW_USEDEFAULT,
                           400, 300, 0, 0,
                           instance,
                           0);

  MSG
    message;

  int
    success;

  while (success = GetMessage (&message, window, 0, 0))
  { 
    if (success == -1)
    {
      break;
    }
    else
    {
      TranslateMessage (&message);
      DispatchMessage (&message);
    }
  }

  return 0;
}

以上不处理用户在编辑框中移动光标。

于 2008-10-27T13:47:49.310 回答
0

我建议启动Spy++并查看哪些 Windows 消息被发送到何处。

http://msdn.microsoft.com/en-us/library/aa264396(VS.60).aspx

于 2008-10-27T23:04:43.447 回答
0

Why not use the EM_GETTHUMB message. (Assuming Rich Edit 2.0 or later).

If you are lucky this bottom position will match EM_GETLINECOUNT.

于 2008-10-28T02:32:09.097 回答
-2

即使有可能,我认为您不应该那样做 - 用户将不知道为什么按钮被禁用。这可能会非常令人困惑,应该不惜一切代价避免让用户感到困惑;-)

这就是为什么大多数许可证对话框都有接受/拒绝单选按钮,默认启用拒绝,因此您必须主动启用接受。

于 2008-10-27T13:49:05.143 回答