PostMessage,SendMessage是不能传送字符串到Edit的,顶多传送一个字符 <br>正确的办法: <br>1.找到 app handle <br>2.找到 edit handle <br>3.SetWindowText(edithandle,'abc') <br><br><br>function getpass(var hwnd: LongInt): string; //获取密码框中的密码文本 <br>var <br>passbuf: integer; <br>passlong: longint; <br>passText: PChar; <br>begin <br>passlong:=SendMessage(hwnd,WM_GETTEXTLENGTH,0,0)+1; //获取此对象的长度 <br>GetMem(passText,passlong); //开辟一个内存区。存放数据长度为passlong <br>passbuf:=LongInt(passtext); //获取此数据区的首地址 <br>postMessage(hwnd,WM_GETTEXT,passlong,passbuf); //发送消息让此对象将密码数据存入首地址为passbuf的数据区。存入长度为passlong <br>result:=passtext; <br>end; <br><br><br>procedure SetWndText(hWnd: LongInt; Text: String); //发送文本到目标程序文本框 <br>Var <br>mText
Char; <br>Buf:Integer; <br>begin <br>GetMem(mText,Length(Text)); <br>StrCopy(mText,PChar(Text)); <br>try <br>Buf:=LongInt(mText); <br>SendMessage(hWnd,WM_SETTEXT,0,Buf); <br>finally <br>FreeMem(mText,Length(Text)); <br>end; <br>end; <br><br><br><br>function EnumChildWndProc(AhWnd:LongInt; //获取窗口内控件句柄 <br>AlParam:lParam):boolean;stdcall; <br>var <br>WndClassName: array[0..254] of Char; <br>WndCaption: array[0..254] of Char; <br>begin <br>GetClassName(AhWnd,wndClassName,254); <br>GetWindowText(aHwnd,WndCaption,254); <br>if n=3 then begin <br>SetWndText(AhWnd, username); //发送文本 <br>end; <br>if n=4 then begin <br>SetWndText(AhWnd, password); //发送文本 <br>end; <br>with form1 do <br>begin <br>n:=n+1; <br>end; <br>result:=true; <br>end; <br><br><br><br>procedure Tform1.WMSysCommand <br>(var Message:TMessage); <br>var <br>lpData
NotifyIconData; <br>begin <br>if Message.WParam = SC_ICON then <br>begin <br>//如果用户最小化窗口则将窗口隐藏并在任务栏上添加图标 <br>lpData := new(PNotifyIconDataA); <br>lpData.cbSize := 88; <br>//SizeOf(PNotifyIconDataA); <br>lpData.Wnd := form1.Handle; <br>lpData.hIcon := form1.Icon.Handle; <br>lpData.uCallbackMessage := WM_BARICON; <br>lpData.uID :=0; <br>lpData.szTip := 'bzgren'; <br>lpData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP; <br>Shell_NotifyIcon(NIM_ADD,lpData); <br>dispose(lpData); <br>form1.Visible := False; <br>end <br>else <br>begin <br>//如果是其它的SystemCommand消息则调用系统缺省处理函数处理之。 <br>DefWindowProc(form1.Handle,Message.Msg,Message.WParam,Message.LParam); <br>end; <br>end; <br><br><br><br>procedure Tform1.WMBarIcon(var Message:TMessage); <br>var <br>lpData
NotifyIconData; <br>begin <br>if (Message.LParam = WM_LBUTTONDOWN) then <br>begin <br>//如果用户点击任务栏图标则将图标删除并回复窗口。 <br>lpData := new(PNotifyIconDataA); <br>lpData.cbSize := 88;//SizeOf(PNotifyIconDataA); <br>lpData.Wnd := form1.Handle; <br>lpData.hIcon := form1.Icon.Handle; <br>lpData.uCallbackMessage := WM_BARICON; <br>lpData.uID :=0; <br>lpData.szTip := 'bzgren'; <br>lpData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP; <br>Shell_NotifyIcon(NIM_DELETE,lpData); <br>dispose(lpData); <br>form1.Visible := True; <br>end; <br>end;