【问题标题】:InputBox Cancel using C++使用 C++ 取消输入框
【发布时间】:2011-09-15 13:35:05
【问题描述】:

我在 Embarcadero 或 Borland C++ 中使用带有默认字符串的 InputBox 组件。 Cancel 键返回与 Enter 按钮相同的默认字符串。

根据文档,取消键应该返回一个空字符串。

String s = InputBox("Title", "Prompt", "Default");
if (s == "") return;  // Cancel key pressed
... use string s

我在 VB 中看到了使用 StrPtr 的解决方案。 C ++中有等价物吗? VB6 InputBox Cancel

【问题讨论】:

    标签: c++ c++builder


    【解决方案1】:

    根据InputBox documentation

    如果用户选择取消按钮,InputBox 返回默认值 价值。

    所以,基本上你可以将默认字符串设为空,它会与取消一起返回。

    【讨论】:

      【解决方案2】:

      我找到了一个使用 InputQuery 而不是 InputBox 的解决方案。如果选择了 Cancel 按钮,InputQuery 函数将返回 FALSE。在 Enter 时返回 DefaultString。

      【讨论】:

      • InputBox() 文档中提到了这一点:“如果应用程序需要知道用户是选择 OK 还是 Cancel,请改用 InputQuery 函数。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-29
      • 1970-01-01
      • 2014-08-23
      相关资源
      最近更新 更多