You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1203 lines
29 KiB
C++

#include "StdAfx.h"
#include "GlobalFunction.h"
#include "PropertiesWnd.h"
#include "BitOperation.h"
#include "GlobalDrawMgr.h"
#include<math.h>
#include "MsgBox.h"
#include "AllThreadMgr.h"
#include "WorkTime.h"
#include "FileMgr.h"
#include "WorkCmdInvoker.h"
#include "CStringFuc.h"
#if 1
UINT RedrawViewByThread(LPVOID pParam)
{
m_pView->RefreshView();
return 0;
}
UINT NewMsgThread(LPVOID pParam)
{
CMsgBox *pMsgBox = (CMsgBox *)pParam;
pMsgBox->ShowSetMsg();
return 0;
}
//<2F><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
CLaiPuLaserView *GetCurViewPtr()
{
CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->GetMainWnd();
CChildFrame *pChild = (CChildFrame*)pFrame->GetActiveFrame();
CLaiPuLaserView *pView = (CLaiPuLaserView*)pChild->GetActiveView();
return pView;
}
//<2F><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD>ļ<EFBFBD>ָ<EFBFBD><D6B8>
CLaiPuLaserDoc *GetCurDocPtr()
{
CLaiPuLaserView *pView = GetCurViewPtr();
CLaiPuLaserDoc *pDoc = pView->GetDocument();
return pDoc;
}
CMainFrame* GetFrame()
{
CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->GetMainWnd();
return pFrame;
}
//ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD>̵߳ķ<CCB5>ʽˢ<CABD><CBA2>view
void RedrawViewByThread()
{
AfxBeginThread(RedrawViewByThread,NULL);
}
#endif
#if 1//<2F><><EFBFBD>η<EFBFBD>Χ<EFBFBD><CEA7><EFBFBD>غ<EFBFBD><D8BA><EFBFBD>
//<2F><><EFBFBD>Ƿ<EFBFBD><C7B7>ھ<EFBFBD><DABE><EFBFBD><EFBFBD><EFBFBD>
bool IsPointInRect(Dbxy point,DbRect rect)
{
if(point.x>= rect.L && point.x<=rect.R && point.y<= rect.T && point.y>=rect.B)
return true;
else
return false;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>
bool IsTwoRectIntersect(DbRect &rect1,DbRect &rect2)
{
if((((rect2.L>=rect1.L)&&(rect2.L<=rect1.R)) || ((rect2.R>=rect1.L)&&(rect2.R<=rect1.R))) &&
(((rect2.T>=rect1.B)&&(rect2.T<=rect1.T)) || ((rect2.B>=rect1.B)&&(rect2.B<=rect1.T))))
return true;
else
return false;
}
//<2F>жϵ<D0B6><CFB5>γɵ<CEB3>ֱ<EFBFBD><D6B1><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ܺ<EFBFBD>rect <20>
//Radius <20><>ֱ<EFBFBD>ߵ<EFBFBD>һ<EFBFBD><EFBFBD><EBB3A4>mm
bool IsLineAndRectIntersect(Dbxy pt,DbRect rect,double Ang,double Radius)
{
//<2F><><EFBFBD><EFBFBD>ֱ<EFBFBD>ߵĶ˵<C4B6>
Dbxy StartPt(Radius*(-1),pt.y);
Dbxy EndPt(Radius,pt.y);
StartPt = RotatoPt(StartPt,Ang,pt);
EndPt = RotatoPt(EndPt,Ang,pt);
return IsLineInRect(StartPt,EndPt,rect);
}
//<2F>ж<EFBFBD><D0B6>߶<EFBFBD><DFB6>Ƿ<EFBFBD><C7B7>ھ<EFBFBD><DABE><EFBFBD><EFBFBD><EFBFBD>
bool IsLineInRect(Dbxy point1,Dbxy point2,DbRect rect)
{
if(IsTwoLineIntersect(point1,point2,Dbxy(rect.R,rect.T),Dbxy(rect.L,rect.B)))
return true;
if(IsTwoLineIntersect(point1,point2,Dbxy(rect.L,rect.T),Dbxy(rect.R,rect.B)))
return true;
if(IsPointInRect(point1,rect) || IsPointInRect(point2,rect))
return true;
return false;
}
void AdjustRange(double &min,double &max,double val)
{
if(min>max)//<2F><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>
{
min = max = val;
}
else
{
if(min > val)
{
min = val;
}
if(max < val)
{
max = val;
}
}
}
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD>ݵ<EFBFBD><DDB5>ı߽緶Χ
DbRect GetDbPointVecRect(vector<Dbxy> &vec)
{
DbRect rect;
vector<Dbxy>::iterator iter = vec.begin();
vector<Dbxy>::iterator iter_end = vec.end();
for(;iter!=iter_end;iter++)
{
AdjustRectByPoint(rect,(*iter));
}
return rect;
}
DbRect GetDbPointVecRect(vector<vector<Dbxy>> &vec)
{
DbRect rect;
vector<vector<Dbxy>>::iterator iter = vec.begin();
vector<vector<Dbxy>>::iterator iter_end = vec.end();
for(;iter!=iter_end;iter++)
{
vector<Dbxy>::iterator iter1 = (*iter).begin();
vector<Dbxy>::iterator iter1_end = (*iter).end();
for(;iter1!=iter1_end;iter1++)
{
AdjustRectByPoint(rect,(*iter1));
}
}
return rect;
}
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>η<EFBFBD>Χ
void AdjustRectByPoint(DbRect &rect,Dbxy pt)
{
AdjustRange(rect.L,rect.R,pt.x);
AdjustRange(rect.B,rect.T,pt.y);
}
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>η<EFBFBD>Χ
void AdjustRectByRect(DbRect &rect1,DbRect rect2)
{
Dbxy pt1(rect2.L,rect2.T);
Dbxy pt2(rect2.R,rect2.B);
AdjustRectByPoint(rect1,pt1);
AdjustRectByPoint(rect1,pt2);
}
#endif
#if 1//<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߶<EFBFBD><DFB6>Ƿ<EFBFBD><C7B7>
#define EPS 1e-8
#define ZERO(x) (((x)>0?(x):-(x))<EPS) //<2F>ж<EFBFBD>double <20>Ƿ<EFBFBD>Ϊ0
//<2F><><EFBFBD><EFBFBD><E3BDBB><EFBFBD>˻<EFBFBD>(P1-P0)x(P2-P0)
double xmult(Dbxy p1,Dbxy p2,Dbxy p0)
{
return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
//<2F>е<EFBFBD><D0B5>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>߶<EFBFBD><DFB6><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>
int dot_online_in(Dbxy p,Dbxy l1,Dbxy l2)
{
return ZERO(xmult(p,l1,l2))&&(l1.x-p.x)*(l2.x-p.x)<EPS&&(l1.y-p.y)*(l2.y-p.y)<EPS;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߶<EFBFBD>ͬ<EFBFBD><CDAC>,<2C><><EFBFBD><EFBFBD><EFBFBD>߶<EFBFBD><DFB6>Ϸ<EFBFBD><CFB7><EFBFBD>0
int same_side(Dbxy p1,Dbxy p2,Dbxy l1,Dbxy l2)
{
return xmult(l1,p1,l2)*xmult(l1,p2,l2)>EPS;
}
//<2F><><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1>ƽ<EFBFBD><C6BD>
int Parallel(Dbxy u1,Dbxy u2,Dbxy v1,Dbxy v2)
{
return ZERO((u1.x-u2.x)*(v1.y-v2.y)-(v1.x-v2.x)*(u1.y-u2.y));
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E3B9B2>
int dots_inline(Dbxy p1,Dbxy p2,Dbxy p3)
{
return ZERO(xmult(p1,p2,p3));
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>߶<EFBFBD><DFB6>Ƿ<EFBFBD><C7B7>
int IsTwoLineIntersect(Dbxy u1,Dbxy u2,Dbxy v1,Dbxy v2)
{
if (!dots_inline(u1,u2,v1)||!dots_inline(u1,u2,v2))
return !same_side(u1,u2,v1,v2)&&!same_side(v1,v2,u1,u2);
return dot_online_in(u1,v1,v2)||dot_online_in(u2,v1,v2)||dot_online_in(v1,u1,u2)||dot_online_in(v2,u1,u2);
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߶εĽ<CEB5><C4BD><EFBFBD>
Dbxy CalIntersection(Dbxy u1,Dbxy u2,Dbxy v1,Dbxy v2)
{
Dbxy ret=u1;
double t=((u1.x-v1.x)*(v1.y-v2.y)-(u1.y-v1.y)*(v1.x-v2.x))/((u1.x-u2.x)*(v1.y-v2.y)-(u1.y-u2.y)*(v1.x-v2.x));
ret.x+=(u2.x-u1.x)*t;
ret.y+=(u2.y-u1.y)*t;
return ret;
}
void IntersectionOfRectAndLineExt(bool &flg,Dbxy &pt1,Dbxy &pt2,Dbxy u1,Dbxy u2,Dbxy v1,Dbxy v2)
{
if(IsTwoLineIntersect(u1,u2,v1,v2))
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E0BDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Dbxy pt = CalIntersection(u1,u2,v1,v2);
if(flg)
{
pt1 = pt;
}
else
{
pt2 = pt;
}
flg =!flg;
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>κ<EFBFBD><CEBA>߶εĽ<CEB5><C4BD><EFBFBD>
Dbxy IntersectionOfRectAndLine(Dbxy LinePt1,Dbxy LinePt2,DbRect rect)
{
bool flg = false;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><E6B5BD>1 <20><><EFBFBD>ǵ<EFBFBD>2
Dbxy pt1,pt2;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߶κ<DFB6>rect <20><><EFBFBD><EFBFBD><EFBFBD>ߵĽ<DFB5><C4BD><EFBFBD>
{
Dbxy TmpPt1(rect.L,rect.T);
Dbxy TmpPt2(rect.L,rect.B);
IntersectionOfRectAndLineExt(flg,pt1,pt2,LinePt1,LinePt2,TmpPt1,TmpPt2);
}
{
Dbxy TmpPt1(rect.L,rect.B);
Dbxy TmpPt2(rect.R,rect.B);
IntersectionOfRectAndLineExt(flg,pt1,pt2,LinePt1,LinePt2,TmpPt1,TmpPt2);
}
{
Dbxy TmpPt1(rect.R,rect.B);
Dbxy TmpPt2(rect.R,rect.T);
IntersectionOfRectAndLineExt(flg,pt1,pt2,LinePt1,LinePt2,TmpPt1,TmpPt2);
}
{
Dbxy TmpPt1(rect.R,rect.T);
Dbxy TmpPt2(rect.L,rect.T);
IntersectionOfRectAndLineExt(flg,pt1,pt2,LinePt1,LinePt2,TmpPt1,TmpPt2);
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>м<EFBFBD><D0BC><EFBFBD>
return CenterPtOfTwoPoint(pt1,pt2);
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>м<EFBFBD><D0BC>ĵ<EFBFBD>
Dbxy CenterPtOfTwoPoint(Dbxy Pt1,Dbxy Pt2)
{
Dbxy ret;
ret.x = (Pt1.x+Pt2.x)/2;
ret.y = (Pt1.y+Pt2.y)/2;
return ret;
}
#endif
#if 1//<2F><><EFBFBD><EFBFBD><E3BAAF>
//<2F><><EFBFBD><EFBFBD><EFBFBD>н<EFBFBD>ת<EFBFBD><D7AA>Ϊ360 <20><>
double AngleTo360(double Angle)
{
double _360Angle;
_360Angle = - Angle*180/PI;
//У<><D0A3>Ϊ<EFBFBD><CEAA>ֵ
if(_360Angle < 0)
{
_360Angle += 360;
}
if(_360Angle > 180)
{
_360Angle -= 360;
}
return _360Angle;
}
//360 <20><>ת<EFBFBD><D7AA>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>(360<36><30><EFBFBD><EFBFBD>=2<>л<EFBFBD><D0BB><EFBFBD>)
double _360ToAngle(double _360Angle)
{
double Angle;
Angle = (_360Angle*PI)/180;
return Angle;
}
//<2F><><EFBFBD><EFBFBD><E3B7B4><EFBFBD>нǶ<D0BD>StartPt: <20><>ת<EFBFBD><D7AA>ʼ<EFBFBD><CABC>EndPt: <20><>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>CenterPt: <20><>ת<EFBFBD><D7AA><EFBFBD>ĵ<EFBFBD>
double CalAngle(Dbxy CenterPt,Dbxy StartPt,Dbxy EndPt)
{
double x2 = CenterPt.x;
double y2 = CenterPt.y;
double x1 = StartPt.x;
double y1 = StartPt.y;
double x3 = EndPt.x;
double y3 = EndPt.y;
double flRlt,flAtanA,flAtanB;
//<2F><><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ת
if(x1==x2)
{
if(y1>y2)
{
flAtanA=PI/2;
}else if(y1<y2)
{
flAtanA=-PI/2;
}else
{
flAtanA=0;
}
flAtanB = 0;
}
//<2F><>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
else if(x3==x2)
{
if(y3>y2)
{
flAtanB=PI/2;
}else if(y3<y2)
{
flAtanB=-PI/2;
}else
{
flAtanB=0;
}
flAtanA=0;
}
else
{
//<2F><><EFBFBD><EFBFBD><EFBFBD>к<EFBFBD><D0BA><EFBFBD>atan <20><><EFBFBD>Խ<EFBFBD>б<EFBFBD><D0B1>ת<EFBFBD><D7AA>Ϊ<EFBFBD>Ƕ<EFBFBD>
flAtanA=atan((y1-y2)/(x1-x2));
flAtanB=atan((y3-y2)/(x3-x2));
if(y1-y2>0&&x1-x2<0){
flAtanA+=PI;
}
if(y1-y2<=0&&x1-x2<0){
flAtanA+=PI;
}
if(y3-y2>0&&x3-x2<0){
flAtanB+=PI;
}
if(y3-y2<=0&&x3-x2<0){
flAtanB+=PI;
}
}
flRlt=flAtanB-flAtanA;
return flRlt*(-1);
}
//ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>360 <20>Ƚ<EFBFBD>
double Cal360AngleByTwoPt(Dbxy pt1,Dbxy pt2)
{
Dbxy StartPt;
StartPt.x = CalDistance(pt1,pt2);
StartPt.y = pt1.y;
//<2F>ȼ<EFBFBD><C8BC><EFBFBD><E3B7B4><EFBFBD>н<EFBFBD>
double angle = CalAngle(pt1,StartPt,pt2);
return AngleTo360(angle);
}
//<2F><>תһ<D7AA><D2BB><EFBFBD><EFBFBD><E3A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD>ĵ<EFBFBD>
//Angle <20>ǻ<EFBFBD><C7BB>Ƚǣ<C8BD>CenterPt <20><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD>ĵ<EFBFBD>
Dbxy RotatoPt(Dbxy pt,double Angle,Dbxy CenterPt)
{
Dbxy ret;
//<2F><>ת-----------------------------------------------
ret.x = ((pt.x-CenterPt.x)*cos(Angle)-(pt.y-CenterPt.y)*sin(Angle))+CenterPt.x;
ret.y = ((pt.y-CenterPt.y)*cos(Angle)+(pt.x-CenterPt.x)*sin(Angle))+CenterPt.y;
return ret;
}
//<2F><><EFBFBD>ݵ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>,<2C>߶εij<CEB5><C4B3><EFBFBD>,<2C>Ƕȼ<C7B6><C8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߶εڶ<CEB5><DAB6><EFBFBD><EFBFBD><EFBFBD>
//angle <20>ǻ<EFBFBD><C7BB>Ƚ<EFBFBD>
Dbxy GetPoint2(Dbxy point1,double length,double angle)
{
Dbxy point2;
point2.x = point1.x+length*cos(angle);
point2.y = point1.y+length*sin(angle);
return point2;
}
#endif
#if 1
//<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>double <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
bool IsTwoDbEqual(double a,double b)
{
if((abs(a-b))<=COORD_EPS)
return true;
else
return false;
}
bool IsTwoDbEqual(double a,double b,double eps)
{
if((abs(a-b))<=eps)
return true;
else
return false;
}
bool IsTwoPtEqual(Dbxy pt1,Dbxy pt2,double eps)
{
return IsTwoDbEqual(pt1.x,pt2.x,eps) && IsTwoDbEqual(pt1.y,pt2.y,eps);
}
bool IsDbEqualZero(double num)
{
if(num<0)
{
num *= -1;
}
if(num <= COORD_EPS)
return true;
else
return false;
}
bool IsDbxyZero(Dbxy pt)
{
return IsDbEqualZero(pt.x) && IsDbEqualZero(pt.y);
}
void SwapTwoPt(Dbxy &pt1,Dbxy &pt2)
{
Dbxy pt = pt1;
pt1 = pt2;
pt2 = pt;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD>ľ<EFBFBD><C4BE><EFBFBD>(<28><><EFBFBD>ɶ<EFBFBD><C9B6><EFBFBD>:Z^2 = X^2 + Y^2)
//<2F><><EFBFBD><EFBFBD>ֵ<EFBFBD>϶<EFBFBD><CFB6>Ǵ<EFBFBD><C7B4><EFBFBD>0 <20><>
double CalDistance(Dbxy pt1,Dbxy pt2)
{
double flRlt;
flRlt=(pt1.x-pt2.x)*(pt1.x-pt2.x)+(pt1.y-pt2.y)*(pt1.y-pt2.y);
flRlt=sqrt(flRlt);
return flRlt;
}
//<2F><><EFBFBD><EFBFBD>num <20>м<EFBFBD>λ
int GetNumDigit(int num)
{
int cnt = 0;
while(num)
{
num /=10;
cnt++;
}
if(cnt==0)//<2F><><EFBFBD><EFBFBD>һλ
cnt = 1;
return cnt;
}
#endif
#if 1
bool CheckStringIsNum(CString str)
{
CString strSet1 = "qwertyuiopasdfghjklzxcvbnm";
CString strSet2 = "QWERTYUIOPASDFGHJKLZXCVBNM";
CString strSet3 = "!@#$%^&*()_+=[]\\{}|;':\",/<>?";
CString strSet = strSet1+strSet2+strSet3;
if(str.FindOneOf(strSet)==-1)
{
return true;
}
return false;
}
//<2F><>str <20><><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ֵ(<28><><EFBFBD><EFBFBD>123.456,789.123)
//<2F><>ȡ<EFBFBD><C8A1>Val1 <20><><EFBFBD><EFBFBD>1,ͬʱ<CDAC><CAB1>ȡ<EFBFBD><C8A1>Val1,Val2 <20><><EFBFBD><EFBFBD>2
//һ<><D2BB>û<EFBFBD><C3BB>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0
int GetTwoNum(CString str,double &Val1,double &Val2)
{
int CommaPos = 0;
//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ж<EFBFBD><D0B6><EFBFBD>
CommaPos = str.Find(',',0);
if(CommaPos!=-1)
{
CString str1(str,CommaPos);
str.Delete(0,CommaPos+1);
CString str2(str);
if(CheckStringIsNum(str1)&&CheckStringIsNum(str2))
{
Val1 = atof(str1);
Val2 = atof(str2);
return 2;
}
}
else
{
if(CheckStringIsNum(str))
{
Val1 = atof(str);
return 1;
}
}
return 0;
}
#endif
#if 1//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//ͨ<><CDA8>x <20><><EFBFBD><EFBFBD>
bool CompareDbxyByX(Dbxy pt1,Dbxy pt2)
{
return pt1.x>pt2.x;
}
bool CompareDbxyByY(Dbxy pt1,Dbxy pt2)
{
return pt1.y>pt2.y;
}
#endif
#if 1
//<2F>ж<EFBFBD>shift <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
bool IsShiftKeyDown()
{
if((GetAsyncKeyState(VK_SHIFT)&0x8000)&&(GetAsyncKeyState(VK_CONTROL)&0x8000))
return true;
else
return false;
}
//ģ<><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(CoordX,CoordY<64><59>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD>)
void MouseLeftBtnClick(int CoordX,int CoordY,bool bDbClick)
{
SetCursorPos(CoordX,CoordY);//<2F><><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD>λ<EFBFBD><CEBB>
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,NULL);//<2F><><EFBFBD><EFBFBD>down<77>¼<EFBFBD>
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,NULL);//<2F><><EFBFBD><EFBFBD>up<75>¼<EFBFBD>
if(bDbClick)//˫<><CBAB>
{
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,NULL);//<2F><><EFBFBD><EFBFBD>down<77>¼<EFBFBD>
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,NULL);//<2F><><EFBFBD><EFBFBD>up<75>¼<EFBFBD>
}
}
//<2F><>ȡlist <20><>ǰѡ<C7B0><D1A1><EFBFBD><EFBFBD><EFBFBD>к<EFBFBD>
int GetCurListIdx(CListCtrl &list)
{
POSITION pos = list.GetFirstSelectedItemPosition();
if(pos == NULL)
{
return -1;
}
else
{
while (pos)
{
int nItem = list.GetNextSelectedItem(pos);
return nItem;
}
}
return -1;
}
#endif
#if 1
int Byte2Int(BYTE x)
{
BYTE c = 0x80;
int a = (IsBitOn(x,7))?c:0;
x = SetBitOff(x,7);
return x+a;
}
//<2F><><EFBFBD><EFBFBD>double С<><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>n λ
double RetainDecimalPlaces(double val,int n)
{
for(int i=0;i<n;i++)
{
val *= 10;
}
int t = (int)val;
val = (double)t;
for(int i=0;i<n;i++)
{
val /= 10;
}
return val;
}
//<2F><>ȡ0~ rang <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
int GetRandVal(int rang)
{
int ret = rand()%rang;
return ret;
}
//n ת<><D7AA>Ϊ16 <20><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>(n>=0 && n<=15)
char Int2HexChar(int n)
{
char c = '0';
if(n>=0 && n<= 9)
c = '0' + n;
else if(n>=10 && n<= 15)
c = 'A' + n - 10;
return c;
}
//16<31><36><EFBFBD>Ƶ<EFBFBD>char ת<><D7AA>Ϊʮ<CEAA><CAAE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int HexChar2Int(char c)
{
int val = 0;
if(c>='0' && c<='9')
val = (c - '0');
else if(c>='A' && c<='F')
val = (c - 'A') + 10;
else if(c>='a' && c<='f')
val = (c - 'a') + 10;
return val;
}
//<2F><><EFBFBD>ֽڵ<D6BD>16 <20><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊʮ<CEAA><CAAE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD>0707 ---->1799<39><39>1179---->4473)
double _4DigitHex2Double(char *buf,int len)
{
double Sum = 0;
for(int k=0;k<len;k++)
{
double m = len-k-1;
double val = HexChar2Int(buf[k]);
Sum += val*pow(16,m);
}
return Sum;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>ֽڵ<D6BD>asc <20>ַ<EFBFBD>ת<EFBFBD><D7AA>Ϊint (<28><><EFBFBD><EFBFBD>"0F" --->15)
int TwoCharHexStringToInt(CString str)
{
int Val = 0;
if(str.GetLength()>=2)
{
char *buf = CStringToLPCSTR(str);
Val = _2CharToHex(buf[0],buf[1]);
}
return Val;
}
//13 88--->5000 20 08--->8200
int HexByte2Int(int Byte1,int Byte2)
{
int Byte4 = Byte1%16;
int Byte3 = (Byte1-Byte4)/16;
int Byte6 = Byte2%16;
int Byte5 = (Byte2-Byte6)/16;
int val =0;
val = (Byte3)*16*16*16+(Byte4)*16*16+(Byte5)*16+(Byte6);
return val;
}
//10C3E4(ʮ<><CAAE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)--->1098724(ʮ<><CAAE><EFBFBD><EFBFBD>)
//Byte3 <20><>λByte2 <20><>λByte1 <20><>λ
double _3HexByteToDouble(unsigned int ByteH,unsigned int ByteM,unsigned int ByteL)
{
unsigned int Byte4 = ByteH%16;
unsigned int Byte3 = (ByteH-Byte4)/16;
unsigned int Byte6 = ByteM%16;
unsigned int Byte5 = (ByteM-Byte6)/16;
unsigned int Byte7 = ByteL%16;
unsigned int Byte8 = (ByteL-Byte7)/16;
double val =0;
val = (Byte3)*16*16*16*16*16+(Byte4)*16*16*16*16+(Byte5)*16*16*16+(Byte6)*16*16+(Byte8)*16 + (Byte7);
return val;
}
double _4HexByteToDouble(unsigned int HexByte1,unsigned int HexByte2,unsigned int HexByte3,unsigned int HexByte4)
{
unsigned int Byte7 = HexByte1%16;
unsigned int Byte8 = (HexByte1-Byte7)/16;
unsigned int Byte5 = HexByte2%16;
unsigned int Byte6 = (HexByte2-Byte5)/16;
unsigned int Byte3 = HexByte3%16;
unsigned int Byte4 = (HexByte3-Byte3)/16;
unsigned int Byte1 = HexByte4%16;
unsigned int Byte2 = (HexByte4-Byte1)/16;
double val =0;
val += (Byte1);
val += (Byte2)*16;
val += (Byte3)*16*16;
val += (Byte4)*16*16*16;
val += (Byte5)*16*16*16*16;
val += (Byte6)*16*16*16*16*16;
val += (Byte7)*16*16*16*16*16*16;
val += (Byte8)*16*16*16*16*16*16*16;
return val;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>ת<EFBFBD><D7AA>Ϊ16 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>charA = 'B' ,charB = 'F' ת<><D7AA>Ϊ 0xBF (ʮ<><CAAE><EFBFBD><EFBFBD>191)
int _2CharToHex(char charA,char charB)
{
int a = HexChar2Int(charA);
int b = HexChar2Int(charB);
return a*16 + b;
}
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊ2 <20>ֽ<EFBFBD>16 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>5000<EFBFBD><EFBFBD>16 <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ0x1388 ,ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
buf[0] = 0x13
buf[1] = 0x88
*/
void IntTo2ByteHex(int n,char *buf)
{
char TmpBuf[128];
memset(TmpBuf,0,128);
//5000->"1388"
itoa(n,TmpBuf,16);
int len = strlen(TmpBuf);
char CharBuf4[4];
memset(CharBuf4,0,4);
int idx = 3;
while(len>0 && idx>=0)
{
CharBuf4[idx] = TmpBuf[len-1];//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>TmpBuf <20>ĺ<EFBFBD><C4BA>漸λ
len--;
idx--;
}
buf[0] = _2CharToHex(CharBuf4[0],CharBuf4[1]);//0x13
buf[1] = _2CharToHex(CharBuf4[2],CharBuf4[3]);//0x88
}
//5000->"1388" <20><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊ<EFBFBD><CEAA><EFBFBD>ֽڵ<D6BD>16<31><36><EFBFBD><EFBFBD>asc <20>ַ<EFBFBD><D6B7><EFBFBD>
CString IntTo4ByteHexStr(int n)
{
CString ValStr = "0000";
char *CharBuf = CStringToLPCSTR(ValStr);
char TmpBuf[128];
memset(TmpBuf,0,128);
//int --> char (16<31><36><EFBFBD><EFBFBD>)
itoa(n,TmpBuf,16);//<2F><><EFBFBD>ñ<EFBFBD>׼<EFBFBD><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int len = strlen(TmpBuf);
int idx = 3;
while(len>0 && idx>=0)
{
CharBuf[idx] = TmpBuf[len-1];//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>TmpBuf <20>ĺ<EFBFBD><C4BA>漸λ
len--;
idx--;
}
//ת<><D7AA><EFBFBD>ɴ<EFBFBD>д<EFBFBD>ַ<EFBFBD>
ValStr.MakeUpper();
return ValStr;
}
//500000->"07 A1 20" <20><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊ<EFBFBD><CEAA><EFBFBD>ֽڵ<D6BD>16<31><36><EFBFBD><EFBFBD>asc <20>ַ<EFBFBD><D6B7><EFBFBD>
CString IntTo6ByteHexStr(int n)
{
CString ValStr = "000000";
char *CharBuf = CStringToLPCSTR(ValStr);
char TmpBuf[128];
memset(TmpBuf,0,128);
//int --> char (16<31><36><EFBFBD><EFBFBD>)
itoa(n,TmpBuf,16);//<2F><><EFBFBD>ñ<EFBFBD>׼<EFBFBD><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int len = strlen(TmpBuf);
int idx = 5;
while(len>0 && idx>=0)
{
CharBuf[idx] = TmpBuf[len-1];//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>TmpBuf <20>ĺ<EFBFBD><C4BA>漸λ
len--;
idx--;
}
//ת<><D7AA><EFBFBD>ɴ<EFBFBD>д<EFBFBD>ַ<EFBFBD>
ValStr.MakeUpper();
return ValStr;
}
CString IntTo8ByteHexStr(int n)
{
CString ValStr = "00000000";
char *CharBuf = CStringToLPCSTR(ValStr);
char TmpBuf[128];
memset(TmpBuf,0,128);
//int --> char (16<31><36><EFBFBD><EFBFBD>)
itoa(n,TmpBuf,16);//<2F><><EFBFBD>ñ<EFBFBD>׼<EFBFBD><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int len = strlen(TmpBuf);
int idx = 7;
while(len>0 && idx>=0)
{
CharBuf[idx] = TmpBuf[len-1];//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>TmpBuf <20>ĺ<EFBFBD><C4BA>漸λ
len--;
idx--;
}
//ת<><D7AA><EFBFBD>ɴ<EFBFBD>д<EFBFBD>ַ<EFBFBD>
ValStr.MakeUpper();
return ValStr;
}
//ByteLow <20><>8λ,ByteHigh <20><>
int TwoByte2Int(BYTE ByteLow,BYTE ByteHigh)
{
int val = 0;
//ByteLow <20><>
for(int k=0;k<8;k++)
{
if(IsBitOn(ByteLow,k))
SetIntBitOn(val,k);
}
//ByteHigh <20><>
for(int k=0;k<8;k++)
{
if(IsBitOn(ByteHigh,k))
SetIntBitOn(val,k+8);
}
return val;
}
//<2F><>ȡint <20><>0~7 λ<><CEBB><EFBFBD><EFBFBD>8~15λ
BYTE Int2Byte(int Val,bool bByteLow)
{
BYTE Byte = 0;
int Start=(bByteLow)?0:8;
for(int k=0;k<8;k++)
{
if((Val>>(k+Start))&1)
{
Byte= Byte |(1<<k);
}
}
return Byte;
}
#endif
#if 1
//<2F>ȴ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD>߳̽<DFB3><CCBD><EFBFBD>
void WaitForThreadExit(CWinThread* pThread)
{
if(pThread == NULL)
return;
DWORD dRet=-2;
MSG msg;
while (1)
{
dRet=MsgWaitForMultipleObjects(1,&pThread->m_hThread,FALSE,INFINITE,QS_ALLINPUT);
if (dRet == WAIT_OBJECT_0)//<2F>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD>߳̽<DFB3><CCBD><EFBFBD>
{
break;
}
else if (dRet == WAIT_OBJECT_0+1)//<2F><><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><><D7AA>
{
while (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else//<2F><><EFBFBD><EFBFBD>
{
break;
}
}
}
//<2F><><EFBFBD><EFBFBD>bool <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>b Ϊ<><CEAA><EFBFBD><EFBFBD>ֵ,<2C><><EFBFBD>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>ͨ<EFBFBD><CDA8>
bool CheckBool(bool b,CString msg)
{
if(!b)
{
CMsgBox MsgBox;
MsgBox.Show(msg);
return false;
}
return true;
}
//<2F><><EFBFBD><EFBFBD>n <20>ķ<EFBFBD>Χ[Start,end]
bool CheckRange(int n,int Start,int end)
{
return n>=Start && n<=end;
}
bool CheckRangeDb(double n,double Start,double end)
{
return n>=Start && n<=end;
}
bool CheckParRangeDb(CString ParName,double n,double Start,double end)
{
if(!CheckRangeDb(n,Start,end))
{
CString s1,s2;
s1 += "[";
s1 += ParName;
s1 += "]<5D><>Χ:";
s2.Format("[%.3f]~[%.3f]",Start,end);
s1 += s2;
CMsgBox MsgBox;
MsgBox.Show(s1);
return false;
}
return true;
}
//ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>CirclePar <20><><EFBFBD><EFBFBD>Բ<EFBFBD><D4B2><EFBFBD>ݵ<EFBFBD>Vec
void CreatCircleData(CCirclePar CirclePar,vector<Dbxy> &Vec)
{
Dbxy CenterPt = CirclePar.CenterPt;
double Radius = CirclePar.Radius;
int DEdgeCnt = CirclePar.DEdgeCnt;
bool bMerge = CirclePar.bMerge;
double StartAng = CirclePar.StartAng;
double EndAng = CirclePar.EndAng;
if(DEdgeCnt == 0)
{
DEdgeCnt = gDraw->GetCirclePtCnt(Radius);
}
//<2F>뾶------------------------------------
double EachAngle = 360/DEdgeCnt;
bool Flg = true;//<2F><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>־
double CurrAngle =StartAng;
Dbxy pt;
Dbxy FirstPt;
bool bLastPt = false;
vector<Dbxy> VecTmp;
while(CurrAngle<(EndAng+0.001))
{
//<2F>Ƕ<EFBFBD>ת<EFBFBD><D7AA>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
double radian = CurrAngle*PI/180;
if(IsDbEqualZero(Radius))//<2F>뾶Ϊ0 <20><>Ϊ<EFBFBD><CEAA>
{
pt = CenterPt;
}
else
{
pt.x = CenterPt.x + Radius*cos(radian);
pt.y = CenterPt.y + Radius*sin(radian);
}
if(Flg)
{
Flg = false;
FirstPt = pt;
VecTmp.push_back(pt);
}
else
{
VecTmp.push_back(pt);
}
if(bLastPt)
break;
CurrAngle += EachAngle;
if(CurrAngle>EndAng)//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
CurrAngle = EndAng;
bLastPt = true;
}
}
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>߶<EFBFBD>
if(bMerge)
{
VecTmp.push_back(FirstPt);
}
if(CirclePar.bReverse)
{
vector<Dbxy>::iterator iter = VecTmp.begin();
vector<Dbxy>::iterator iter_end = VecTmp.end();
reverse(iter,iter_end);
}
vector<Dbxy>::iterator iter = VecTmp.begin();
vector<Dbxy>::iterator iter_end = VecTmp.end();
for(;iter!=iter_end;iter++)
{
Dbxy pt = *iter;
pt.Cx = CenterPt.x;//<2F><><EFBFBD><EFBFBD>Բ<EFBFBD><D4B2><EFBFBD><EFBFBD>Ϣ
pt.Cy = CenterPt.y;
pt.bArc = true;
pt.bDir = CirclePar.bReverse;//Բ<><D4B2><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD>(<28><><EFBFBD><EFBFBD>˳ʱ<CBB3><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>)
Vec.push_back(pt);
}
}
//<2F><><EFBFBD><EFBFBD>Բ<EFBFBD><D4B2><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD>
bool GetArcDir(vector<Dbxy> &PtVec,Dbxy CenterPt)
{
int size = PtVec.size();
if(size>3)
{
Dbxy pt1 = PtVec[0];
Dbxy pt2 = PtVec[size/2];
Dbxy pt3 = PtVec[size-1];
if(((pt2.x-pt1.x)*(pt3.y-pt2.y)-(pt2.y-pt1.y)*(pt3.x-pt2.x))<0)
return true;
else
return false;
}
return true;
}
//΢<><EFBFBD><EBBCB6>ʱ<EFBFBD><CAB1>usΪ΢<CEAA><CEA2>
void ExactDelay(unsigned int us)
{
if(us>0)
{
LARGE_INTEGER ClockFre;
QueryPerformanceFrequency(&ClockFre);
LARGE_INTEGER start, end;
LONGLONG count = (us*ClockFre.QuadPart)/(1000*1000);
QueryPerformanceCounter(&start);
count = count + start.QuadPart ;
do
{
QueryPerformanceCounter(&end);
}while(end.QuadPart<count);
}
}
//ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Բ<EFBFBD><D4B2>
CCirclePar CalCircleByThreePt(Dbxy Pt1,Dbxy Pt2,Dbxy Pt3)
{
Dbxy Midpt1,Midpt2;
Midpt1.x = (Pt2.x+Pt1.x)/2;
Midpt1.y = (Pt2.y+Pt1.y)/2;
Midpt2.x = (Pt3.x+Pt1.x)/2;
Midpt2.y = (Pt3.y+Pt1.y)/2;
double K1 = -(Pt2.x-Pt1.x)/(Pt2.y-Pt1.y);
double K2 = -(Pt3.x-Pt1.x)/(Pt3.y-Pt1.y);
CCirclePar CD;
CD.CenterPt.x = (Midpt2.y - Midpt1.y -K2*Midpt2.x + K1*Midpt1.x)/(K1-K2);
CD.CenterPt.y = Midpt1.y + K1*(Midpt2.y - Midpt1.y - K2*Midpt2.x + K2*Midpt1.x)/(K1-K2);
CD.Radius = sqrtf((CD.CenterPt.x-Pt1.x)*(CD.CenterPt.x-Pt1.x)+(CD.CenterPt.y-Pt1.y)*(CD.CenterPt.y-Pt1.y));
return CD;
}
//<2F>ж<EFBFBD><D0B6><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>
bool IsDlgItemStrChange(int ID,CString Str,vector<CDlgItemStr> &DlgItemStrVec)
{
int size = DlgItemStrVec.size();
for(int k=0;k<size;k++)
{
CDlgItemStr &ItemStr = DlgItemStrVec[k];
if(ItemStr.m_ID == ID)
{
bool ret = (Str != ItemStr.m_Str);
if(ret)//<2F><>¼<EFBFBD>
{
ItemStr.m_Str = Str;
}
return ret;
}
}
//û<>ҵ<EFBFBD><D2B5>½<EFBFBD>һ<EFBFBD><D2BB>
CDlgItemStr ItemStr;
ItemStr.m_ID = ID;
ItemStr.m_Str = Str;
DlgItemStrVec.push_back(ItemStr);
return true;
}
//<2F><>ѯWndName <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
bool IsWndExist(CString WndName)
{
HWND hWnd;
hWnd = (HWND)::FindWindow(NULL,WndName);
return !(hWnd == NULL);
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΪWndName <20>Ĵ<EFBFBD><C4B4>ڷ<EFBFBD><DAB7><EFBFBD><EFBFBD><EFBFBD>ϢWndMsg
bool SendMsgToWnd(CString &WndName,CString &WndMsg)
{
HWND hWnd;
hWnd = (HWND)::FindWindow(NULL,WndName);
if(hWnd == NULL)
return false;
COPYDATASTRUCT cpd;
cpd.dwData = 0;
cpd.cbData = WndMsg.GetLength()+1;//<2F><>1 <20><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>
cpd.lpData = (void*)(CStringToLPCSTR(WndMsg));
SendMessage(hWnd,WM_COPYDATA,0, (LPARAM)&cpd);
return true;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>Dlg <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>ǰ<EFBFBD><C7B0>cmd <20><>list
void SendComLogToWnd(bool bSend,CString WndName,CString Msg)
{
CString WndMsg = gWorkTime.GetCurTime(":");
if(bSend)
WndMsg += " Send->";
else
WndMsg += " Rev->";
WndMsg += Msg;
SendMsgToWnd(WndName,WndMsg);
}
#endif
#if 1
//ms ת<><D7AA>Ϊus
int Ms2Us(int ms)
{
return ms*1000;
}
int MM2UM(double mm)
{
return mm*1000;
}
double UM2MM(int um)
{
return um/1000;
}
double D_UM2MM(double um)
{
return um/1000;
}
#endif
//<2F><><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD><DFB3><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>Ϣ
void ShowMsgInNewThread(CString s)
{
if(gMsgBox.IsbShowing())
return;
gMsgBox.SetMsg(s);
AfxBeginThread(NewMsgThread,&gMsgBox);
}
//ʹ<><CAB9>windows ͼƬ<CDBC><EFBFBD><E9BFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼƬ
BOOL PictureWindows(const CString &strPicFile)
{
CString sPicturePara= "shimgvw.dll ImageView_Fullscreen "+ strPicFile ;
ShellExecute(NULL, NULL, "rundll32.exe",
sPicturePara,"C:\\WINDOWS\\system32", SW_SHOW);
return TRUE;
}
void InitYearComb(CString FilePath,CComboBox &ComboBox)
{
ComboBox.ResetContent();//<2F><><EFBFBD><EFBFBD>
CWorkTime WorkTime;
vector<CString> YearPathVec;
//<2F><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
CFileMgr FileMgr;
FileMgr.GetChildFileOrDirName(true,FilePath,YearPathVec,"");
CString ThisYear = WorkTime.GetCurYear();
int size = YearPathVec.size();
if(size<1)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
ComboBox.InsertString(0,ThisYear);
ComboBox.SetCurSel(0);
return;
}
int SelIdx = 0;
for(int k=0;k<size;k++)
{
CString Year = FileMgr.GetFileNameFromPath(YearPathVec[k],true);
if(IsStringDigit(Year))
{
ComboBox.InsertString(k,Year);
if(Year == ThisYear)
SelIdx = k;
}
}
ComboBox.SetCurSel(SelIdx);
}
void InitMonthComb(CComboBox &ComboBox)
{
CWorkTime WorkTime;
CString Month = WorkTime.GetCurMonth();
int DefualtIdx = 0;
ComboBox.InsertString(0,SEL_ALL_STR);
for(int i=1;i<=12;i++)
{
CString s;
if(i<10)
s.Format("0%ld",i);
else
s.Format("%ld",i);
ComboBox.InsertString(i,s);
if(Month == s)
DefualtIdx = i;
}
//<2F><><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD>
ComboBox.SetCurSel(DefualtIdx);
}
//<2F><>list <20>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD><EFBFBD>
void ResetListCtrl(CListCtrl &List)
{
List.DeleteAllItems();
int nColumnCount = List.GetHeaderCtrl()->GetItemCount();
// Delete all of the columns.
for (int i=0; i < nColumnCount; i++)
{
List.DeleteColumn(0);
}
}
//<2F>ȴ<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ms(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ⳤʱ<E2B3A4><CAB1><EFBFBD><EFBFBD>Sleep<65><70>ʱ)
bool WaitDelayTime(int DelayTime)
{
int TotalDelay = DelayTime;//<2F>ܹ<EFBFBD><DCB9>ȴ<EFBFBD><C8B4><EFBFBD>ʱ<EFBFBD><CAB1>ms
int CheckDelay = 300;//ÿ<><C3BF>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD>ʱ
int CurDelay = 0;//<2F><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ
while(1)
{
if(gStopAllWrokCmd)
{
return false;
}
Sleep(CheckDelay);
CurDelay += CheckDelay;
if(CurDelay>TotalDelay)//ʱ<><EFBFBD><E4B5BD>
break;
}
return true;
}
//MFC <20><>CString ת<><D7AA>ΪC++ string
//<2F><>Ҫʹ<D2AA><CAB9>CString <20><>GetBuffer <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>й©<D0B9>ķ<EFBFBD><C4B7><EFBFBD>
char* CStringToLPCSTR(CString s)
{
return (char*)(LPCTSTR)s;
}
/*
//DirPath = E:\\LaipuLaserData\\ParaModifyRecord\\
//-->E:\\LaipuLaserData\\ParaModifyRecord\\2022\\01\\19\\
*/
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰʱ<C7B0><CAB1><EFBFBD><EFBFBD>Ŀ¼
CString CreatDataTimePath(CString DirPath)
{
CString Path = DirPath;
CFileMgr FileMgr;
CWorkTime WorkTime;
Path += WorkTime.GetCurYear();
Path += "\\"+WorkTime.GetCurMonth();
Path += "\\"+WorkTime.GetCurDay();
Path += "\\";
if(!FileMgr.IsDirectoryExists(Path))
{
FileMgr.CreatDir(Path);
}
return Path;
}