1、CDC画图
CDC *pDC=GetDC(); //CDC方式创建
pDC->MoveTo(x1, y1); //起点
pDC->LineTo(x2, y2); //终点
ReleaseDC(pDC);
这段代码写在OnPaint()函数的else中,放在CDialogEx::OnPaint();后面,在CDialogEx::OnPaint();前面会不出图。
https://paulfzm.iteye.com/blog/974630
else
{
CDialogEx::OnPaint();
CDC *pDC = m_hist.GetDC();
//通过GetDC();函数创建了一个CDC 类型对象
//如此你就可以通过指针名pDC访问这个对象的成员函数。例如:pDC->MoveTo(10,10)
CPen Pen(PS_SOLID, 2, RGB(0, 0, 255));//创建画笔
//CPen(int nPenStyle, int nWidth, COLORREF crColor);RGB(红绿蓝)
pDC->SelectObject(&Pen); //选择画笔
pDC->MoveTo(0, 0);
pDC->LineTo(30, 50);
ReleaseDC(pDC);//所有调用GetWindowDC和GetDC获取的DC对象必须使用ReleaseDC来释放
}
就是GetDC或GetWindowDC获得的DC要使用ReleaseDC释放
Create得到的DC要用Delete释放
https://blog.csdn.net/business122/article/details/9612299
SetTextColor和SetBkColor来分别设置输出文本的前景色和背景色。
CDC::FillSolidRect
Call this member function to fill the given rectangle with the specified solid color.
void FillSolidRect(
LPCRECT lpRect,
COLORREF clr);
void FillSolidRect(
int x,
int y,
int cx,
int cy,
COLORREF clr);
https://docs.microsoft.com/zh-cn/cpp/mfc/reference/cdc-class?view=vs-2017#fillsolidrect
CDC::Rectangle
Draws a rectangle using the current pen.
BOOL Rectangle(
int x1,
int y1,
int x2,
int y2);
BOOL Rectangle(LPCRECT lpRect);
CDC::BitBlt
Copies a bitmap from the source device context to this current device context.
BOOL BitBlt(
int x,
int y,
int nWidth,
int nHeight,
CDC* pSrcDC,
int xSrc,
int ySrc,
DWORD dwRop);
2、meset()
void *memset(void *s,int c,size_t n)
总的作用:将已开辟内存空间 s 的首 n 个字节的值设为值 c。
作用是在一段内存块中填充某个给定的值,它是对较大的结构体或数组进行清零操作的一种最快方法。
举例:
struct UserSetting{};
UserSetting m_UserSetting;
meset(&m_UserSetting,0,sizeof(UserSetting));//初始化
3、设置字体:
CFont *m_font;
m_font = new CFont;
m_font->CreateFont(15, // nHeight
0, // nWidth
0, // nEscapement
0, // nOrientation
FW_BOLD, // nWeight
FALSE, // bItalic
FALSE, // bUnderline
0, // cStrikeOut
ANSI_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_DEFAULT_PRECIS, // nClipPrecision
DEFAULT_QUALITY, // nQuality
DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
_T("Arial")); // lpszFac
GetDlgItem(IDC_BUTTON1)->SetFont(m_font);
https://www.cnblogs.com/gcczhongduan/p/3986683.html
4、