Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI
2 rating:
 1 out of 5     Rate this Document

How Can I Launch and Control Another Application in LabWindows/CVI?

Primary Software: LabWindows/CVI Development Systems>>Full Development System
Primary Software Version: 2.0
Primary Software Fixed Version: N/A
Secondary Software: LabWindows/CVI Development Systems>>Full Development System

Problem:
I have to launch another application in LabWindows/CVI and control the status (such as windows size) of the application, how do I implement this?

Solution:
First let's review a basic knowledge of ANSI C. An ANSI C code always has a main entrance that will be first executed as soon as the program is launched. Generally, the main function is like the following:

int main (int argc, char *argv[])
{
 if (InitCVIRTE (0, argv, 0) == 0)
  return -1; /* out of memory */

The first parameter "argc" indicates how many formal parameters are introduced when called, and the second one "argv" contains the value of each formal parameter. Generally, there will be at least one formal parameter introduced when the application is being launched, and typically will be the file name of the application (with file extention).

Take a Windows cmd command for example, when we want to view the network settings of our computer, we type the following command into cmd window:
                                                                  ipconfig /all
As we mentioned before, when the ipconfig.exe be execuated, the two parameters will be:
                                argc = 2, argv[0] ="ipconfig.exe" , argv[1] = "all"
Here we can see that by resolving these parameters in our main function, we can initiate the application to a different status.

Here is an example that shows how to implement two applications, one's window size can be contolled by another when launched.

  • Step 1: Make an application named Test with the main function as:

    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;
      }

  • Step 2: Make an application with two command control described as in table 1:
                                     table 1  Controls  Description

    Control  Name   CallBack CallBack Function Details

    Full Screen
                                  
    LaunchFull  LaunchExecutableEx ("test_dbg.exe /C full", LE_SHOWMINIMIZED, &exeHandle);
    Original Screen  LaunchOriginal LaunchExecutable ("test_dbg.exe");

  • Step 3: Compile the two projects, run the application made in step 2, see the results. You will find we can lauch test.exe with a normal or full widow.

    Notes: The source code can be found in the Attachments section of this KnowledgeBase.



Related Links:
KnowledgeBase 0ZD9LMTL: What Are the Different Areas of Memory and What Is Their Scope?
The C Programming Language, Second Edition by Brian W. Kernighan and Dennis M. Ritchie

Attachments:

CVI Windows Control.zip




Report Date: 11/20/2008
Last Updated: 12/01/2008
Document ID: 4RJ56TLT

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit