m8815010
版主
   
 發表:99 回覆:372 積分:289 註冊:2003-11-13
發送簡訊給我
|
引言:
在OnKeyPress 中可以擷取到英文,數字AScii Code,如果輸入中文要如何擷取到中的內碼及HEX Code????
eric888你好 : 用 class="code">
In .h ~~ class TForm1 : public TForm
{
__published: // IDE-managed Components
TEdit *Edit1;
TMemo *Memo1;
void __fastcall Edit1KeyDown(TObject *Sender, WORD &Key,
TShiftState Shift);
private: // User declarations
TWndMethod OldEditWndProc; //add this line
void __fastcall EditWndProc(TMessage& Message); //add this line
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1; ~~
In .cpp ~~ TForm1 *Form1; //---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
OldEditWndProc = Edit1->WindowProc; //assign new window procedure for Edit1
Edit1->WindowProc = EditWndProc;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::EditWndProc(TMessage& Message)
{
OldEditWndProc(Message); if (Message.Msg==WM_IME_CHAR) { //當Edit1收到double byte的字元時
int bytecode=(int)Message.WParam; //印出byte code
Memo1->Lines->Add(IntToHex(bytecode,2));
}
} ~~
嗯,意思就是在範例中的Edit1元件上輸入中文,則在Memo1中就會show出它的byte code!
注意攔這個訊息只針對double byte的字元,如果還要加攔single byte的字元的話,就再
追加攔WM_CHAR訊息即可!或是直接在onkeypress事件中撰寫對應的程式碼也可以! 但注意事件與事件之間不要collision就好了! All !
|