▲ 绘制一行简单文字
OnPaint() 消息。
void CMFCApplication6Dlg::OnPaint()
{
CPaintDC cdc(this);
/***OnPaint 绘制简单文字*****/
cdc.TextOutW(100, 100, TEXT("你好,MFC!"));
if (IsIconic())
{
CPaintDC dc(this); // 用于绘制的设备上下文
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// 使图标在工作区矩形中居中
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;
// 绘制图标
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialogEx::OnPaint();
}
}
函数内,下面这个是自己测试的代码:
CPaintDC cdc(this);
/***OnPaint 绘制简单文字*****/
cdc.TextOutW(100, 100, TEXT("你好,MFC!"));
标签:MFC,cdc,int,OnPaint,100,绘制
From: https://www.cnblogs.com/huvjie/p/17982935