To download NI software, including the products shown below, visit ni.com/downloads.
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
Steps to Implement or Execute Code
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.**
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.