๋ฐ˜์‘ํ˜•

๋”๋ธ” ๋ฒ„ํผ๋ง์— ๋Œ€ํ•œ ๋‚ด์šฉ์€ ์•„๋ž˜ ๊ธ€์„ ์ฝ์–ด์ฃผ์„ธ์š”.


์ด๋ฒˆ์—๋Š” GDI+ ๋”๋ธ” ๋ฒ„ํผ๋ง ์‚ฌ์šฉ๋ฒ•์„ ์•Œ๋ ค๋“œ๋ฆฌ๊ณ ์ž ํ•ฉ๋‹ˆ๋‹ค.

GDI ๋”๋ธ” ๋ฒ„ํผ๋ง ์‚ฌ์šฉ ๋ฐฉ๋ฒ•์€ ์•„๋ž˜ ๊ธ€์„ ์ฐธ๊ณ ํ•ด์ฃผ์„ธ์š”.


๋˜ํ•œ, GDI+๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ ์ค€๋น„๋‹จ๊ณ„๋ฅผ ์ฐธ๊ณ ํ•ด์ฃผ์„ธ์š”.



ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ ํ›„ OnDrawImage()๋ผ๋Š” ํ•จ์ˆ˜์— ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค.

์ฝ”๋“œ ์‚ฌ์šฉ๋ฒ•

void CDoubleBufferingDlg::OnDrawImage()
{
	// Picture Control DC๋ฅผ ์ƒ์„ฑ.
	CClientDC dc(GetDlgItem(IDC_PC_IMAGE));
	
	// Picture Control ํฌ๊ธฐ๋ฅผ ์–ป๋Š”๋‹ค.
	CRect rect;
	GetDlgItem(IDC_PC_IMAGE)->GetClientRect(&rect);

	// Picture Control์— ํ˜ธํ™˜๋˜๋Š” Graphics ์ƒ์„ฑ.
	Graphics mainG(dc.GetSafeHdc());

	// Picture Control ํฌ๊ธฐ๋กœ ๋น„ํŠธ๋งต(์ž„์‹œ ๋ฒ„ํผ) ์ƒ์„ฑ.
	Bitmap memBmp(rect.Width(), rect.Height());

	// ์ž„์‹œ ๋ฒ„ํผ์— ํ˜ธํ™˜๋˜๋Š” Graphics ์ƒ์„ฑ.
	Graphics memG(&memBmp);

	// ์ž„์‹œ ๋ฒ„ํผ์— ๊ฒ€์€์ƒ‰์œผ๋กœ ์ฑ„์šฐ๊ธฐ.
	SolidBrush brs(Color(255, 0, 0, 255));
	memG.FillRectangle(&brs, 0, 0, rect.Width(), rect.Height());

	// ๊ทธ๋ฆฌ๋Š” ์ž‘์—….
	// ...
	// ...

	// ์ž„์‹œ ๋ฒ„ํผ๋ฅผ Picture Control์— ๊ทธ๋ฆฌ๊ธฐ.
	mainG.DrawImage(&memBmp, 0, 0);
}


GDI๋ž‘ ๋น„๊ตํ•ด์„œ GDI+์˜ ์ฝ”๋“œ๊ฐ€ ์กฐ๊ธˆ์€ ๊ฐ„๊ฒฐํ•ด์กŒ์ฃ ?


์ด๋ฏธ์ง€๋‚˜ CrossLine, ๋„ํ˜•๊ฐ™์€ ๊ฒƒ์„ ๊ทธ๋ฆด ๋•Œ ํ‘œ์‹œํ•œ ๋ถ€๋ถ„์˜ ์œ„์น˜์—์„œ memG์— ๊ทธ๋ฆฌ๋ฉด ๋”๋ธ” ๋ฒ„ํผ๋ง์œผ๋กœ ๋™์ž‘ํ•ฉ๋‹ˆ๋‹ค.

OnDrawImage()๋ผ๋Š” ํ•จ์ˆ˜๋Š” OnPaint() ๋˜๋Š” ์‚ฌ์šฉ์ž ์ •์˜ ์œ„์น˜์—์„œ ํ˜ธ์ถœํ•ด๋„ ์ƒ๊ด€ ์—†์Šต๋‹ˆ๋‹ค.


โ€ป ์ฐธ๊ณ ๋กœ, ์œ„ ์˜ˆ์ œ๋Š” Picture Control ์ด๋ผ๋Š” Control์— ๊ทธ๋ฆฌ๋Š” ์ž‘์—…์ด๊ธฐ ๋•Œ๋ฌธ์— CClientDC๋ฅผ ์‚ฌ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค.

Custom UI ์ž‘์—… ์‹œ OnPaint์—์„œ ์ž‘์—…ํ•˜๋Š” ๊ฒฝ์šฐ์—๋Š” CPaintDC๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.



๋ฐ˜์‘ํ˜•