delphi - 显示另一个窗口时,控件的 OnExit 会占用新控件的 mouseup 事件

标签 delphi delphi-7

我在Experts-Exchange上发现了这个问题.

Control's OnExit eats up mouseup event for new control when showing another window

The problem can be replicated easily.

place 3 tedits on a form. write a showmessage('exit') in edit1's onexit event run the program give edit1 focus use the mouse to give edit3 focus, click ok to the showmessage observe how you can't write anything in edit3 now, until you click with the mouse somewhere on the form ! give edit2 focus, then use to the mouse to give edit3 focus observe how you can type what you want in edit3 now !

So far I've established that the problem lies in the fact that edit3 doesn't receive a mouseup-message when the old controls onExit event displays a window of any kind, i've tried it as well with showing a form of my own in the onExit event, same result. In fact, windows is under the impression that the mouse is held down over edit3 after you've clicked Ok to the showmessage

I guess it's a bug in Delphi/Windows but how to work around it ? I know i can force a WM_LBUTTONUP on edit3's onMouseDown event (since its the last event called in the process) but that's more than tedious, and not always applicable

我正在尝试做类似的事情:

在 onexit 事件中,我显示一个警告框,然后想要继续 像往常一样 - 将焦点移动到用户实际单击的位置。 这可能吗?

最佳答案

PostMessage 再次来救援!将对话框延迟一段时间,以便 Windows 完成焦点更改。给自己发一条消息,而不是直接显示对话框:

const
  WM_SHOWMYDIALOG = WM_APP + 321;

TForm1 = class(TForm)
  Edit1: TEdit;
  Edit2: TEdit;
  procedure Edit1Exit(Sender: TObject);
private
  procedure WMSHOWMYDIALOG(var Message: TMessage); message WM_SHOWMYDIALOG;
end;

procedure TForm1.Edit1Exit(Sender: TObject);
begin
  PostMessage(Self.Handle, WM_SHOWMYDIALOG, 0, 0);
end;

procedure TForm1.WMSHOWMYDIALOG(var Message: TMessage);
begin
  ShowMessage('Nice one');
end;

一切都很好:)

关于delphi - 显示另一个窗口时,控件的 OnExit 会占用新控件的 mouseup 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7079960/

相关文章:

mysql - Delphi Firemonkey XE8 - 如何使用 DataSnap 正确发送/接收图像

delphi - 我可以将 map2dbg 与 64 位 Delphi 可执行文件一起使用吗?

delphi - 将 Delphi 7 属性编辑器转换为 Delphi XE2

delphi - 使用 WinAPI 将击键发送到另一个应用程序

delphi - 错误 'Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another'

delphi - 将 TPopupMenu 与窗体的右侧对齐?

delphi - 在 Delphi 中如何找出哪个过程引发了异常?

delphi - 将两个字节合并为 WideChar

delphi - 在Delphi 7中制作Windows集成窗体样式

windows - ImageList_Add 在由 pcAnywhere 控制的 PC 上返回 -1