How to activate certain application

How to activate certain application?

I have used programm code from DaFox answered on question:"Send an email and attachment with Outlook Express".
There is two commanbds:

   WndList := DisableTaskWindows(0);
     EnableTaskWindows( WndList );

it seems to be solve my problem. but as a result I got activated not my application but another, why so happened. My application main form is MDIForm and I have proceed new form in Modal view. From last one I execute procedure to send mail (from DaFox) which include
     MapiSendMail(MAPI_Session, Handle, MapiMessage, MAPI_DIALOG, 0);
after that the Modal form is not Modal, why so happened ?

Please help. Thanks.

   
yurastaubAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DaFoxCommented:
Hi yurastaub!

First of all, I can't reproduce your problem on my Win2k.
If I add another form to my test project, open Form2 modal and use my mapi code Form2 is still modal after it.

You really don't need the DisableTaskWindow/EnableTaskWindows stuff. It's just for security reasons.

Markus
0
yurastaubAuthor Commented:
DaFox,
very strange, I have also Win2K. I have develop simple project with two forms. Last one is in Modal view, from it I proceed sendMAPI - as a result form is not modal jet ?

yurastaub
0
yurastaubAuthor Commented:
DaFox,
very strange, I have also Win2K. I have develop simple project with two forms. Last one is in Modal view, from it I proceed sendMAPI - as a result form is not modal jet ?

yurastaub
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

DaFoxCommented:
Could you send me your code or post it here?
As I said before: You don't need to disable/enable the windows. What happens if you comment these lines out?

Markus
0
yurastaubAuthor Commented:
Sure Markus,
in first form execute second:

procedure TForm1.Button1Click(Sender: TObject);
  var fform:TForm2;
begin
  fform:=TForm2.Create(self);
  fform.ShowModal;
end;

in second form those commands were commented:

function TForm2.SendEMail(Handle: THandle; Mail: TStrings): Cardinal;
type
 TAttachAccessArray = array [0..0] of TMapiFileDesc;
 PAttachAccessArray = ^TAttachAccessArray;
var
 MapiMessage: TMapiMessage;
 Receip: TMapiRecipDesc;
 Attachments: PAttachAccessArray;
 AttachCount: Integer;
 i1: integer;
 FileName: string;
 dwRet: Cardinal;
 MAPI_Session: Cardinal;
 WndList: Pointer;
begin
 WndList := DisableTaskWindows(Handle);
 dwRet := MapiLogon(Handle,
   PChar(''),
   PChar(''),
   MAPI_LOGON_UI or MAPI_NEW_SESSION,
   0, @MAPI_Session);

 if (dwRet <> SUCCESS_SUCCESS) then
 begin
   MessageBox(Handle,
     PChar('Error while trying to send email'),
     PChar('Error'),
     MB_ICONERROR or MB_OK);
 end
 else
 begin
   FillChar(MapiMessage, SizeOf(MapiMessage), #0);
   Attachments := nil;
   FillChar(Receip, SizeOf(Receip), #0);

   if Mail.Values['to'] <> '' then
   begin
     Receip.ulReserved := 0;
     Receip.ulRecipClass := MAPI_TO;
     Receip.lpszName := StrNew(PChar(Mail.Values['to']));
     Receip.lpszAddress := StrNew(PChar('SMTP:' + Mail.Values['to']));
     Receip.ulEIDSize := 0;
     MapiMessage.nRecipCount := 1;
     MapiMessage.lpRecips := @Receip;
   end;

   AttachCount := 0;

   for i1 := 0 to MaxInt do
   begin
     if Mail.Values['attachment' + IntToStr(i1)] = '' then
       break;
     Inc(AttachCount);
   end;

   if AttachCount > 0 then
   begin
     GetMem(Attachments, SizeOf(TMapiFileDesc) * AttachCount);

     for i1 := 0 to AttachCount - 1 do
     begin
       FileName := Mail.Values['attachment' + IntToStr(i1)];
       Attachments[i1].ulReserved := 0;
       Attachments[i1].flFlags := 0;
       Attachments[i1].nPosition := ULONG($FFFFFFFF);
       Attachments[i1].lpszPathName := StrNew(PChar(FileName));
       Attachments[i1].lpszFileName :=
         StrNew(PChar(ExtractFileName(FileName)));
       Attachments[i1].lpFileType := nil;
     end;
     MapiMessage.nFileCount := AttachCount;
     MapiMessage.lpFiles := @Attachments^;
   end;

   if Mail.Values['subject'] <> '' then
     MapiMessage.lpszSubject := StrNew(PChar(Mail.Values['subject']));
   if Mail.Values['body'] <> '' then
     MapiMessage.lpszNoteText := StrNew(PChar(Mail.Values['body']));

//   WndList := DisableTaskWindows(0);
   try
     Result := MapiSendMail(MAPI_Session, Handle,
     MapiMessage, MAPI_DIALOG, 0);
   finally
//     EnableTaskWindows( WndList );
   end;

   for i1 := 0 to AttachCount - 1 do
   begin
     StrDispose(Attachments[i1].lpszPathName);
     StrDispose(Attachments[i1].lpszFileName);
   end;

   if Assigned(MapiMessage.lpszSubject) then
     StrDispose(MapiMessage.lpszSubject);
   if Assigned(MapiMessage.lpszNoteText) then
     StrDispose(MapiMessage.lpszNoteText);
   if Assigned(Receip.lpszAddress) then
     StrDispose(Receip.lpszAddress);
   if Assigned(Receip.lpszName) then
     StrDispose(Receip.lpszName);
   MapiLogOff(MAPI_Session, Handle, 0, 0);
 end;

end;

procedure TForm2.Button1Click(Sender: TObject);
  var mail: TStringList;
begin
    mail := TStringList.Create;
    try
      mail.values['to'] := 'yst@astros.lv';
      mail.values['subject'] := 'from GG mail';
      mail.values['body'] := 'from GG mail';
//      mail.values['attachment0'] := ExtractFilePath(Application.ExeName)+'export.pdf';
      // mail.values['attachment1']:='C:\Test2.txt';
      sendEMail(self.Handle, mail);
    finally
      mail.Free;
    end;

0
DaFoxCommented:
I'll try to take a look at it this evening/night. Just came home from work.

Markus
0
DaFoxCommented:
yurastaub,

the good news: I could reproduce your prob. You were absolutely right.
the bad news: It seems to be a mapi problem. After the MAPISendMail() call Form2 isn't shown modal anymore... If you comment it out, everything is fine except that your mails hasn't been send ;-)

Step 1: Comment out the MAPISendMail() call. -> Form2 modal
Step 2: replace MAPI_DIALOG with MAPI_LOGON_UI -> Form2 modal
Step 3: replace MAPI_DIALOG with MAPI_NEW_SESSION -> Form2 modal

I searched the net for a solution, but I couldn't find something useful... :/
I'd ask a question in the Microsoft newsgroup. Sorry that I couldn't help you that much :(

Markus
0
yurastaubAuthor Commented:
Markus,

It sound to be good.
Please, inform me any answer from Microsoft.

Thank you very much.

Yura
0
DaFoxCommented:
Hi Yura.

I didn't do this yet. I said "I'd ask a question in the Microsoft newsgroup" (if I were you) ;-)

Markus
0
yurastaubAuthor Commented:
really, hmmm ;)))

Markus, ok I will.
0
CleanupPingCommented:
yurastaub:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
snehanshuCommented:
Hi!
No comment has been added lately and this question is therefore classified abandoned.

If asker wishes to close the question, then refer to
http://www.experts-exchange.com/help/closing.jsp

Otherwise, I will leave a recommendation in the Cleanup topic area that this question is:

PAQ'd and pts refunded

Please leave any comments here within the next seven days. It is assumed that any participant not responding to this request is no longer interested in its final disposition.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

...Snehanshu
EE Cleanup Volunteer

P.S.
  PAQ in hope that yurastaub will post a solution if he finds one and because the discussion may be useful for others.
0
Computer101Commented:
PAQed, with points refunded (75)

Computer101
E-E Admin
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.