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

📄 config.c

📁 采用MINIGUI开发的一套GUI界面
💻 C
字号:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <pwd.h>
#include <math.h>
#include <minigui/common.h>
#include <minigui/minigui.h>
#include <minigui/gdi.h>
#include <minigui/window.h>
#include <minigui/control.h>
#include <sys/types.h>
#include <sys/shm.h>
#include <sys/ipc.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "common.h"
#include "fonts.h"
#include "config.h"
#include "serial.h"
  void ShowC1Left(HWND hDlg)
{int i;
bLeftShow=1;
oldseconds=nowseconds;//记住当前时间

for(i=0; i<6;i++)
	
	ShowWindow(GetDlgItem (hDlg, CONF_UP+i),SW_SHOW) ;

}
  
void HideC1Left(HWND hDlg)
{
int i;
for(i=0; i<6;i++)
	ShowWindow(GetDlgItem (hDlg, CONF_UP+i),SW_HIDE) ;
}


//响应组态按扭
void ShowConfDlg (HWND hWnd  ,int id2)
{
int id;
	id=id2;
	
	if(id==CONF_BUT_CHAN)
             {
          SendMessage( GetDlgItem(hWnd,CONF_BUT_CHAN),BM_SETSTATE,0,0 );
    

	 	 strcpy(topinfo,"组态    通道            ");	
		 bfresh_conf=1;	
		DlgConfAi(hWnd);
	 	strcpy(topinfo,"组态                     ");	
		bfresh_conf=1;

	      }
	if(id==CONF_BUT_DISP)
	{
       	SendMessage( GetDlgItem(hWnd,CONF_BUT_DISP) ,BM_SETSTATE,0,0 );
	 	strcpy(topinfo,"组态    显示             ");	
		bfresh_conf=1;
		
        	DlgConfDisp(hWnd);
			
	 	strcpy(topinfo,"组态                      ");	
		bfresh_conf=1;
         	}
	if(id==CONF_BUT_TOOL)
		{
  		 SendMessage( GetDlgItem(hWnd,CONF_BUT_TOOL) ,BM_SETSTATE,0,0 );
		strcpy(topinfo,"组态     工具配置");		
		bfresh_conf=1;	
		DlgConfToolTimer(hWnd);
		strcpy(topinfo,"组态                        ");	
	 	bfresh_conf=1;
    	}
 	if(id==CONF_BUT_METE)
 		{
  		 SendMessage( GetDlgItem(hWnd,CONF_BUT_METE) ,BM_SETSTATE,0,0 );
 		
 		strcpy(topinfo,"组态     板卡  ");			
		bfresh_conf=1;
		//FluxMeterCom();
		//SetBourate(4800);
 		   
                DlgMeterConf(hWnd);	
		printf("gdisp_mode=%d\n",gdisp_mode);
		strcpy(topinfo,"组态                          ");	
		bfresh_conf=1;
		}
	 if(id==CONF_BUT_CUMUL)
          {
  		 SendMessage( GetDlgItem(hWnd,CONF_BUT_CUMUL) ,BM_SETSTATE,0,0 );
          
			 strcpy(topinfo,"组态     累积          ");		
			 bfresh_conf=1;
			 DlgCumul(hWnd);
			 strcpy(topinfo,"组态                    ");	
			 bfresh_conf=1;
			 }
	 if(id==CONF_BUT_EQUIP)
			{
			
   		 SendMessage( GetDlgItem(hWnd,CONF_BUT_EQUIP) ,BM_SETSTATE,0,0 );
				strcpy(topinfo,"组态     装置设定    ");		
				bfresh_conf=1;
				DlgConfEquip(hWnd);
				 strcpy(topinfo,"组态                       ");	
				bfresh_conf=1;//设定对话框返回时刷新组态总页面
				
			 }
      if(id==CONF_BUT_TIME)
           	{
 		strcpy(topinfo,"组态    时间日期    ");		
		bfresh_conf=1;
		DlgConfTime(hWnd);	
		strcpy(topinfo,"组态                         ");	
		 bfresh_conf=1;
		
		}
	if(id==CONF_BUT_SYST)
         {
			 strcpy(topinfo,"组态     系统信息");		
			 bfresh_conf=1;
			DlgConfSystem(hWnd);  			
		strcpy(topinfo,"组态                      ");	
		bfresh_conf=1;
	}


}

void FreshConfPage(HDC hWnd)
{
   HDC  hdc,hmemDC;
  gal_pixel back_color;
  unsigned char str_conf_txt[20];
  
  hdc=GetClientDC(hWnd);
	hmemDC=CreateCompatibleDC(hdc);  
  	SetBrushColor(hmemDC,PIXEL_lightwhite);
      SetBkMode(hmemDC,BM_TRANSPARENT);
      FillBox(hmemDC,0,0,WIDTH-LEFT,HEIGHT-TOP-BOTTOM);		
	
	back_color=RGB2Pixel(hmemDC,0,128,0);
  	SetBrushColor(hmemDC,back_color);
  	FillBox(hmemDC,0, 0,WIDTH-LEFT,120);
		back_color=RGB2Pixel(hmemDC,255,255,0);//黄色
              SetBrushColor(hmemDC,back_color);
              FillBox(hmemDC,0, 120,WIDTH-LEFT,300);
			  
  	SelectFont(hmemDC,song26font);
   	SetTextColor(hmemDC,PIXEL_lightwhite);
   	 SetBkColor(hmemDC,back_color);
   	sprintf(str_conf_txt,"%s","  组 态设定");//strcpy(buf,"DI       ");
 	TextOut(hmemDC,160,50,str_conf_txt);
	
	BitBlt(hmemDC,0,0,WIDTH,HEIGHT-TOP-BOTTOM,hdc,LEFT,TOP,0);
 	DeleteCompatibleDC(hmemDC);		 
	ReleaseDC(hdc);
}


int  ConfDialogProc (HWND hDlg, int message, WPARAM wParam, LPARAM lParam)
{  gal_pixel back_color;
  unsigned char str_conf_txt[20];
HDC hdc,hmemDC;
    static int ctrl_conf_id;//按键ID号或者是文本焦点号码
static int conf_rectx;
   int id; 
    id= LOWORD (wParam);
    switch (message) 
    { 
    case MSG_INITDIALOG:		

		
		
		 ctrl_conf_id=CONF_BUT_CHAN; 
  		SetFocusChild( GetDlgItem(hDlg,CONF_BUT_CHAN));

		
	return 1;
	  case MSG_SHOWWINDOW:
			{  
				
		      }  		      
		 break;       	        
	 case MSG_USER1: 
	 	printf("MSG_USER1!\n");
		HideC1Left(hDlg);
	 	break;	
		
	case MSG_PAINT:
    		hdc = BeginPaint(hDlg);  
			
		if( !bLeftShow) 
			{
			conf_rectx=0;
		 HideC1Left( hDlg);
			}
		else
			{
			conf_rectx=LEFT;
		 ShowC1Left( hDlg);
			}
		
         	hmemDC=CreateCompatibleDC(hdc); 
    SetBrushColor(hmemDC,PIXEL_lightwhite);
      SetBkMode(hmemDC,BM_TRANSPARENT);
	  
      FillBox(hmemDC,0,0,WIDTH-conf_rectx,HEIGHT-TOP-BOTTOM);		
	
	back_color=RGB2Pixel(hmemDC,0,128,0);
  	SetBrushColor(hmemDC,back_color);
  	FillBox(hmemDC,0, 0,WIDTH-conf_rectx,120);
		
  		back_color=RGB2Pixel(hmemDC,255,255,0);//黄色
              SetBrushColor(hmemDC,back_color);
              FillBox(hmemDC,0, 120,WIDTH-conf_rectx,300);
			  
  	SelectFont(hmemDC,song26font);
   	SetTextColor(hmemDC,PIXEL_lightwhite);
   	 SetBkColor(hmemDC,back_color);
   	sprintf(str_conf_txt,"%s","  组 态设定");//strcpy(buf,"DI       ");
 	TextOut(hmemDC,160,50,str_conf_txt);
	
	BitBlt(hmemDC,0,0,WIDTH-conf_rectx,HEIGHT-TOP-BOTTOM,hdc,0,0,0);

	
             		//PIXEL_lightgreen;//RGB2Pixel(hmemDC,0,0,255);//文字颜色	 
   /*             	SetBrushColor(hmemDC,PIXEL_darkgreen);//lightwhite
                	SetBkMode(hmemDC,BM_TRANSPARENT);//?   SetBkMode
               	FillBox(hmemDC,0,0,WIDTH-LEFT,400);
			SetBrushColor(hmemDC,PIXEL_yellow);
    			FillBox(hmemDC,0,0,560,120);*/
     //           BitBlt(hmemDC,0,0,WIDTH-LEFT,HEIGHT-TOP-BOTTOM,hdc,LEFT,0,0);
                DeleteCompatibleDC(hmemDC);   
		//----------------------------------		
               /* 	SetTextColor(hdc,PIXEL_black);
     	      		SetBkColor(hdc,PIXEL_lightgray);
     			SelectFont(hdc,songgb16font);
                	SetTextColor(hdc,PIXEL_black);
     	      		SetBkColor(hdc,PIXEL_lightgray);
	    		TextOut(hdc, 160,413, "年");
			TextOut(hdc, 240,413, "月");
	    		TextOut(hdc, 320,413, "日");
			TextOut(hdc, 400,413, "时");
			TextOut(hdc, 480,413, "分");
*/			
     		EndPaint(hDlg,hdc);
    
		
		 break; 
		 
	case MSG_KEYDOWN:
		
	if(!keydowned)
		{
	if(id==KEY_LEFT)			SendDlgItemMessage(hDlg, CONF_LEFT, MSG_LBUTTONDOWN, 0,0);
	if(id==KEY_RIGHT)		SendDlgItemMessage(hDlg, CONF_RIGHT, MSG_LBUTTONDOWN, 0,0);
	if(id==KEY_UP)			SendDlgItemMessage(hDlg, CONF_UP, MSG_LBUTTONDOWN, 0,0);
	if(id==KEY_DOWN)		SendDlgItemMessage(hDlg, CONF_DOWN, MSG_LBUTTONDOWN, 0,0);
	 if(id==KEY_ENTER)		SendDlgItemMessage(hDlg, CONF_ENTER, MSG_LBUTTONDOWN, 0,0);
		keydowned=1; 
		}
	  break;	
	

	
	 case MSG_KEYUP:
	{
//SetFocusChild( GetDlgItem(hWnd,ctrl_conf_id+CONF_BUT_CHAN));
		keydowned=0;

			if(	(id==KEY_LEFT)||(id==KEY_RIGHT)||
					(id==KEY_UP)||(id==KEY_DOWN)||
					(id==KEY_ENTER)||(id==KEY_EXIT))
		ShowC1Left( hDlg);


		if(id==KEY_EXIT)  		EndDialog (hDlg, 0);
	if(id==KEY_LEFT)		
		{
		SendDlgItemMessage(hDlg, CONF_LEFT, MSG_LBUTTONUP, 0,0);
		ctrl_conf_id=conf_id_left[ctrl_conf_id-CONF_BUT_CHAN];
		SetFocusChild( GetDlgItem(hDlg,ctrl_conf_id));
		}
	if(id==KEY_RIGHT)	
		{
		SendDlgItemMessage(hDlg, CONF_RIGHT, MSG_LBUTTONUP, 0,0);
		ctrl_conf_id=conf_id_right[ctrl_conf_id-CONF_BUT_CHAN];
		SetFocusChild( GetDlgItem(hDlg,ctrl_conf_id));
		}
	if(id==KEY_UP)	
		{
		SendDlgItemMessage(hDlg, CONF_UP, MSG_LBUTTONUP, 0,0);
		ctrl_conf_id=conf_id_up[ctrl_conf_id-CONF_BUT_CHAN];
		SetFocusChild( GetDlgItem(hDlg,ctrl_conf_id));
		}
	if(id==KEY_DOWN)	
		{
		SendDlgItemMessage(hDlg, CONF_DOWN, MSG_LBUTTONUP, 0,0);
		ctrl_conf_id=conf_id_down[ctrl_conf_id-CONF_BUT_CHAN];
		SetFocusChild( GetDlgItem(hDlg,ctrl_conf_id));
		}
	 if(id==KEY_ENTER)	
	 	{
	 	SendDlgItemMessage(hDlg, CONF_ENTER, MSG_LBUTTONUP, 0,0);
		//SendMessage(hDlg,MSG_COMMAND,ctrl_conf_id,0);
		ShowConfDlg (  hDlg  ,ctrl_conf_id);
	 	}
	 if(id==KEY_SAVE)			
	 	SendDlgItemMessage(hDlg,  CONF_SAVE, BM_SETSTATE, 0,0);
	 if(id==KEY_LOAD)			SendDlgItemMessage(hDlg,  CONF_LOAD, BM_SETSTATE, 0,0);
	 if(id==KEY_DEFAULT)		SendDlgItemMessage(hDlg,  CONF_DEFAULT, BM_SETSTATE, 0,0);
	 if(id==SCANCODE_F2)		
	 	{
	 	SendDlgItemMessage(hDlg,  CONF_DBACK, BM_SETSTATE, 0,0);
		EndDialog (hDlg, 0);
	 	}
		
	 	}
		  break;	
	case MSG_COMMAND:
       {       
	   	  


	   
     if(id==CONF_DBACK) EndDialog (hDlg, 0);


	 
	}
	break;
	case MSG_DESTROY :			
			DestroyAllControls(hDlg);
			bLeftShow=1;
		break;	
    case MSG_CLOSE:
	
		
		EndDialog (hDlg, 0);

	break;
    	}
   	 return DefaultDialogProc (hDlg, message, wParam, lParam);
    

}
/*
组态总页面

*/
void  DlgConf  (HWND hWnd)
{
    DlgConfig.controls = ctrl_conf_but;
    
    DialogBoxIndirectParam (&DlgConfig, hWnd, ConfDialogProc, 0L);
}
//--------------------------------------------------------
//操作页面初始化
/*





*/
void InitOperateDlg(HWND hDlg)
{
 	const   unsigned char *operate_job[]={
	"启动DO","启动AO","启动DO",
	"启动定时器","启动计数器","启动累加器",
	"不动作"
	};  	
 	unsigned char i;
	 unsigned char str[10];

     for (i=0;i<=6;i++){
	 SendDlgItemMessage(hDlg,BOX_CHOOSE,LB_ADDSTRING,0,(LPARAM)operate_job[i]);
     	}
	   for (i=0;i<=6;i++){
	   	 sprintf(str,"%02d",i);
	 SendDlgItemMessage(hDlg,BOX_CONTENT,LB_ADDSTRING,0,(LPARAM)str);
     	}
     for (i=0;i<=6;i++){
	 		 sprintf(str,"%s %02d",operate_job[i],i);
	 SendDlgItemMessage(hDlg,BOX_CHOOSED,LB_ADDSTRING,0,(LPARAM)str);
     	}

}


 
/*操作按钮弹出的对话框*/
int  OperateDialogProc (HWND hDlg, int message, WPARAM wParam, LPARAM lParam)
{
HDC hdc,hmemDC;
   int id; 
    LISTBOXITEMINFO lbii;
   static HICON hIcon1;
   char tempStr[12];
    id= LOWORD (wParam);
	
    switch (message) 
    { 
    	case MSG_INITDIALOG:		
		InitOperateDlg(hDlg);  

 
		return 1;
	  case MSG_SHOWWINDOW:
			{  
		      }  		      
		 break;       	        
	case MSG_PAINT:
			hdc = BeginPaint(hDlg);  
	              SetTextColor(hdc,PIXEL_black);
     	      		SetBkColor(hdc,PIXEL_lightgray);
     			SelectFont(hdc,songgb16font);
                	SetTextColor(hdc,PIXEL_black);
     	      		SetBkColor(hdc,PIXEL_lightgray);
					
			TextOut(hdc, OPERATE_X1,OPERATE_Y1-30, "选择类型:");
	    		TextOut(hdc, OPERATE_X2,OPERATE_Y1-30, "具体项:");
			TextOut(hdc, OPERATE_X3,OPERATE_Y1-30, "操作列表:");

			

			
			EndPaint(hDlg,hdc);		
		 break;    
	case MSG_KEYDOWN:
	 
		  break;	
case MSG_KEYUP:
	  	 if(id==KEY_EXIT)  		EndDialog (hDlg, 0);
		  break;	

		
	case MSG_COMMAND:
       	{  
		if(id==BN_CANCEL)EndDialog (hDlg, 0);
			
		}
		break;
case MSG_DESTROY :			
			DestroyAllControls(hDlg);
			
		break;		
    case MSG_CLOSE:		
		EndDialog (hDlg, 0);

		break;
    	}
   	 return DefaultDialogProc (hDlg, message, wParam, lParam);
    
}
/*
下载页面
根据通道号码,时间
下载历史数据到U盘

*/
 void  DlgConfOperate  (HWND hWnd)
{
    DlgOperate.controls = ctrl_Operate;
    
    DialogBoxIndirectParam (&DlgOperate, hWnd, OperateDialogProc, 0L);
}



⌨️ 快捷键说明

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