⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sample4_1.c

📁 经典LabWindows CVI方面的教材《LabWindows CVI开发入门和进阶》一书例题1-4章中的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <ansi_c.h>#include <cvirte.h>		/* Needed if linking in external compiler; harmless otherwise */#include <userint.h>#include "sample4_1.h" static int panelHandle;void CVICALLBACK MenuDimmerCallback (int menuBarHandle, int panel);      int main (int argc, char *argv[]){	if (InitCVIRTE (0, argv, 0) == 0)	/* Needed if linking in external compiler; harmless otherwise */		return -1;	/* out of memory */	if ((panelHandle = LoadPanel (0, "sample4_1.uir", PANEL)) < 0)		return -1;	InstallMenuDimmerCallback ( GetPanelMenuBar(panelHandle), MenuDimmerCallback);  	DisplayPanel (panelHandle); 	RunUserInterface ();	return 0;}    /* Dim the menu items appropriately when the menubar is clicked on */void CVICALLBACK MenuDimmerCallback (int menuBarHandle, int panel){    int textAvailable, bitmapAvailable, activeCtrl;    int num;         ClipboardGetText(0, &textAvailable);        /* check if text is available on the clipboard */    ClipboardGetBitmap(0, &bitmapAvailable);    /* check if a bitmap is available on the clipboard */	activeCtrl = GetActiveCtrl(panel);              SetMenuBarAttribute (menuBarHandle, MAIN_MENU_EDIT_PASTE , ATTR_DIMMED, !textAvailable && !bitmapAvailable);    SetMenuBarAttribute (menuBarHandle, MAIN_MENU_EDIT_COPYCONTROL  , ATTR_DIMMED, activeCtrl <= 0);	GetNumTextBoxLines (panelHandle, PANEL_TEXTBOX_1, &num);	SetMenuBarAttribute (menuBarHandle, MAIN_MENU_EDIT_COPY, ATTR_DIMMED, num<=0);	SetMenuBarAttribute (menuBarHandle, MAIN_MENU_EDIT_CUT, ATTR_DIMMED, num<=0);  }//panel callback funint CVICALLBACK panel (int panel, int event, void *callbackData,		int eventData1, int eventData2){	int MenuHandle;	switch (event)	{		case EVENT_RIGHT_CLICK:			MenuHandle = GetPanelMenuBar (panelHandle);						RunPopupMenu (MenuHandle, MAIN_MENU_EDIT, panelHandle, eventData1,eventData2, 0, 0, 0, 0);						//MessagePopup("Help","sample4_1 sample program");			break;	}	return 0;}// Exit button callback funint CVICALLBACK Exit (int panel, int control, int event,		void *callbackData, int eventData1, int eventData2){	switch (event)	{		case EVENT_COMMIT:			QuitUserInterface (0);			break;	}	return 0;}//Canvas control callback fun   , not used ,return 1;int CVICALLBACK Canvas (int panel, int control, int event,		void *callbackData, int eventData1, int eventData2){	return 1;}//ClearA button callback fun   int CVICALLBACK ClearB (int panel, int control, int event,		void *callbackData, int eventData1, int eventData2){	switch (event)	{		case EVENT_COMMIT:			ResetTextBox (panelHandle, PANEL_TEXTBOX_2, "");			break;		case EVENT_RIGHT_DOUBLE_CLICK:			MessagePopup("Help","The destinate edit box to paste the text form clipboard");       			break;	}	return 0;}//ClearB button callback fun   int CVICALLBACK ClearA (int panel, int control, int event,		void *callbackData, int eventData1, int eventData2){	switch (event)	{		case EVENT_COMMIT:			ResetTextBox (panelHandle, PANEL_TEXTBOX_1, "");  			break;		case EVENT_RIGHT_DOUBLE_CLICK:			MessagePopup("Help","The destinate edit box to copy the text to clipboard");			break;	}	return 0;}//ClearCanvas button callback fun int CVICALLBACK ClearCanvas (int panel, int control, int event,		void *callbackData, int eventData1, int eventData2){	switch (event)	{		case EVENT_COMMIT:			CanvasClear (panelHandle, PANEL_CANVAS, VAL_ENTIRE_OBJECT);			break;	}	return 0;}//Menu Exit callback fun  void CVICALLBACK MExit (int menuBar, int menuItem, void *callbackData,		int panel){	QuitUserInterface (0);}//Menu copy callback fun void CVICALLBACK Copy(int menuBar, int menuItem, void *callbackData,		int panel){     int     length;    char    *text;      GetCtrlAttribute(panel, PANEL_TEXTBOX_1 , ATTR_STRING_TEXT_LENGTH, &length);    length = length + 1;        /* add space for the nul terminating byte at the end of the string */    /* allocate a buffer to copy the text in the text box control into */    text = (char *)malloc(length);          if (text != NULL)        {        GetCtrlVal(panel, PANEL_TEXTBOX_1 , text);    /* put the text in the buffer */        ClipboardPutText(text);             /* put the text in the buffer on the clipboard */        free(text);                         /* free the buffer */        }			  }//Menu copy control callback fun void CVICALLBACK CopyCONTROL (int menuBar, int menuItem, void *callbackData,		int panel){    int ctrl;    int bitmap;    int includeLabel;        ctrl = GetActiveCtrl(panel);    if (ctrl > 0)        {        includeLabel = ConfirmPopup("拷贝面板或控件图形","是否拷贝控件标号?");        GetCtrlDisplayBitmap(panel, ctrl, includeLabel, &bitmap);         ClipboardPutBitmap(bitmap);                           DiscardBitmap(bitmap);              }					   }//Menu cut callback fun void CVICALLBACK Cut (int menuBar, int menuItem, void *callbackData,		int panel){     int     length;    char    *text;      GetCtrlAttribute(panel, PANEL_TEXTBOX_1 , ATTR_STRING_TEXT_LENGTH, &length);    length = length + 1;    /* add space for the nul terminating byte at the end of the string */    /* allocate a buffer to copy the text in the text box control into */    text = (char *)malloc(length);          if (text != NULL)        {        GetCtrlVal(panel, PANEL_TEXTBOX_1 , text);    /* put the text in the buffer */        ClipboardPutText(text);             /* put the text in the buffer on the clipboard */        free(text);                         /* free the buffer */        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -