The following code shows how to manage application (start) and hide/show the F# interactive console applications.
//module ApplMgm
open System
open System.Diagnostics
open System.Collections.Generic
open System.Runtime.InteropServices;
System.Console.Title<-"AppMgm"
[< dllimport("user32.dll")>]
extern IntPtr FindWindow(string lpClassName,string lpWindowName);
[<dllimport("user32.dll")>]
extern bool ShowWindow(IntPtr hWnd, int nCmdShow)
let fsharpPath= @"C:\Program Files (x86)\Microsoft F#\v4.0\fsi.exe"
type Process={Path:string;ExecName:string;ConsoleName:string}
type AppMgm()=
let mutable applications= new Dictionary()
let fsharpPath= @"C:\Program Files (x86)\Microsoft F#\v4.0\fsi.exe"
member this.Apps with get() = applications and set a = applications <- a
member this.fsharpFullPath= @"C:\Program Files (x86)\Microsoft F#\v4.0\fsi.exe"
member this.start(keyName:string) =
let procPath=applications.[keyName].Path
let procName=applications.[keyName].ExecName
Process.Start(fsharpPath,@"--readline+ --load:"+"\""+procPath+procName+"\"") |>ignore
()
member this.hide(keyName:string) =
let consName=applications.[keyName].ConsoleName
let hWnd = FindWindow(null, consName)
if (hWnd <> 0n) then
let b1=ShowWindow(hWnd, 0); // 0 = SW_HIDE
()
member this.show(keyName:string) =
let consName=applications.[keyName].ConsoleName
let hWnd = FindWindow(null, consName)
if (hWnd <> 0n) then
let b1=ShowWindow(hWnd, 1); // 1 = SW_SHOWNORMA
()
//--------------------------------------------------------------------------------------------------
//Configuration
let A= new AppMgm()
let d= new Dictionary()
let projPath= @"C:\Users\caxelrud\Documents\Visual Studio 2010\Projects\Utilities\"
d.Add("ap1",{Path=projPath;ExecName="app_1.fsx";ConsoleName="Application1"})
d.Add("ap2",{Path=projPath;ExecName="app_2.fsx";ConsoleName="Application2"})
//d.["ap2"]
A.Apps<-d
//A.Apps
A.start("ap1")
A.hide("ap1")
A.show("ap1")
No comments:
Post a Comment