From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
|
int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
函数第一个参数 "argc"表示程序被调用的时候传入的形参的个数,第二个参数 "argv" 包含个各个被传入的参数的具体值。 一般来说,程序被启动时至少会传入一个参数,那就是程序的名称(包含扩展名的全称)。
以Windows的cmd命令为例,当我们要查看本机的网络设置的时候,我们一般输入下面命令:
ipconfig /all
正如我们前面提到的一样,当ipconfig.exe被执行的时候,main函数的两个形参的值分别为:
argc = 2, argv[0] ="ipconfig.exe" , argv[1] = "all"
从这里我们可以看出,通过解析这些参数实际上可以实现将我们的应用程序初始化到不同的状态。
下面我们看一个例子,该例中我们实现了两个应用程序,其中以可是实现控制另外一个程序的窗口的大小。
1: 编程实现一个名称为test的应用程序,他的main函数代码如下:int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "test.uir", PANEL)) < 0)
return -1;
if (argc > 1 && !(strcmp(argv[2],"full")))
{
int height,width,monitor;
SetPanelAttribute (panelHandle, ATTR_LEFT, 0);
SetPanelAttribute (panelHandle, ATTR_TOP, 0);
GetMonitorFromPanel (panelHandle,&monitor );
GetMonitorAttribute (monitor, ATTR_HEIGHT, &height);
GetMonitorAttribute (monitor, ATTR_WIDTH, &width);
SetPanelSize (panelHandle, height, width);
}
DisplayPanel (panelHandle);
RunUserInterface ();
DiscardPanel (panelHandle);
return 0;
}
2: 实现一个具有两个用户控件的应用程序,这两个控件的详细描述如表1.:
表 1 控件描述
控件名称 | 回调函数 | 回调函数的具体细节 |
Full Screen |
LaunchFull | LaunchExecutableEx ("test_dbg.exe /C full", LE_SHOWMINIMIZED, &exeHandle); |
Original Screen | LaunchOriginal | LaunchExecutable ("test_dbg.exe"); |
3: 分别编译这两个工程,然后运行即可查看到执行结果。
附注: 这个例子的源代码可以在附件中下载到.
|