๋ฐ˜์‘ํ˜•

์ง€๋‚œ ํฌ์ŠคํŒ…์—์„œ Dialog ๊ธฐ๋ฐ˜ Dynamic Layout ์ ์šฉ ๋ฐฉ๋ฒ•์„ ์†Œ๊ฐœํ–ˆ์—ˆ์Šต๋‹ˆ๋‹ค.

[MFC] Dynamic Layout ์ ์šฉํ•˜์—ฌ ์ปจํŠธ๋กค Resizing ํ•˜๊ธฐ(์˜ˆ์ œ ํฌํ•จ)

 

[MFC] Dynamic Layout ์ ์šฉํ•˜์—ฌ ์ปจํŠธ๋กค Resizingํ•˜๊ธฐ(์˜ˆ์ œ ํฌํ•จ)

์†Œ๊ฐœ Visual Studio 2015 MFC์—๋Š” ๋™์  ๋ ˆ์ด์•„์›ƒ(Dynamic Layout) ๊ธฐ๋Šฅ์ด ์ถ”๊ฐ€๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ด ๊ธฐ๋Šฅ์€ Dialog์˜ Resizing์— ๋”ฐ๋ผ ์ž๋™์œผ๋กœ Control๋“ค์˜ ํฌ๊ธฐ๊ฐ€ ์กฐ์ •๋˜๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ์•„๋ž˜ ์• ๋‹ˆ๋ฉ”์ด์…˜์„ ๋ณด๋ฉด..

luckygg.tistory.com

์ด๋ฒˆ ํฌ์ŠคํŒ…์—์„œ๋Š” CFormView ๊ธฐ๋ฐ˜ Dynamic Layout ์ ์šฉ ๋ฐฉ๋ฒ•์„ ์†Œ๊ฐœํ•˜๊ณ ์ž ํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฒˆ์— ๋‹ค๋ฃฐ ์˜ˆ์ œ๋Š” ์•„๋ž˜ ๋งํฌ์˜ ์˜ˆ์ œ ๊ธฐ๋ฐ˜์œผ๋กœ ์ž‘์„ฑ๋  ์˜ˆ์ •์ž…๋‹ˆ๋‹ค.

[MFC] Tab Control์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  ์—ฌ๋Ÿฌ Form ์Šค์œ„์นญํ•˜๊ธฐ(์˜ˆ์ œ ํฌํ•จ)

 

[MFC] Tab Control์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  ์—ฌ๋Ÿฌ Form ์Šค์œ„์นญํ•˜๊ธฐ(์˜ˆ์ œ ํฌํ•จ)

์ง€๋‚œ ํฌ์ŠคํŒ…์—์„œ ๋ฉ”์ธ ๋‹ค์ด์–ผ๋กœ๊ทธ์— ์ƒˆ๋กœ์šด ๋‹ค์ด์–ผ๋กœ๊ทธ๋ฅผ ๋ถ™์ด๋Š” ์˜ˆ์ œ๋ฅผ ๋ณด์—ฌ๋“œ๋ ธ์—ˆ์Šต๋‹ˆ๋‹ค. [MFC] Dialog์— Form(Dialog) ๋ถ™์ด๊ธฐ(์˜ˆ์ œ ํฌํ•จ) [MFC] Dialog์— Form(Dialog) ๋ถ™์ด๊ธฐ(์˜ˆ์ œ ํฌํ•จ) Dialog์— Dialog๋ฅผ ๋ถ™.

luckygg.tistory.com

์†Œ๊ฐœ

์ด๋ฒˆ ์˜ˆ์ œ๋Š” Main Dialog์— Picture Control๋กœ ์˜์—ญ์„ ์ง€์ •ํ•˜๊ณ , ํ•ด๋‹น ์˜์—ญ์— ์—ฌ๋Ÿฌ ๊ฐœ์˜ Dialog๋ฅผ ์Šค์œ„์นญํ•˜๋ฉฐ ๋ณด์—ฌ์ฃผ๋Š” ๋™์ž‘์„ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค. Main Dialog ๋ฐ ํ•˜์œ„ Dialog๊ฐ€ ์žˆ๋Š” ์ƒํƒœ์—์„œ Dynamic Layout์„ ์ ์šฉํ•˜๋ ค๋ฉด ์–ด๋–ป๊ฒŒ ํ•ด์•ผํ• ๊นŒ์š”?

์˜ˆ์ œ ํ”„๋กœ๊ทธ๋žจ ๊ตฌ์„ฑ

์‚ฌ์‹ค ์•„์ฃผ ๊ฐ„๋‹จํ•ฉ๋‹ˆ๋‹ค. Main Dialog์—์„œ ํ•˜์œ„ Dialog 3๊ฐœ๋ฅผ Dyname Layout์— ๋“ฑ๋กํ•˜๊ณ , ๊ฐ ํ•˜์œ„ Dialog์—์„œ๋Š” ๋™์ž‘ํ•  ์ปจํŠธ๋กค์„ ๋“ฑ๋กํ•˜๋ฉด ๋˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๊ฑด ์ฐจ๋ก€์ฐจ๋ก€ ์˜ˆ์ œ ์ฝ”๋“œ๋กœ ์„ค๋ช…ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

์ด๋ฒˆ ์˜ˆ์ œ๋„ Visual Studio 2015 MFC ๊ธฐ์ค€, Dialog ํ”„๋กœ์ ํŠธ์—์„œ ์ง„ํ–‰ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ์ฝ”๋“œ์˜ ์ค‘์š”ํ•œ ๋ถ€๋ถ„๋งŒ ๋ณธ๋ฌธ์—์„œ ์†Œ๊ฐœํ•˜๊ณ , ์ž์„ธํ•œ ๋‚ด์šฉ์€ ์ฒจ๋ถ€๋œ ์˜ˆ์ œ ์ฝ”๋“œ์—์„œ ํ™•์ธํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.

๋”ฐ๋ผ ํ•˜๊ธฐ

UI ์ปจํŠธ๋กค ๊ตฌ์„ฑ

์•„๋ž˜ ๋งํฌ์˜ ์˜ˆ์ œ ์ฝ”๋“œ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ Dynamic Layout์„ ์†Œ๊ฐœํ•ฉ๋‹ˆ๋‹ค. ์•ฝ๊ฐ„์˜ UI๊ฐ€ ๋ณ€๊ฒฝ๋์ง€๋งŒ, ์–ด๋ ต์ง€ ์•Š์œผ๋ฏ€๋กœ ๋„˜์–ด๊ฐ€๊ฒ ์Šต๋‹ˆ๋‹ค. 

[MFC] Tab Control์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  ์—ฌ๋Ÿฌ Form ์Šค์œ„์นญํ•˜๊ธฐ(์˜ˆ์ œ ํฌํ•จ)

๊ฐ ํ•˜์œ„ Dialog์— ๋ฒ„ํŠผ์„ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค. 

๊ฐ ํ•˜์œ„ Dialog UI ๊ตฌ์„ฑ

Main Dialog์˜ ๋™์  ๋ ˆ์ด์•„์›ƒ ์„ค์ •

Main Dialog์—์„œ ๋™์  ๋ ˆ์ด์•„์›ƒ ์ ์šฉ์„ ์œ„ํ•ด, ์•„๋ž˜์˜ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค. ์ด์ „ ์˜ˆ์ œ์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ, ์—ฌ๋Ÿฌ ๊ฐœ์˜ ์ด๋™ ๋ฐ ํฌ๊ธฐ ์กฐ์ • ์˜ต์…˜์„ ๋ณด์—ฌ์ฃผ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ํ•˜์œ„ Dialog๋Š” ์ด๋™ํ•˜์ง€ ์•Š๊ณ , X, Y ๋ฐฉํ–ฅ์œผ๋กœ 100% ๋น„์œจ๋กœ ํฌ๊ธฐ๋งŒ ์กฐ์ •ํ•˜๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.

void CExamDynamicLayoutDlg::SetupForDynamicLayout()
{
	// ๋™์  ๋ ˆ์ด์•„์›ƒ ํ™œ์„ฑํ™”.
	this->EnableDynamicLayout();

	/* ์ด๋™ ์˜ต์…˜ */
	// 1. ์ด๋™ํ•˜์ง€ ์•Š์Œ.
	auto move_none = CMFCDynamicLayout::MoveSettings{};
	// 2. X,Y ๋ฐฉํ–ฅ์œผ๋กœ 100% ๋น„์œจ ์ด๋™.
	auto move_both_100 = CMFCDynamicLayout::MoveSettings{};
	move_both_100.m_nXRatio = 100;
	move_both_100.m_nYRatio = 100;
	// 3. X ๋ฐฉํ–ฅ์œผ๋กœ๋งŒ 100% ๋น„์œจ ์ด๋™.
	auto move_x_100 = CMFCDynamicLayout::MoveSettings{};
	move_x_100.m_nXRatio = 100;
	// 4. Y ๋ฐฉํ–ฅ์œผ๋กœ๋งŒ 100% ๋น„์œจ ์ด๋™.
	auto move_y_100 = CMFCDynamicLayout::MoveSettings{};
	move_y_100.m_nYRatio = 100;
	/* ํฌ๊ธฐ ์กฐ์ • ์˜ต์…˜ */
	// 1. ํฌ๊ธฐ ์กฐ์ •ํ•˜์ง€ ์•Š์Œ.
	auto size_none = CMFCDynamicLayout::SizeSettings{};
	// 2. X,Y ๋ฐฉํ–ฅ์œผ๋กœ 100% ๋น„์œจ ํฌ๊ธฐ ์กฐ์ •.
	auto size_both_100 = CMFCDynamicLayout::SizeSettings{};
	size_both_100.m_nXRatio = 100;
	size_both_100.m_nYRatio = 100;
	// 3. X ๋ฐฉํ–ฅ์œผ๋กœ๋งŒ 100% ๋น„์œจ ํฌ๊ธฐ ์กฐ์ •.
	auto size_x_100 = CMFCDynamicLayout::SizeSettings{};
	size_x_100.m_nXRatio = 100;
	// 4. Y ๋ฐฉํ–ฅ์œผ๋กœ๋งŒ 100% ๋น„์œจ ํฌ๊ธฐ ์กฐ์ •.
	auto size_y_100 = CMFCDynamicLayout::SizeSettings{};
	size_y_100.m_nYRatio = 100;

	// Dialog์˜ ๋™์  ๋ ˆ์ด์•„์›ƒ ํฌ์ธํ„ฐ ํš๋“.
	auto manager = this->GetDynamicLayout();
	// ๋™์  ๋ ˆ์ด์•„์›ƒ ์ƒ์„ฑ.
	manager->Create(this);
	// ๋™์  ๋ ˆ์ด์•„์›ƒ์— ๋“ฑ๋กํ•  ์ปจํŠธ๋กค ์ถ”๊ฐ€.
	manager->AddItem(IDD_DIALOG_FORM1, move_none, size_both_100);
	manager->AddItem(IDD_DIALOG_FORM2, move_none, size_both_100);
	manager->AddItem(IDD_DIALOG_FORM3, move_none, size_both_100);
}

์œ„ ํ•จ์ˆ˜๋Š” OnOnInitDialog()์— ์ถ”๊ฐ€ํ•˜์—ฌ, ๋‹ค์ด์–ผ๋กœ๊ทธ ์ดˆ๊ธฐํ™” ๋•Œ ํ˜ธ์ถœ๋˜๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.

BOOL CExamDynamicLayoutDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	//...

	// ํ•˜์œ„ Dialog ์ดˆ๊ธฐํ™”.
	InitializeForms();

	// ๋™์  ๋ ˆ์ด์•„์›ƒ ์„ค์ •.
	SetupForDynamicLayout();
	
	// ๋ฆฌ์‚ฌ์ด์ง• ์ตœ์†Œ ํฌ๊ธฐ๋ฅผ ์œ„ํ•œ ์˜์—ญ ํš๋“.
	GetClientRect(&m_rcMinimumDialog);
	CalcWindowRect(m_rcMinimumDialog);

	return TRUE;  // ํฌ์ปค์Šค๋ฅผ ์ปจํŠธ๋กค์— ์„ค์ •ํ•˜์ง€ ์•Š์œผ๋ฉด TRUE๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
}

InitializeForms()๋Š” ํ•˜์œ„ Dialog ์ดˆ๊ธฐํ™”๋ฅผ ์œ„ํ•œ ํ•จ์ˆ˜์ด๊ณ , GetClientRect(), CalcWindowRect()๋Š” Resizing ์‹œ ์ตœ์†Œ ๊ฐ’์„ ์„ค์ •ํ•˜๊ธฐ ์œ„ํ•œ ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค.

ํ•˜์œ„ Dialog์˜ ๋™์  ๋ ˆ์ด์•„์›ƒ ์„ค์ •

์ด ์˜ˆ์ œ์˜ ํ•˜์œ„ Dialog๋Š” CDialogEx๋ฅผ ์ƒ์†๋ฐ›์€ ๊ฒƒ์ด ์•„๋‹ˆ๋ผ, CFormView๋ฅผ ์ƒ์†๋ฐ›์€ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ, ๋™์  ๋ ˆ์ด์•„์›ƒ์˜ ์„ค์ •์€ OnInitDialog()๊ฐ€ ์•„๋‹Œ HandleInitDialog()์ธ ์ ์— ์ฃผ์˜๋ฅผ ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. HandleInitDialog()๋Š” ํด๋ž˜์Šค ๋งˆ๋ฒ•์‚ฌ์—์„œ ๋“ฑ๋ก์ด ์•ˆ๋˜๋ฏ€๋กœ, ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ฝ”๋“œ์—์„œ ๋“ฑ๋กํ•ฉ๋‹ˆ๋‹ค.

// CForm Header ์ •์˜.
LRESULT HandleInitDialog(WPARAM, LPARAM);
void SetupForDynamicLayout();

// CForm Source ๊ตฌํ˜„.
BEGIN_MESSAGE_MAP(CForm1, CFormView)
	ON_MESSAGE(WM_INITDIALOG, HandleInitDialog)
END_MESSAGE_MAP()

LRESULT CForm1::HandleInitDialog(WPARAM, LPARAM)
{
	Default();  // allow default to initialize first (common dialogs/etc)

	// create OLE controls
	COccManager* pOccManager = afxOccManager;
	if ((pOccManager != NULL) && (m_pOccDialogInfo != NULL))
	{
		if (!pOccManager->CreateDlgControls(this, m_lpszTemplateName,
			m_pOccDialogInfo))
		{
			TRACE0("Warning: CreateDlgControls failed during form view init.\n");
			return FALSE;
		}

		SetupForDynamicLayout();
	}

	return FALSE;   // don't set focus until later
}

void CForm1::SetupForDynamicLayout()
{
	this->EnableDynamicLayout();

	auto move_none = CMFCDynamicLayout::MoveSettings{};
	
	auto size_both_100 = CMFCDynamicLayout::SizeSettings{};
	size_both_100.m_nXRatio = 100;
	size_both_100.m_nYRatio = 100;

	auto manager = this->GetDynamicLayout();

	manager->Create(this);
	manager->AddItem(IDC_BUTTON1, move_none, size_both_100);
}

์ด์™€ ๊ฐ™์€ ๋ฐฉ์‹์œผ๋กœ ํ•˜์œ„ Dialog ๋ชจ๋‘ ๋™์  ๋ ˆ์ด์•„์›ƒ์„ ์œ„ํ•œ ์ฝ”๋“œ๋ฅผ ์ ์šฉํ•ฉ๋‹ˆ๋‹ค. ๋ณธ๋ฌธ์— ์ฒจ๋ถ€๋œ ์˜ˆ์ œ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ฒฐ๊ณผ๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ฝ”๋“œ ๊ฒฐ๊ณผ
Exam_DynamicLayout - MultiForm.zip
0.14MB

๋ฐ˜์‘ํ˜•