Heike Posted February 6, 2003 Posted February 6, 2003 There is an application that calls an EXE that I developped in VB.NET This EXE opens a word application: objWordInstance = GetObject(, "Word.Application") If objWordInstance Is Nothing Then objWordInstance = CreateObject("Word.Application") End If After that I try to show a MessageBox but it is always hidden behind my word application. Any idea what to do? Quote
Cywizz Posted February 6, 2003 Posted February 6, 2003 Hi One of the overloaded parameters in the Messagebox.show method, takes in a 'owner' parameter of type: IWin32Window. This will render the messagebox infront of this specified window (Your word doc) You will need to get the Handle on this window from your exe to be used by your messagebox. Cheers Quote Howzit??
Heike Posted February 6, 2003 Author Posted February 6, 2003 OK. But how can I get the handle of my word app? Quote
Leaders quwiltw Posted February 6, 2003 Leaders Posted February 6, 2003 Admittedly wild guess, you might try the ActiveWindow property? as in, objWordInstance.ActiveWindow Quote --tim
Heike Posted February 6, 2003 Author Posted February 6, 2003 Good idea but unfortunately it only leads to "Specified cast is not valid". Quote
Cywizz Posted February 6, 2003 Posted February 6, 2003 Heike You can check, while debugging if the ActiveWindow property implement IWin32Window (You can use the command window) But, I've got another solution: // Stephen Toub // [email]stoub@microsoft.com[/email] // // ActiveWindow.cs v1.0.0 // 8/28/02 // // Implements IWin32Window where Handle returns the handle of the system's foreground window. // Can be used with MessageBox to display the box in front of the active window, such as: // MessageBox.Show(ActiveWindow.Active, "Hello, World!"); using System; using System.Windows.Forms; using System.Runtime.InteropServices; namespace Toub.Windows.Forms { /// <summary>Used to get an IWin32Window for the active window.</summary> public class ActiveWindow : IWin32Window { #region Private Members /// <summary>Static instance to use for factory pattern.</summary> private static ActiveWindow _window = new ActiveWindow(); #endregion #region Construction /// <summary>Prevent external instantiation.</summary> private ActiveWindow() {} #endregion #region Public Properties /// <summary>Gets an IWin32Window for the active window.</summary> public static IWin32Window Active { get { return _window; } } #endregion #region Private Functions /// <summary>Finds the frontmost window using the Win32 API.</summary> [DllImport("user32.dll")] private static extern int GetForegroundWindow(); /// <summary>Gets a handle to the active window.</summary> System.IntPtr IWin32Window.Handle { get { return new System.IntPtr(GetForegroundWindow()); } } #endregion } } above is a class sample, downloaded of gotdotnet site. It will get the IWin32Window object by using a API. It's in C# but I'm sure you'll get the idea..:) Let me know if you must have the vb version Cheers Quote Howzit??
Heike Posted February 6, 2003 Author Posted February 6, 2003 Indeed, I'm getting the idea but don't know exactly what to do. I copied the source and tried to convert it to vb but the first error I get is "classes can inherit only from other classes". Therefore I would be obliged if you could give me a vb version. Thanks Quote
Cywizz Posted February 6, 2003 Posted February 6, 2003 short and sweet..... : Imports System Imports System.Windows.Forms Imports System.Runtime.InteropServices Public Class ActiveWindow Implements IWin32Window Private Sub New() End Sub Private Declare Function GetForegroundWindow Lib "user32.dll" () As Integer Private Shared _window As ActiveWindow = New ActiveWindow() Public Shared ReadOnly Property Active() As IWin32Window Get Return _window End Get End Property Public ReadOnly Property Handle() As IntPtr Implements System.Windows.Forms.IWin32Window.Handle Get Return New System.IntPtr(GetForegroundWindow()) End Get End Property End Class Cheers Quote Howzit??
Heike Posted February 6, 2003 Author Posted February 6, 2003 Thank you very much. I only made one try, yet, but it seems to work. I will test it more intensely but I'm sure my problem will be solved. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.