📄 workdlg.cpp
字号:
// workDlg.cpp : implementation file
//
#include "stdafx.h"
#include "work.h"
#include "workDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CWorkDlg dialog
CWorkDlg::CWorkDlg(CWnd* pParent /*=NULL*/)
: CDialog(CWorkDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CWorkDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CWorkDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CWorkDlg)
DDX_Text(pDX, IDC_EDIT1, m_r);
DDV_MinMaxUInt(pDX, m_r, 1, 99);
DDX_Text(pDX, IDC_EDIT2, m_B);
DDX_Text(pDX, IDC_EDIT3, m_T);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CWorkDlg, CDialog)
//{{AFX_MSG_MAP(CWorkDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_EN_UPDATE(IDC_EDIT2, OnUpdateEdit2)
ON_EN_UPDATE(IDC_EDIT3, OnUpdateEdit3)
ON_EN_UPDATE(IDC_EDIT1, OnUpdateEdit1)
ON_WM_MOUSEWHEEL()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWorkDlg message handlers
BOOL CWorkDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CWorkDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CWorkDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CWorkDlg::OnUpdateEdit2()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function to send the EM_SETEVENTMASK message to the control
// with the ENM_UPDATE flag ORed into the lParam mask.
// TODO: Add your control notification handler code here
}
void CWorkDlg::OnUpdateEdit3()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function to send the EM_SETEVENTMASK message to the control
// with the ENM_UPDATE flag ORed into the lParam mask.
// TODO: Add your control notification handler code here
}
void CWorkDlg::OnUpdateEdit1()
{
UpdateData(true);
m_B=4*m_r*m_r*3.14;
m_T=4*m_r*m_r*m_r*3.14/3;
UpdateData(false);
CDC* pDC=GetDlgItem(IDC_STATIC)->GetDC();
CRect m_rc;
GetDlgItem(IDC_STATIC)->GetWindowRect(&m_rc);
CPoint zhongxin;
zhongxin.y=(m_rc.bottom+m_rc.top)/2;
zhongxin.x=(m_rc.left+m_rc.right)/2;
RedrawWindow();
if (m_r<100)
{
MidpointEllipse(pDC,zhongxin.x-10,zhongxin.y-160,m_r,m_r,RGB(255,0,0,0));
MidpointEllipse(pDC,zhongxin.x-10,zhongxin.y-160,m_r,0.2*m_r,RGB(255,0,0,0));
MidpointEllipse(pDC,zhongxin.x-10,zhongxin.y-160,0.2*m_r,m_r,RGB(255,0,0,0));
}
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function to send the EM_SETEVENTMASK message to the control
// with the ENM_UPDATE flag ORed into the lParam mask.
// TODO: Add your control notification handler code here
}
BOOL CWorkDlg::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
// TODO: Add your message handler code here and/or call default
CDC* pDC=GetDlgItem(IDC_STATIC)->GetDC();
CRect m_rc;
GetDlgItem(IDC_STATIC)->GetWindowRect(&m_rc);
CPoint zhongxin;
zhongxin.y=(m_rc.bottom+m_rc.top)/2;
zhongxin.x=(m_rc.left+m_rc.right)/2;
if (zDelta>0)
{ m_r++;
m_B=4*m_r*m_r*3.14;
m_T=4*m_r*m_r*m_r*3.14/3;
UpdateData(false);
}else
{m_r--;
m_B=4*m_r*m_r*3.14;
m_T=4*m_r*m_r*m_r*3.14/3;
UpdateData(false);}
RedrawWindow();
if (m_r<100)
{
MidpointEllipse(pDC,zhongxin.x-10,zhongxin.y-160,m_r,m_r,RGB(255,0,0,0));
MidpointEllipse(pDC,zhongxin.x-10,zhongxin.y-160,m_r,0.2*m_r,RGB(255,0,0,0));
MidpointEllipse(pDC,zhongxin.x-10,zhongxin.y-160,0.2*m_r,m_r,RGB(255,0,0,0));
}
//MidpointEllipse(pDC,200,200,100,100,RGB(255,255,0,0));
//pDC->Ellipse(m_rc.left-90-m_r,m_rc.top-235+m_r,m_rc.right+60+m_r,m_rc.bottom-85-m_r);
return CDialog::OnMouseWheel(nFlags, zDelta, pt);
}
void CWorkDlg::MidpointEllipse(CDC* aC,int xc,int yc,int a,int b,int color)
{
int aa=a*a;
int bb=b*b;
int twoaa=2*aa;
int twobb=2*bb;
int x=0;
int y=b;
int d;
int dx=0;
int dy=twoaa*y;
d=int(bb+aa*(-b+0.25)+0.5);
aC->SetPixel(xc+x,yc+y,color);
aC->SetPixel(xc+x,yc-y,color);
aC->SetPixel(xc-x,yc+y,color);
aC->SetPixel(xc-x,yc-y,color);
while(dx<dy)
{
x++;
dx+=twobb;
if(d<0)
{
d+=bb+dx;
}else{
dy-=twoaa;
d+=bb+dx-dy;
y--;
}
aC->SetPixel(xc+x,yc+y,color);
aC->SetPixel(xc+x,yc-y,color);
aC->SetPixel(xc-x,yc+y,color);
aC->SetPixel(xc-x,yc-y,color);
}
d=int(bb*(x+0.5)*(x+0.5)+aa*(y-1)*(y-1)-aa*bb+0.5);
while(y>0)
{
y--;
dy-=twoaa;
if(d>0)
{d+=aa-dy;
}else{
x++;
dx+=twobb;
d+=aa-dy+dx;
}
aC->SetPixel(xc+x,yc+y,color);
aC->SetPixel(xc+x,yc-y,color);
aC->SetPixel(xc-x,yc+y,color);
aC->SetPixel(xc-x,yc-y,color);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -