📄 minigui.txt
字号:
/*****************************************************************************************
** 实验程之曲线动态显示
**
**--------------文件信息--------------------------------------------------------------------------------
**文 件 名: qx.C
**创 建 人:
**最后修改日期: 2006年2月9日
**描 述: 一个简单的画曲线程序,用于对采集的数据进行图形方式显示
********************************************************************************************************/
#include <stdio.h>
#include <string.h>
#include <minigui/common.h>
#include <minigui/minigui.h>
#include <minigui/gdi.h>
#include <minigui/window.h>
#include <minigui/control.h>//控件的头文件
#include <pthread.h> //线程头文件
//----------------------------网络头文件--------------------
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <netdb.h>
#include <netinet/in.h>
//********************************控件定义及消息定义 ***********************************************************
#define IDC_STATIC 100
#define IDC_SELEL 110
#define IDC_STAT 120 //标签框的ID
#define IDC_EDIT 160 //刷新标签框的ID
#define IDC_STAT1 121
#define MSG_MY1 (MSG_USER+1) //自定义 加一消息
#define MSG_MY2 (MSG_USER+2) //自定义 减一消息
//********************************控制过程参数定义 *************************************************************
#define TIME_CAIJI 200 //采集时间2秒
#define TIME_SHUAXIN 200 //刷新显示时间2秒
#define TIME_BAOCUN 400 //保存数据时间间隔
#define QUXIANSHU 4 //曲线数量
#define LIANJIEDIANSHU 20 //构成曲线的点数
#define WIDTH 100 //曲线屏的宽度
#define HEIGHT 60 //曲线屏的高度
#define XINHAO_MAICHONG 1 //信号类型为脉冲
#define XINHAO_MONI_1_5V 2 //信号类型为模拟0-5V
#define XINHAO_MONI_0_5V 3 //信号类型为模拟1-5V
#define XINHAO_MONI_0_3V 4 //信号类型为模拟0-3V
#define XINHAO_SHUZI 5 //信号类型为数字信号
//--------------------------------------------网络端口定义-----------------------------
#define RECEIVER_PORT 40 //指定接收端口
#define SENDER_PORT 41 //指定发送端口
#define BACKLOG 100
#define BUFSIZE 100
#define MAXSELECT 100
#define MAXSIZE 80
//------------------------------------------------------------------------
#define BUFFER_SIZE 400
//************************************定义类型*******************************************************************
typedef struct huaxian_type{ //定义曲线函数参数类型
float Max[QUXIANSHU];
float Min[QUXIANSHU];
float LeiJi[QUXIANSHU][LIANJIEDIANSHU];
int dian;
HDC XC_hdc;
}HUAXIAN, *PHUAXIAN;
//------------
typedef struct miniInit_type{ //初始化函数参数类型
HWND hStaticP[8];
HWND hStaticT[8];
HWND hStaticS[8];
HWND hStaticM[8];
HWND hEditP[8];
HWND hEditT[8];
HWND hEditS[8];
HWND hEditM[8];
char * mingcheng[32]; //标签名
BITMAP bmp_TX; //图象
BITMAP bmp_WB;
} MINIINIT, *PMINIINIT;
//----------------
typedef struct Maxmin{ //初始化函数参数类型
float Max[32];
float Min[32];
} MAXMIN, *PMAXMIN;
//--------------------------------------- //线程共享数据区结构
struct prodcons { //定义结构类型
char * buffer[BUFFER_SIZE]; /* 缓冲区 */
pthread_mutex_t lock; /* 互斥量 */
int readpos, writepos; /* 读写指针 */
pthread_cond_t notempty; /* 信号不空条件 */
pthread_cond_t notfull; /* 信号不满条件*/
};
//*************************************定义全局变量***************************************************************
static float XinHaoMax[QUXIANSHU]; //信号上限
static float XinHaoMin[QUXIANSHU]; //信号下限
static float ShunShi[QUXIANSHU][LIANJIEDIANSHU]; //瞬时量
static float Leiji[QUXIANSHU][LIANJIEDIANSHU]; //累积量
static float YuanShiLeiji[QUXIANSHU][LIANJIEDIANSHU]; //原始累积量
static LOGFONT *logfontgb12; //定义字体用于显示中文
static int jishu; //计数用
static char ji[1]; //控件显示计数值用
char *oooo="中国人"; //字符串
int Xs_Fs; //显示方式
pthread_t th_a; //定义线程
//---------------------------
int client[MAXSELECT];
int sockfd,con_fd,sock,unmbytes,ret,maxfd,maxi,i,nready,len;
fd_set allset,rset;
struct sockaddr_in my_addr;
struct sockaddr_in their_addr;
int sin_size;
char recvs[MAXSIZE];
char * buf;
struct hostent *hp;
struct prodcons buffer; //定义变量为新定义的类型共享数据区
//创建监听套接字
//------------------------------------
//*************************************定义全局函数***************************************************************
static PMINIINIT InitMiniQX(HWND hwnd); //程序初始化
static void huaxian(PHUAXIAN pHuanXian); //内存中画曲线
static void BaoCun(void); //参数保存
static void Show(PMINIINIT Xianshi,int panduan); //控件是否显示
static PMAXMIN CanShu(PMAXMIN zuizhi,int fls); //参数保存和提取
static void * producer(void * data); //线程处理函数
static void init(struct prodcons * b); //线程初始化
static void put(struct prodcons * b, char * data); //往共享数据区写数据
static char * get(struct prodcons * b);
//********************************************************************************************************************
static void my_notif1_proc (HWND hwnd, int id, int nc, DWORD add_data)//加1按纽的回调函数
{
if ( nc == BN_CLICKED)
{
/* jishu++;
ji[0]=jishu;
SetWindowText(GetDlgItem(GetParent(hwnd),IDC_STAT),ji);*/
}
}
static void my_notif2_proc (HWND hwnd, int id, int nc, DWORD add_data)
{
if ( nc == BN_CLICKED)
{
/*jishu--;
ji[0]=jishu;
SetWindowText(GetDlgItem(GetParent(hwnd),IDC_STAT),ji); */
}
}
/*
************************************************************************************************************************
**函数原型 : static int ZYHWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
**参数说明 :
**返回 值 :
**创 建 人: 赵悦辉
**最后修改日期: 2006年2月9日
**描 述: 主窗体的回调函数
************************************************************************************************************************
*/
static int ZYHWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
HUAXIAN HuaXian; //曲线显示传递参数
PMAXMIN Zui_Zi;
int i;
static BITMAP bmp;
HDC hdc,Neihdc;//界面hdc和内存hdc
static MINIINIT Kongjian;
static PMINIINIT pKongjian=NULL; //初始化参数和返回值
//图象
static MAXMIN maxmin;
switch (message) {
case MSG_INITDIALOG:
logfontgb12=CreateLogFont(NULL,"song","GB2312",FONT_WEIGHT_REGULAR,FONT_SLANT_ROMAN,\
FONT_SETWIDTH_NORMAL,FONT_SPACING_CHARCELL,FONT_UNDERLINE_NONE,FONT_STRUCKOUT_NONE,12,0);
SetWindowFont(hWnd,logfontgb12);
return 1;
case MSG_CREATE:
Xs_Fs=0;
pKongjian=InitMiniQX(hWnd); //初始化
//--------------------------------更新数据----------------------------------------------------
Kongjian.bmp_TX=pKongjian->bmp_TX;
Kongjian.bmp_WB=pKongjian->bmp_WB;
for(i=0;i<8;i++)
{
Kongjian.hStaticP[i]=pKongjian->hStaticP[i];
Kongjian.hStaticT[i]=pKongjian->hStaticT[i];
Kongjian.hStaticS[i]=pKongjian->hStaticS[i];
Kongjian.hStaticM[i]=pKongjian->hStaticM[i];
Kongjian.hEditP[i]=pKongjian->hEditP[i];
Kongjian.hEditT[i]=pKongjian->hEditT[i];
Kongjian.hEditS[i]=pKongjian->hEditS[i];
Kongjian.hEditM[i]=pKongjian->hEditM[i];
}
//------------------------------------------------------------------------------------------------------
//Zui_Zi=CanShu(Zui_Zi,0); //读取参数
SetTimer (hWnd, 100, TIME_SHUAXIN); //定时器2秒 ID是100
Show(&Kongjian,0); //确定是否显示控件
Show(&Kongjian,1);
SendMessage(hWnd,MSG_PAINT,0,0); //刷新画面
return 0;
case MSG_PAINT://更新界面
hdc = BeginPaint (hWnd);
if(Xs_Fs==1)
{
FillBoxWithBitmap (hdc, 0, 0, 640,480, &(Kongjian.bmp_TX)); //图象方式显示
//Rectangle(hdc, 0, 0, 640, 480);
}
else
{
FillBoxWithBitmap (hdc, 0, 0, 640, 480, &(Kongjian.bmp_WB)); //文本方式显示
//Rectangle(hdc, 0, 0, 640, 480);
}
EndPaint (hWnd, hdc);
return 0;
case MSG_MY1: //接收加一消息
return 0;
case MSG_MY2: //接收减一消息
return 0;
case MSG_CHAR:
if(wParam=='a') //a控制切换显示内容
{
if(Xs_Fs==1)
{ Xs_Fs=0;}
else
{Xs_Fs=1;}
SendMessage(hWnd,MSG_PAINT,0,0); //刷新画面
Show(&Kongjian,Xs_Fs); //确定是否显示控件
}
if(wParam=='b') //b停止线程
{
int *retval;
if(pthread_cancel(th_a)==0) {
if (pthread_join(th_a,(void **)(&retval))!=0) {
return (-1);
}
else
printf("producer stopped!\n");
}
}
return 0;
case MSG_TIMER:
if (wParam == 100) //ID是100
{
//时间到,读取公共缓冲区的数据
char * d;
d = get(&buffer);
SetWindowText(Kongjian.hEditT[0],d);
printf("sssss %s\n",d);
if(Xs_Fs==1) //曲线显示方式
{
HDC X_hdc=GetClientDC(hWnd);
//------------------------------------
for(i=0;i<20;i++)HuaXian.LeiJi[0][i]=10;
HuaXian.XC_hdc= X_hdc;
HuaXian.Max[0]=12;
huaxian(&HuaXian); //画曲线函数
//--------------------------------
ReleaseDC(X_hdc);
}
else
{
Show(&Kongjian,Xs_Fs); //文本送数
}
}
return 0;
case MSG_CLOSE:
KillTimer (hWnd,100);
DestroyLogFont(logfontgb12);
UnloadBitmap (&(Kongjian.bmp_TX));
UnloadBitmap (&(Kongjian.bmp_WB));
DestroyMainWindow (hWnd);
PostQuitMessage (hWnd);
return 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -