RAD Studio XE6、XE7有一个Bug,就是当虚拟键盘显示出来后,如果用虚拟键盘上的关闭按钮关闭虚拟键盘,此时再想用手机上的硬返回键关闭程序,则程序无法关闭。
解决这个问题,只需拦截硬返回键的按下的消息,在其中加入关闭程序的代码即可。
如果需要在虚拟键盘出现时,按一次取消虚拟键盘,按第二次才关闭程序,可用下面方式:
当然,不管上面用哪种方法,都别忘了还要在窗口的OnClose事件中,加入完全退出程序的代码:
解决这个问题,只需拦截硬返回键的按下的消息,在其中加入关闭程序的代码即可。
void __fastcall TForm1::FormKeyUp(TObject *Sender, WORD &Key, System::WideChar &KeyChar,
TShiftState Shift)
{
if(Key == vkHardwareBack)
{
Close();
}
}
如果需要在虚拟键盘出现时,按一次取消虚拟键盘,按第二次才关闭程序,可用下面方式:
void __fastcall TForm1::FormKeyUp(TObject *Sender, WORD &Key, System::WideChar &KeyChar,
TShiftState Shift)
{
if(Key == vkHardwareBack)
{
if (TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXVirtualKeyboardService)))
{
_di_IFMXVirtualKeyboardService FService = NULL;
FService = TPlatformServices::Current->GetPlatformService(__uuidof(IFMXVirtualKeyboardService));
if(FService!=NULL && FService->VirtualKeyboardState.Contains(TVirtualKeyboardState::Visible)==true)
{
//上面方法在使用虚拟键盘上的关闭键关闭虚拟键盘时,判断不准确(仍然判断为显示)
//所以这里加上这句,让虚拟键盘显示出来再自动关闭
FService->ShowVirtualKeyboard(NULL);
}
else
{
Close();
}
}
}
}
当然,不管上面用哪种方法,都别忘了还要在窗口的OnClose事件中,加入完全退出程序的代码:
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
exit(0);
}