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

📄 main.c

📁 采用MINIGUI开发的一套GUI界面
💻 C
📖 第 1 页 / 共 2 页
字号:
			{
			
				SendMessage (GetDlgItem(hWnd,LEFT_BUTTON_PAGE),BM_SETSTATE,0,0);
			if(gdisp_mode==STATIC_MODE)	//状态页面上,按页面键返回到浏览页面
				gdisp_mode=1;
        		if(gdisp_mode>1)//当模式为数显,柱图,实时显示可以翻页
				{gchanpage++;
       			if(gchanpage>gchanpage_sum)gchanpage=1;
        			}
       			InvalidateRect(hWnd,NULL,TRUE);//同模式下重绘制显示
       		}
	   if(id==KEY_MODE)  //切换显示模式
			{  
			SendMessage (GetDlgItem(hWnd,LEFT_BUTTON_MODE),BM_SETSTATE,0,0);
			gdisp_mode++;				
       		if(gdisp_mode>4)gdisp_mode=1;
			//当为实时显示模式形式时
			//清除按钮改为缩放按钮
			if(gdisp_mode==4)SetDlgItemText(hWnd,  BOTTOM_BUTTON_CLEA,"缩放\nF4" );
			else if(gdisp_mode==1)SetDlgItemText(hWnd,  BOTTOM_BUTTON_CLEA,"清除\nF4" );
			InvalidateRect(hWnd,NULL,TRUE);//不同模式下重绘制显示
	   		}
           if(id==KEY_HIST)  //进入历史页面
			{  
			SendMessage (GetDlgItem(hWnd,LEFT_BUTTON_HIST),BM_SETSTATE,0,0);
			//last_mode=gdisp_mode;
			last_mode= disp_mode;
			disp_mode=HIST_MODE;
			  sprintf(topinfo,"历史%2d/%2d/%2d",year,mont,days);	
			 HistoryDlg(hWnd);	//显示历史页面
			disp_mode=last_mode;
			 
  		 
 			//页面刷新
			 	
     	 		 }		
		if(id==KEY_EVENT)  
			{
			SendMessage (GetDlgItem(hWnd,LEFT_BUTTON_EVEN),BM_SETSTATE,0,0);
			sprintf(topinfo,"报警事件      " );
				
				last_mode=disp_mode;
				gdisp_mode= ALERT_MODE;
			DlgConfAlert(hWnd);	
			disp_mode=last_mode;
			}
		if(id==KEY_STAT)  
			{   
			SendMessage (GetDlgItem(hWnd,LEFT_BUTTON_STAT),BM_SETSTATE,0,0);
				 //切换状态查询模式
				sprintf(topinfo,"状态查询      " );		 
		  	 	 
				last_mode=gdisp_mode;
				gdisp_mode= STATIC_MODE;
				//按页面键返回到浏览页面
				//按模式键切换到DI,DO 状态等
				
 			}
		if(id==KEY_EXIT)  
			{   
			SendMessage (GetDlgItem(hWnd,LEFT_BUTTON_EXIT),BM_SETSTATE,0,0);


			}


}
/*
说明: wait_flag为异步中断产生标志
RecvLength:本次通讯接收的数据长度
RecvBuf:接收缓冲区
Commfd2:串口句柄
*/
void  CommFunc(void)
{	 
	int readlen;
	int lastreadlen=0;
  	RecvLength=0;	
     while(1)
      { 
          while ((wait_flag==0)) //串口中断后wait_flag==0
           { 
		printf("w...");
		readlen = read(Commfd2, RecvBuf+RecvLength, 1000); 
		//printf("readlen=%d ",readlen);	
		RecvLength=readlen+RecvLength; 
		if(((readlen>0)&&(readlen<20))||((lastreadlen!=0)&&(readlen==0)))
			{
			lastreadlen=readlen;
			//printf("lastreadlen=%d ",lastreadlen);
			if(!devices_registed)  
				{
					
				//	DeviceRegist();//注册devices
					//devices_registed=1;
				}
			else 
				{
			/*	if(!channel_registed)
					{
					}
			   	else
					{}
				
				 if(!b_wr_config)
						GotPV();// 定时读取PV
			 	else {
					if(RecvBuf[1]==0x03)GotConf();//得到所有参数
					if(RecvBuf[1]==0x06)CheckSetConf();//校验组态设定是否成功
					//

			 		}*/
				
				}
			   	//ReceiveASCII (readlen); 	  //ASCII数据处理
			         //等待下一个串口中断
			  	//得到 PV值后通知minigui更新实时显示的数值
			 RecvLength=0;
       		}
		//RTU判断
		if(readlen>0)	
			{
			//ReceiveRTU(readlen);	//
		    //  	PostMessage(gMainWnd,MSG_COM,0,0) ; //表示成功接收,需要更新数据
			} 
		wait_flag = 1;
	    }	
	}
}

int MiniGUIMain (int args, const char* arg[])
{
    MSG Msg;   
    HWND hMainWnd;
	MAINWINCREATE window_info;  
pthread_t thread;
int i,ret;


	
#ifdef _LITE_VERSION
    int i;
    const char* layer = NULL;
    RECT max_rect = {0, 0, 0, 0};

    for (i = 1; i < args; i++) {
        if (strcmp (arg[i], "-layer") == 0) {
            layer = arg[i + 1];
            break;
        }
    }

    GetLayerInfo (layer, &max_rect, NULL, NULL, NULL);

    if (JoinLayer (layer, arg[0], 
                max_rect.left, max_rect.top, 
                max_rect.left + 1024, 
                max_rect.top + 768) == INV_LAYER_HANDLE) {
        printf ("JoinLayer: invalid layer handle.\n");
        return 1;
    }
#endif

	if (!InitMiniGUIExt()) {
        return 2;
	}//WS_BORDER  WS_CAPTION
window_info.dwStyle       = WS_VISIBLE ;
window_info.dwExStyle   = WS_EX_NONE;
window_info.spCaption     = "wideplus";
window_info.hMenu        = 0;
window_info.hCursor       = GetSystemCursor(0);
window_info.hIcon        = 0;
window_info.MainWindowProc   = MainWinProc;
window_info.lx              = 0;
window_info.ty             = 0;
window_info.rx             = WIDTH;
window_info.by             = HEIGHT;
window_info.iBkColor       = COLOR_darkblue;
window_info.dwAddData  = 0;
window_info.hHosting      = HWND_DESKTOP;

hMainWnd         = CreateMainWindow(&window_info);

if (hMainWnd == HWND_INVALID)return(0);
gMainWnd=hMainWnd;
 ShowWindow(hMainWnd, SW_SHOWNORMAL);
ret=pthread_create(&thread,NULL,(void*)CommFunc,NULL);
if(ret!=0){
printf ("Create pthread error!\n");
}
else
	printf("Create pthread ok!\n");




while (GetMessage(&Msg, hMainWnd))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
MainWindowThreadCleanup(hMainWnd);
  return(0);
}

#ifndef _LITE_VERSION
#include <minigui/dti.c>
#endif

static void ExitSystem (HWND hWnd, int id) 
{
    KillTimer(hWnd,_ID_TIMER); 
    if (MessageBox (hWnd, 
            "确定要退出系统吗?", 
            "退出系统", 
            MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2) == IDYES)
            {
       SendMessage (hWnd, MSG_CLOSE, 0, 0L);	   
    		}  
}


 void CreateBottom(HWND hWnd)
{	
     int i;
    for(i=0; i<dim(CtrlhBottom);i++){
        		CtrlhBottom[i].hwndControl =  CreateWindow(
                 CtrlhBottom[i].spClassName,
		             CtrlhBottom[i].spCaption,
		             WS_CHILD|CtrlhBottom[i].dwStyle ,
		             CtrlhBottom[i].conID,
		             CtrlhBottom[i].conx,
		             CtrlhBottom[i].cony,
		             CtrlhBottom[i].conw,
		             CtrlhBottom[i].conh,
		             hWnd,
		             0);		
                 }
	
	
}
  void ShowBottom(HWND hWnd)
{int i;

for(i=0;i<dim(CtrlhBottom);i++) 
		 {
		ShowWindow(CtrlhBottom[i].hwndControl,SW_SHOW); 
		} 
}
  
 
void HideBottom(HWND hWnd)
{
	int i;
	for(i=0;i<dim(CtrlhBottom);i++) 
	   {
               ShowWindow(CtrlhBottom[i].hwndControl,SW_HIDE); 
     } 
}

void CreateLeft(HWND hWnd)
{int i;
    for(i=0; i<dim(CtrlhLeft);i++){
        		CtrlhLeft[i].hwndControl =  CreateWindow(
                 CtrlhLeft[i].spClassName,
		             CtrlhLeft[i].spCaption,
		             WS_CHILD|CtrlhLeft[i].dwStyle ,
		             CtrlhLeft[i].conID,
		             CtrlhLeft[i].conx,
		             CtrlhLeft[i].cony,
		             CtrlhLeft[i].conw,
		             CtrlhLeft[i].conh,
		             hWnd,
		             0);		
                 }

}
  void ShowLeft(HWND hWnd)
{int i;


	
	for(i=0;i<dim(CtrlhLeft);i++) 
		 {
		ShowWindow(CtrlhLeft[i].hwndControl,SW_SHOW); 
		} 
}
  
void HideLeftButton(HWND hWnd)
{
	int i;
	for(i=0;i<dim(CtrlhLeft);i++) 
	   {
               ShowWindow(CtrlhLeft[i].hwndControl,SW_HIDE); 
     } 
}


//得到系统时间,
//   在MSG_TIMER  (定时显示)中调用
void GetTime( HWND hWnd)
{  
	time_t t;
	struct tm* tm;
  	time(&t);  
  	nowseconds=(long)t;//保存当前秒数
   	if((bLeftShow)&&(nowseconds-oldseconds)>10)
  	{
  	bLeftShow=0;//左侧菜单10秒后自动消失
	HideLeftButton(hWnd);
	bFreshtop=1;//更新TOPBAR
	SendMessage(GetActiveWindow(),MSG_USER1,0,0) ;
	InvalidateRect(hWnd,NULL,TRUE);
  	}
  	tm = localtime(&t); 
	if((hour!=tm->tm_hour)||(seco!=tm->tm_sec))
 	 sprintf(str_time, "     %02d:%02d:%02d",tm->tm_hour,tm->tm_min,
	 tm->tm_sec);
	  if((days!=tm->tm_mday)||(mont!=tm->tm_mon))
	  sprintf(str_date, " %02d/%02d/%02d",tm->tm_year+1900, tm->tm_mon+1,
		  tm->tm_mday);
	  if(minu!=tm->tm_min)
	  	{CheckMemory();
	  	}
  	year  =(BYTE)tm->tm_year+1900;
	mont = (BYTE)tm->tm_mon+1;
	 days= (BYTE)tm->tm_mday;
	hour  =(BYTE)tm->tm_hour;
	minu=  (BYTE)tm->tm_min;
	seco= (BYTE) tm->tm_sec;
}
//检测所有通道的是否报警
int  DetectAlarm(void)
{    
		int ipv;
		int LL,L,H,HH;
		int id;
		static int speed;
		int alarm_type;
for (id=0;id<gchannum;id++) 	
  	{
	channel_disp[id].point[RealIndex]=GetCurveHeight(id);
	ipv=channel_disp[id].fpv;
	HH=(int)channel_conf[id].hh_alarm;
	H= (int)channel_conf[id].h_alarm;	
	L=(int) channel_conf[id].l_alarm;	  	
	LL= (int)channel_conf[id].ll_alarm;	  	
 	//channel_disp[id].color_old=channel_disp[id].color;
//	if(ipv < L)
//	channel_disp[id].color=PIXEL_red; //RGB2Pixel(hmemDC,id*30,128,abs(8-id)*64)
//	else	if(ipv > H)channel_disp[id].color=PIXEL_yellow; 
//	 else channel_disp[id].color=channel_disp[id].color_old; 
	//判断是否报警登陆
 	alarm_id_type=GetAlarmType(id);//得到报警类型
//if((alarm_id_type%7)!=6) printf("alarm_id_type=%d\n",alarm_id_type);
	//if(channel_disp[id].line1_job1==ON_ALARM)
	//deal_alarm_report(GetDlgItem (hDlg, IDC_ALERT_LIST),alarm_type) ;	
}


}

// 更新状态栏
void FreshTopPage(HDC hdc)
{
   HDC   hmemDC;
  
hmemDC=hdc;
	//hmemDC=CreateCompatibleDC(hdc);  
  //	SetBrushColor(hmemDC,PIXEL_lightwhite);
    //  SetBkMode(hmemDC,BM_TRANSPARENT);
  //    FillBox(hmemDC,0,0,WIDTH-LEFT,TOP);	

	//左上产品标志显示区

	SetBrushColor(hmemDC,PIXEL_darkgreen);    
	FillBox(hmemDC,0,0,80,40);	
	SelectFont(hmemDC,song26font);
	
       SetTextColor(hmemDC,PIXEL_lightwhite);
	SetBkColor(hmemDC,PIXEL_darkgreen);
       TextOut(hmemDC, 12, 10, STR_DEMO);

	      if(bFreshtop)	  
      {
      		SetBrushColor(hdc,PIXEL_lightwhite);    
      		FillBox(hdc,480,2,156,36);	
      		bFreshtop=0;
      }

		  
FillBoxWithBitmap(hmemDC,444,4,32,32,&save_bmp);
	//显示存储量
	SetBkColor(hmemDC,PIXEL_darkblue);
	
	SelectFont(hmemDC,helfont14);
	SetBrushColor(hmemDC,PIXEL_darkblue);    
	FillBox(hmemDC,482,21,38,16);
	SetBrushColor(hmemDC,PIXEL_darkblue);    
	FillBox(hmemDC,482,21,38,16);
	strcpy(memo," 37%");
	TextOut(hmemDC, 482, 01, " mem ");
	TextOut(hmemDC, 482, 18, memo);
	
	SetTextColor(hmemDC,PIXEL_lightwhite);
       TextOut(hmemDC, 522, 01, "even");
	   strcpy(memo,"51% ");
	TextOut(hmemDC, 522, 18, memo);
	

	
	
       //右上时间显示区
      

	FillBox(hmemDC,558,04,78,16);
	FillBox(hmemDC,558,21,78,16);
	SetTextColor(hmemDC,PIXEL_lightwhite);		
      	 TextOut(hmemDC, 558, 18, str_time);

	 TextOut(hmemDC, 558, 01, str_date);		 
	 //根据不同显示模式下页面更新内容
 	
	
//	BitBlt(hmemDC,0,0,WIDTH-LEFT,TOP,hdc,0,0,0);
 //	DeleteCompatibleDC(hmemDC);		 

}


//输入:是否有左侧菜单
// 		是否已经弹出底侧菜单
//设定要更新的显示区域
void SetFreshZero(void )
{
int addr_x,addr_h;
if(bLeftShow)addr_x=LEFT;
			else			addr_x=0;
			if(bDoorOpen)	addr_h=HEIGHT-TOP-BOTTOM;
			else    addr_h=HEIGHT-TOP;

	 if(gdisp_mode>0) 
			 	{
			 	SetRect (&top_rect, addr_x,0,640,addr_h);
	 		
				}
		 else  //gdisp_mode=0表示为组态页面
		 	{
		 	if(bfresh_conf==1)
			{	SetRect (&top_rect, 0,0,440,40);			
        		     
		 	}
			else SetRect (&top_rect, 440,0,640,40);	
				
		 	}

}
/*

更新显示区



*/
void FreshDispZero(HDC hdc)
{
	static 	int 		chan_num=0;
	unsigned char 	buf[20];
	unsigned int x,h;
	int mode;
	int page;
	mode=gdisp_mode;
	page=gchanpage;
		  
	if(bLeftShow)x=LEFT; 
			else			x=0;
			if(bDoorOpen)	h=HEIGHT-TOP-BOTTOM;
			else    h=HEIGHT-TOP;	

			
    if(gdisp_mode==PACT_MODE)
			{
			strcpy(buf,"总览 ");
			TextOut(hdc, 200,8, buf);	
			//同模式下根据通道页面显示gchanpage
			//根据按钮是否出来的情况来显示
		 	SetCoordinate(0,13,x,h);	
                   	DrawDigital(hdc,0,13,x,h);
			}	
       else  if(gdisp_mode==DIGITAL_MODE)
			{
			//一个页面显示PCHAN_MAX个通道
			//  13 个通道 gchanpage_sum=3,     gchanpage

⌨️ 快捷键说明

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