graphpa.cpp
来自「VC做的矢量画图程序!」· C++ 代码 · 共 750 行 · 第 1/2 页
CPP
750 行
}
BEGIN_MESSAGE_MAP(ColorSetDialog, CDialog)
//{{AFX_MSG_MAP(ColorSetDilaog)
ON_BN_CLICKED(IDOK,OnOk)
ON_BN_CLICKED(IDCANCEL,OnCancel)
ON_BN_CLICKED(ID_YS_XG,nrxg)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
// NOTE: the ClassWizard will add message map macros here
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// ColorSet message handlers
/////////////////////////////////////////////////////////////////////////////
// LineSetDialog dialog
LineSetDialog::LineSetDialog(CWnd* pParent /*=NULL*/)
: CDialog(LineSetDialog::IDD, pParent)
{
//{{AFX_DATA_INIT(LineSetDialog)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
//构造函数
//参数:LineType-当前选择的线型的序号
LineSetDialog::LineSetDialog(int LineType,CWnd* pParent /*=NULL*/)
: CDialog(LineSetDialog::IDD, pParent)
{
m_LineType=LineType;
}
void LineSetDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(LineSetDialog)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
//绘制函数,绘制各个线型
void LineSetDialog::draw()
{
CRect r1;
int x1,x2,y1,y2,y3,y4,y5;
long color;
CPen *pPen,*pOldPen;
CPaintDC dc(this);
CBrush Brush(p_GraphPara->GetColor(0));
CBrush *pOldBrush=dc.SelectObject(&Brush);
pPen=new CPen(0,1,p_GraphPara->GetColor(0));
pOldPen=dc.SelectObject(pPen);
CStatic* pbut=(CStatic *)GetDlgItem(IDC_STATIC1);
pbut->GetWindowRect(&r1); //得到第1个绘制区域的屏幕坐标
ScreenToClient(&r1); //将屏幕坐标转换成客户区坐标
r1.top+=10; //调整绘制区域
dc.Rectangle(r1);
y1=(r1.top+r1.bottom)/2; //得到绘制直线的纵坐标
pbut=(CStatic *)GetDlgItem(IDC_STATIC2);
pbut->GetWindowRect(&r1); //得到第2个绘制区域的屏幕坐标
ScreenToClient(&r1); //将屏幕坐标转换成客户区坐标
r1.top+=10; //调整绘制区域
dc.Rectangle(r1);
y2=(r1.top+r1.bottom)/2; //得到绘制直线的纵坐标
pbut=(CStatic *)GetDlgItem(IDC_STATIC3);
pbut->GetWindowRect(&r1); //得到第3个绘制区域的屏幕坐标
ScreenToClient(&r1); //将屏幕坐标转换成客户区坐标
r1.top+=10; //调整绘制区域
dc.Rectangle(r1);
y3=(r1.top+r1.bottom)/2; //得到绘制直线的纵坐标
pbut=(CStatic *)GetDlgItem(IDC_STATIC4);
pbut->GetWindowRect(&r1); //得到第4个绘制区域的屏幕坐标
ScreenToClient(&r1); //将屏幕坐标转换成客户区坐标
r1.top+=10; //调整绘制区域
dc.Rectangle(r1);
y4=(r1.top+r1.bottom)/2; //得到绘制直线的纵坐标
pbut=(CStatic *)GetDlgItem(IDC_STATIC5);
pbut->GetWindowRect(&r1); //得到第5个绘制区域的屏幕坐标
ScreenToClient(&r1); //将屏幕坐标转换成客户区坐标
r1.top+=10; //调整绘制区域
dc.Rectangle(r1);
y5=(r1.top+r1.bottom)/2; //得到绘制直线的纵坐标
x1=r1.left;
x2=r1.right;
color=p_GraphPara->GetColor(1);
//以下绘制第1种线型的直线
pPen=new CPen(0,1,color);
pOldPen=dc.SelectObject(pPen);
dc.MoveTo(x1,y1);
dc.LineTo(x2,y1);
dc.SelectObject(pOldPen);
delete pPen;
//以下绘制第2种线型的直线
pPen=new CPen(1,1,color);
pOldPen=dc.SelectObject(pPen);
dc.MoveTo(x1,y2);
dc.LineTo(x2,y2);
dc.SelectObject(pOldPen);
delete pPen;
//以下绘制第3种线型的直线
pPen=new CPen(2,1,color);
pOldPen=dc.SelectObject(pPen);
dc.MoveTo(x1,y3);
dc.LineTo(x2,y3);
dc.SelectObject(pOldPen);
delete pPen;
//以下绘制第4种线型的直线
pPen=new CPen(3,1,color);
pOldPen=dc.SelectObject(pPen);
dc.MoveTo(x1,y4);
dc.LineTo(x2,y4);
dc.SelectObject(pOldPen);
delete pPen;
//以下绘制第5种线型的直线
pPen=new CPen(4,1,color);
pOldPen=dc.SelectObject(pPen);
dc.MoveTo(x1,y5);
dc.LineTo(x2,y5);
dc.SelectObject(pOldPen);
delete pPen;
dc.SelectObject(pOldBrush);
}
//保存对线型的选择退出对话框
void LineSetDialog::OnOk()
{
int pb[7];
//以下得到各选择钮的选择状态
CButton* pBtn=(CButton*)(GetDlgItem(IDC_LINE1));
pb[0]=pBtn->GetCheck();
pBtn=(CButton*)(GetDlgItem(IDC_LINE2));
pb[1]=pBtn->GetCheck();
pBtn=(CButton*)(GetDlgItem(IDC_LINE3));
pb[2]=pBtn->GetCheck();
pBtn=(CButton*)(GetDlgItem(IDC_LINE4));
pb[3]=pBtn->GetCheck();
pBtn=(CButton*)(GetDlgItem(IDC_LINE5));
pb[4]=pBtn->GetCheck();
//得到当前选择的线型序号
if(pb[0]==1)
m_LineType=0;
else if(pb[1]==1)
m_LineType=1;
else if(pb[2]==1)
m_LineType=2;
else if(pb[3]==1)
m_LineType=3;
else if(pb[4]==1)
m_LineType=4;
EndDialog(IDOK);
}
void LineSetDialog::OnCancel()
{
EndDialog(IDCANCEL);
}
//初始化函数
BOOL LineSetDialog::OnInitDialog()
{
CButton* pBtn;
//以下设置各选择钮的初始状态
if(m_LineType==0)
pBtn=(CButton*)(GetDlgItem(IDC_LINE1));
else if(m_LineType==1)
pBtn=(CButton*)(GetDlgItem(IDC_LINE2));
else if(m_LineType==2)
pBtn=(CButton*)(GetDlgItem(IDC_LINE3));
else if(m_LineType==3)
pBtn=(CButton*)(GetDlgItem(IDC_LINE4));
else if(m_LineType==4)
pBtn=(CButton*)(GetDlgItem(IDC_LINE5));
pBtn->SetCheck(1);
return TRUE;
}
BEGIN_MESSAGE_MAP(LineSetDialog, CDialog)
//{{AFX_MSG_MAP(LineSetDialog)
ON_BN_CLICKED(IDOK,OnOk)
ON_COMMAND(IDOK,CMOK)
ON_BN_CLICKED(IDCANCEL,OnCancel)
ON_COMMAND(IDCANCEL,CMCancel)
ON_WM_PAINT()
// NOTE: the ClassWizard will add message map macros here
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// LineSetDialog message handlers
/////////////////////////////////////////////////////////////////////////////
// LayerSetDialog dialog
LayerSetDialog::LayerSetDialog(CWnd* pParent /*=NULL*/)
: CDialog(LayerSetDialog::IDD, pParent)
{
//{{AFX_DATA_INIT(LayerSetDialog)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
//类的构造函数
//layerlist-指向存储层的结构数组;nLayerNumb-图层的数目;LayerIndex-当前层的序号
LayerSetDialog::LayerSetDialog(LayerStruct* LayerList,int nLayerNumb,int LayerIndex,CWnd* pParent /*=NULL*/)
: CDialog(LayerSetDialog::IDD, pParent)
{
m_LayerList1=new LayerStruct[p_GraphPara->n_LayerNumbAll];
m_nLayerNumb=nLayerNumb;
for(int i=0;i<m_nLayerNumb;i++)
m_LayerList1[i]=LayerList[i];
m_LayerIndex=LayerIndex;
p_LayerList=LayerList;
}
void LayerSetDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(LayerSetDialog)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
//在列表框中选中一个图层时的消息处理函数
void LayerSetDialog::nrcs1()
{
int nn=plist1->GetCurSel();
if(nn<0)
return;
CFont font;
font.CreateFont(30,10,0,0,50,0,0,0,255,OUT_TT_PRECIS,CLIP_CHARACTER_PRECIS,DEFAULT_QUALITY,FIXED_PITCH,"cjc");
CEdit *pEdit=(CEdit *)GetDlgItem(ID_FC_EDIT1);
pEdit->SetFont(&font,0);
pcom1->SetCurSel(1-m_LayerList1[nn].b_Display);
SetDlgItemText(ID_FC_EDIT1,m_LayerList1[nn].m_Name);
m_LayerIndex=nn;
}
//增加一个图层
void LayerSetDialog::nrzj()
{
char p2[22],p1[50];
GetDlgItemText(ID_FC_EDIT1,p2,20);
if(strlen(p2)<1)
{
AfxMessageBox("没有输入层的名称");
return;
}
if(strlen(p2)>20)
p2[20]=0;
strcpy(m_LayerList1[m_nLayerNumb].m_Name,p2);
m_LayerList1[m_nLayerNumb].b_Display=1;
sprintf(p1,"%d",m_nLayerNumb);
strcat(p1," ");
strcat(p1,p2);
strcat(p1," √");
plist1->AddString(p1);
plist1->SetCurSel(m_nLayerNumb);
nrcs1();
m_nLayerNumb++;
}
//修改当前选择的图层
void LayerSetDialog::nrxg()
{
char p2[20],p1[50];
int nn=plist1->GetCurSel();
if(nn<0)
return;
int nn1=pcom1->GetCurSel();
if(nn1<0)
{
AfxMessageBox("没有选择层的显示状态");
return;
}
GetDlgItemText(ID_FC_EDIT1,p2,21);
if(strlen(p2)<1)
{
AfxMessageBox("没有输入层的名称");
return;
}
m_LayerList1[nn].b_Display=1-nn1;
if(strlen(p2)>20)
p2[20]=0;
strcpy(m_LayerList1[nn].m_Name,p2);
sprintf(p1,"%d",nn);
strcat(p1," ");
strcat(p1,p2);
if(nn1==0)
strcat(p1," √");
plist1->DeleteString(nn);
if(nn==m_nLayerNumb-1)
plist1->AddString(p1);
else
plist1->InsertString(nn,p1);
plist1->SetCurSel(nn);
}
//保存对图层的修改和选择退出对话框
void LayerSetDialog::OnOk()
{
int i;
for(i=0;i<m_nLayerNumb;i++)
p_LayerList[i]=m_LayerList1[i];
delete m_LayerList1;
EndDialog(IDOK);
}
//放弃对图层的修改,退出对话框
void LayerSetDialog::OnCancel()
{
delete m_LayerList1;
EndDialog(IDCANCEL);
}
//被初始化函数调用,设置对话框的初始状态
void LayerSetDialog::InitNamesLst()
{
char p1[50],p2[10];
int nn,i;
pcom1=(CComboBox*)(GetDlgItem(ID_FC_COM1));
plist1=(CListBox*)(GetDlgItem(ID_FC_LIST1));
nn=plist1->GetCount();
if(nn>0)
plist1->ResetContent();
nn=pcom1->GetCount();
if(nn>0)
pcom1->ResetContent();
pcom1->AddString("显示");
pcom1->AddString("隐藏");
for(i=0;i<m_nLayerNumb;i++) //在列表框中加入各个图层
{
sprintf(p2,"%d",i);
strcpy(p1,p2);
strcat(p1," ");
strcat(p1,m_LayerList1[i].m_Name);
if(m_LayerList1[i].b_Display==1) //如果处于显示状态
strcat(p1," √");
plist1->AddString(p1);
}
plist1->SetCurSel(m_LayerIndex);
nrcs1();
}
//初始化函数
BOOL LayerSetDialog::OnInitDialog()
{
InitNamesLst();
return TRUE;
}
BEGIN_MESSAGE_MAP(LayerSetDialog, CDialog)
//{{AFX_MSG_MAP(LayerSetDialog)
ON_BN_CLICKED(IDOK,OnOk)
ON_BN_CLICKED(IDCANCEL,OnCancel)
ON_BN_CLICKED(ID_FC_ZJ,nrzj)
ON_BN_CLICKED(ID_FC_XG,nrxg)
ON_LBN_SELCHANGE(ID_FC_LIST1,nrcs1)
// NOTE: the ClassWizard will add message map macros here
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// LayerSetDialog message handlers
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?