📄 标尺dlg.cpp
字号:
// 标尺Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "标尺.h"
#include "标尺Dlg.h"
#include "center_dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyDlg dialog
CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMyDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMyDlg)
m_edit1 = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyDlg)
DDX_Control(pDX, IDC_SLIDER1, m_slider);
DDX_Text(pDX, IDC_EDIT1, m_edit1);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
//{{AFX_MSG_MAP(CMyDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_DISP, OnButtonDisp)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BUTTON_COLOR, OnButtonColor)
ON_WM_MOVE()
ON_NOTIFY(NM_CUSTOMDRAW, IDC_SLIDER1, OnCustomdrawSlider1)
ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
ON_EN_UPDATE(IDC_EDIT1, OnUpdateEdit1)
ON_NOTIFY(NM_OUTOFMEMORY, IDC_SLIDER1, OnOutofmemorySlider1)
ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER1, OnReleasedcaptureSlider1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyDlg message handlers
BOOL CMyDlg::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
SetTimer(1,1,NULL);
linecolor=RGB(255,0,0);
textcolor=RGB(255,105,255);
pen.CreatePen(PS_SOLID,0,linecolor);
myFont.CreateFont(
16,
8,
0,
0,
FW_NORMAL,
FALSE,
FALSE,
0,DEFAULT_CHARSET,OUT_DEVICE_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,
"华文新魏");
// TODO: Add extra initialization here
m_scale=10;
m_slider.SetRange(5,20);
m_slider.SetPos(m_scale);
//获得屏幕大少
/* 屏幕dc初始化*/
HDC screenDC;
screenDC = CreateDC("DISPLAY",NULL,NULL,NULL);
/* 检索设备 */
win_rect.right = GetDeviceCaps(screenDC,HORZRES);
win_rect.bottom = GetDeviceCaps(screenDC,VERTRES);
/* 清除 */
DeleteDC(screenDC);
center_x=win_rect.right/2;
center_y=win_rect.bottom/2;
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 CMyDlg::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 CMyDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMyDlg::OnButtonDisp()
{
// TODO: Add your control notification handler code here
center_dlg centerdlg;
centerdlg.DoModal();
center_x=centerdlg.center_x;
center_y=centerdlg.center_y;
//刷新整个屏幕
ICONMETRICS im;
im.cbSize=sizeof(ICONMETRICS);
SystemParametersInfo(SPI_GETICONMETRICS,sizeof(ICONMETRICS),(PVOID)&im,0);
SystemParametersInfo(SPI_SETICONMETRICS,sizeof(ICONMETRICS),(PVOID)&im,SPIF_SENDCHANGE);
}
void CMyDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CWindowDC dc(NULL);
oldpen=dc.SelectObject(&pen);
// dc.SetTextColor(RGB(255,105,255));
dc.SetTextColor(textcolor);
dc.SetBkMode(TRANSPARENT);
oldFont=dc.SelectObject(&myFont);
dc.MoveTo(0,center_y);
dc.LineTo(win_rect.right,center_y);
dc.MoveTo(center_x,0);
dc.LineTo(center_x,win_rect.bottom);
// dc.TextOut(center_x+4,center_y+6,"0");
int i;
char msg[2];
//绘制X方向的刻度
for(i=1;(center_x+m_scale*i)<win_rect.right;i++)
{ if(i%10)
{ dc.MoveTo(center_x+m_scale*i,center_y-5);
dc.LineTo(center_x+m_scale*i,center_y+5);
}
else
{ dc.MoveTo(center_x+m_scale*i,center_y-10);
dc.LineTo(center_x+m_scale*i,center_y+10);
wsprintf(msg,"%d",i/10);
dc.TextOut(center_x+m_scale*i-4,center_y+10,msg);
}
}
for(i=1;m_scale*i<center_x;i++)
{ if(i%10)
{ dc.MoveTo(center_x-m_scale*i,center_y-5);
dc.LineTo(center_x-m_scale*i,center_y+5);
}
else
{ dc.MoveTo(center_x-m_scale*i,center_y-10);
dc.LineTo(center_x-m_scale*i,center_y+10);
wsprintf(msg,"-%d",i/10);
dc.TextOut(center_x-m_scale*i-8,center_y+10,msg);
}
}
//绘制Y方向的刻度
for(i=1;(center_y+m_scale*i)<win_rect.bottom;i++)
{ if(i%10)
{ dc.MoveTo(center_x-5,center_y+m_scale*i);
dc.LineTo(center_x+5,center_y+m_scale*i);
}
else
{ dc.MoveTo(center_x-10,center_y+m_scale*i);
dc.LineTo(center_x+10,center_y+m_scale*i);
wsprintf(msg,"-%d",i/10);
dc.TextOut(center_x+15,center_y-8+m_scale*i,msg);
}
}
for(i=1;m_scale*i<center_y;i++)
{ if(i%10)
{ dc.MoveTo(center_x-5,center_y-m_scale*i);
dc.LineTo(center_x+5,center_y-m_scale*i);
}
else
{ dc.MoveTo(center_x-10,center_y-m_scale*i);
dc.LineTo(center_x+10,center_y-m_scale*i);
wsprintf(msg,"%d",i/10);
dc.TextOut(center_x+15,center_y-8-m_scale*i,msg);
}
}
dc.SelectObject(oldFont);
dc.SelectObject(oldpen);
CDialog::OnTimer(nIDEvent);
}
void CMyDlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
void CMyDlg::OnButtonColor()
{
// TODO: Add your control notification handler code here
CColorDialog dlg;
int iResult;
iResult=dlg.DoModal();
if(iResult=IDOK)
{
textcolor=dlg.GetColor();
}
}
void CMyDlg::OnMove(int x, int y)
{
CDialog::OnMove(x, y);
//刷新整个屏幕
ICONMETRICS im;
im.cbSize=sizeof(ICONMETRICS);
SystemParametersInfo(SPI_GETICONMETRICS,sizeof(ICONMETRICS),(PVOID)&im,0);
SystemParametersInfo(SPI_SETICONMETRICS,sizeof(ICONMETRICS),(PVOID)&im,SPIF_SENDCHANGE);
// InvalidateRect(NULL,true);
// UpdateWindow();
}
void CMyDlg::OnCustomdrawSlider1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
m_edit1=m_slider.GetPos();
this->UpdateData(false);
*pResult = 0;
}
void CMyDlg::OnChangeEdit1()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CMyDlg::OnUpdateEdit1()
{
// 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 CMyDlg::OnOutofmemorySlider1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
*pResult = 0;
}
void CMyDlg::OnReleasedcaptureSlider1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
m_scale=m_edit1;
//刷新整个屏幕
ICONMETRICS im;
im.cbSize=sizeof(ICONMETRICS);
SystemParametersInfo(SPI_GETICONMETRICS,sizeof(ICONMETRICS),(PVOID)&im,0);
SystemParametersInfo(SPI_SETICONMETRICS,sizeof(ICONMETRICS),(PVOID)&im,SPIF_SENDCHANGE);
*pResult = 0;
}
BOOL CMyDlg::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
//刷新整个屏幕
ICONMETRICS im;
im.cbSize=sizeof(ICONMETRICS);
SystemParametersInfo(SPI_GETICONMETRICS,sizeof(ICONMETRICS),(PVOID)&im,0);
SystemParametersInfo(SPI_SETICONMETRICS,sizeof(ICONMETRICS),(PVOID)&im,SPIF_SENDCHANGE);
return CDialog::DestroyWindow();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -