Question: How do I get the Falconview App's window handle
How do I get the Falconview App's window handle?
Environment
| FalconView Version: | FalconView 3.3.1 |
| Interface: | IMap |
| Language: | Visual C++ |
-- Main.PatrickSimpson? - 28 Jun 2007
Answer
Here a C# method that will find your process:
using System.Diagnostics;
.
.
.
Process FindFalconViewProcess()
{
//find the window handle for falconview (if available) and
//display the result in the text box
string fvName = "FalconView";
Process fvProcess = null;
Process[] processes = Process.GetProcesses();
for (int i = 0; i < processes.Length; i++)
{
try
{
if (processes[i].MainModule.ModuleName.Equals("fvw.exe"))
{
fvProcess = processes[i];
}
}
catch {
//someone failed (probably a null somewhere),
//but we don't care - just move on to the next process
}
}
if (fvProcess == null)
{
//error handling
}
return fvProcess;
}
If you are in Process (Implementing ILayerEditor) it is easier:
System.Diagnostics.Process process = System.Diagnostics.Process.GetCurrentProcess();
Once you have the process get the mail window handle:
process.MainWindowHandle;
If you want to use this as the parent form (in managed code) you need to convert it to a IWin32Window. Which the following trivial class does:
// window wrapper is a helper class that allows up to convert a window handle to a IWin32Window for use in Managed Code
// in unmanaged C++ you would not need this
public class WindowWrapper : System.Windows.Forms.IWin32Window
{
public WindowWrapper(IntPtr handle)
{
_hwnd = handle;
}
public IntPtr Handle
{
get { return _hwnd; }
}
private IntPtr _hwnd;
}
Finally to use it:
System.Diagnostics.Process process = System.Diagnostics.Process.GetCurrentProcess(); MessageBox.Show(new WindowWrapper(new WindowWrapper(process.MainWindowHandle)), "Hello World!");
