edit 用 SendMessage(edt1.Handle,WM_SETFOCUS,0,0);无法输入.如何解决? ( 积分: 50 )

  • 主题发起人 主题发起人 神经蛋白质
  • 开始时间 开始时间

神经蛋白质

Unregistered / Unconfirmed
GUEST, unregistred user!
当焦点在其他控件上时,用&nbsp;SendMessage(edt1.Handle,WM_SETFOCUS,0,0);时EDIT1获得焦点.这时无法输入.如何解决?<br>是其他程序窗口上的EDIT控件.
 
Edit的句柄已经用findwindow得到了.现在就是要让他得到焦点,并对其控制.
 
GRID得到句柄后如何控制其记录上下移动?
 
PostMessage,SendMessage是不能传送字符串到Edit的,顶多传送一个字符&nbsp;<br>正确的办法:&nbsp;<br>1.找到&nbsp;app&nbsp;handle&nbsp;<br>2.找到&nbsp;edit&nbsp;handle&nbsp;<br>3.SetWindowText(edithandle,'abc')&nbsp;<br><br><br>function&nbsp;getpass(var&nbsp;hwnd:&nbsp;LongInt):&nbsp;string;&nbsp;//获取密码框中的密码文本&nbsp;<br>var&nbsp;<br>passbuf:&nbsp;integer;&nbsp;<br>passlong:&nbsp;longint;&nbsp;<br>passText:&nbsp;PChar;&nbsp;<br>begin&nbsp;<br>passlong:=SendMessage(hwnd,WM_GETTEXTLENGTH,0,0)+1;&nbsp;//获取此对象的长度&nbsp;<br>GetMem(passText,passlong);&nbsp;//开辟一个内存区。存放数据长度为passlong&nbsp;<br>passbuf:=LongInt(passtext);&nbsp;//获取此数据区的首地址&nbsp;<br>postMessage(hwnd,WM_GETTEXT,passlong,passbuf);&nbsp;//发送消息让此对象将密码数据存入首地址为passbuf的数据区。存入长度为passlong&nbsp;<br>result:=passtext;&nbsp;<br>end;&nbsp;<br><br><br>procedure&nbsp;SetWndText(hWnd:&nbsp;LongInt;&nbsp;Text:&nbsp;String);&nbsp;//发送文本到目标程序文本框&nbsp;<br>Var&nbsp;<br>mText:PChar;&nbsp;<br>Buf:Integer;&nbsp;<br>begin&nbsp;<br>GetMem(mText,Length(Text));&nbsp;<br>StrCopy(mText,PChar(Text));&nbsp;<br>try&nbsp;<br>Buf:=LongInt(mText);&nbsp;<br>SendMessage(hWnd,WM_SETTEXT,0,Buf);&nbsp;<br>finally&nbsp;<br>FreeMem(mText,Length(Text));&nbsp;<br>end;&nbsp;<br>end;&nbsp;<br><br><br><br>function&nbsp;EnumChildWndProc(AhWnd:LongInt;&nbsp;//获取窗口内控件句柄&nbsp;<br>AlParam:lParam):boolean;stdcall;&nbsp;<br>var&nbsp;<br>WndClassName:&nbsp;array[0..254]&nbsp;of&nbsp;Char;&nbsp;<br>WndCaption:&nbsp;array[0..254]&nbsp;of&nbsp;Char;&nbsp;<br>begin&nbsp;<br>GetClassName(AhWnd,wndClassName,254);&nbsp;<br>GetWindowText(aHwnd,WndCaption,254);&nbsp;<br>if&nbsp;n=3&nbsp;then&nbsp;begin&nbsp;<br>SetWndText(AhWnd,&nbsp;username);&nbsp;//发送文本&nbsp;<br>end;&nbsp;<br>if&nbsp;n=4&nbsp;then&nbsp;begin&nbsp;<br>SetWndText(AhWnd,&nbsp;password);&nbsp;//发送文本&nbsp;<br>end;&nbsp;<br>with&nbsp;form1&nbsp;do&nbsp;<br>begin&nbsp;<br>n:=n+1;&nbsp;<br>end;&nbsp;<br>result:=true;&nbsp;<br>end;&nbsp;<br><br><br><br>procedure&nbsp;Tform1.WMSysCommand&nbsp;<br>(var&nbsp;Message:TMessage);&nbsp;<br>var&nbsp;<br>lpData:PNotifyIconData;&nbsp;<br>begin&nbsp;<br>if&nbsp;Message.WParam&nbsp;=&nbsp;SC_ICON&nbsp;then&nbsp;<br>begin&nbsp;<br>//如果用户最小化窗口则将窗口隐藏并在任务栏上添加图标&nbsp;<br>lpData&nbsp;:=&nbsp;new(PNotifyIconDataA);&nbsp;<br>lpData.cbSize&nbsp;:=&nbsp;88;&nbsp;<br>//SizeOf(PNotifyIconDataA);&nbsp;<br>lpData.Wnd&nbsp;:=&nbsp;form1.Handle;&nbsp;<br>lpData.hIcon&nbsp;:=&nbsp;form1.Icon.Handle;&nbsp;<br>lpData.uCallbackMessage&nbsp;:=&nbsp;WM_BARICON;&nbsp;<br>lpData.uID&nbsp;:=0;&nbsp;<br>lpData.szTip&nbsp;:=&nbsp;'bzgren';&nbsp;<br>lpData.uFlags&nbsp;:=&nbsp;NIF_ICON&nbsp;or&nbsp;NIF_MESSAGE&nbsp;or&nbsp;NIF_TIP;&nbsp;<br>Shell_NotifyIcon(NIM_ADD,lpData);&nbsp;<br>dispose(lpData);&nbsp;<br>form1.Visible&nbsp;:=&nbsp;False;&nbsp;<br>end&nbsp;<br>else&nbsp;<br>begin&nbsp;<br>//如果是其它的SystemCommand消息则调用系统缺省处理函数处理之。&nbsp;<br>DefWindowProc(form1.Handle,Message.Msg,Message.WParam,Message.LParam);&nbsp;<br>end;&nbsp;<br>end;&nbsp;<br><br><br><br>procedure&nbsp;Tform1.WMBarIcon(var&nbsp;Message:TMessage);&nbsp;<br>var&nbsp;<br>lpData:PNotifyIconData;&nbsp;<br>begin&nbsp;<br>if&nbsp;(Message.LParam&nbsp;=&nbsp;WM_LBUTTONDOWN)&nbsp;then&nbsp;<br>begin&nbsp;<br>//如果用户点击任务栏图标则将图标删除并回复窗口。&nbsp;<br>lpData&nbsp;:=&nbsp;new(PNotifyIconDataA);&nbsp;<br>lpData.cbSize&nbsp;:=&nbsp;88;//SizeOf(PNotifyIconDataA);&nbsp;<br>lpData.Wnd&nbsp;:=&nbsp;form1.Handle;&nbsp;<br>lpData.hIcon&nbsp;:=&nbsp;form1.Icon.Handle;&nbsp;<br>lpData.uCallbackMessage&nbsp;:=&nbsp;WM_BARICON;&nbsp;<br>lpData.uID&nbsp;:=0;&nbsp;<br>lpData.szTip&nbsp;:=&nbsp;'bzgren';&nbsp;<br>lpData.uFlags&nbsp;:=&nbsp;NIF_ICON&nbsp;or&nbsp;NIF_MESSAGE&nbsp;or&nbsp;NIF_TIP;&nbsp;<br>Shell_NotifyIcon(NIM_DELETE,lpData);&nbsp;<br>dispose(lpData);&nbsp;<br>form1.Visible&nbsp;:=&nbsp;True;&nbsp;<br>end;&nbsp;<br>end;
 
楼上真热情.先谢谢啦.<br>我只是想对其他程序进行控制.想控制他的程序里面的GRID数据框数据上下移动,鼠标双击,打开信息保存.所以才想要得到焦点.不知道有什么思路方法没有?<br>用程序来自动完成人用鼠标点击要做的事情.
 
没必要得到焦点吧?直接sendmessage模拟鼠标、键盘操作,对于键盘也可以直接产生键盘事件keybd_event
 
直接用sendMessage模拟就可以了
 
多人接受答案了。
 
后退
顶部