MessageBox - return 框没有取消按钮时的值
MessageBox - return value when box has no Cancel button
根据 MessageBox 文档:
Return value
Type: int
If a message box has a Cancel button, the function returns
the IDCANCEL value if either the ESC key is pressed or the Cancel
button is selected. If the messagebox has no Cancel button, pressing
ESC has no effect.
如果我希望有一个 没有取消按钮 但我想区分 OK 和 close/ESC?
What if I wish to have a a box that has no Cancel button but I want to distinguish between OK and close/ESC?
标准对话框不提供这种行为,因为它的设计非常糟糕。作为一个原则,GUI 应该允许通过鼠标或键盘执行操作。只能通过键盘访问的隐藏操作是设计不佳的标志。
如果你真的想制作这样的对话框,你必须自己实现。但是,你不应该。显示带有确定和取消按钮的对话框。
MessageBox()
不支持您正在寻找的行为。您必须使用 SetWindowsHookEx()
或 SetWinEventHook()
直接挂钩对话框,以检测它是否已关闭。
改用TaskDialogIndirect()
。它有一个 TDF_ALLOW_DIALOG_CANCELLATION
标志:
Indicates that the dialog should be able to be closed using Alt-F4, Escape, and the title bar's close button even if no cancel button is specified in either the dwCommonButtons or pButtons members.
所有这些条件都将 return IDCANCEL
。
根据 MessageBox 文档:
Return value
Type: int
If a message box has a Cancel button, the function returns the IDCANCEL value if either the ESC key is pressed or the Cancel button is selected. If the messagebox has no Cancel button, pressing ESC has no effect.
如果我希望有一个 没有取消按钮 但我想区分 OK 和 close/ESC?
What if I wish to have a a box that has no Cancel button but I want to distinguish between OK and close/ESC?
标准对话框不提供这种行为,因为它的设计非常糟糕。作为一个原则,GUI 应该允许通过鼠标或键盘执行操作。只能通过键盘访问的隐藏操作是设计不佳的标志。
如果你真的想制作这样的对话框,你必须自己实现。但是,你不应该。显示带有确定和取消按钮的对话框。
MessageBox()
不支持您正在寻找的行为。您必须使用 SetWindowsHookEx()
或 SetWinEventHook()
直接挂钩对话框,以检测它是否已关闭。
改用TaskDialogIndirect()
。它有一个 TDF_ALLOW_DIALOG_CANCELLATION
标志:
Indicates that the dialog should be able to be closed using Alt-F4, Escape, and the title bar's close button even if no cancel button is specified in either the dwCommonButtons or pButtons members.
所有这些条件都将 return IDCANCEL
。