SetWindowState in csharp

D

Dom

My program has "Tools" in the menu. You can click on a program and it
starts up, which I achieve this way:

--------------------------------------------
using System.Diagnostics;
Process m_Process = null;

m_Process = Process.Startup (<MyProgramTool>);
--------------------------------------------

If the user exits MyProgramTool, I capture the event and reset
m_Process to null, but I won't bother you with the code -- trust me,
it works well.

I set things so that if the user again tries to start MyProgramTool,
the program will detect that the process is already started, and it
will just bring it to the Foreground:

--------------------------------------------------
using System.Runtime.InteropServices;

[DllImport("USER32.DLL", CharSet = CharSet.Auto)]
static extern bool SetForegroundWindow(IntPtr hWnd);

SetForegroundWindow(m_Process.MainWindowHandle);
 
D

Dom

My program has "Tools" in the menu.  You can click on a program and it
starts up, which I achieve this way:

--------------------------------------------
using System.Diagnostics;
Process m_Process = null;

m_Process = Process.Startup (<MyProgramTool>);
--------------------------------------------

If the user exits MyProgramTool, I capture the event and reset
m_Process to null, but I won't bother you with the code -- trust me,
it works well.

I set things so that if the user again tries to start MyProgramTool,
the program will detect that the process is already started, and it
will just bring it to the Foreground:

--------------------------------------------------
using System.Runtime.InteropServices;

[DllImport("USER32.DLL", CharSet = CharSet.Auto)]
static extern bool SetForegroundWindow(IntPtr hWnd);

SetForegroundWindow(m_Process.MainWindowHandle);
----------------------------------------------------

But if the user has minimized MyProgramTool, the program should
instead set the window state to WS_NORMAL.  That's what I can't do.
Any help?

Well, I figured it out on my own. I used a DLL Viewer to see what I
had in User32.dll, and I saw "ShowWindow". From my C/C++ days, I
recognized this as the function I needed. So I checked at Microsoft,
to get the arguments, and I found the following:

ShowWindow (IntPtr WindowHandle, int nCmdShow)

.... and a list of nCmdShow values, including SW_Normal = 1.

So I included the following lines of code in the proper places, and it
all worked as I wanted.

------------------------------------------------------------------
using System.Runtime.InteropServices;

[DllImport("User32")]
private static extern int ShowWindow(IntPtr hwnd, int nCmdShow);

ShowWindow(InstitutionSearchProcess.MainWindowHandle, 1);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top