📄 trend.c
字号:
LineTo(hdc,Curve[i].left+(j+1)*HLabelWidth,Curve[i].top+HLabelHeight*2);
}
}
}
ReleaseDC(hdc);
/****************初始化各个方框结束*****************/
/****************初始化各个方框上面的坐标短线*****************/
hdc=GetClientDC(hWnd);
for(j=0;j<13;j++)
{
for(i=0;i<5;i++)
{
Coordinate[i].start.x=Curve[i].left+j*(CurveWidth/12);
Coordinate[i].start.y=Curve[i].bottom-(ShortLineHeight>>1);
Coordinate[i].end.x=Curve[i].left+j*(CurveWidth/12);
Coordinate[i].end.y=Curve[i].bottom+(ShortLineHeight>>1);
Coordinate[i].slcolor=SysPixelIndex[10+i];
Coordinate[i].Hstart.x=Curve[i].left;
Coordinate[i].Hstart.y=Curve[i].top+((RECTH(Curve[i]))>>1);
Coordinate[i].Hend.x=Curve[i].left+RECTW(Curve[i]);
Coordinate[i].Hend.y=Curve[i].top+((RECTH(Curve[i]))>>1);
}
DrawShortLine(hdc,Coordinate,5);
}
ReleaseDC(hdc);
/****************初始化各个方框的坐标短线结束*****************/
/****************初始化各个方框的时间坐标线*********************/
hdc=GetClientDC(hWnd);
for(i=0;i<5;i++)
{
TimeLine[i].start.x=Curve[i].left+SendMessage(GetDlgItem(hWnd,ID_ScroBar),TBM_GETPOS,0,0)+1;
TimeLine[i].start.y=Curve[i].top+1;
TimeLine[i].end.x=Curve[i].left+SendMessage(GetDlgItem(hWnd,ID_ScroBar),TBM_GETPOS,0,0)+1;
TimeLine[i].end.y=Curve[i].top+ShortLineHeight;
TimeLine[i].slcolor=COLOR_yellow;
TimeLine[i].Hend.x=0;
TimeLine[i].Hend.y=0;
TimeLine[i].Hstart.x=0;
TimeLine[i].Hstart.y=0;
}
DrawShortLine(hdc,TimeLine,5);
ReleaseDC(hdc);
/****************初始化各个方框的时间坐标线结束*****************/
/****************初始化各个方框的纵坐标数值*********************/
hdc=GetClientDC(hWnd);
for(i=0;i<5;i++)
{
//上
CoordinateLabel[i*3].bkclor=COLOR_black;
CoordinateLabel[i*3].fontcolor=SysPixelIndex[10+i];
CoordinateLabel[i*3].framcolor=COLOR_black;
CoordinateLabel[i*3].Height=(ColorEditHeight>>1);
CoordinateLabel[i*3].Width=(ColorEditWidth>>1)+5;
CoordinateLabel[i*3].Xorg=Curve[i].left-CoordinateLabel[i*3].Width-2;
CoordinateLabel[i*3].Yorg=Curve[i].top;
CoordinateLabel[i*3].text=CoLabelText[i*3];
//中
CoordinateLabel[i*3+1].bkclor=COLOR_black;
CoordinateLabel[i*3+1].fontcolor=SysPixelIndex[10+i];
CoordinateLabel[i*3+1].framcolor=COLOR_black;
CoordinateLabel[i*3+1].Height=(ColorEditHeight>>1);
CoordinateLabel[i*3+1].Width=(ColorEditWidth>>1)+5;
CoordinateLabel[i*3+1].Xorg=Curve[i].left-CoordinateLabel[i*3+1].Width-2;
CoordinateLabel[i*3+1].Yorg=Curve[i].top+((RECTH(Curve[i]))>>1)-(CoordinateLabel[i*3+1].Height>>1);
CoordinateLabel[i*3+1].text=CoLabelText[i*3+1];
//下
CoordinateLabel[i*3+2].bkclor=COLOR_black;
CoordinateLabel[i*3+2].fontcolor=SysPixelIndex[10+i];
CoordinateLabel[i*3+2].framcolor=COLOR_black;
CoordinateLabel[i*3+2].Height=(ColorEditHeight>>1);
CoordinateLabel[i*3+2].Width=(ColorEditWidth>>1)+5;
CoordinateLabel[i*3+2].Xorg=Curve[i].left-CoordinateLabel[i*3+2].Width-2;
CoordinateLabel[i*3+2].Yorg=Curve[i].bottom-(CoordinateLabel[i*3+2].Height);
CoordinateLabel[i*3+2].text=CoLabelText[i*3+2];
}
for(i=0;i<15;i++)
{
DrawLabel(hdc,CoordinateLabel[i],'R');
}
ReleaseDC(hdc);
/****************初始化各个方框的纵坐标数值结束*****************/
/****************初始化方框下面的点数坐标*********************/
hdc=GetClientDC(hWnd);
for(i=0;i<5;i++)
{
Pointnum[i].Yorg=Curve[4].bottom+1;
Pointnum[i].Height=ColorEditHeight-8;
Pointnum[i].Width=ColorEditWidth>>1;
Pointnum[i].Xorg=Curve[4].left+(CurveWidth/12)*3*i-(Pointnum[i].Width>>1);
Pointnum[i].bkclor=COLOR_black;
Pointnum[i].fontcolor=COLOR_yellow;
Pointnum[i].framcolor=COLOR_black;
Pointnum[i].text=(char *)malloc(4);
sprintf(Pointnum[i].text,"%d",i*100);
DrawLabel(hdc,Pointnum[i],'H');
free(Pointnum[i].text);
}
ReleaseDC(hdc);
/****************初始化方框下面的点数坐标结束*****************/
/****************初始化方框下面的点数时间*********************/
hdc=GetClientDC(hWnd);
strcpy(s,GetWindowCaption(GetDlgItem(hWnd,109)));
k=(s[0]-48)*10+(s[1]-48);
k/=4;
if(GetValueFromEtcFile("./res/config.cfg","系统","时间",s,10)<0)//从文件中获取开机时间
printf("GetValueFromEtcFile error\n");
j=(s[0]-48)*10+(s[1]-48);//初始的小时
for(i=0;i<5;i++)
{
pointtime[i].Yorg=Curve[3].bottom+1;
pointtime[i].Height=ColorEditHeight-8;
pointtime[i].Width=ColorEditWidth;
pointtime[i].Xorg=Curve[3].left+(CurveWidth/12)*3*i-(pointtime[i].Width>>1);
pointtime[i].bkclor=COLOR_black;
pointtime[i].fontcolor=COLOR_magenta;
pointtime[i].framcolor=COLOR_black;
pointtime[i].text=(char *)malloc(10);
sprintf(pointtime[i].text,"%02d:%02d",((j+i*k)<24)?((j+i*k)):(j+i*k-24),(s[3]-48)*10+(s[4]-48));
DrawLabel(hdc,pointtime[i],'H');
free(pointtime[i].text);
}
ReleaseDC(hdc);
/****************初始化方框下面的点数时间结束*****************/
/****************初始化滑动条两边的箭头*****************/
hdc=GetClientDC(hWnd);
SetPenColor(hdc,COLOR_cyan);
Rectangle(hdc,ScroBarXorg-ScroBarHeight,ScroBarYorg,ScroBarXorg,ScroBarYorg+ScroBarHeight-1);
//画那个方框中的箭头(左箭头)
MoveTo(hdc, ScroBarXorg-ScroBarHeight+3*(ScroBarHeight>>2), ScroBarYorg+(ScroBarHeight>>2));
LineTo(hdc, ScroBarXorg-ScroBarHeight+3*(ScroBarHeight>>2), ScroBarYorg+(ScroBarHeight>>2)*3);
LineTo(hdc, ScroBarXorg-ScroBarHeight+(ScroBarHeight>>2), ScroBarYorg+(ScroBarHeight>>2)*2);
LineTo(hdc, ScroBarXorg-ScroBarHeight+3*(ScroBarHeight>>2), ScroBarYorg+(ScroBarHeight>>2));
//右方框和右箭头
Rectangle(hdc,ScroBarXorg+ScroBarWidth-1,ScroBarYorg,ScroBarXorg+ScroBarWidth+ScroBarHeight,ScroBarYorg+ScroBarHeight-1);
MoveTo(hdc,ScroBarXorg+ScroBarWidth-1+(ScroBarHeight>>2), ScroBarYorg+(ScroBarHeight>>2));
LineTo(hdc, ScroBarXorg+ScroBarWidth-1+(ScroBarHeight>>2), ScroBarYorg+(ScroBarHeight>>2)*3);
LineTo(hdc, ScroBarXorg+ScroBarWidth-1+(ScroBarHeight>>2)*3, ScroBarYorg+(ScroBarHeight>>2)*2);
LineTo(hdc,ScroBarXorg+ScroBarWidth-1+(ScroBarHeight>>2), ScroBarYorg+(ScroBarHeight>>2));
ReleaseDC(hdc);
/****************初始化滑动条两边的箭头结束*************/
}
/**********************************************************************
**函数名:static void CtrlAdd(const char * spClassName,
const char * spCaption,
DWORD dwStyle,
DWORD dwExStyle,
int id,
int x,
int y,
int w,
int h,
HWND hParentWnd,
DWORD dwAddData,
NOTIFPROC PROC
)
**功能:添加控件函数,包括该控件的回调函数名称,整合了两个函数
**参数:控件的各种参数加上该控件的回调函数名称
**返回值:无
**作者:陈永奎
**时间:2008.03.31
***********************************************************************/static void CtrlAdd(const char * spClassName,
const char * spCaption,
DWORD dwStyle,
DWORD dwExStyle,
int id,
int x,
int y,
int w,
int h,
HWND hParentWnd,
DWORD dwAddData,
NOTIFPROC PROC
)
{
HWND hwnd;
hwnd=CreateWindowEx(spClassName,spCaption,dwStyle,dwExStyle,id,x,y,w,h,hParentWnd,dwAddData);
SetNotificationCallback (hwnd,PROC);
}/**********************************************************************
**函数名:static int TrendProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
**功能:“趋势”窗口的总的回调函数
**参数:主回调函数所有参数
**返回值:无
**作者:陈永奎
**时间:2008.03.31
***********************************************************************/static int TrendProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
switch (message) {
case MSG_CREATE:
// 注册自定义彩色文本控件
RegisterColorEditControl();
inintctrl(hWnd);//初始化各个控件
break;
case MSG_PAINT:
//当绘制窗口时该消息产生,您可以添加些绘图函数,我们“Hello world ”就是在这里实现
inittrend(hWnd);
hdc = BeginPaint (hWnd);
EndPaint(hWnd,hdc);
return 0;
case MSG_CLOSE://当窗口关闭时该消息产生
DestroyMainWindow (hWnd);//注销窗口
UnregisterColorEditControl ();//注销彩色文本控件
PostQuitMessage (hWnd);
return 0;
}
return DefaultMainWinProc(hWnd, message, wParam, lParam);//未处理的函数在此默认处理
}/************************************************************************函数名:HWND Trend_Create(HWND Hose_Wnd)**功能:建立"趋势"窗口**参数:Hose_Wnd;"趋势"窗口的托管窗口,填写为主窗口或者桌面的句柄,填写为主窗口句柄,趋势窗口的句柄将添加**在Hose_Wnd窗口的附加数据中.**返回值:建立"趋势"窗口的句柄**作者:陈永奎**时间:2008.03.31***********************************************************************/int Trend_Create(HWND Hose_Wnd){ HWND hWnd_F2; MAINWINCREATE CreateInfo;//定义主窗口结构 MSG Msg;//定义消息 CreateInfo.dwStyle = WS_SYSMENU | WS_VISIBLE | WS_BORDER | WS_CAPTION ;//设置主窗口风格
CreateInfo.dwExStyle = WS_EX_NONE;//设置主窗口扩展风格
CreateInfo.spCaption = "Trend";//设置主窗口标题
CreateInfo.hMenu = 0; //设置主窗口菜单
CreateInfo.hCursor = GetSystemCursor(0); //设置主窗口鼠标光标
CreateInfo.hIcon = 0; //设置主窗口图标
CreateInfo.MainWindowProc = TrendProc; //设置主窗口消息处理函数过程
CreateInfo.lx = TrendXorg; //设置主窗口位置x坐标
CreateInfo.ty = TrendYorg; //设置主窗口位置y坐标
CreateInfo.rx = TrendXorg+TrendWidth ; //设置主窗口宽度
CreateInfo.by = TrendYorg+TrendHeight; //设置主窗口高度
CreateInfo.iBkColor = COLOR_black; //设置主窗口客户区背景色
CreateInfo.dwAddData = 0; //设置主窗口的附加数据,通常不需要
CreateInfo.hHosting = Hose_Wnd; //设置主窗口的托管窗口,通常为桌面DESKTOP
hWnd_F2 = CreateMainWindow (&CreateInfo);//创建主窗口 if (hWnd_F2 == HWND_INVALID)//失败则退出
return -1; SetWindowAdditionalData(Hose_Wnd,(DWORD)hWnd_F2);//添加趋势窗口的句柄到主窗口附加数据中 ShowWindow(hWnd_F2, SW_SHOWNORMAL);//显示主窗口SW_SHOW
while (GetMessage(&Msg, hWnd_F2)) { //进入消息处理
TranslateMessage(&Msg);
DispatchMessage(&Msg); }
MainWindowThreadCleanup (hWnd_F2);
return 0;}/************************************************************************函数名:int Trend_Close(HWND hWndMain)**功能:关闭"趋势"窗口**参数:hWndMain;"趋势"窗口的托管窗口句柄,托管窗口的附加数据为"趋势"窗口的句柄**作者:陈永奎**时间:2008.03.31***********************************************************************/int Trend_Close(HWND hWndMain){ HWND temp; temp=(HWND)GetWindowAdditionalData(hWndMain); SendMessage(temp,MSG_CLOSE,0,0); return(0);}
/*********************************************************************************
******************************从此处开始为彩色文本控件代码************************
**********************************************************************************/
static int ColorEditConProc (HWND hwnd, int message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
RECT rc; // rc为文本矩形
const char *TempS; //临时存放文本内容
GetClientRect(hwnd, &rc); // 取得控件的大小
switch(message)
{
case MSG_CREATE:
SetWindowBkColor(hwnd, COLOR_black);
break;
case MSG_PAINT:
hdc = BeginPaint (hwnd);
//SetBkMode(hdc, BM_TRANSPARENT); // 让文本框背景透明
// 设置边框颜色-浅蓝色,并绘制边框
SetPenColor(hdc, RGB2Pixel (hdc, 11, 244 , 244));
Rectangle (hdc, rc.left, rc.top, rc.right-1, rc.bottom-1);
// 设置文本颜色——浅蓝色,文本背景色——黑色
SetTextColor(hdc, RGB2Pixel (hdc, 11, 244 , 244));
SetBkColor(hdc, COLOR_black);
rc.right = rc.right-2; // 文字到右边框留的距离为3
// 输出文本内容,右对齐、上下居中显示
DrawText(hdc, GetWindowCaption (hwnd), -1, &rc, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
EndPaint (hwnd, hdc);
break;
case MSG_SETTEXT: // 此消息是为了使得SetDlgItemText()函数(此函数会发出MSG_SETTEXT消息)可用
// 将设置的文本保存到caption中
SetWindowCaption (hwnd, (char*)lParam);
hdc = GetClientDC (hwnd);
// 设置边框颜色-绿色,并绘制边框
SetPenColor(hdc, COLOR_cyan);
Rectangle (hdc, rc.left, rc.top, rc.right, rc.bottom-1);
// 设置文本颜色——浅蓝色,文本背景色——黑色
SetTextColor(hdc, RGB2Pixel (hdc, 11, 244 , 244));
SetBkColor(hdc, COLOR_black);
rc.right = rc.right-3; // 文字到右边框留的距离为3
// 用黑色刷新文字区域
SetBrushColor(hdc, 0);
FillBox (hdc, rc.left+1, rc.top+1, rc.right-rc.left-1, rc.bottom-rc.top-2); // 加1减1目的是为了防止把边框刷掉
// 输出文本内容,右对齐、上下居中显示
DrawText(hdc, (char*)lParam, -1, &rc, DT_NOCLIP | DT_CENTER | DT_VCENTER | DT_SINGLELINE);
ReleaseDC (hdc);
break;
case MSG_USER: //设置文本颜色
TempS=GetWindowCaption(hwnd);
hdc = GetClientDC (hwnd);
// 设置边框颜色-绿色,并绘制边框
SetPenColor(hdc, COLOR_cyan);
Rectangle (hdc, rc.left, rc.top, rc.right, rc.bottom-1);
// 设置文本颜色——浅蓝色,文本背景色——黑色
SetTextColor(hdc, (DWORD)wParam);
SetBkColor(hdc, COLOR_black);
rc.right = rc.right-3; // 文字到右边框留的距离为3
// 用黑色刷新文字区域
SetBrushColor(hdc, 0);
FillBox (hdc, rc.left+1, rc.top+1, rc.right-rc.left-1, rc.bottom-rc.top-2); // 加1减1目的是为了防止把边框刷掉
// 输出文本内容,右对齐、上下居中显示
DrawText(hdc, TempS, -1, &rc, DT_NOCLIP | DT_CENTER | DT_VCENTER | DT_SINGLELINE);
ReleaseDC (hdc);
break;
}
// DefaultControlProc()调用DefaultMainWinProc(),其内包含对MSG_GETTEXT消息的处理
return DefaultControlProc (hwnd, message, wParam, lParam);
}
static BOOL RegisterColorEditControl (void)
{
WNDCLASS MyClass;
MyClass.spClassName = "coloredit";
MyClass.dwStyle = WS_NONE;
MyClass.dwExStyle = WS_EX_NONE;
MyClass.hCursor = GetSystemCursor (IDC_ARROW);
MyClass.iBkColor = COLOR_black;
MyClass.WinProc = ColorEditConProc;
return RegisterWindowClass (&MyClass);
}
static void UnregisterColorEditControl (void)
{
UnregisterWindowClass ("coloredit");
}
/*********************************************************************************
******************************彩色文本控件代码到此结束****************************
**********************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -