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

问题描述 投票:0回答:1

我在 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
}
c++ messagebox builder
1个回答
0
投票

这是写代码

'

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;
}
//---------------------------------------------------------------------------

'

© www.soinside.com 2019 - 2024. All rights reserved.