简体   繁体   English

防止双击MFC-Dialog按钮

[英]Prevent double click on MFC-Dialog button

i'm developing Autocad/Bricscad-Dialogs in MFC C++. 我正在使用MFC C ++开发Autocad / Bricscad-Dialogs。 Know i detected a bigger problem. 知道我发现了一个更大的问题。 There is a dialog which sets metadata for 'special' drawing objects. 有一个对话框,用于设置“特殊”绘图对象的元数据。 I update the data of every 'special' drawing object with this dialog (in a loop). 我用这个对话框(在一个循环中)更新每个'特殊'绘图对象的数据。 So if you have ten 'special' drawing objects, the same dialog will open ten times (successively). 因此,如果您有十个“特殊”绘图对象,则相同的对话框将打开十次(连续)。 Now i have the problem that the user sometimes make a double click on the "OK"-Button. 现在我遇到的问题是用户有时会双击“OK”-Button。 But if this double click is fast enough, the "OK"-Button of the next instance of this dialog will clicked automatically. 但是如果双击足够快,则会自动单击此对话框的下一个实例的“确定” - 按钮。 I tried a lot (for example disabling the button if it was clicked) but nothing solved my problem. 我尝试了很多(例如,如果点击它就禁用按钮),但没有解决我的问题。 Maybe someone of you have a good idea. 也许你们中的某个人有个好主意。

Best regards, Simon 最好的问候,西蒙

When you open a new dialog you can flush the message queue of mouse click messages before going into your normal message loop, eg: 当您打开一个新对话框时,您可以在进入正常的消息循环之前刷新鼠标单击消息的消息队列,例如:

MSG msg;
while (PeekMessage(&msg, hWndDlg, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE));

I try to extend the answer of Jonathan Potter. 我试图扩展乔纳森波特的答案。

When you open a new dialog and OnInitDIalog is called, just remove the mouse messages from the queue and wait for 1/10 of a second. 当您打开一个新对话框并调用OnInitDIalog时,只需从队列中删除鼠标消息并等待1/10秒。

MSG msg;
DWORD dwStart = ::GetTickCount():
while (PeekMessage(&msg, hWndDlg, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE)!=0 ||
       (::GetTickCount() - dwStart) < 100))
      ;

The trick with the PeekMessage will work, the problem is that you need to run the loop as long as a "double click" will take. 使用PeekMessage的技巧可行,问题是只要“双击”就需要运行循环。 If the clicks have a distance of 1/10th of a second you need to remove all mouse clicks for this period of time. 如果点击距离为1/10秒,则需要在这段时间内删除所有鼠标点击。

And also OnInitDialog is the correct position. 并且OnInitDialog也是正确的位置。 You may extend this flush to all mouse messages WM_MOUSEFIRST/WM_MOUSELAST... to get all clicks. 您可以将此刷新扩展到所有鼠标消息WM_MOUSEFIRST / WM_MOUSELAST ...以获取所有点击。

The delay of 1/10 second when launching the next dialog isn't expensive or annoying. 启动下一个对话框时延迟1/10秒并不昂贵或烦人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM