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

📄 guimsg.c

📁 基于NuCleus操作系统下的一个GUI界面
💻 C
📖 第 1 页 / 共 5 页
字号:
#include  "..\NUCLEUS\nucleus.h"
#include "io.h"
#include "main.h"
//#include "C:\diab42b\4.2b\include\sys\types.h"
#include <memory.h>
#include <stdlib.h>
#include <string.h>

#include "guimsg.h"
#include "dotreal.h"
#include <math.h>
#define MAXSAMPLE_gui  512

extern int  AdcData_Ua_INT[512],AdcData_Ub_INT[512],AdcData_Uc_INT[512],AdcData_Ud_INT[512];
extern int  AdcData_Ia_INT[512],AdcData_Ib_INT[512],AdcData_Ic_INT[512],AdcData_Id_INT[512];
extern int  Draw_Ua_INT[512],Draw_Ub_INT[512],Draw_Uc_INT[512],Draw_Ud_INT[512];
extern int  Draw_Ia_INT[512],Draw_Ib_INT[512],Draw_Ic_INT[512],Draw_Id_INT[512];
extern float AdcData_Ua[512],AdcData_Ub[512],AdcData_Uc[512],AdcData_Ia[512],AdcData_Ib[512],AdcData_Ic[512];
extern float Curratio_Ua,Curratio_Ub,Curratio_Uc,Curratio_Ia,Curratio_Ib,Curratio_Ic;
extern uint Ylen_FFT[MAXSAMPLE_gui];
extern SCR scr1;
extern GUI_FORM frmSet;
extern GUI_WINCONTROL txtlist_set[0];

int Ystore_Ua[512]=0,Ystore_Ia[512]=0,Ystore_Ub[512]=0,
	Ystore_Ib[512]=0,Ystore_Uc[512]=0,Ystore_Ic[512]=0,Ystore_Ud[512]=0,Ystore_Id[512]=0;

int Ylook_Ua[512]=0,Ylook_Ia[512]=0,Ylook_Ub[512]=0,
	Ylook_Ib[512]=0,Ylook_Uc[512]=0,Ylook_Ic[512]=0,Ylook_Ud[512]=0,Ylook_Id[512]=0;

int cntx=0;
/*
RGB  RGB_Black={0,0,0};
RGB  RGB_White={0xff,0xff,0xff};
RGB  RGB_Red = {0x1f,0x00,0x00};
RGB  RGB_Green = {0x00,0x3c,0x00};
RGB  RGB_Blue = {0x00,0x00,0x1f};
RGB  RGB_Yellow=  {0x1f,0x3f,0x00};*/

//注意两个颜色声明要统一
RGB  RGB_Black={0,0,0};
RGB  RGB_White={0xff,0xff,0xff};
RGB  RGB_Red = {0x1f,0x00,0x00};
RGB  RGB_Yellow=  {0x15,0x20,0x00};
//RGB  RGB_Yellow=  {0x1f,0x3f,0x00};
RGB  RGB_Green = {0x00,0x20,0x00};
//RGB  RGB_Green = {0x00,0x3f,0x00};
RGB  RGB_Blue = {0x00,0x00,0x1f};
RGB  RGB_LightBlue ={0x00,0xff,0x1f};

RGB  RGB_Purple =   {182 ,88 ,157};
/*#define rgbEdge  	{0,0,0}
#define rgbBlack     {0,0,0}
#define rgbWhite    {0xff,0xff,0xff}
#define rgbFormBk {0xff,0xff,0xff}
#define rgbRed     {0x1f,0x00,0x00}
#define rgbGreen {0x00,0x3f,0x00}
#define rgbBlue    {0x00,0x00,0x1f}
#define rgblightBlue    {0x00,0xff,0x1f}
#define rgbYellow {0x1c,0x3f,0x00}
*/
unsigned char GBK[]={
			//#include "gbk1212.txt"
			#include "gbk1616.txt"
		};
		
unsigned char Asci[]={
			//#include "asc1212.txt"
			#include "asc1616.txt"

		};	
// a serial of pumps Bitmap;

unsigned char BmpOn[][2]=
{ /*0x07,0xE0,0x0A,0x90,0x34,0x8C,0x28,0x84,0x50,0x82,0xA0,0x81,0xC0,0x81,0x80,0x81,
0x80,0x81,0x80,0x81,0x80,0x81,0x40,0x82,0x20,0x84,0x30,0x8C,0x08,0x90,0x07,0xE0
*/
/*0x07,0xE0,0x08,0x10,0x30,0x0C,0x20,0x04,0x40,0x02,0x80,0x01,0x80,0x01,0x80,0x01,
0xFF,0xFF,0x80,0x01,0x80,0x01,0x40,0x02,0x20,0x04,0x30,0x0C,0x08,0x10,0x07,0xE0
*/
0x00,0x00,0x01,0x01,0x02,0x02,0x03,0x03,0x04,0x04,0x05,0x05,0x06,0x06,0x07,0x07,
0x08,0x08,0x09,0x09,0x10,0x10,0x11,0x11,0x12,0x12,0x13,0x13,0x14,0x14,0x15,0x15
};  //Set ON

unsigned char BmpOff[][2]=
{0x07,0xE0,0x08,0x10,0x30,0x4C,0x20,0x84,0x41,0x02,0x82,0x01,0x84,0x01,0x88,0x01,
0xF0,0x3F,0x80,0x01,0x80,0x01,0x40,0x02,0x20,0x04,0x30,0x0C,0x08,0x10,0x07,0xE0
/*0x07,0xE0,0x08,0x10,0x30,0x4C,0x20,0x84,0x41,0x02,0x82,0x01,0x84,0x01,0x88,0x01,
0xF0,0x3F,0x80,0x01,0x80,0x01,0x40,0x02,0x20,0x04,0x30,0x0C,0x08,0x10,0x07,0xE0
*/
};  // Set Off
 
unsigned char BmpRes[][2]=
{0x0F,0xF8,0x04,0x90,0x02,0xA0,0x01,0xC0,0x0F,0xF8,0x00,0x80,0x00,0x80,0x00,0x80,
0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80
}; // 发光二极管


BOOL	bMessage = FALSE;
uint		mbResult;

GUI_FORM gfMessageBox = {"消息框",GF_COMMON,(SCR_WIDTH - MSGBOX_WIDTH)/2,
							(SCR_HEIGHT - MSGBOX_HEIGHT)/2,MSGBOX_WIDTH,
							MSGBOX_HEIGHT," ",TRUE,0,rgbFormBk,NULL,NULL,NULL,
							NULL,NULL,NULL};

GUI_WINCONTROL gwMB_Caption = {"text",GWC_TEXT,0,0,MSGBOX_WIDTH,18,
							"提示",FALSE,TRUE,0,rgbBlack,GT_CENTER,0,FontsW,rgbWhite,
							NULL,0,NULL,NULL,NULL};

GUI_WINCONTROL gwMB_Text = {"text",GWC_TEXT,1,20,MSGBOX_WIDTH-2,MSGBOX_HEIGHT-46,
							" ",FALSE,TRUE,0,rgbFormBk,GT_CENTER,0,FontsW,rgbBlack,
							NULL,0,NULL,NULL,NULL};

/*
GUI_WINCONTROL gwMB_Text = {"text",GWC_TEXT,1,20,MSGBOX_WIDTH-1,MSGBOX_HEIGHT-22-23,
							" ",FALSE,TRUE,0,rgbFormBk,GT_CENTER,0,FontsW,rgbBlack,
							NULL,0,NULL,NULL,NULL};
*/
GUI_WINCONTROL gwMB_OK = {"MBOK",GWC_BUTTON,14,MSGBOX_HEIGHT-24,40,22,
							"确定",TRUE,TRUE,0,rgbFormBk,GT_CENTER,0,FontsW,rgbBlack,
							NULL,0,NULL,NULL,NULL};

GUI_WINCONTROL gwMB_CANCEL = {"MBCANCEL",GWC_BUTTON,60,MSGBOX_HEIGHT-24,40,22,
							"取消",TRUE,TRUE,0,rgbFormBk,GT_CENTER,0,FontsW,rgbBlack,
							NULL,0,NULL,NULL,NULL};


//Pump Register Mirror


//初始化Q_Msg,给它分配一个信号量
int	InitInputMsgQueue(Q_INPUTMSG* pQ_Msg,NU_SEMAPHORE* pSema_in)
{
	pQ_Msg->iMsgInputFirst= 0;				
	pQ_Msg->iMsgInputLast= 0;
	if(pSema_in)
		pQ_Msg->pSema_input = pSema_in;
	else
		return	ERR_POINTER_EMPTY;
	return	GUI_SUCCESS;
}
//发送Q_Msg,参数包括控件,类型等等
int	SendGMessage(Q_INPUTMSG* pQ_Msg,HWND handle,int iMsgType,int wParam,int lParam)
{
	STATUS	status;
	//if next pointer of Last record equ first,then we think queue is full
	//要保证发送后未Get的Q_Msg不超过MSG_MAX,即最多40个,如果已经满了
	//则不再发送新的Q_Msg,直到里面的消息被Get走
	if(pQ_Msg->iMsgInputFirst !=(( pQ_Msg->iMsgInputLast+1)%MSG_MAX))
		{
		pQ_Msg->GMSG_ARRAY[pQ_Msg->iMsgInputLast].handle = handle;
		pQ_Msg->GMSG_ARRAY[pQ_Msg->iMsgInputLast].msgtype = iMsgType;
		pQ_Msg->GMSG_ARRAY[pQ_Msg->iMsgInputLast].wParam = wParam;
		pQ_Msg->GMSG_ARRAY[pQ_Msg->iMsgInputLast].lParam = lParam;	
		pQ_Msg->iMsgInputLast = ( pQ_Msg->iMsgInputLast+1)%MSG_MAX;
		status = NU_Release_Semaphore(pQ_Msg->pSema_input);
		//这里利用了NuCleus操作系统里的信号量的概念,通过发送信号量来传递消息
		return status;
		}
	else
		return	ERR_MSGINPUTQ_FULL;
}


//收取Q_Msg
int	GetGMessage(PGUI_MSG pmsg,Q_INPUTMSG* pQ_Msg)
{
	STATUS status;
	//首先要获取信号量
	status = NU_Obtain_Semaphore(pQ_Msg->pSema_input,NU_SUSPEND);
	if(NU_SUCCESS == status)
		{
		//if iMsgInputFirst equ iMsgInputLast ,then queue is empty.
		//如果受到的消息是空的,则直接退出
		if(pQ_Msg->iMsgInputFirst != pQ_Msg->iMsgInputLast)
			{
			pmsg->handle   = pQ_Msg->GMSG_ARRAY[pQ_Msg->iMsgInputFirst].handle;
			pmsg->msgtype = pQ_Msg->GMSG_ARRAY[pQ_Msg->iMsgInputFirst].msgtype;	
			pmsg->wParam  = pQ_Msg->GMSG_ARRAY[pQ_Msg->iMsgInputFirst].wParam;	
			pmsg->lParam   = pQ_Msg->GMSG_ARRAY[pQ_Msg->iMsgInputFirst].lParam;
			pQ_Msg->iMsgInputFirst = (pQ_Msg->iMsgInputFirst+1)%MSG_MAX;
			}
		else
			return	ERR_MSGINPUTQ_EMPTY;
		}
	return status;
}


//这个函数是把Form添加到Screen里面,数据以链表的形式联系起来
int	AddFormToScreen(GUI_FORM* pForm,SCR* pScreen)
{
	if((pForm!=NULL)&&(pScreen!=NULL))       //如果pForm和pScreen非空
		{
		pForm->pNextForm= NULL;
		pForm->pPrevForm= NULL;		
		pForm->pScreen = pScreen;		//把pForm里的pScreen指向我们的SCR
	
		if(pScreen->formlink.pLastForm)	//如果链表非空
			{
			pForm->pPrevForm = pScreen->formlink.pLastForm;//把pForm添加到链表的最后
			pScreen->formlink.pLastForm->pNextForm = pForm;
			pScreen->formlink.pLastForm = pForm;
			pForm->pNextForm = NULL;
			}
		else
			//formlink的pLastForm指针为空的话
			//说明该屏的form链中尚无内容
			{
			pScreen->formlink.pFirstForm = pForm;
			//pScreen->formlink.pCurrentForm = NULL;
			//pScreen->formlink.pCurrentForm = pForm;
			pScreen->formlink.pLastForm = pForm;
			pForm->pPrevForm = NULL;
			pForm->pNextForm = NULL;
			}
		//只要pForm是可切换的Form,就把pScreen的当前链表指针指向pForm
		if((NULL == pScreen->formlink.pCurrentForm)&&(GF_NOT_SWITCH!=pForm->type))
			pScreen->formlink.pCurrentForm = pForm;
		}
	else
		return  ERR_POINTER_EMPTY;

	return	GUI_SUCCESS;
}

//这个函数把各种控件添加到Form中
int	AddControlToForm(GUI_FORM* pForm,HWND hwnd)
{
	if((pForm!=NULL)&&(hwnd!=NULL))
		{
		hwnd->pNext = NULL;
		hwnd->pPrev = NULL;		
		hwnd->pOwner = pForm;		//控件的所有者指向pForm
		
		if(pForm->pLastChild)			//如果pForm的链表非空,则把这个控件加入到链表的最后
			{
			hwnd->pPrev = pForm->pLastChild;
			pForm->pLastChild->pNext = hwnd;
			pForm->pLastChild = hwnd;
			hwnd->pNext = NULL;			
			}
		else							//如果链表中没有内容,则把这个控件作为他的第一个内容
			{
			pForm->pFirstChild = hwnd;
			pForm->pLastChild = hwnd;
			hwnd->pNext = NULL;
			hwnd->pPrev = NULL;
			}
		//如果form还没有焦点控件,而hwnd的canfocus
		//为真并且该hwnd是可见的,则将form的焦点控件设为hwnd
		if((NULL == pForm->pFocusChild)&&hwnd->canFocus&&hwnd->visibled)
			pForm->pFocusChild = hwnd;
		}
	else
		return  ERR_POINTER_EMPTY;

	return	GUI_SUCCESS;
}
//初始化SCR控件,包括清空它的Form链表,以及和一个信号量关联
int	InitScr(SCR* pScr,NU_SEMAPHORE* pSema_Lcd)
{
	pScr->iMsgLcdFirst = 0;
	pScr->iMsgLcdLast = 0;
	pScr->formlink.pCurrentForm = NULL;
	pScr->formlink.pFirstForm = NULL;
	pScr->formlink.pLastForm = NULL;
	memset(pScr->framebuffer,0xff,sizeof(pScr->framebuffer));

	//初始化gfMessageBox中的控件
	AddControlToForm(&gfMessageBox, &gwMB_Caption);
	AddControlToForm(&gfMessageBox, &gwMB_Text);
	AddControlToForm(&gfMessageBox, &gwMB_OK);
	AddControlToForm(&gfMessageBox, &gwMB_CANCEL);	
	if(pSema_Lcd)
	{
		pScr->pSema_lcd = pSema_Lcd;
	}
	else
		return	ERR_POINTER_EMPTY;

	return	GUI_SUCCESS;
	
}
//发送LCD消息,以供液晶显示用,即通知液晶任务刷新相应区域
int	SendLcdMessage(SCR* pScr,uint iLeft,uint iTop,uint iWidth,uint iHeight)
{
	STATUS	status;
	if(pScr)
	{
	//要保证发送后未Get的LCD消息不超过MSG_MAX,即最多40个,如果已经满了
	//则不再发送新的LCD消息,直到里面的消息被Get走
		if(pScr->iMsgLcdFirst != ((pScr->iMsgLcdLast+1)%MSG_MAX))
		{
			pScr->LMSG_ARRAY[pScr->iMsgLcdLast].left = iLeft;
			pScr->LMSG_ARRAY[pScr->iMsgLcdLast].top = iTop;
			pScr->LMSG_ARRAY[pScr->iMsgLcdLast].width = iWidth;
			pScr->LMSG_ARRAY[pScr->iMsgLcdLast].height = iHeight;
			pScr->iMsgLcdLast = (pScr->iMsgLcdLast+1)%MSG_MAX;
			status = NU_Release_Semaphore(pScr->pSema_lcd);
			return status;			
		}
		else
			return	ERR_MSGLCD_FULL;
	}
	else
		return	ERR_POINTER_EMPTY;
}

//获取LCD消息,即获取SendLcdMessage发送的信号量
int	GetLcdMessage(LCD_MSG* pmsg,SCR* pScr)
{
	STATUS status;
	status = NU_Obtain_Semaphore(pScr->pSema_lcd,NU_SUSPEND);
	if(NU_SUCCESS == status)
	{
		//if iMsgLcdFirst equ iMsgLcdLast ,then queue is empty.
		//如果发现收到的LCD消息是空的则程序直接退出
		if(pScr->iMsgLcdFirst != pScr->iMsgLcdLast)
		{
			pmsg->left = pScr->LMSG_ARRAY[pScr->iMsgLcdFirst].left;
			pmsg->top = pScr->LMSG_ARRAY[pScr->iMsgLcdFirst].top;
			pmsg->width = pScr->LMSG_ARRAY[pScr->iMsgLcdFirst].width;
			pmsg->height = pScr->LMSG_ARRAY[pScr->iMsgLcdFirst].height;
			pScr->iMsgLcdFirst = (pScr->iMsgLcdFirst+1)%MSG_MAX;
		}
		else
			return	ERR_MSGLCD_EMPTY;
	}
	return status;
}

//显示一个Form
int	FormShow(GUI_FORM*	pForm)
{
	GUI_WINCONTROL*	pWcontrol;
	
	if(pForm)
	{
		//将form所在区域清除成背景颜色,
		//然后重新画边缘和所有控件
		pForm->visibled = TRUE;				//将这个Form设置成可视
		FillRect((SCR*)(pForm->pScreen), pForm->left, pForm->top, pForm->width, pForm->height, &(pForm->backcolor));
		//画出这个Form的外围矩形区域,注意这里仅仅是更新pScreen里的framebuffer
		DrawRect((SCR*)(pForm->pScreen), pForm->left, pForm->top, pForm->width, pForm->height, &RGB_Black);
		//画出这个Form的背景填充色,注意这里也仅仅是更新pScreen里的framebuffer
		pWcontrol = pForm->pFirstChild;
		//依次更新这个Form里的控件,注意这里也仅仅是更新pScreen里的framebuffer
		while(pWcontrol)
		{
			if(pWcontrol->visibled)
			{
				WinControlShowWithoutUpdate(pWcontrol);
			}
			pWcontrol = pWcontrol->pNext;
		}
		//向液晶任务发送消息,包括SCR以及更新的区域
		SendLcdMessage((SCR*)(pForm->pScreen),pForm->left,pForm->top,pForm->width,pForm->height);		
	}
	else 
		return ERR_POINTER_EMPTY;

	return	GUI_SUCCESS;
}


//显示当前SCR里面包含的所有的可以显示的Form
int	AllVisableShow(SCR* pScr)
{
	GUI_FORM*	pForm;

	if(pScr)
	{
		pForm = pScr->formlink.pFirstForm;
		pScr->formlink.pCurrentForm = NULL;
		while(pForm)
		{
			if(pForm->visibled)
			{
				if(GF_COMMON == pForm->type)
				{
					//当该窗口是可切换窗口时
					//将当前窗口设为该窗口
					pScr->formlink.pCurrentForm = pForm;
				
				}

				FormShow(pForm);
			}
			pForm = pForm->pNextForm;
		}
	}
	else
		return	ERR_POINTER_EMPTY;

	return	GUI_SUCCESS;
		
}

//这个函数的功能是,关闭当前显示的Form,而去显示pForm
int	SwitchToForm(SCR* pscr, GUI_FORM* pForm)
{
	
	if(pForm)
		{
			//当前窗口不能是不可切换窗口,
			//所以要切换到的下一个窗口也
			//不可以是不可切换窗口。
			pscr->formlink.pCurrentForm->visibled = FALSE;
			pscr->formlink.pCurrentForm = pForm;
			FormShow(pForm);
			
		}
	else
		return ERR_POINTER_EMPTY;

	return GUI_SUCCESS;
}

//这个函数的功能是,关闭当前显示的Form,而去显示链表中下一个Form,如果
//当前的Form已经是链表中最后一个Form,则去显示第一个Form
int	SwitchToNextForm(SCR* pScr)
{
	GUI_FORM* pForm;
	
	if(pScr)
		{
		pForm = pScr->formlink.pCurrentForm;
		//在AddFormToScreen已经将pCurrentForm初始化
		if(pForm)
			{
			//当前窗口不能是不可切换窗口,
			//所以要切换到的下一个窗口也
			//不可以是不可切换窗口。
			do
				{
				pForm = pForm->pNextForm;
				if(!pForm)
					{
					pForm = pScr->formlink.pFirstForm;
					}
				}
			while((GF_NOT_SWITCH == pForm->type)&&(pForm != pScr->formlink.pCurrentForm));
			pScr->formlink.pCurrentForm->visibled = FALSE;
			pScr->formlink.pCurrentForm = pForm;
			FormShow(pForm);
			}
		}
	else
		return ERR_POINTER_EMPTY;

	return GUI_SUCCESS;
}


//这个函数的功能是,关闭当前显示的Form,而去显示链表中上一个Form,如果
//当前的Form已经是链表中第一个Form,则去显示最后一个Form
int	SwitchToPrevForm(SCR* pScr)
{
	GUI_FORM* pForm;
	
	if(pScr)
		{
		pForm = pScr->formlink.pCurrentForm;
		//在AddFormToScreen已经将pCurrentForm初始化
		if(pForm)
			{
			//当前窗口不能是不可切换窗口,
			//所以要切换到的前一个窗口也
			//不可以是不可切换窗口。
			do
				{
				pForm = pForm->pPrevForm;
				if(!pForm)
					{
					pForm = pScr->formlink.pLastForm;
					}

⌨️ 快捷键说明

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