Example Code

Using Maximize/Minimize panel events in LabWindows/CVI

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview
This example program shows how to handle minimize/maximize panel events for your LabWindows/CVI panels.


Description
By catching an event in which the user minimizes the windows, one could let the program know not to update the display, since it won't be necessary when the panel is minimized. This is just one example as to when this could be useful.


Requirements

  • LabWindows/CVI 2012 (or compatible)


Steps to Implement or Execute Code

  1. Open the .prj file in LabWindows/CVI
  2. Run the program by either clicking the Run arrow in the toolbar or by selecting Run>Debug panel.exe from the menu bar.
  3. Observe how the program plots data onto the chart while the panel is maximized. When the panel is minimized the data generation and plotting will pause. When you maximize the panel, the data will once again generate and plot.

Additional Information or References
C code 

// This program shows how to handle minimize and maximize events of a panel.

#include <ansi_c.h>

#include <cvirte.h>

#include <userint.h>

#include "panel.h"

static int panelHandle;

// flag to track if panel is maximized

static int Is_Maximized;

// variable which attribute variable which corresponds to the active panel's ATTR_WINDOW_ZOOM

static int panelZoom;

//variables used for random point generation and plotting

static int count;

static double dataPoints[3];

int main (int argc, char *argv[])

{

          // since panel is originally maximized, set the flag to 1 (true);

          Is_Maximized = 1;

 

          if (InitCVIRTE (0, argv, 0) == 0)

                    return -1;          /* out of memory */

          if ((panelHandle = LoadPanel (0, "panel.uir", PANEL)) < 0)

                    return -1;

 

          // display panel and run user interface

          DisplayPanel (panelHandle);

          RunUserInterface ();

          DiscardPanel (panelHandle);

 

          return 0;

}

// Panel callback. This was generated by giving the callback a name under the properties of the panel

// and creating code under Code>Generate>Panel Callback from the menu bar.

int CVICALLBACK PANEL_CALLBACK (int panel, int event, void *callbackData,

                    int eventData1, int eventData2)

{

          switch (event)

          {

                    case EVENT_GOT_FOCUS:

                              // If there is focus on the panel, then set the maximized flag to 1

                               Is_Maximized = 1;

                              break;

                    case EVENT_LOST_FOCUS:

                              // If there is NOT focus on the panel AND it is also minimized, set the maximized flag to false

                              GetPanelAttribute (panelHandle, ATTR_WINDOW_ZOOM, &panelZoom);

                              if (panelZoom == VAL_MINIMIZE)

                              {

                                         Is_Maximized = 0;

                              }

                              break;

                    case EVENT_CLOSE:

                              // If user closes panel, quit user interface

                                 QuitUserInterface(0);

                              break;

          }

          return 0;

}

// This callback uses a timer uir component to execute code at a tick of the coutner.

// The timing of this is set up from within the properties menu of the imter in the.uir file

int CVICALLBACK TimerCB (int panel, int control, int event,

                    void *callbackData, int eventData1, int eventData2)

{

          switch (event) {

                    // This case executes at every tick of the counter

                    case EVENT_TIMER_TICK:

                              // Check if the pane is maximized, Only if pane maximized flag is true then update the randomized points and plot them.

                              if (Is_Maximized == 1)

                              {

                                        dataPoints[0] = rand()/32767.0 * 100.0;

                                        dataPoints[1] = 30.0;

                                        dataPoints[2] = 70.0;

                                        PlotStripChart (panelHandle, PANEL_CHART, dataPoints, 3, 0, 0, VAL_DOUBLE);

                              }

                              break;

          }

          return 0;

}

 

  **This document has been updated to meet the current required format for the NI Code Exchange.**

 

 

Daniel G.
Semiconductor & Wireless
National Instruments

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.