?
Solved

How to activate certain application

Posted on 2003-03-12
13
Medium Priority
?
334 Views
Last Modified: 2010-04-16
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.

   
0
Comment
Question by:yurastaub
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
LVL 6

Expert Comment

by:DaFox
ID: 8121857
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
 

Author Comment

by:yurastaub
ID: 8126265
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
 

Author Comment

by:yurastaub
ID: 8126332
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:DaFox
ID: 8126724
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
 

Author Comment

by:yurastaub
ID: 8127034
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
 
LVL 6

Expert Comment

by:DaFox
ID: 8130888
I'll try to take a look at it this evening/night. Just came home from work.

Markus
0
 
LVL 6

Expert Comment

by:DaFox
ID: 8132191
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
 

Author Comment

by:yurastaub
ID: 8135068
Markus,

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

Thank you very much.

Yura
0
 
LVL 6

Expert Comment

by:DaFox
ID: 8135339
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
 

Author Comment

by:yurastaub
ID: 8135551
really, hmmm ;)))

Markus, ok I will.
0
 

Expert Comment

by:CleanupPing
ID: 9316818
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
 
LVL 5

Expert Comment

by:snehanshu
ID: 10096028
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
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 10149071
PAQed, with points refunded (75)

Computer101
E-E Admin
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month13 days, 3 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question