   MFC Painting question ...
  Hey everyone. I am making an icon editor application. Well, so far I have the grid of pixels. And I have a dialog bar on the left side of the application's window (SDI app, BTW). And a color toolbox docked at the bottom.Well, in the dialog bar at the left (toolbox), there is a static control for a normal-sized icon preview. Well, here is how I call 'OnPaint' for the main view:void CIconEditView::OnPaint() {CPaintDC dc(this); // device context for paintingCMainFrame *pFrame = (CMainFrame*) AfxGetMainWnd();CRect rc;// TODO: Add your message handler code herefor (int x = 0; x < 32; x++) {dc.MoveTo((x * 16), 0);dc.LineTo((x * 16), (32 * 16));}for (int y = 0; y < 32; y++) {dc.MoveTo(0, (y * 16));dc.LineTo((32 * 16), (y * 16));}for (x = 0; x < 32; x++) {for (y = 0; y < 32; y++) {rc.left   = (x * 16) + 1;rc.right  = (x * 16) + 16;rc.top    = (y * 16) + 1;rc.bottom = (y * 16) + 16;dc.FillRect(&rc, new CBrush(m_clrPixels[x][y]));}}// Do not call CView::OnPaint() for painting messages}Well, when I process mouse messages (drawing on mouse move when left mouse button is down) it correctly draws the icon preview. Right now, when I resize the window, the icon "pixel grid" (the main view) still displays correctly.But, when I add this code:// In 'OnPaint'CDC *pDC = pFrame->m_wndToolbox.GetDlgItem(IDC_PREVIEW)->GetDC();   // Get DC for preview window control// ...dc.FillRect(&rc, new CBrush(m_clrPixels[x][y]));  // Fill "pixel" at 'x','y' in main viewpDC->SetPixel(x, y, m_clrPixels[x][y]);    // Set preview window's pixel at 'x','y'// ...It still draws fine, until I resize, maximize, etc., the entire window, the preview control and the main view is cleared. If I take the extra code out, it works fine (but doesn't redraw the preview icon). 'm_clrPixels' is declared as:COLORREF m_clrPixels[32][32];// Array that holds individual pixel colorsDoes anyone have any idea why this happens, and hopefully how I can fix this problem?Thanks in advance,    Matt U.   