C++ Builder如何清除MessageBox期间按下的键

tez616oj  于 11个月前  发布在  其他
关注(0)|答案(1)|浏览(110)

我在Windows 7上使用Embarcaderro C++ Builder XE7。
我有几个热键在我的形式定义如下:

void __fastcall Twindow::FormKeyUp(TObject *Sender, WORD &Key, TShiftState Shift)
{
    switch(Key)
    {
        case vkEscape:
            Close();
            break;
        //and other cases for different keys
    }
}

字符串
在某些时候,我的表单创建了一个带有问题的消息框。它工作得很好,但是当有人决定使用键盘来回答消息框时,问题就开始了。如果我按ESC关闭这个消息框,那么这个退出按钮消息肯定会关闭框,但是它也会发送到表单,表单以上面定义的方式响应(它关闭)。
我想我可能必须在发送和回复待处理的消息之前以某种方式清除它们.
我的消息框代码看起来像这样:

if(Application->MessageBoxW(L"Do you want to procees?", L"Box?", MB_OKCANCEL) == ID_OK)
{
    //proceed
}

oxosxuxt

oxosxuxt1#

这是写代码

'

void __fastcall TForm1::FormKeyUp(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
 switch(Key)
    {
        case VK_ESCAPE:

        if(!CloseForm)
            Close();
            break;
        //and other cases for different keys
    }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  CloseForm=False;
if(Application-> MessageBoxA ("Save the file?", "Save As"  ,1) == IDOK)
{
   int x=1;
}
else
  CloseForm=True;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormKeyPress(TObject *Sender, char &Key)
{
CloseForm=false;
}
//---------------------------------------------------------------------------

字符串
'

相关问题