当然有,比如oldWNDProc: LRESULT; procedure SetMyKeyCallBackOfComboBox; function InitWndProcCombox(hWnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): Longint; stdcall; begin if (msg=WM_KEYDOWN) and ((WPARAM=39) Or (WPARAM=37)) then begin if (WPARAM=37) then EdtHeTongCode.SetFocus else EdtHeTongYear.SetFocus; result:=0; end else result:= CallWindowProc(TFNWndProc(oldWNDProc),hWnd,Msg,wParam,lParam) end; begin oldWNDProc:=SetWindowLong(Handle, GWL_WNDPROC, Longint(@InitWndProcCombox)); end;
GUI线程的消息泵会自动发送到这个窗口的窗口过程去吧。呵呵,不要用MFC的方式来理解VCL,MFC的class wizard可以为你自动声场重载窗体指定消息的函数,实际上那是afx的宏命令挂接上去。在VCL中,你可以在每个你自己窗体的class定义里面直接定义一个过程,后面有message关键字加消息常量,这样就重载了这个消息了。
当然你还可以用TApplicaton的OnMessage属性,来过滤主线程的所有windows消息,不过要处理好,不然CPU的占用率怕上居高不下
procedure SetMyKeyCallBackOfComboBox;
function InitWndProcCombox(hWnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): Longint; stdcall;
begin
if (msg=WM_KEYDOWN) and ((WPARAM=39) Or (WPARAM=37)) then
begin
if (WPARAM=37) then EdtHeTongCode.SetFocus
else EdtHeTongYear.SetFocus;
result:=0;
end
else
result:= CallWindowProc(TFNWndProc(oldWNDProc),hWnd,Msg,wParam,lParam)
end;
begin
oldWNDProc:=SetWindowLong(Handle, GWL_WNDPROC, Longint(@InitWndProcCombox));
end;