D
DelphiVip
Unregistered / Unconfirmed
GUEST, unregistred user!
我用Api创建一窗体,并创建一个Edit.<br><br>但怎么写出EDIT的事件过程(Event)?<br><br>如:OnkeyDown这个事件?.<br><br>非Api的窗体事件过程是:<br><br>procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); <br><br>那Api该怎么写才能返回:键盘输入的值?.我尝试过创建消息循环.Wm_Command,但是此函数会返回鼠标按下,键盘按下的实件.Wm_Keydown并不能返回键盘按下的事件.<br><br>当然我不是想返回是否按下了键盘这个事件,而是想返回键盘按下时,并取得它的按下的值.<br><br>举个例子,按下键盘后,会自动将键盘的值sendmenssage到记事本中.? 该怎么操作?.<br><br>非Api的代码:<br><br>procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);<br>var<br> vHandle: Integer;<br>begin<br> vHandle := FindWindow('Notepad', nil);<br> if vHandle = 0 then Exit;<br> vHandle := FindWindowEx(vHandle, 0, 'Edit', nil);<br> if vHandle = 0 then Exit;<br> SendMessage(vHandle, WM_CHAR, Ord(Key), 0);<br>end;<br><br>但是我的Edit是Api创建的.就难操作了.<br><br>附API创建窗体代码:<br><br>procedure MainCreate;<br>begin<br> attstart:=true;<br> hMutex:=createmutex(nil,true,'Bome2001');<br> releasemutex(hMutex);<br>end;<br><br>function WindowProc(hWnd,Msg,wParam,lParam:integer):Longint; stdcall;<br>begin<br> Result:=DefWindowProc(hWnd,Msg,wParam,lParam);<br> case Msg of WM_COMMAND:<br> if lParam= hEditEmail then showmessage('ok'); // 这个是按下鼠标或者键盘都会弹出,而且无法拦截它输入的信息。<br> end;<br>end;<br><br>function CreateEdit(namechar;x1,y1,x2,y2:integer):hwnd;<br>begin<br>Result:=CreateWindowEx(WS_EX_CLIENTEDGE,'Edit',name,WS_VISIBLE or WS_CHILD or ES_LEFT or ES_AUTOHSCROLL,x1,y1,x2,y2,Handle,0,hInst,nil);<br>end;<br>function CreateMain(namechar;x1,y1,x2,y2:integer):hwnd;<br>begin<br> hInst:=GetModuleHandle(nil);<br> with wClass do<br> begin<br> Style:= CS_CLASSDC or CS_PARENTDC;<br> hIcon:= LoadIcon(hInst,'MAINICON');<br> lpfnWndProc:= @WindowProc;<br> hInstance:= hInst;<br> hbrBackground:= COLOR_BTNFACE+1;<br> lpszClassName:= 'MainClass';<br> hCursor:= LoadCursor(0,IDC_ARROW);<br> end;<br> RegisterClass(wClass);<br> Result:=CreateWindow(wClass.lpszClassName,name,WS_OVERLAPPEDWINDOW or WS_VISIBLE,x1,y1,x2,y2,0,0,hInst,nil);<br>end;<br><br>begin<br> handle:=CreateMain(exename,mrect.left,mrect.top,806,625);<br> hEditEmail:=CreateEdit('',358,258,94,14);<br> while(GetMessage(Msg,Handle,0,0))do<br> begin<br> TranslateMessage(Msg);<br> DispatchMessage(Msg);<br> end;<br>end.