Jump to content
  • Advertisement
Sign in to follow this  
TFS_Waldo

MFC Painting question ...

This topic is 4860 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 painting

	CMainFrame *pFrame = (CMainFrame*) AfxGetMainWnd();
	CRect rc;
	
	// TODO: Add your message handler code here
	for (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 view

pDC->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 colors Does anyone have any idea why this happens, and hopefully how I can fix this problem? Thanks in advance, Matt U.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!