📄 funappimg.cpp
字号:
// FunAppImg.cpp : implementation file
//
#include "stdafx.h"
#include "neuronetsample.h"
#include "FunAppImg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFunAppImg
CFunAppImg::CFunAppImg()
{
m_pMemDC = NULL;
m_pWndDC = NULL;
}
CFunAppImg::~CFunAppImg()
{
if (m_pMemDC != NULL)
delete m_pMemDC;
}
BEGIN_MESSAGE_MAP(CFunAppImg, CStatic)
//{{AFX_MSG_MAP(CFunAppImg)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFunAppImg message handlers
void CFunAppImg::InitImg()
{
// BITMAP stBitmap;
RECT rect;
GetClientRect(&rect);
int iWidth = rect.right;
int iHeight = rect.bottom;
m_pMemDC = new CDC;
m_pWndDC = GetDC();
m_pMemDC->CreateCompatibleDC(m_pWndDC);
// stBitmap.bmType = 0;
// stBitmap.bmWidth = rect.right;
// stBitmap.bmHeight = rect.bottom;
// stBitmap.
// m_pBitmap->CreateBitmapIndirect()
m_Bitmap.CreateCompatibleBitmap(m_pWndDC, iWidth, iHeight);
m_pMemDC->SelectObject(&m_Bitmap);
ClearPaint();
}
void CFunAppImg::PaintImg(double* pOut, int iSamples, double dMax, BOOL bAutoScale, BOOL bStemGraph)
{
//clear graph
POINT p;
RECT rect;
GetClientRect(&rect);
int iWidth = rect.right;
int iHeight = rect.bottom;
//show graph
char szMax [10];
memset(szMax,0, 10);
sprintf(szMax, "%5.4e", dMax);
CPen* pPen = new CPen;
LOGPEN stLogPen;
stLogPen.lopnStyle = PS_SOLID;
stLogPen.lopnWidth = CPoint(0,0);
stLogPen.lopnColor = 0x00000000;
pPen->CreatePenIndirect(&stLogPen);
m_pMemDC->SelectObject(pPen);
int iFontSize = 10;
m_pMemDC->TextOut(3, 3, szMax);
m_pMemDC->TextOut(20 - iFontSize, iHeight/2, "0");
m_pMemDC->TextOut(iWidth-20-iFontSize, iHeight/2-iFontSize-4, "2π");
m_pMemDC->MoveTo(10, iHeight/2);
m_pMemDC->LineTo(iWidth-10,iHeight/2);
pPen->DeleteObject();
stLogPen.lopnStyle = PS_SOLID;
stLogPen.lopnWidth = CPoint(0,0);
stLogPen.lopnColor = 0x00FF0000;
pPen->CreatePenIndirect(&stLogPen);
m_pMemDC->SelectObject(pPen);
m_pMemDC->OffsetViewportOrg(20,10);
int iWidth1 = iWidth - 40;
int iHeight1 = iHeight - 20;
p.y = iHeight1/2;
p.x = 0;
m_pMemDC->MoveTo(p);
p.y = iHeight1/2 - pOut[0]/max(dMax,1) * iHeight1/2;
m_pMemDC->LineTo(p);
int i;
for (i = 1; i < iSamples; i++)
{
p.y = iHeight1/2;
if (!bAutoScale)
p.x = double(iWidth1)/(iSamples-1) * i;
else
p.x = iWidth1/(iSamples-1) * i;
if (bStemGraph)
m_pMemDC->MoveTo(p);
p.y = iHeight1/2 - pOut[i]/max(dMax,1) * iHeight1/2;
m_pMemDC->LineTo(p);
}
m_pMemDC->OffsetViewportOrg(-20,-10);
m_pWndDC->BitBlt(0,0, iWidth, iHeight, m_pMemDC, 1, 1, SRCCOPY);
delete pPen;
}
void CFunAppImg::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
RECT rect;
GetClientRect(&rect);
int iWidth = rect.right;
int iHeight = rect.bottom;
m_pWndDC->BitBlt(0,0, iWidth, iHeight, m_pMemDC, 1, 1, SRCCOPY);
// Do not call CStatic::OnPaint() for painting messages
}
void CFunAppImg::ClearPaint()
{
RECT rect;
GetClientRect(&rect);
int iWidth = rect.right;
int iHeight = rect.bottom;
m_pMemDC->FillSolidRect(&rect, 0x00FFFFFF);
m_pWndDC->BitBlt(0,0, iWidth, iHeight, m_pMemDC, 1, 1, SRCCOPY);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -