📄 bargrdlg.cpp
字号:
// bargrdlg.cpp : implementation file
//
#include "stdafx.h"
#include "bargraph.h"
#include "bargrdlg.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBargraphDlg dialog
CBargraphDlg::CBargraphDlg(CWnd* pParent /*=NULL*/)
: CDialog(CBargraphDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CBargraphDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CBargraphDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBargraphDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBargraphDlg, CDialog)
//{{AFX_MSG_MAP(CBargraphDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBargraphDlg message handlers
BOOL CBargraphDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CenterWindow();
//Get the client area extent.
CRect rectWindow;
CWnd::GetClientRect(&rectWindow);
int barWidth = rectWindow.Width() / 13;
int barHeight = rectWindow.Height() / 2;
CRect rect(barWidth, barHeight, barWidth * 2, rectWindow.Height() * .9);
//Create the buttons.
myButton1 = new CButton;
myButton1->Create("", WS_VISIBLE | WS_CHILD, rect, this, IDC_BUTTON1);
rect1 = rect;
myButton2 = new CButton;
rect.left += barWidth * 2;
rect.right += barWidth * 2;
myButton2->Create("", WS_VISIBLE | WS_CHILD, rect, this, IDC_BUTTON2);
rect2 = rect;
myButton3 = new CButton;
rect.left += barWidth * 2;
rect.right += barWidth * 2;
myButton3->Create("", WS_VISIBLE | WS_CHILD, rect, this, IDC_BUTTON3);
rect3 = rect;
myButton4 = new CButton;
rect.left += barWidth * 2;
rect.right += barWidth * 2;
myButton4->Create("", WS_VISIBLE | WS_CHILD, rect, this, IDC_BUTTON4);
rect4 = rect;
myButton5 = new CButton;
rect.left += barWidth * 2;
rect.right += barWidth * 2;
myButton5->Create("", WS_VISIBLE | WS_CHILD, rect, this, IDC_BUTTON5);
rect5 = rect;
myButton6 = new CButton;
rect.left += barWidth * 2;
rect.right += barWidth*2;
myButton6->Create("", WS_VISIBLE | WS_CHILD, rect, this, IDC_BUTTON6);
rect6 = rect;
maxHeight = rectWindow.Height() * .8;
deltaHeight = rectWindow.Height() * .1;
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 CBargraphDlg::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 CBargraphDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CBargraphDlg::OnButton1()
{
if (rect1.Height() < maxHeight)
rect1.top -= deltaHeight;
else
rect1.top = rect1.bottom - deltaHeight;
myButton1->SetWindowPos(&wndTop,
rect1.left,
rect1.top,
rect1.Width(),
rect1.Height(),
SWP_NOZORDER);
}
void CBargraphDlg::OnButton2()
{
if (rect2.Height() < maxHeight)
rect2.top -= deltaHeight;
else
rect2.top = rect2.bottom - deltaHeight;
myButton2->SetWindowPos(&wndTop,
rect2.left,
rect2.top,
rect2.Width(),
rect2.Height(),
SWP_NOZORDER);
}
void CBargraphDlg::OnButton3()
{
if (rect3.Height() < maxHeight)
rect3.top -= deltaHeight;
else
rect3.top = rect3.bottom - deltaHeight;
myButton3->SetWindowPos(&wndTop,
rect3.left,
rect3.top,
rect3.Width(),
rect3.Height(),
SWP_NOZORDER);
}
void CBargraphDlg::OnButton4()
{
if (rect4.Height() < maxHeight)
rect4.top -= deltaHeight;
else
rect4.top = rect4.bottom - deltaHeight;
myButton4->SetWindowPos(&wndTop,
rect4.left,
rect4.top,
rect4.Width(),
rect4.Height(),
SWP_NOZORDER);
}
void CBargraphDlg::OnButton5()
{
if (rect5.Height() < maxHeight)
rect5.top -= deltaHeight;
else
rect5.top = rect5.bottom - deltaHeight;
myButton5->SetWindowPos(&wndTop,
rect5.left,
rect5.top,
rect5.Width(),
rect5.Height(),
SWP_NOZORDER);
}
void CBargraphDlg::OnButton6()
{
if (rect6.Height() < maxHeight)
rect6.top -= deltaHeight;
else
rect6.top = rect6.bottom - deltaHeight;
myButton6->SetWindowPos(&wndTop,
rect6.left,
rect6.top,
rect6.Width(),
rect6.Height(),
SWP_NOZORDER);
}
void CBargraphDlg::OnDestroy()
{
CDialog::OnDestroy();
delete myButton1;
delete myButton2;
delete myButton3;
delete myButton4;
delete myButton5;
delete myButton6;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -