[LabWindows_CVI測試技術及工程應用]3.7滾動條及儀器驅(qū)動使用(學習雜記)
Scroll?Bar?滾動條
儀器驅(qū)動裝載
Instrument——〉Load(路徑為\National Instruments\CVI2017\toolslib\custctrl\scroll.fp)
滾動條控件(水平?垂直)


滾動條編程



????具體細節(jié)參考https://www.bilibili.com/read/cv4728312操作,這里不再啰嗦,再自己摸索graph屬性的配置,相信你一定能行!!
產(chǎn)生并修改源碼
#include "scroll.h"
#include <cvirte.h>
#include <userint.h>
#include "scrollbar.h"
static int panelHandle;
void getvalue(void);
int main (int argc, char *argv[])
{
int value;
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "scrollbar.uir", PANEL)) < 0)
return -1;
//將繪圖控件轉化成滾動條
ScrollBar_ConvertFromGraph(panelHandle, PANEL_GRAPH_VERTICAL,
? scrollbarCB, &panelHandle);
ScrollBar_GetAttribute(panelHandle, PANEL_GRAPH_VERTICAL, ATTR_SB_VALUE, &value);//獲取滾動條當前位置
SetCtrlVal(panelHandle, PANEL_NUMERIC_VERTICAL_VAL, value);//在NUMERIC_VERTIVAL_VAL中顯示滾動條的位置
GetCtrlVal(panelHandle, PANEL_NUMERIC_VERTICAL_MIN, &value);//獲取滾動條最小值
ScrollBar_SetAttribute(panelHandle, PANEL_GRAPH_VERTICAL,ATTR_SB_DOC_MIN, value);
GetCtrlVal(panelHandle, PANEL_NUMERIC_VERTICAL_MAX, &value);//獲取滾動條最大值
ScrollBar_SetAttribute(panelHandle, PANEL_GRAPH_VERTICAL,ATTR_SB_DOC_MAX, value);
GetCtrlVal(panelHandle, PANEL_NUMERIC_VERTICAL_HEIG, &value);//獲取滾動條高度
ScrollBar_SetAttribute(panelHandle, PANEL_GRAPH_VERTICAL,ATTR_SB_HEIGHT, value);
GetCtrlVal(panelHandle, PANEL_NUMERIC_VERTICAL_WID, &value);//獲取滾動條寬度
ScrollBar_SetAttribute(panelHandle, PANEL_GRAPH_VERTICAL,ATTR_SB_WIDTH, value);
GetCtrlVal(panelHandle, PANEL_COLORNUM_COLOR, &value);//獲取滾動條顏色
ScrollBar_SetAttribute(panelHandle, PANEL_GRAPH_VERTICAL,ATTR_SB_COLOR, value);
GetCtrlVal(panelHandle, PANEL_TOGGLEBUTTON_MODE, &value);//獲取滾動條顯示方式
ScrollBar_SetAttribute(panelHandle, PANEL_GRAPH_VERTICAL,ATTR_SB_VERTICAL, value);
GetCtrlVal(panelHandle, PANEL_NUMERIC_VERTICAL_VIEW, &value);//獲取滾動條每次滾動大小
ScrollBar_SetAttribute(panelHandle, PANEL_GRAPH_VERTICAL,ATTR_SB_VIEW_SIZE, value);
DisplayPanel (panelHandle);
RunUserInterface ();
DiscardPanel (panelHandle);
return 0;
}
//滾動條回調(diào)函數(shù)
int CVICALLBACK scrollbarCB (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_SB_UP_BUTTON:
getvalue();
break;
case EVENT_SB_DOWN_BUTTON:
getvalue();
break;
case EVENT_SB_PAGE_UP:
getvalue();
break;
case EVENT_SB_PAGE_DOWN:
getvalue();
break;
case EVENT_SB_THUMB_CHANGE:
getvalue();
break;
case EVENT_SB_COMMIT:
getvalue();
break;
}
return 0;
}
//所有Numeric控件的回調(diào)函數(shù)
int CVICALLBACK adjustvalue (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
int value;
switch (event)
{
case EVENT_COMMIT:
GetCtrlVal(panelHandle, control, &value);//獲取控件值
switch(control) //根據(jù)控件名設置滾動條相應屬性
{
case PANEL_NUMERIC_VERTICAL_MIN: //滾動條最小值
ScrollBar_SetAttribute(panelHandle, PANEL_GRAPH_VERTICAL,
? ATTR_SB_DOC_MIN, value);
break;
case PANEL_NUMERIC_VERTICAL_VAL: //滾動條當前位置值
ScrollBar_SetAttribute(panelHandle, PANEL_GRAPH_VERTICAL,
? ATTR_SB_VALUE, value);
break;
case PANEL_NUMERIC_VERTICAL_MAX: //滾動條最大值
ScrollBar_SetAttribute(panelHandle, PANEL_GRAPH_VERTICAL,
? ATTR_SB_DOC_MAX, value);
break;
case PANEL_NUMERIC_VERTICAL_HEIG: //滾動條高度
ScrollBar_SetAttribute(panelHandle, PANEL_GRAPH_VERTICAL,
? ATTR_SB_HEIGHT, value);
break;
case PANEL_NUMERIC_VERTICAL_WID: //滾動條寬度
ScrollBar_SetAttribute(panelHandle, PANEL_GRAPH_VERTICAL,
? ATTR_SB_WIDTH, value);
break;
case PANEL_COLORNUM_COLOR: //滾動條顏色
ScrollBar_SetAttribute(panelHandle, PANEL_GRAPH_VERTICAL,
? ATTR_SB_COLOR, value);
break;
case PANEL_TOGGLEBUTTON_MODE: //滾動條顯示方式(垂直 水平)
ScrollBar_SetAttribute(panelHandle, PANEL_GRAPH_VERTICAL,
? ATTR_SB_VERTICAL, value);
break;
case PANEL_NUMERIC_VERTICAL_VIEW: //滾動條一次滾動的大小
ScrollBar_SetAttribute(panelHandle, PANEL_GRAPH_VERTICAL,
? ATTR_SB_VIEW_SIZE, value);
break;
}
break;
}
return 0;
}
int CVICALLBACK QuitCallback (int panel, int control, int event,
? void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
QuitUserInterface (0);
break;
}
return 0;
}
void getvalue(void)
{
int value;
ScrollBar_GetAttribute(panelHandle, PANEL_GRAPH_VERTICAL, ATTR_SB_VALUE, &value);//獲取滾動條當前位置
SetCtrlVal(panelHandle, PANEL_NUMERIC_VERTICAL_VAL, value);//在NUMERIC_VERTIVAL_VAL中顯示滾動條的位置
}