如何在 Delphi 5 中从 TDBGrid 获取选定的单元格

发布于 2024-07-19 04:36:07 字数 107 浏览 11 评论 0原文

我在表单上有一个 DBGrid,并且我做了多个选择,我现在需要将选定的单元格(它们是电子邮件地址)发送到 Outlook 的“收件人框”,我该怎么做,我将不胜感激任何帮助(Delphi5) 提前致谢

I have a DBGrid on a form and I have made multiple selections, I now need to send the selected cells (they are email addresses) to the "TO Box" of Outlook how can I do this, I will appreciate any help ( Delphi5)
Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

怎会甘心 2024-07-26 04:36:07

要获取所选电子邮件的列表,您可以使用此过程。 对于 Outlook,您可能需要使用 shellexec 和 mailto: 或使用 API(如果有)。

var
i: Integer;
S: TStringList;
begin
S:=TStringList.Create;
if DBGrid1.SelectedRows.Count > 0 then
begin
for i:=0 to DBGrid1.SelectedRows.Count-1 do
begin
Table1.GotoBookmark(pointer(DBGrid1.SelectedRows[i]));
S.Add(Table1EMail.AsString);
end;
//Outlook procedure goes here 
end;

S.Free;
end;

To get list of selected E-Mails you can use this procedure. For outlook you might want to use shellexec and mailto: or use API if there's any.

var
i: Integer;
S: TStringList;
begin
S:=TStringList.Create;
if DBGrid1.SelectedRows.Count > 0 then
begin
for i:=0 to DBGrid1.SelectedRows.Count-1 do
begin
Table1.GotoBookmark(pointer(DBGrid1.SelectedRows[i]));
S.Add(Table1EMail.AsString);
end;
//Outlook procedure goes here 
end;

S.Free;
end;
爱你不解释 2024-07-26 04:36:07

smok1:您检查过您的解决方案是否真正有效吗? 尝试单击“发送”按钮。 OE 说虽然在文本框中没有输入地址。 或者单击文本框左侧的图标。 OE 看不到使用 WM_SETTEXT 输入的地址。 您必须手动输入它。

smok1: have you checked if your solution is actually working? Try to click Send button. OE says there is no address antered although it is in text box. Or click the icon on the left of text box. OE doesn't see address enterered using WM_SETTEXT. You have to manually type it.

笑饮青盏花 2024-07-26 04:36:07

Windows 中的每个(几乎)控件本身就是一个窗口。 它有它的类和实例名称。 由于每个邮件客户端中每个 MailTo 窗口的构造保持相同,因此在了解如何找到适当的控件后,可以构建解决方案。
这就是 Visual Studio 中的 Spy++ 派上用场的地方(如果您没有它,请尝试找到一些类似的工具,有一个免费软件版本 http://msdn.microsoft.com/pl-pl/magazine/cc163617(en-us).aspx 但它缺乏酷搜索工具)。
因此,启动 Spy++ 和邮件程序后,我们点击“新邮件”,就会出现邮件窗口。 在 Spy++ 中刷新,然后使用“查找窗口”工具 - 单击您的 TO 列表,您将看到它是如何构建的。
我从 Outlook Express 开始。 邮件窗口是ATH_Note类,然后地址区域内是一个OE_Envelope类的窗口,该窗口内有几个窗口,其中一些是RichEdit20W类的窗口。 “收件人”字段是第一个字段。

procedure UpdateToOE;
var
  Window:Thandle;
Text:PChar;
begin
  {Lets find Mail window}
  Window:=FindWindow('ATHNote',nil);
  if (Window = 0) then Exit;
  {Lets find adress area inside}
  Window:= FindWindowEx(Window,0,'OEEnvelope',nil);
  if (Window = 0) then Exit;
  {Lets find TO field - remeber this is the first field of this class}
  Window:= FindWindowEx(Window,0,'RichEdit20W',nil);
  if (Window = 0) then Exit;
  {Prepare text into PChar}
  Text:='[email protected]';
  {Send message WMSETTEXT which will set our text in control}
  SendMessage(Window,WMSETTEXT,0,Integer(Text));

  {Sending one extra space to prevent OE does not notice - answer to grzegorz's question}
  SendMessage(Window,WM_CHAR,32,1);
  //done!
End;

注意:当第二个参数为 0 时,FindWindowEx 将始终搜索行中的第一个 - 所以,但如果您执行以下操作:

Window:=FindWindow('ATH_Note',nil);<br>
if (Window = 0) then Exit;<br>
Window:= FindWindowEx(Window,0,'OE_Envelope',nil);<br>
if (Window = 0) then Exit;<br>
Sibling:= FindWindowEx(Window,0,'RichEdit20W',nil);<br>
if (Sibling = 0) then Exit;<br>
Window:=FindWindowEx(Window, Sibling, 'RichEdit20W',nil);<br>
if (Window = 0) then Exit;<br>
Text:='[email protected]';<br>
SendMessage(Window,WM_SETTEXT,0,Integer(Text));<br>

文本将被放入第二个编辑字段中。 请参阅 FindWindowEx 的 msdn。

因此,这对于 OE (XP SP3 IE7) 有好处。 但是 MS Outlook 又如何呢? 我在工作中用 Spy++ 检查了它,“To”字段是连续第二个“RichEdit20WPT”类(末尾注意 T),父类是“#32770(对话框)”,其父类是“AfxWndW”,并且一次同样,父类是“AfxWndW”(这是 TPanel 中的某种 MS 风格的 TPanel)和 – tadam! – 邮件窗口属于“rctrl_renwnd32”类。 所以伪代码是:

Window:=FindWindow('rctrl_renwnd32',nil);<br>
Window:= FindWindowEx(Window,0,’AfxWndW’,nil);<br>
Window:= FindWindowEx(Window,0,’AfxWndW’,nil);<br>
Window:= FindWindowEx(Window,0,’#32770 (Dialog)’,nil);<br>
//Search for FIRST (don’t know what it is)<br>
Sibling:= FindWindowEx(Window,0,’RichEdit20WPT’,nil);<br>
//Search for TO field<br>
Window:= FindWindowEx(Window,Sibling,’RichEdit20WPT’,nil);<br>
Text:='[email protected]';<br>
SendMessage(Window,WM_SETTEXT,0,Integer(Text));<br>

也许您会想要使用 WM_GETTEXT 来提取当前文本并相应地更新新文本,但这超出了进入编辑字段的范围。
顺便说一句:此代码强烈依赖于 Outlook 版本,因此请先尝试使用 Spy++ 检查您的版本)。

Every (almost) control in Windows is a window itself. It has got its class and instance name. Since the construction of every MailTo window in each mail client remains the same, after gaining knowledge how to find appropriate control a solution can be built.
This is where Spy++ from Visual Studio comes in handy (if you do not have it, try to find some similar tool, there is a freeware version at http://msdn.microsoft.com/pl-pl/magazine/cc163617(en-us).aspx but it lacks cool searching tool).
So, After starting Spy++ and mail program, we hit “New mail” and mailing window will appear. Refresh in Spy++, and use “Find window” tool – click on your TO list, and you will se how it is built.
I started with Outlook Express. The mail window is of class ATH_Note, then inside address area is a window of class OE_Envelope and inside this window there are several windows, some of them are of class RichEdit20W. The “To” field is the first one.

procedure UpdateToOE;
var
  Window:Thandle;
Text:PChar;
begin
  {Lets find Mail window}
  Window:=FindWindow('ATHNote',nil);
  if (Window = 0) then Exit;
  {Lets find adress area inside}
  Window:= FindWindowEx(Window,0,'OEEnvelope',nil);
  if (Window = 0) then Exit;
  {Lets find TO field - remeber this is the first field of this class}
  Window:= FindWindowEx(Window,0,'RichEdit20W',nil);
  if (Window = 0) then Exit;
  {Prepare text into PChar}
  Text:='[email protected]';
  {Send message WMSETTEXT which will set our text in control}
  SendMessage(Window,WMSETTEXT,0,Integer(Text));

  {Sending one extra space to prevent OE does not notice - answer to grzegorz's question}
  SendMessage(Window,WM_CHAR,32,1);
  //done!
End;

Note: FindWindowEx when second param is 0 will always search for FIRST in the row – so, but if you will do sth like this:

Window:=FindWindow('ATH_Note',nil);<br>
if (Window = 0) then Exit;<br>
Window:= FindWindowEx(Window,0,'OE_Envelope',nil);<br>
if (Window = 0) then Exit;<br>
Sibling:= FindWindowEx(Window,0,'RichEdit20W',nil);<br>
if (Sibling = 0) then Exit;<br>
Window:=FindWindowEx(Window, Sibling, 'RichEdit20W',nil);<br>
if (Window = 0) then Exit;<br>
Text:='[email protected]';<br>
SendMessage(Window,WM_SETTEXT,0,Integer(Text));<br>

The text will be put in a SECOND edit field. See msdn for FindWindowEx.

So, this is good for OE (XP SP3 IE7). But what with MS Outlook? I checked it with Spy++ at work and “To” Field is a second in a row “RichEdit20WPT” class (note T on the end), parent class is “#32770 (Dialog)”, parent of this is “AfxWndW” and once again parent class is “AfxWndW” (this is some kind MS-style TPanel in TPanel) and – tadam! – mail window is of a class “rctrl_renwnd32”. So the pseudocode for this will be:

Window:=FindWindow('rctrl_renwnd32',nil);<br>
Window:= FindWindowEx(Window,0,’AfxWndW’,nil);<br>
Window:= FindWindowEx(Window,0,’AfxWndW’,nil);<br>
Window:= FindWindowEx(Window,0,’#32770 (Dialog)’,nil);<br>
//Search for FIRST (don’t know what it is)<br>
Sibling:= FindWindowEx(Window,0,’RichEdit20WPT’,nil);<br>
//Search for TO field<br>
Window:= FindWindowEx(Window,Sibling,’RichEdit20WPT’,nil);<br>
Text:='[email protected]';<br>
SendMessage(Window,WM_SETTEXT,0,Integer(Text));<br>

Probably you will want to use WM_GETTEXT to extract current text and update new text accordingly, but this is beyond the scope of getting into edit field.
BTW: This code strongly depends of outlook version, so try to check your version with Spy++ before).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文