void HistogramDrawDlg::OnPaint()
{
CPaintDC dc(this);
if(m_histogramDib.m_nBitCount != 8 && m_histogramDib.m_nBitCount != 24)
return ;
CRect clientRect;
GetDlgItem(IDC_STATIC_HisRect)->GetWindowRect(&clientRect);
ScreenToClient(&clientRect);
BeginWaitCursor(); // Draw Back Ground
//画背景
dc.SelectStockObject(NULL_BRUSH);
dc.Rectangle(clientRect.left-1, clientRect.top,
clientRect.right+3, clientRect.bottom+1);
//画直方图灰度频率与直方图绘制矩形区域比例关系,画直方图
unsigned int max=0;;
for(int i = 0;i < 256; i++)
{
if(m_histogramDib.m_histArray[i] > max)
max = m_histogramDib.m_histArray[i];
}
DWORD bufTemp[256];
double x = clientRect.Height();
for(int i = 0; i < 256; i++)
bufTemp[i]=(unsigned long)((float)m_histogramDib.m_histArray[i]*x/max);
for(int i = clientRect.left; i <= clientRect.right; i++)
{
dc.MoveTo(i, clientRect.bottom);
dc.LineTo(i, clientRect.bottom - bufTemp[i-clientRect.left]);
}
EndWaitCursor();
}
很久以前遇到多这个问题,记不太清楚了
原因好像是 IDC_STATIC_HisRect 这个是STATIC控件,本身有绘制消息,所以闪了一下就没了
使用DLG的区域直接用试试
谢谢了,不过我还是想知道这是为什么。