yurastaub
asked on
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.
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,
after that the Modal form is not Modal, why so happened ?
Please help. Thanks.
ASKER
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
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
ASKER
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
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
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
As I said before: You don't need to disable/enable the windows. What happens if you comment these lines out?
Markus
ASKER
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].lpszPathNa me := StrNew(PChar(FileName));
Attachments[i1].lpszFileNa me :=
StrNew(PChar(ExtractFileNa me(FileNam e)));
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] .lpszPathN ame);
StrDispose(Attachments[i1] .lpszFileN ame);
end;
if Assigned(MapiMessage.lpszS ubject) then
StrDispose(MapiMessage.lps zSubject);
if Assigned(MapiMessage.lpszN oteText) then
StrDispose(MapiMessage.lps zNoteText) ;
if Assigned(Receip.lpszAddres s) then
StrDispose(Receip.lpszAddr ess);
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(Applicatio n.ExeName) +'export.p df';
// mail.values['attachment1'] :='C:\Test 2.txt';
sendEMail(self.Handle, mail);
finally
mail.Free;
end;
in first form execute second:
procedure TForm1.Button1Click(Sender
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['
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
Attachments[i1].flFlags := 0;
Attachments[i1].nPosition := ULONG($FFFFFFFF);
Attachments[i1].lpszPathNa
Attachments[i1].lpszFileNa
StrNew(PChar(ExtractFileNa
Attachments[i1].lpFileType
end;
MapiMessage.nFileCount := AttachCount;
MapiMessage.lpFiles := @Attachments^;
end;
if Mail.Values['subject'] <> '' then
MapiMessage.lpszSubject := StrNew(PChar(Mail.Values['
if Mail.Values['body'] <> '' then
MapiMessage.lpszNoteText := StrNew(PChar(Mail.Values['
// WndList := DisableTaskWindows(0);
try
Result := MapiSendMail(MAPI_Session,
MapiMessage, MAPI_DIALOG, 0);
finally
// EnableTaskWindows( WndList );
end;
for i1 := 0 to AttachCount - 1 do
begin
StrDispose(Attachments[i1]
StrDispose(Attachments[i1]
end;
if Assigned(MapiMessage.lpszS
StrDispose(MapiMessage.lps
if Assigned(MapiMessage.lpszN
StrDispose(MapiMessage.lps
if Assigned(Receip.lpszAddres
StrDispose(Receip.lpszAddr
if Assigned(Receip.lpszName) then
StrDispose(Receip.lpszName
MapiLogOff(MAPI_Session, Handle, 0, 0);
end;
end;
procedure TForm2.Button1Click(Sender
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']
// mail.values['attachment1']
sendEMail(self.Handle, mail);
finally
mail.Free;
end;
I'll try to take a look at it this evening/night. Just came home from work.
Markus
Markus
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
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
ASKER
Markus,
It sound to be good.
Please, inform me any answer from Microsoft.
Thank you very much.
Yura
It sound to be good.
Please, inform me any answer from Microsoft.
Thank you very much.
Yura
Hi Yura.
I didn't do this yet. I said "I'd ask a question in the Microsoft newsgroup" (if I were you) ;-)
Markus
I didn't do this yet. I said "I'd ask a question in the Microsoft newsgroup" (if I were you) ;-)
Markus
ASKER
really, hmmm ;)))
Markus, ok I will.
Markus, ok I will.
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.
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.
Hi!
No comment has been added lately and this question is therefore classified abandoned.
If asker wishes to close the question, then refer to
https://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.
No comment has been added lately and this question is therefore classified abandoned.
If asker wishes to close the question, then refer to
https://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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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/EnableTa
Markus