Fold Group Box
다음 내용은 www.codeproject.com의 Button Control 섹션의 "CGroup - A Powerful Group Control" 부분에서 참고한 내용입니다.
그림에서 보다시피 Group Box 안에 들어가는 컨트롤들이 접히는 것을 볼 수 있습니다. 물론 옵션에 따라 그런 기능을 없앨수도 있습니다. 위의 Group Box 는 접히는 기능을 없앤 것이고, 아래의 Group Box는 그 기능이 있는 것이죠. 비교할 수 있게 두 개의 그림을 놓았습니다.

다음과 같은 순서로 따라하시면 됩니다.
1. 다이얼로그 베이스로 새로운 프로젝트를 만듭니다. 여기서는 프로젝트 이름을 GroupFolder 라고 정했습니다.
2. Group.h / cpp 파일을 프로젝트에 추가 (소스파일 다운로드)
3. 다이얼로그 템플릿 위에 Group Box를 놓습니다. 그리고 테스트 삼아 아무 컨트롤이나 그 위에 올려놓습니다.
이때 반드시 컨트롤이 Group Box 안에 완전히 들어가도록 놓아야 합니다.
만약 컨트롤이 Group Box를 벗어나면 Group Box가 접힐 때, 그 컨트롤은 Group Box에 포함되지 않아 사라지지 않습니다.
4. Group Box 의 ID를 IDC_STATIC에서 다른 것으로 바꿉니다. 여기서는 IDC_GROUP1 로 바꾸도록 하죠
5. Class Wizard의 Member Variables 탭에서 Group Box (앞에서 ID를 IDC_GROUP1 로 정했던 것) 에 멤버변수를 다음처럼 연결합니다.
Member variable name: m_Group1
Category: Control
Variable type:
CButton
6. GroupFolderDlg.h 파일의 CButton m_Group1 부분을 다음처럼 고칩니다.
CButton m_Group1 ===> CGroup m_Group1
그리고 이 파일의 제일 위에 다음처럼 헤더파일을 인클루드 시켜줍니다.
#include "Group.h"
7. 여기까지 작업 후 컴파일을 하면, 끝입니다. 기본적인 사용법은 아주 간단하죠.
8. CGroup 클래스의 멤버함수는 OnInitDialog 함수 내에서 다음처럼 사용하면 됩니다.
BOOL CGroupFolderDlg::OnInitDialog()
{
CDialog::OnInitDialog();
.................
// TODO: Add extra initialization
here
m_Group1.SetBarColor(RGB(128,128,0));
m_Group1.SetTextColor(RGB(100,200,30));
m_Group1.SetBarHeight(20);
m_Group1.SetFold(false);
return TRUE; // return
TRUE unless you set the focus to a control
}
9. CGroup 클래스의 멤버함수는 다음과 같습니다.
// CGroup 객체의 포인터 반환
CGroup* GetGroupCtrl() { return this;
}
// 타이틀바 색깔 변경
void SetBarColor(COLORREF color) { m_barColor
= color; Invalidate(); }
// 타이틀바 글자 색깔 변경
void SetTextColor(COLORREF color) { m_textColor
= color; Invalidate(); }
// Tells the group whether it attracts other groups
or not
// Attraction is vertical and descending. Any CGroup
placed under the current
// CGroup will be, if they didn't disable their attraction,
attracted.
void SetAttract(bool
toggle = false) { m_attract = toggle; Invalidate();
}
// Group Box가 접힐지(fold) 아닐지 설정
void SetFold(bool
toggle = true);
// Add a bitmap to the title bar and assign a color
mask
// If the bitmap is bigger than the title bar, you
can
// choose to resize the bar automatically.
void SetBitmap(UINT bmpID,COLORREF mask = RGB(0,0,0),bool resizeBar = false);
// Toggle to tell whether the group can be attracted
void SetAttraction(bool
toggle = true) { m_IsAttracted = toggle; Invalidate();
}
// 폰트 설정 (LOGFONT 구조체 또는 각종 변수 이용)
void SetTextFont (LOGFONT lf);
void SetTextFont (CString face,int
size = 12,bool
bold = true,bool
italic = false,bool
underline = false);
// 타이틀바 높이 설정
void SetBarHeight(int
h);
//Set whether the group will change its height
or not when attracted
// (ie the bottom of the group area will remain the
same, hence increasing or
// decreasing the height of the group as other groups
fold above it)
void SetLastGroup(bool
toggle = false) {m_last = toggle; Invalidate();
}
//Set whether the last control (lowest) in the
group will have its height modified by attraction
void SetLastCtrl(bool
toggle = false) {m_extendLastCtrl = toggle;
Invalidate(); }
//Toggle the display of the frame for the group
void DrawGroupBorder(bool
toggle = true) { m_borders = toggle; Invalidate();
}
//toggle the display the frame for the title bar
void DrawBarBorder(bool
toggle = true) { m_barBorders = toggle; Invalidate();
}
- the end -