我有以下功能,我用MS Outlook 2010發送郵件 Outlook不時出現在我的應用程序(MDI應用程序pmNone ,poDefaultPosOnly) 當Outlook在前面彈出並剛剛在後臺打開時(圖標在狀態欄上閃爍),我還沒有找到任何連續性 我的問題是:是否有任何強制Outlook彈出在所有其他應用程序前面?強制MS Outlook前(在我的應用程序頂部)
function SendMailOutlook(const aFrom, aSubject, aBody, aTo, aCc, aBcc: string; aMailFiles: TStringList; aReceipt: boolean; aPreview: boolean = True): boolean;
var
Outlook: OleVariant;
MailItem: OleVariant;
i: integer;
const
olMailItem = $00000000;
begin
try
try
Outlook := GetActiveOleObject('Outlook.Application');
except
Outlook := CreateOleObject('Outlook.Application');
end;
MailItem := Outlook.CreateItem(olMailItem);
if olAccountValid(aFrom) then
MailItem.SendUsingAccount := Outlook.Session.Accounts.Item(aFrom);
MailItem.To := aTo;
MailItem.Cc := aCc;
MailItem.Bcc := aBcc;
MailItem.Subject := aSubject;
MailItem.Body := aBody;
for i := 0 to aMailFiles.Count - 1 do
MailItem.Attachments.Add(aMailFiles.Strings[i]);
MailItem.ReadReceiptRequested := aReceipt;
MailItem.OriginatorDeliveryReportRequested := aReceipt;
if aPreview = True then
MailItem.Display(True)
else
MailItem.Send;
Result := MailItem.Sent;
except
on E:Exception do
begin
Logfile.Error('U_Mailing.Outlook.SendMailOutlook: ' + E.Message);
Result := False;
end;
end;
end;
我不知道如何顯示我工作的代碼,所以我只是編輯我的問題,並將其添加到那裏。請原諒,如果不是這樣做的話。
function SendMailOutlook(const aFrom, aSubject, aBody, aTo, aCc, aBcc: string; aMailFiles: TStringList; aReceipt: boolean; aPreview: boolean = True): boolean;
var
Outlook: OleVariant;
MailItem: OleVariant;
i: integer;
MailInspector: variant;
const
olMailItem = $00000000;
begin
try
try
Outlook := GetActiveOleObject('Outlook.Application');
except
Outlook := CreateOleObject('Outlook.Application');
end;
MailItem := Outlook.CreateItem(olMailItem);
if olAccountValid(aFrom) then
MailItem.SendUsingAccount := Outlook.Session.Accounts.Item(aFrom);
MailItem.To := aTo;
MailItem.Cc := aCc;
MailItem.Bcc := aBcc;
MailItem.Subject := aSubject;
MailItem.Body := aBody;
for i := 0 to aMailFiles.Count - 1 do
MailItem.Attachments.Add(aMailFiles.Strings[i]);
MailItem.ReadReceiptRequested := aReceipt;
MailItem.OriginatorDeliveryReportRequested := aReceipt;
if aPreview = True then
begin
MailInspector := MailItem.GetInspector;
MailInspector.Display(True);
end
else
MailItem.Send;
Result := MailItem.Sent;
except
on E:Exception do
begin
Logfile.Error('U_Mailing.Outlook.SendMailOutlook: ' + E.Message);
Result := False;
end;
end;
end;
參見[如何顯示在前面(而不是背景)在Outlook與OLE新的電子郵件的形式?(http://stackoverflow.com/q/9972866/576719)。 –
已嘗試過Outlook.ActiveWindow.Activate;但是這會導致程序崩潰。 – OZ8HP
你是否也從'MailItem.Display'中刪除了模態參數? –