Note that there are some explanatory texts on larger screens.

plurals
  1. POC# show hidden window
    primarykey
    data
    text
    <p>I am developing an add in for excel. At some point, I can receive async events. I need to be able to show the Excel window if hidden on these events.</p> <p>I am able to store the <code>Hwnd</code> property, which I believe must be an immutable int/reference to identify my Excel window.</p> <p>Can someone elaborate on this Hwnd ? and explain how I can show a hidden window from C# using it ?</p> <p>Thanks in advance folks ;)</p> <p>UPDATE : shortly, that was the piece of code that sorted my problems :</p> <pre><code> /// &lt;summary&gt;Enumeration of the different ways of showing a window using /// ShowWindow&lt;/summary&gt; private enum WindowShowStyle : uint { /// &lt;summary&gt;Hides the window and activates another window.&lt;/summary&gt; /// &lt;remarks&gt;See SW_HIDE&lt;/remarks&gt; Hide = 0, /// &lt;summary&gt;Activates and displays a window. If the window is minimized /// or maximized, the system restores it to its original size and /// position. An application should specify this flag when displaying /// the window for the first time.&lt;/summary&gt; /// &lt;remarks&gt;See SW_SHOWNORMAL&lt;/remarks&gt; ShowNormal = 1, /// &lt;summary&gt;Activates the window and displays it as a minimized window.&lt;/summary&gt; /// &lt;remarks&gt;See SW_SHOWMINIMIZED&lt;/remarks&gt; ShowMinimized = 2, /// &lt;summary&gt;Activates the window and displays it as a maximized window.&lt;/summary&gt; /// &lt;remarks&gt;See SW_SHOWMAXIMIZED&lt;/remarks&gt; ShowMaximized = 3, /// &lt;summary&gt;Maximizes the specified window.&lt;/summary&gt; /// &lt;remarks&gt;See SW_MAXIMIZE&lt;/remarks&gt; Maximize = 3, /// &lt;summary&gt;Displays a window in its most recent size and position. /// This value is similar to "ShowNormal", except the window is not /// actived.&lt;/summary&gt; /// &lt;remarks&gt;See SW_SHOWNOACTIVATE&lt;/remarks&gt; ShowNormalNoActivate = 4, /// &lt;summary&gt;Activates the window and displays it in its current size /// and position.&lt;/summary&gt; /// &lt;remarks&gt;See SW_SHOW&lt;/remarks&gt; Show = 5, /// &lt;summary&gt;Minimizes the specified window and activates the next /// top-level window in the Z order.&lt;/summary&gt; /// &lt;remarks&gt;See SW_MINIMIZE&lt;/remarks&gt; Minimize = 6, /// &lt;summary&gt;Displays the window as a minimized window. This value is /// similar to "ShowMinimized", except the window is not activated.&lt;/summary&gt; /// &lt;remarks&gt;See SW_SHOWMINNOACTIVE&lt;/remarks&gt; ShowMinNoActivate = 7, /// &lt;summary&gt;Displays the window in its current size and position. This /// value is similar to "Show", except the window is not activated.&lt;/summary&gt; /// &lt;remarks&gt;See SW_SHOWNA&lt;/remarks&gt; ShowNoActivate = 8, /// &lt;summary&gt;Activates and displays the window. If the window is /// minimized or maximized, the system restores it to its original size /// and position. An application should specify this flag when restoring /// a minimized window.&lt;/summary&gt; /// &lt;remarks&gt;See SW_RESTORE&lt;/remarks&gt; Restore = 9, /// &lt;summary&gt;Sets the show state based on the SW_ value specified in the /// STARTUPINFO structure passed to the CreateProcess function by the /// program that started the application.&lt;/summary&gt; /// &lt;remarks&gt;See SW_SHOWDEFAULT&lt;/remarks&gt; ShowDefault = 10, /// &lt;summary&gt;Windows 2000/XP: Minimizes a window, even if the thread /// that owns the window is hung. This flag should only be used when /// minimizing windows from a different thread.&lt;/summary&gt; /// &lt;remarks&gt;See SW_FORCEMINIMIZE&lt;/remarks&gt; ForceMinimized = 11 } [DllImport("user32.dll")] static extern bool ShowWindow(IntPtr hWnd, WindowShowStyle nCmdShow); static void ContentClick(object obj, EventArgs ea) { Microsoft.Office.Interop.Excel.Application oExcelApp = (Microsoft.Office.Interop.Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application"); oExcelApp.Visible = true; ShowWindow( (System.IntPtr) Globals.ThisWorkbook.Application.Hwnd, WindowShowStyle.ShowMaximized); } </code></pre>
    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.
    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