-
Notifications
You must be signed in to change notification settings - Fork 0
/
ThirdoneDlg.cpp
150 lines (118 loc) · 3.37 KB
/
ThirdoneDlg.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// ThirdoneDlg.cpp : 实现文件
//
#include "stdafx.h"
#include "demodoc.h"
#include "ThirdoneDlg.h"
#include "afxdialogex.h"
#include "ContentListDlg.h"
// CThirdoneDlg 对话框
IMPLEMENT_DYNAMIC(CThirdoneDlg, CDialogEx)
CThirdoneDlg::CThirdoneDlg(CWnd* pParent /*=NULL*/)
: CDialogEx(CThirdoneDlg::IDD, pParent)
{
}
CThirdoneDlg::~CThirdoneDlg()
{
}
void CThirdoneDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BOOL CThirdoneDlg::OnInitDialog()
{
ShowWindow(SW_MAXIMIZE);
CRect rect(574,173,1130,236);
imgfile = _T("res\\3-1.jpg");
Show_picture(imgfile);
CEdit *editp =(CEdit *) GetDlgItem(IDC_EDIT1);
editp->MoveWindow( rect.left*xScale,rect.top*yScale, (rect.right-rect.left)*xScale,(rect.bottom-rect.top)*yScale );
LOGFONT lf;
memset(&lf,0,sizeof(lf));
lf.lfHeight = 35; //改变大小
font.CreateFontIndirect(&lf) ;
editp->SetFont(&font,TRUE);
CDialogEx::OnInitDialog();
return TRUE;
}
BEGIN_MESSAGE_MAP(CThirdoneDlg, CDialogEx)
ON_WM_LBUTTONDOWN()
ON_WM_PAINT()
END_MESSAGE_MAP()
// CThirdoneDlg 消息处理程序
void CThirdoneDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CRect rect1(614,634,835,805); //yirengongsi
CRect rect2(1046,631,1257,808); //heziyouxiangongsi
CRect rect3(1453,460,1680,520);//tuishangye
CRect rect4(1694,460,1893,520);//tuisouye
CRect rect5(1135,171,1318,239);//sousuoanniu
if (true == isPointInRect( point , rect1)){
CContentListDlg dlg;
mynum=1;
dlg.totaltypenum=mynum+fromwherenum;
dlg.DoModal();
}
if (true == isPointInRect( point , rect2)){
CContentListDlg dlg;
mynum=2;
dlg.totaltypenum=mynum+fromwherenum;
dlg.DoModal();
}
if (true == isPointInRect( point , rect3)){
CDialogEx::OnCancel();
}
if (true == isPointInRect( point , rect4)){
CDialogEx::OnCancel();
}
CDialogEx::OnLButtonDown(nFlags, point);
}
void CThirdoneDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: 在此处添加消息处理程序代码
// 不为绘图消息调用 CDialogEx::OnPaint()
Show_picture(imgfile);
}
bool CThirdoneDlg::Show_picture(CString imgPath)
{
int height, width;
CRect rect;//定义矩形类
CRect rect1;
CImage image; //创建图片类
image.Load(imgPath);
height = image.GetHeight();
width = image.GetWidth();
this->GetClientRect(&rect); //获得pictrue控件所在的矩形区域
CDC *pDc = this->GetDC();//获得pictrue控件的Dc
SetStretchBltMode(pDc->m_hDC,STRETCH_HALFTONE);
xScale=(float)rect.Width()/(float)width;
yScale=(float)rect.Height()/(float)height;
if(width<=rect.Width() && height<=rect.Width()) //小图片,不缩放
{
rect1 = CRect(rect.TopLeft(), CSize(width,height));
image.StretchBlt(pDc->m_hDC,rect,SRCCOPY); //将图片画到Picture控件表示的矩形区域
return TRUE;
}
else
{
xScale=(float)rect.Width()/(float)width;
yScale=(float)rect.Height()/(float)height;
float ScaleIndex=(xScale<=yScale?xScale:yScale);
rect1 = CRect(rect.TopLeft(), CSize((int)width*ScaleIndex,(int)height*ScaleIndex));
image.StretchBlt(pDc->m_hDC,rect,SRCCOPY); //将图片画到Picture控件表示的矩形区域
}
ReleaseDC(pDc);//释放picture控件的Dc
return TRUE;
}
bool CThirdoneDlg::isPointInRect(CPoint point ,CRect rect)
{
float a = xScale*rect.left;
float b = yScale*rect.top;
float c = xScale*rect.right;
float d = yScale*rect.bottom;
if (point.x > a && point.y> b && point.x < c && point.y< d){
return true;
}
return false;
}