Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You might need to bring Word to the forefront. This is a bit different from bringing a form in your app to the top.</p> <p>You'll need to have a reference to two APIs, <strong>FindWindow</strong> and <strong>SetWindowPos</strong> - the first one can find the windows handle for another application that is running, and the second sends a message to the operating system to give an application focus (it uses the windows handle from FindWindow)</p> <p>Here's some sample code.</p> <pre><code>Public Class Form1 &lt;Runtime.InteropServices.DllImport("user32.dll", SetLastError:=True, CharSet:=Runtime.InteropServices.CharSet.Auto)&gt; _ Private Shared Function FindWindow(ByVal lpClassName As String, _ ByVal lpWindowName As String) As IntPtr End Function &lt;Runtime.InteropServices.DllImport("user32.dll", SetLastError:=True)&gt; _ Private Shared Function SetWindowPos(ByVal hWnd As IntPtr, ByVal hWndInsertAfter As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal uFlags As Integer) As Boolean End Function Private Shared ReadOnly HWND_TOPMOST As New IntPtr(-1) Private Shared ReadOnly HWND_NOTOPMOST As New IntPtr(-2) Private Const SWP_NOSIZE As Integer = &amp;H1 Private Const SWP_NOMOVE As Integer = &amp;H2 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Shell("calc.exe") End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click Dim myHandle As IntPtr = FindWindow(Nothing, "Calculator") SetWindowPos(myHandle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE) SetWindowPos(myHandle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE) End Sub End Class </code></pre> <p>Clicking the first button will instantiate a copy of Calculator, the second button will make it topmost, then set it back to normal... so it will still be the top form, but the user can activate other windows as well.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload