How to get selected cells from TDBGrid in Delphi 5

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

+1
source share
3 answers

To get a list of selected emails, you can use this procedure. For Outlook, you can use shellexec and mailto: or use the API, if 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; 
+3
source

smok1: did you check if your solution really works? Try clicking the submit button. OE says the address is missing, although it is in the text box. Or click the icon to the left of the text box. OE does not see the address entered using WM_SETTEXT. You must manually enter it.

+1
source

Every (almost) control in Windows is the window itself. It has a class and instance name. Since the construction of each MailTo window in each mail client remains the same, after gaining knowledge on how to find the appropriate control, you can create a solution.
Here Spy ++ from Visual Studio comes in handy (if you don’t have one, try to find some similar tool, there is a free version at http://msdn.microsoft.com/pl-pl/magazine/cc163617(en-us). aspx , but it lacks a cool search tool).
So, after launching Spy ++ and the mail program, we will click "New Mail" and a mailing window will appear. Update in Spy ++ and use the Find Window tool - click on your TO list and you will see how it is built.
I started with Outlook Express. The mail window has the ATH_Note class, then the internal address area is the window of the OE_Envelope class, and there are several windows inside this window, some of them have the RichEdit20W class. The To field is the first.

 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:=' test@test.com '; {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 question} SendMessage(Window,WM_CHAR,32,1); //done! End; 


Note: FindWindowEx, when the second parameter is 0, will always look for FIRST in the string - so, but if you do it 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:=' test@test.com ';<br> SendMessage(Window,WM_SETTEXT,0,Integer(Text));<br> 

The text will be placed in the SECOND edit box. See Msdn for FindWindowEx.

So, this is good for OE (XP SP3 IE7). But what about MS Outlook? I tested it with Spy ++ at work, and the To field is the second in the RichEdit20WPT row (note the T at the end), the parent class is # 32770 (Dialog), the parent is AfxWndW, and one once again the parent class is "AfxWndW" (this is a kind of TPanel MS style in TPanel) and - tadam! - the mail window has a class of "rctrl_renwnd32". So the pseudo code for this would 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:=' test@test.com ';<br> SendMessage(Window,WM_SETTEXT,0,Integer(Text));<br> 



You probably want to use WM_GETTEXT to extract the current text and update the new text, respectively, but this is beyond the scope of the input in the edit box.
BTW: this code is highly dependent on the version of Outlook, so try checking your version with Spy ++ earlier).

-2
source

All Articles