2008. 1. 24. 20:27

CVI에서 컨트롤을 동적으로 생성하기



CVI에서 동적으로 컨트롤을 생성하는 방법이다.

일반적인GUI프로그램에서 사용하고자 하는 컨트롤을 Panel에 미리 배치해놓고 작업을 하게 된다.
하지만 경우에 따라 버튼을 클릭한다거나 했을 때 동적으로 panel에 생성할 필요가 있을 때가 있다.

이 때 LabWindows/CVI에서 사용할 수 있는 함수가 NewCtrl()함수이다.

인자로 panel핸들, 컨트롤의 스타일, 컨트롤의 label, 위치(상, 좌)가 있고, int형의 컨트롤 ID를 반환한다.

NewCtrl

int NewCtrl (int panelHandle, int controlStyle, char controlLabel[], int controlTop, int controlLeft);

Purpose

Creates a new control and returns a control ID that you can use to specify the control in subsequent function calls.
If you call this function to add a timer control to a panel, you must do so in the same thread in which you create or load the panel.

Parameters

Input
Name Type Description
panelHandle integer Specifier for a particular panel that is currently in memory. You obtain this handle from LoadPanel, NewPanel, or DuplicatePanet.
controlStyle integer Select one of the following control styles.

Type Style
Numeric CTRL_NUMERIC
CTRL_NUMERIC_LS
Color Numeric CTRL_COLOR_NUMERIC
CTRL_COLOR_NUMERIC_LS

Numeric Slide CTRL_NUMERIC_THERMOMETER
CTRL_NUMERIC_THERMOMETER_LS
CTRL_NUMERIC_TANK
CTRL_NUMERIC_TANK_LS
CTRL_NUMERIC_GAUGE
CTRL_NUMERIC_GAUGE_LS
CTRL_NUMERIC_METER
CTRL_NUMERIC_METER_LS
CTRL_NUMERIC_KNOB
CTRL_NUMERIC_KNOB_LS
CTRL_NUMERIC_DIAL
CTRL_NUMERIC_DIAL_LS
CTRL_NUMERIC_VSLIDE
CTRL_NUMERIC_HSLIDE
CTRL_NUMERIC_FLAT_VSLIDE
CTRL_NUMERIC_FLAT_HSLIDE
CTRL_NUMERIC_LEVEL_VSLIDE
CTRL_NUMERIC_LEVEL_VSLIDE_LS
CTRL_NUMERIC_LEVEL_HSLIDE
CTRL_NUMERIC_LEVEL_HSLIDE_LS
CTRL_NUMERIC_POINTER_VSLIDE
CTRL_NUMERIC_POINTER_VSLIDE_LS
CTRL_NUMERIC_POINTER_HSLIDE
CTRL_NUMERIC_POINTER_HSLIDE_LS

String CTRL_STRING
CTRL_STRING_LS

Text Message CTRL_TEXT_MSG

Text Box CTRL_TEXT_BOX
CTRL_TEXT_BOX_LS

Command Button CTRL_SQUARE_COMMAND_BUTTON
CTRL_SQUARE_COMMAND_BUTTON_LS
CTRL_OBLONG_COMMAND_BUTTON
CTRL_ROUND_COMMAND_BUTTON
CTRL_ROUNDED_COMMAND_BUTTON

Picture Button CTRL_PICTURE_COMMAND_BUTTON
CTRL_PICTURE_COMMAND_BUTTON_LS
CTRL_PICTURE_TOGGLE_BUTTON
CTRL_PICTURE_TOGGLE_BUTTON_LS

Toggle Button CTRL_ROUND_BUTTON
CTRL_SQUARE_BUTTON
CTRL_SQUARE_BUTTON_LS
CTRL_ROUND_FLAT_BUTTON
CTRL_SQUARE_FLAT_BUTTON
CTRL_ROUND_PUSH_BUTTON
CTRL_SQUARE_PUSH_BUTTON
CTRL_SQUARE_PUSH_BUTTON_LS
CTRL_ROUND_PUSH_BUTTON2
CTRL_SQUARE_PUSH_BUTTON2

Text Button CTRL_SQUARE_TEXT_BUTTON
CTRL_SQUARE_TEXT_BUTTON_LS
CTRL_OBLONG_TEXT_BUTTON
CTRL_ROUND_TEXT_BUTTON
CTRL_ROUNDED_TEXT_BUTTON

Radio Button CTRL_ROUND_RADIO_BUTTON
CTRL_SQUARE_RADIO_BUTTON
CTRL_CHECK_BOX

LED CTRL_ROUND_LIGHT
CTRL_SQUARE_LIGHT
CTRL_ROUND_LED
CTRL_ROUND_LED_LS
CTRL_SQUARE_LED
CTRL_SQUARE_LED_LS

Binary Switch CTRL_HSWITCH
CTRL_VSWITCH
CTRL_GROOVED_HSWITCH
CTRL_GROOVED_VSWITCH
CTRL_TOGGLE_HSWITCH
CTRL_TOGGLE_HSWITCH_LS
CTRL_TOGGLE_VSWITCH
CTRL_TOGGLE_VSWITCH_LS

Ring CTRL_RING
CTRL_RING_LS
CTRL_RECESSED_MENU_RING
CTRL_RECESSED_MENU_RING_LS
CTRL_MENU_RING
CTRL_MENU_RING_LS
CTRL_POPUP_MENU_RING
CTRL_POPUP_MENU_RING_LS

Ring Slide CTRL_RING_VSLIDE
CTRL_RING_HSLIDE
CTRL_RING_FLAT_VSLIDE
CTRL_RING_FLAT_HSLIDE
CTRL_RING_LEVEL_VSLIDE
CTRL_RING_LEVEL_VSLIDE_LS
CTRL_RING_LEVEL_HSLIDE
CTRL_RING_LEVEL_HSLIDE_LS
CTRL_RING_POINTER_VSLIDE
CTRL_RING_POINTER_VSLIDE_LS
CTRL_RING_POINTER_HSLIDE
CTRL_RING_POINTER_HSLIDE_LS
CTRL_RING_THERMOMETER
CTRL_RING_THERMOMETER_LS
CTRL_RING_TANK
CTRL_RING_TANK_LS
CTRL_RING_GAUGE
CTRL_RING_GAUGE_LS
CTRL_RING_METER
CTRL_RING_METER_LS
CTRL_RING_KNOB
CTRL_RING_KNOB_LS
CTRL_RING_DIAL
CTRL_RING_DIAL_LS

Picture Ring CTRL_PICTURE_RING
CTRL_PICTURE_RING_LS

List Box CTRL_LIST
CTRL_LIST_LS

Decoration
CTRL_RAISED_BOX
CTRL_RAISED_BOX_LS
CTRL_RECESSED_BOX
CTRL_RECESSED_BOX_LS
CTRL_FLAT_BOX
CTRL_RAISED_CIRCLE
CTRL_RECESSED_CIRCLE
CTRL_FLAT_CIRCLE
CTRL_RAISED_FRAME
CTRL_RECESSED_FRAME
CTRL_RECESSED_NARROW_FRAME
CTRL_FLAT_FRAME
CTRL_RAISED_ROUND_FRAME
CTRL_RECESSED_ROUND_FRAME
CTRL_FLAT_ROUND_FRAME
CTRL_RAISED_ROUNDED_BOX
CTRL_RECESSED_ROUNDED_BOX
CTRL_FLAT_ROUNDED_BOX
CTRL_SMOOTH_VERTICAL_BOX_LS
CTRL_SMOOTH_HORIZONTAL_BOX_LS

Graph CTRL_GRAPH
CTRL_GRAPH_LS

Digital Graph CTRL_DIGITAL_GRAPH
CTRL_DIGITAL_GRAPH_LS

Strip Chart CTRL_STRIP_CHART
CTRL_STRIP_CHART_LS

Picture CTRL_PICTURE
CTRL_PICTURE_LS

Timer CTRL_TIMER

Canvas CTRL_CANVAS

Table CTRL_TABLE
CTRL_TABLE_LS

ActiveX CTRL_ACTIVEX

Tree
CTRL_TREE
CTRL_TREE_LS

Splitter CTRL_HORIZONTAL_SPLITTER
CTRL_HORIZONTAL_SPLITTER_LS
CTRL_VERTICAL_SPLITTER
CTRL_VERTICAL_SPLITTER_LS

Tab CTRL_TABS
controlLabel string Label of the new control. Pass "" or 0 for no label.

Note: This parameter is ignored for splitters, tabs, and decorations.
controlTop integer Vertical coordinate at which to place the upper left corner of the control, not including labels.

The coordinate must be an integer value from –32,768 to 32,767. The origin (0,0) is at the upper-left corner of the panel, directly below the title bar, before the panel is scrolled.
controlLeft integer Horizontal coordinate at which to place the upper left corner of the control, not including labels.

The coordinate must be an integer value from –32,768 to 32,767. The origin (0,0) is at the upper-left corner of the panel, directly below the title bar, before the panel is scrolled.

Return Value

Name Type Description
controlID integer Returns the ID you can use to specify the control in subsequent function calls. Negative values indicate that an error occurred. Zero is not a valid ID.

참고 : CVI 정보나눔, NI LabWindows/CVI Help

'Programmings > CVI' 카테고리의 다른 글

CVI에서 Dynamic Link Library(DLL) 만들기  (0) 2008.02.01
CVI에서 Static Library 만들기  (0) 2008.02.01
GetActiveCtrl() 함수  (0) 2008.01.24
GetCtrlVal() 함수  (0) 2008.01.24
LabWindows/CVI에서 Win32 API를 사용하는 방법  (0) 2008.01.18