2013-07-22 49 views
0

我正在創建一個Outlook消息。有時Outlook Compose窗口出現在其他窗口後面。如何使Outlook Compose窗口最頂層?

我怎樣才能讓它成爲最頂級的?

String address = "[email protected]"; 

Outlook.Application oApp = new Outlook.Application(); 
Outlook._MailItem oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem); 
oMailItem.To = address; 

oMailItem.Subject = "Help"; 

oMailItem.BodyFormat = Outlook.OlBodyFormat.olFormatPlain; 
oMailItem.Attachments.Add("H:\\file.txt"); 

oMailItem.Body = "Call me"; 
// body, bcc etc... 
oMailItem.Display(true); 

我使用的WinForm和.NET 2.0(目標)

+0

我編輯了你的標題。請參閱:「[應該在其標題中包含」標籤「](http://meta.stackexchange.com/questions/19190/)」,其中的共識是「不,他們不應該」。 –

+0

用[贖回] [1]來解決這個問題 [1]:http://stackoverflow.com/questions/17792853/how-to-make-the-outlook-compose-window-top-最 –

回答

-1

首先,調用MailItem.GetInspector拿到檢查對象(那麼你可以調用Inspector.Display),其次,投給督察IOleWindow的接口並調用IOleWindows :: GetWindow來檢索檢查器的HWND。一旦你有了,你可以調用SetForegroundWindow。有一點需要記住的是,如果父進程不在前臺,Windows將不會將窗口置於前臺。你需要使用AttachThreadInput函數 - 見下面(Delphi):

function ForceForegroundWindow(hWnd: THandle): BOOL; 
var 
    hCurWnd: THandle; 
begin 
    hCurWnd := GetForegroundWindow; 
    AttachThreadInput(
    GetWindowThreadProcessId(hCurWnd, nil), 
    GetCurrentThreadId, True); 
    Result := SetForegroundWindow(hWnd); 
    AttachThreadInput(
    GetWindowThreadProcessId(hCurWnd, nil), 
    GetCurrentThreadId, False); 
end; 
相關問題