C++Builder 捕获Ctrl+C Ctrl+V Ctrl+X消息,限制文本输入数字时间:2021-02-13 08:10:25最近经常看见别人提起如何限制文本输入数字,并且屏蔽掉Ctrl+C Ctrl+V Ctrl+X 快捷键的输入, 所以做了个测试 本测试在C++Builder6.0 +Windows XP 下测试通过: /************************************************************************************* Author : zhouzhangkui* DateTime : 2009-10-08* Version : unknown* Modify : unknown* Function : 限制文本框输入数字**************************************************************************************///.h 部分public: // User declarations __fastcall TForm1(TComponent* Owner); void __fastcall AppMessage(tagMSG &Msg, bool &Handled) ; //添加//.cpp 部分代码//Form1上添加Edit1 文本框__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner){ Application->OnMessage=AppMessage;}//---------------------------------------------------------------------------void __fastcall TForm1::AppMessage(tagMSG &Msg, bool &Handled){ if (Msg.message == WM_KEYDOWN) { if(GetKeyState(VK_CONTROL) & 0x80) if(Msg.wParam == 'c' || Msg.wParam == 'C' ||Msg.wParam == 'v' || Msg.wParam == 'V' ||Msg.wParam == 'z' || Msg.wParam == 'Z' ||Msg.wParam == 'x' || Msg.wParam == 'X') { //ShowMessage("WM_COPY"); // } }}//---------------------------------------------------------------------------void __fastcall TForm1::Edit1KeyPress(TObject *Sender, char &Key){ if(Key != VK_BACK && (Key < '0' || Key > '9')) Key = 0;//限制数字,}//---------------------------------------------------------------------------