?? globle.c
字號:
/****************************************************************************
* 文件名:globle.C
* 功能:全局功能函數及變量定義
****************************************************************************/
#include "includes.h"
#define judge(y) ((y%4==0)&&(y%100!=0)||(y%400==0))
TemiStatus TStatus; //定義終端狀態全局變量
uint8 WinId; //定義當前窗體狀態
uint8 debug; //調試開關,默認關閉
extern HWND hwnd ;
extern HDC hdc;
extern TMQ *task1_tmq;
uint8 init_beep[] = { 20,50, 0,5, 20,50, 0,5, 20,50, 0,5, 0,0}; //音頻設置
//函數聲明
void SetVideoMode(uint8 mode);
void DispString (uint8 x, uint8 y, char *str, uint8 mode);
void SetFont(uint8 type);
void gotoxy (uint8 x, uint8 y);
void Debug(char *Err);
uint8 GetDate(char *Buff);
uint8 measure();
//void clr_kb();
uint8 Cvt_SecordToStr(INT16U Secord,char *Str);
INT16U Cvt_StrToSecord(char *Str);
/*
void OpenComm();
void CloseComm();
void ReadComm(char c);
void WriteComm(char c);
void GPRSInit();
void GPRSDial(); //撥號函數
void GPRSHangup(); //斷開連接函數
void GPRSOnline(); //檢測是否處于在線狀態函數
void GPRSBuffFlush (); // 清空buffer */
/*********************************以下需要根據硬件寫函數*/
/****************************************************************************
* 函數名:OpenComm
* 功能:打開串口
****************************************************************************/
void OpenComm(char c)
{
}
/****************************************************************************
* 函數名:CloseComm
* 功能:關閉串口
****************************************************************************/
void CloseComm()
{
}
/****************************************************************************
* 函數名:ReadComm
* 功能:讀串口數據
****************************************************************************/
void ReadComm(char c)
{
}
/****************************************************************************
* 函數名:WriteComm
* 功能:寫串口數據
****************************************************************************/
void WriteComm(char c)
{
/*ES = 0;
SBUF = c;
while(TI==0);
TI=0;
ES = 1;*/
}
/****************************************************************************
* 函數名:
* 功能:全局功能函數及變量定義
****************************************************************************/
void SetFont(uint8 type)
{
;//設置用戶字體,1為12*12 / 2為16*16
}
/****************************************************************************
* 函數名:
* 功能:全局功能函數及變量定義
****************************************************************************/
void SetVideoMode(uint8 mode)
{
;//設置反顯模式
//mode為0 正常顯示/1 反顯
}
void DispKey (INT16U x, INT16U y, char *str, uint8 mode)
{
INT16U ShowLen,fontx; //入參字符串的長度
INT16U sx,ex,sy,ey,relx,rely;
RECT rc;
HBRUSH hbr,hbr2;
hbr=CreateSolidBrush(RGB(255,0,0));
hbr2=CreateSolidBrush(RGB(100,100,100));
SetRect(&rc,x-4,y-4,x+72,y+24);
FillRect(hdc,&rc,(HBRUSH)GetStockObject(GRAY_BRUSH));
ShowLen = strlen(str);
if(ShowLen == 4)
relx = x+16;
else
relx = x;
if(ShowLen == 2)
fontx = x+1;
else
fontx = x;
if(NULL == str || ShowLen >8)
{
DispString(0,0,(char *)"系統錯誤",1);
if(debug)
DispString(0,0,(char *)"DispPhoto入參為空",0);
return;
}
if(x==0)
return;
/*if ((y < 4 || y > 216) || (x < 4 || x > 248))
{
DispString(0,0,(char *)"顯示菜單時XY錯誤",0);
if(debug)
DispString(0,0,(char *)"DispPhoto畫點時的邊距參數錯誤",0);
return;
}*/
if(mode == 1)
{
SetRect(&rc,x-4,y-4,x+72,y+24);
FillRect(hdc,&rc,hbr);
SetTextColor(hdc,RGB(0,0,255));
SetBkColor(hdc,RGB(255,0,0));
TextOut(hdc,relx,y,str,strlen(str)); //打印文字
}
else
{
SetRect(&rc,x-4,y-4,x+72,y+24);
FillRect(hdc,&rc,hbr2);
SetTextColor(hdc,RGB(0,0,255));
SetBkColor(hdc,RGB(100,100,100));
TextOut(hdc,relx,y,str,strlen(str)); //打印文字
}
}
/****************************************************************************
* 函數名:
* 功能:全局功能函數及變量定義
****************************************************************************/
void clr_scr()
{
//清屏函數
//PC_DispClrScr(DISP_BGND_LIGHT_GRAY);
//HBRUSH hbr;
int8 s[40];
RECT rc;
//hbr=CreateSolidBrush(RGB(100,200,255));
SetRect(&rc,0,16,320,240);
//FillRect(hdc,&rc,(HBRUSH)GetStockObject(BLACK_BRUSH));
FillRect(hdc,&rc,(HBRUSH)GetStockObject(GRAY_BRUSH));
//以下代碼測試時用到
line(0,0,0,240,0x0000ff); //lcd區域
//line(0,0,320,0,0x0000ff);
line(320,0,320,240,0x0000ff);
line(0,240,320,240,0x0000ff);
DispKey (500, 120, (char *)"向上5", 1);
DispKey (500, 200, (char *)"向下2", 1);
DispKey (400, 160, (char *)"向左1", 1);
DispKey (600, 160, (char *)"向右3", 1);
DispKey (500, 160, (char *)"功能ent", 1);
DispKey (500, 40, (char *)"測量esc", 1);
}
/****************************************************************************
* 函數名:
* 功能:全局功能函數及變量定義
****************************************************************************/
void on_beeper(uint8 frequency[])
{
;//根據指定的頻率提示音給用戶
}
/****************************************************************************
* 函數名:
* 功能:全局功能函數及變量定義
****************************************************************************/
void gotoxy (uint8 x, uint8 y)
{
;//將屏幕指針指向X/Y處
//置顯存地址
}
/****************************************************************************
* 函數名:
* 功能:清除鍵盤緩存消息
****************************************************************************/
void clr_kb()
{
;//清除鍵盤緩存消息
}
/****************************************************************************
* 函數名:
* 功能:全局功能函數及變量定義
****************************************************************************/
void DispString (uint8 x, uint8 y, char *str, uint8 mode)
{
uint16 relx,rely,len;
relx = x*16;
rely = y*16;
if ( y > 14 || x > 39)
return;
if(mode ==1)
{
SetTextColor(hdc,RGB(255,0,0));
SetBkColor(hdc,RGB(128,128,128));
TextOut(hdc,relx,rely,str,strlen(str)); //打印文字
//PC_DispStr(x, y, str, DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY);
}
else
{
SetTextColor(hdc,RGB(0,0,255));
SetBkColor(hdc,RGB(128,128,128));
TextOut(hdc,relx,rely,str,strlen(str)); //打印文字
//PC_DispStr(x, y, str, DISP_FGND_YELLOW + DISP_BGND_BLUE);
}
//ReleaseDC(hwnd,hdc); //釋放DC
}
/****************************************************************************
* 函數名:顯示字符
* 功能:全局功能函數及變量定義
****************************************************************************/
void DispChar (uint8 x, uint8 y, char *str, uint8 mode)
{
uint16 relx,rely,len;
relx = x*16;
rely = y*16;
if ( y > 14 || x > 39)
return;
if(mode ==1)
{
SetTextColor(hdc,RGB(255,0,0));
SetBkColor(hdc,RGB(128,128,128));
TextOut(hdc,relx,rely,str,strlen(str)); //打印文字
}
else
{
SetTextColor(hdc,RGB(0,0,255));
SetBkColor(hdc,RGB(100,100,100));
TextOut(hdc,relx,rely,str,strlen(str)); //打印文字
//PC_DispStr(x, y, str, DISP_FGND_YELLOW + DISP_BGND_BLUE);
}
//ReleaseDC(hwnd,hdc); //釋放DC
}
/****************************************************************************
* 函數名:
* 功能:全局功能函數及變量定義
****************************************************************************/
void ShowFont(INT16U x, INT16U y, char *str)
{
;//增加代碼
}
/****************************************************************************
* 函數名:
* 功能:全局功能函數及變量定義
****************************************************************************/
void ShowMatrix(uint8 sx,uint8 sy,uint8 ex,uint8 ey,uint8 color)
{
uint8 i;
int8 str1,str2;
str1='-';
str2='|';
for(i=sx;i<ex;i++)
{
PC_DispChar(i, sy, str1, color);
PC_DispChar(i, ey, str1, color);
}
for(i=sy;i<ey;i++)
{
PC_DispChar(sx, i, str2, color);
PC_DispChar(ex, i, str2, color);
}
}
/****************************************************************************
* 函數名:
* 功能:一個菜單固定顯示4個漢字字符,周圍用背景色包圍
顯示長度為8 包圍的空隙為2(即漢字與邊框距離為4個點
漢字16*16 /屏幕為320*240
一行可顯示13個菜單
一列可顯示10個菜單
x,y為漢字起始點 4<x<300 4<y<220
****************************************************************************/
void DispPhoto (INT16U x, INT16U y, char *str, uint8 mode)
{
INT16U ShowLen,fontx; //入參字符串的長度
INT16U sx,ex,sy,ey,relx,rely;
RECT rc;
HBRUSH hbr,hbr2;
hbr=CreateSolidBrush(RGB(255,0,0));
hbr2=CreateSolidBrush(RGB(100,100,100));
SetRect(&rc,x-4,y-4,x+72,y+24);
FillRect(hdc,&rc,(HBRUSH)GetStockObject(GRAY_BRUSH));
ShowLen = strlen(str);
if(ShowLen == 4)
relx = x+16;
else
relx = x;
if(ShowLen == 2)
fontx = x+1;
else
fontx = x;
if(NULL == str || ShowLen >8)
{
DispString(0,0,(char *)"系統錯誤",1);
if(debug)
DispString(0,0,(char *)"DispPhoto入參為空",0);
return;
}
if(x==0)
return;
if ((y < 4 || y > 216) || (x < 4 || x > 248))
{
DispString(0,0,(char *)"顯示菜單時XY錯誤",0);
if(debug)
DispString(0,0,(char *)"DispPhoto畫點時的邊距參數錯誤",0);
return;
}
if(mode == 1)
{
SetRect(&rc,x-4,y-4,x+72,y+24);
FillRect(hdc,&rc,hbr);
SetTextColor(hdc,RGB(0,0,255));
SetBkColor(hdc,RGB(255,0,0));
TextOut(hdc,relx,y,str,strlen(str)); //打印文字
}
else
{
SetRect(&rc,x-4,y-4,x+72,y+24);
FillRect(hdc,&rc,hbr2);
SetTextColor(hdc,RGB(0,0,255));
SetBkColor(hdc,RGB(100,100,100));
TextOut(hdc,relx,y,str,strlen(str)); //打印文字
}
}
/****************************************************************************
* 函數名:
* 功能:一個菜單固定顯示4個漢字字符,周圍用背景色包圍
顯示長度為8 包圍的空隙為2(即漢字與邊框距離為4個點
漢字16*16 /屏幕為320*240
一行可顯示13個菜單
一列可顯示10個菜單
x,y為漢字起始點 4<x<300 4<y<220
mode: 0表示延時1秒, 1表示用戶選擇
****************************************************************************/
uint8 DispMessage (INT16U x, INT16U y, int8 *str, uint8 mode)
{
INT16U ShowLen,fontx; //入參字符串的長度
INT16U sx,ex,sy,ey,relx,rely;
uint8 i,type;
int8 row1[37],row2[37];
RECT rc;
MSGtemp *pMsg; //聲明消息
HBRUSH hbr,hbr2;
hbr=CreateSolidBrush(RGB(255,0,0));
hbr2=CreateSolidBrush(RGB(100,100,100));
FillRect(hdc,&rc,(HBRUSH)GetStockObject(GRAY_BRUSH));
ShowLen = strlen(str);
clr_scr();
if(ShowLen <= 14)
{
type = 0; //一行
strcpy(row1,str);
}
else
{
type = 1; //二行
for(i=0;i<ShowLen;i++)
if(str[i] =='?')
break;
strcpy(row1,SubString(str,0,i));
strcpy(row2,SubString(str,i+1,ShowLen-i-1));
}
if(ShowLen == 4)
relx = x+16;
else
relx = x;
if(ShowLen == 2)
fontx = x+1;
else
fontx = x;
if(NULL == str || ShowLen >72)
{
DispString(0,0,(char *)"系統錯誤",1);
if(debug)
DispString(0,0,(char *)"DispPhoto入參為空",0);
return 2;
}
if(x==0)
return 0;
if ((y < 8 || y > 200) || (x < 8 || x > 240))
{
DispString(0,0,(char *)"顯示菜單時XY錯誤",0);
if(debug)
DispString(0,0,(char *)"DispPhoto畫點時的邊距參數錯誤",0);
return 2;
}
if(type == 0)
SetRect(&rc,x-8,y-8,x+ShowLen*8+8,y+24);
else
SetRect(&rc,x-8,y-8,x+strlen(row1)*8+8,y+40);
if(mode == 1)
{
FillRect(hdc,&rc,hbr);
SetTextColor(hdc,RGB(0,0,255));
SetBkColor(hdc,RGB(255,0,0));
if(type == 1)
TextOut(hdc,relx,y+16,row2,strlen(row2)); //打印文字
TextOut(hdc,relx,y,row1,strlen(row1)); //打印文字
TextOut(hdc,relx,y,row1,strlen(row1)); //打印文字
while ((GetMessagetemp(task1_tmq))->message == 0x00);
//if(pMsg->message == TM_KEYOK)
return 1;
}
else
{
FillRect(hdc,&rc,hbr2);
SetTextColor(hdc,RGB(0,0,255));
SetBkColor(hdc,RGB(255,0,0));
if(type == 1)
TextOut(hdc,relx,y+16,row2,strlen(row2)); //打印文字
TextOut(hdc,relx,y,row1,strlen(row1)); //打印文字
TextOut(hdc,relx,y,row1,strlen(row1)); //打印文字
OSTimeDly(OS_TICKS_PER_SEC);
}
return 0;
}
//先畫矩陣框,再顯示字體
/*ShowMatrix(startregionx,startregiony,endregionx,endregiony,backcolor);
startregionx = x - (INT16U)((8 - ShowLen) / 2); //漢字的起始點
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -