用sendmessage如何向一个窗题发送一个固定的键值
比如 向某个窗题发送一个‘enter’ 问题点数:100、回复次数:3Top
1 楼outer2000(天外流星)回复于 2002-10-28 14:11:43 得分 50
The keybd_event function synthesizes a keystroke. The system can use such a synthesized keystroke to generate a WM_KEYUP or WM_KEYDOWN message. The keyboard driver's interrupt handler calls the keybd_event function.
VOID keybd_event(
BYTE bVk, // virtual-key code
BYTE bScan, // hardware scan code
DWORD dwFlags, // flags specifying various function options
DWORD dwExtraInfo // additional data associated with keystroke
);
Top
2 楼forgot(忘记forgot2000)回复于 2002-10-28 14:16:30 得分 40
unit Umain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Spin, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
SpinEdit1: TSpinEdit;
Label3: TLabel;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
cnt : Integer = 0;
function EnumWindowsProc(Hwnd:THandle;lParam:LParam):boolean;Stdcall;
function EnumChildProc(Hwnd:THandle;lParam:LParam):boolean;Stdcall;
implementation
{$R *.DFM}
function EnumWindowsProc(Hwnd:THandle;lParam:LParam):boolean;
var
WindowCaption:array[0..254] of Char;
begin
GetWindowText(Hwnd,WindowCaption,255);
if StrPas(WindowCaption)=Form1.Edit1.Text then
begin
cnt := 0;
EnumChildWindows(Hwnd,@EnumChildProc,0);
Result := False;
Exit;
end;
Result := True;
end;
function EnumChildProc(Hwnd:THandle;lParam:LParam):boolean;
var
WindowCaption,WindowClass:array[0..254] of Char;
begin
GetClassName(Hwnd,WindowClass,255);
if Pos('EDIT',UpperCase(StrPas(WindowClass))) > 0 then
begin
Inc(cnt);
SendMessage(Hwnd,WM_SETTEXT,0,LongInt(PChar(IntToStr(cnt))));
////此处换成SendMessage(Hwnd,WM_SETTEXT,0,LongInt(PChar('你想送的字符串')));即可
end;
Result := True;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Enumwindows(@EnumWindowsProc,0);
end;
end.Top
3 楼pazee(耙子)(今年过年不收礼,收礼只收尿不湿)回复于 2002-10-28 14:21:00 得分 10
用PostMessage 好些。
handle是你那个窗体的handle
PostMessage(Handle, WM_KEYDOWN, VK_RETURN, 0)Top




