以下是PB中的代码:
String ls_filename
Long ll_wstyle=1
long ll_hwnd,ll_nShowCmd
string ls_lpOperation,ls_lpFile,ls_lpParameters,ls_lpDirectory
ll_hwnd=handle(w_main)
ls_lpOperation="open"
ls_lpFile="CPRM.exe"
ls_lpParameters="aaaaaaaaa"
ls_lpDirectory=""
ll_nShowCmd=1 //3最大化
ShellExecute(ll_hwnd,ls_lpOperation,ls_lpFile,ls_lpParameters,ls_lpDirectory,ll_nShowCmd)
C#:
在Program.cs中,原有的Main函数是这样的:
view plaincopy to clipboardprint?
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
将其改为:
view plaincopy to clipboardprint?
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (args.Length == 1)
Application.Run(new Form1(args[0]));
else Application.Run(new Form1());
}
即可接收参数的传递,上面的代码只对参数数目为1的情况进行了判断及处理,有其它需求也可以做类似的处理,由于上面调用了Form1的两种构造函数,那么还需要对Form1的构造函数进行重写:
view plaincopy to clipboardprint?
public Form1()
{
InitializeComponent();
}
public Form1(string cmdArg)
{
testString = cmdArg;
InitializeComponent();
}
private string testString="";