MDI(Multi Document Interface)로 개발하기5

앞에서 SDI로 프로젝트를 개발하고 MDI로 변환 하는 방법을 알아 보았습니다.
이장에서는 MDI 에서 CDialogBar를 사용하는 방법을 알아 보겠습니다.

CMainFrame과 CChildFrame의 차이와 CDialogBar에 개념이해 정도를 살펴 볼 것 입니다.

먼저 CDialogBar는 CDialog를 Frame에 ToolBar처럼 Docking되는 컨트롤이라고 보시면 됩니다.
실제로 CDialogBar는 CControlBar를 상속 받았으며 내부 코드로 구현 할 거의 없습니다.
이런 이유 때문에 코드가 Frame과 섞이게 되는 개인적으로는 만족스럽지 못하다고 느낍니다.

구현된 그림을 보면
imageCDialog를 ToolBar 처럼 프레임에 도킹시켜서, UI를 좀더 보기 좋게 만들 수 있습니다.
툴바를 대신할 수 있는 기능이라고 이해 하시면 됩니다.

콤보박스는 물론 리치에디터도 올릴 수가 있습니다.

 

 

 

자 그럼 구현 방법을 살펴 보겠습니다.

먼저 CDialog Class를 하나 생성하고 리소스에서 폼 속성 Style을 Child
Border속성을 None으로 바꾸어 줍니다.
image

생성된 CDialog클래스 에서 부모 클래스를 CDialogBar 로 바꾸어 줍니다.
저는 CDlgCtrl이라고 Dialog클래스를 만들었으므로 “class CDlgCtrl : public CDialogBar”와 같이 바꾸었으며
생성자를 변경했습니다.

“DlgCtrl.h”
class CDlgCtrl : public CDialogBar
{
// Construction
public:
CDlgCtrl(CWnd* parent=NULL);
“DlgCtrl.cpp”
CDlgCtrl::CDlgCtrl(CWnd* pParent /*=NULL*/)//CDialog(CDlgCtrl::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgCtrl)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}

CDialogBar의 부모클래스가 CDialog가 아니고 CControlBar이므로 생성자의 모양이 다릅니다.
CDialog상속에서 CDialogBar으로 바뀌었으니 부모클래스를 호출하는 부분도 모두 바꾸어 주어야 합니다.

void CDlgCtrl::OnSize(UINT nType, int cx, int cy)
{
CDialogBar::OnSize(nType, cx, cy);
//Child Frame에서 CDlgCtrl을 사용하기 위해 헤더에 CDlgCtrl를 하나 선언합니다.
#include "DlgCtrl.h"
class CChildFrame : public CMDIChildWnd
{
DECLARE_DYNCREATE(CChildFrame)
public:
CChildFrame();
CDlgCtrl m_DlgCtrl;
//그리고 “ChildFrame.cpp”에 도킹을 구현 합니다.
int CChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
if (!m_DlgCtrl.Create(this, IDD_DIALOG_CTRL,
CBRS_FLOAT_MULTI|CBRS_ALIGN_LEFT|CBRS_TOOLTIPS|CBRS_TOP|CBRS_BOTTOM|WS_CHILD|WS_VISIBLE|CBRS_SIZE_DYNAMIC,>AFX_IDW_DIALOGBAR))
{
TRACE0("Failed to create dialogbar\n");
return -1;        // fail to create
}
EnableDocking(CBRS_ALIGN_ANY); //프레임에 도킹허용
m_DlgCtrl.EnableDocking(CBRS_ALIGN_LEFT|CBRS_ALIGN_TOP|CBRS_ALIGN_BOTTOM); //Dialog bar가 도킹 될 수 있는 위치 설정
DockControlBar(&m_DlgCtrl,AFX_IDW_DOCKBAR_LEFT);   //프레임 좌측에 Dialgbar 도킹
RecalcLayout(); //Layout 재 계산
return 0;
}

도킹된 컨트롤러 사이즈 변경
ChildFrame이 Layout을 변경할 때 도킹된 Dialogbar도 프레임 사이즈에 맞게 변경되도록 합니다.

void CChildFrame::RecalcLayout(BOOL bNotify)
{
// TODO: Add your specialized code here and/or call the base class
if(m_DlgCtrl.GetSafeHwnd())
{
CRect rect;
CMDIChildWnd::GetWindowRect(rect) ;
m_DlgCtrl.MoveWindow(rect);
}
CMDIChildWnd::RecalcLayout(bNotify);
}

도킹컨트롤 숨기기, 보이기 메뉴 구현
도킹된 DialgBar를 메뉴에서 보이거나 숨기기 위해 Child 프레임에서 메뉴이벤트를 받아서
도킹컨트롤을 보여주거나 숨기도록 합니다.

void CChildFrame::OnViewDlgbar()
{
BOOL b_show=!m_DlgCtrl.IsWindowVisible();
ShowControlBar(&m_DlgCtrl,b_show,TRUE);
}

메뉴에 체크 버튼 넣기
도킹 컨트롤바의 상태를 알아내어 상태를 보여줍니다.
ON_UPDATE_COMMAND_UI에서 컨트롤바의 상태에 따라 메뉴를 Check 상태로 만들어 줍니다.

void CChildFrame::OnUpdateViewDlgbar(CCmdUI* pCmdUI)
{
if(m_DlgCtrl.IsWindowVisible()) pCmdUI->SetCheck(1);
else pCmdUI->SetCheck(0);
}

<도킹컨트롤의 도킹상태 알아내기
CDailoBar는 컨트롤바 이므로 컨트롤바의 도킹 상태를 알아 낼 수 있습니다.
이렇게 도킹상태를 파악하여 부착위치가 Top,left 등이 상태 인지에 따라서 버튼의 크기를 조절 할 수 있습니다.

BOOL CDlgCtrl::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult)
{
DWORD bs=    GetBarStyle();
if(bs== (CBRS_ALIGN_TOP|CBRS_ALIGN_BOTTOM) )
i_align=1;
else   i_align=0;
switch(message)
{
case 310:
Resize();
break;
}
TRACE("%d\r\n",message);
return CDialogBar::OnChildNotify(message, wParam, lParam, pLResult);
}
void CDlgCtrl::Resize()
{
CFrameWnd* p_Frame= GetDockingFrame();
CRect m_Rect,mrec;
if(!m_Btn1.GetSafeHwnd() && (this!=NULL))
{
m_Btn1.SubclassDlgItem(ID_CHILD_BTN,this);
}
if(!m_Btn1.GetSafeHwnd()) return;
p_Frame->GetWindowRect(&mrec);
CDialogBar::MoveWindow(0,0,mrec.right,mrec.Height());
if(i_align==0)    m_Rect.SetRect(4,4,110,40);
else//Herizen
m_Rect.SetRect(4,4,mrec.Width()-18,30);    
 m_Btn1.MoveWindow(m_Rect);
}

윈도우배경 색상 및 컨트롤의 색상 바꾸기
OnCtlColor에서 Dialog또는 버튼의 색상을 바 꿀 수 있습니다.

HBRUSH CDlgCtrl::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialogBar::OnCtlColor(pDC, pWnd, nCtlColor);
hbr=hbrush;
CString m_txt;
COLORREF RefBg=RGB(25,200,240);
COLORREF cReffnt=RGB(25,200,24);
CObject* pobj=pWnd;
if(IsKindOf(RUNTIME_CLASS(CComboBox)))//콤보박스 인 경우의 색상
{
pDC->SetTextColor(RGB(0xFF,0xDC,0x07));
pDC->SetBkColor( RefBg );
}
switch (pWnd->GetDlgCtrlID())
{
case ID_CHILD_BTN:
pDC->SetTextColor(RGB(230,230,250) );
pDC->SetBkColor(RGB(130,130,150) );
break;
case IDC_CHECK1:
pDC->SetTextColor(RGB(130,130,150));
pDC->SetBkColor(RefBg );
break;
default:
break;
}
return hbr;
}

여태 까지 구현된 결과화면은 바로 아래의 그림과 같은 모양이 됩니다.
왼쪽은 ChildFrame에 DialogBar를 도킹한 것이고 오른쪽은 아무런 코딩을 하지 않은
또 하나의 ChildFrame이 활성화 된 상태입니다.
물론 두개의 다른 Document Type이 하나의 MDI Project에 올려진 상태입니다.

imageimage

MDI에서 MainFrame과 ChildFrame의 역할을 좀더 이해하기가 용이 할 것입니다.

세세하게 더 많은 것을 설명하려고 했는데 막상 그렇지 못해서 아쉽습니다.

하나하나 풀어서 설명하려니 한도 끝도 없는 것 같아
MDI(Multi Document Interface)로 개발하기는 여기까지 설명하고 마칩니다.

기본적인 개념 이해화 향후 재사용 가능한 뼈대는 만들어 진 상태 입니다.
현재까지 코딩한 내용 소스첨부 하여 올려 놓았으니 참조 하시고 이해 하는데 도움이 되었으면 합니다.

지금 까지 의 내용은 Multi Document Interface 와 Single Document Interface를  이해하기 위한
코드를 소개 했습니다.

다음에는 컨트롤 바를 동적으로 사이즈 조절이 가능하게 하고
Log기능을 강화 해서 최종 아키텍쳐를 완성할 예정입니다.

 

 

이전

“MDI(Multi Document Interface)로 개발하기5”의 105개의 댓글

  1. I do not even know how I ended up here, but I thought this post was great.
    I don’t know who you are but certainly you’re going
    to a famous blogger if you are not already 😉 Cheers!

  2. Hey there just wanted to give you a quick heads up and let you know a few of the pictures aren’t loading properly.
    I’m not sure why but I think its a linking issue.
    I’ve tried it in two different internet browsers and both show the same results.

  3. My programmer is trying to persuade me to move to .net
    from PHP. I have always disliked the idea because of the
    costs. But he’s tryiong none the less. I’ve been using WordPress on a variety of websites for about a year
    and am concerned about switching to another platform. I have
    heard very good things about blogengine.net. Is there a way I can transfer all my wordpress
    posts into it? Any kind of help would be really appreciated!

  4. I really love your site.. Pleasant colors & theme.
    Did you make this amazing site yourself? Please reply back as I’m looking to
    create my own site and want to learn where you got this from or just what the theme is named.
    Kudos!

  5. I simply want to tell you that I am new to blogging and site-building and honestly loved your web blog. Probably I’m likely to bookmark your site . You absolutely come with tremendous posts. Regards for revealing your webpage.

  6. When I originally commented I clicked the -Alert me when brand-new comments are included- checkbox and also currently each time a remark is included I get 4 emails with the same comment. Exists any way you can eliminate me from that service? Many thanks!

  7. I discovered your blog site on google and also inspect a few of your very early articles. Continue to keep up the very good run. I simply additional up your RSS feed to my MSN Information Visitor. Looking for ahead to finding out more from you later on!?

  8. Can I just claim what a relief to discover a person that in fact knows what theyre speaking about online. You absolutely know exactly how to bring an issue to light and also make it important. More individuals require to read this as well as comprehend this side of the tale. I angle think youre not more preferred due to the fact that you definitely have the gift.

  9. Can I simply state what a relief to locate someone who really knows what theyre speaking about on the web. You most definitely understand how to bring an issue to light and also make it important. More individuals need to read this and understand this side of the story. I cant believe youre not a lot more popular because you most definitely have the present.

  10. Oh my benefits! an outstanding post guy. Thank you Nonetheless I am experiencing problem with ur rss. Don?t understand why Not able to subscribe to it. Exists any individual getting identical rss issue? Any person who understands kindly respond. Thnkx

  11. Can I just say what a relief to locate someone that really recognizes what theyre discussing on the web. You most definitely recognize how to bring an issue to light and make it crucial. More people require to read this as well as understand this side of the tale. I angle think youre not much more preferred since you certainly have the gift.

  12. After research study a few of the blog posts on your site now, and I truly like your way of blogging. I bookmarked it to my book mark site listing as well as will be examining back soon. Pls check out my website too and let me understand what you think.

  13. I?m impressed, I must say. Really seldom do I experience a blog that?s both informative and entertaining, and also let me tell you, you have struck the nail on the head. Your concept is superior; the issue is something that not enough people are talking intelligently about. I am really delighted that I stumbled across this in my search for something relating to this.

  14. Youre so trendy! I do not mean Ive review anything similar to this before. So great to find somebody with some original ideas on this subject. realy thanks for starting this up. this website is something that is required on the web, somebody with a little originality. beneficial task for bringing something brand-new to the web!

  15. That is the excellent mindset, nonetheless is just not help to make every sence whatsoever preaching about that mather. Virtually any method many thanks in addition to i had endeavor to promote your own article in to delicius nevertheless it is apparently a dilemma using your information sites can you please recheck the idea. thanks once more.

  16. Thanks for all of the labor on this site. My mother take interest in conducting research and it’s simple to grasp why. Many of us hear all regarding the lively mode you deliver great items on the website and as well as attract participation from others on the matter then my princess is in fact becoming educated a lot. Take advantage of the rest of the new year. You have been carrying out a remarkable job.

  17. 핑백: nằm mơ thấy sập nhà

  18. 핑백: mơ thấy người khác chết đuối

  19. An excellent share, I just offered this onto an associate that was doing a little analysis on this. As well as he actually got me breakfast since I located it for him. smile. So let me reword that: Thnx for the reward! But yeah Thnkx for investing the moment to discuss this, I really feel highly about it and also love reading more on this subject. When possible, as you come to be know-how, would you mind upgrading your blog site with more details? It is extremely useful for me. Big thumb up for this blog post!

  20. I simply want to mention I am just beginner to weblog and truly enjoyed you’re web-site. Likely I’m want to bookmark your site . You really come with fabulous posts. With thanks for sharing your web site.

  21. Heya i’m for the primary time here. I found this board and I to find It truly helpful & it helped me out a lot. I hope to provide something back and help others such as you helped me.

  22. Aw, this was a very nice post. In idea I would like to put in writing like this additionally – taking time and actual effort to make an excellent article… however what can I say… I procrastinate alot and in no way seem to get something done.

  23. I simply want to say I’m very new to blogging and actually liked this web-site. Very likely I’m going to bookmark your blog post . You surely come with very good articles. Regards for sharing your website.

  24. This is really interesting, You’re a very skilled blogger. I’ve joined your rss feed and look forward to seeking more of your wonderful post. Also, I’ve shared your web site in my social networks!

  25. Excellent read, I just passed this onto a colleague who was doing some research on that. And he just bought me lunch because I found it for him smile So let me rephrase that: Thank you for lunch! “Life is a continual upgrade.” by J. Mark Wallace.

  26. With havin so much content and articles do you ever run into any issues of plagorism or copyright violation? My site has a lot of unique content I’ve either written myself or outsourced but it looks like a lot of it is popping it up all over the internet without my authorization. Do you know any solutions to help reduce content from being stolen? I’d really appreciate it.

  27. A person essentially help to make seriously articles I would state. This is the first time I frequented your website page and thus far? I surprised with the research you made to make this particular publish incredible. Fantastic job!

  28. I would like to thank you for the efforts you have put in writing this blog. I’m hoping the same high-grade website post from you in the upcoming as well. Actually your creative writing skills has inspired me to get my own web site now. Really the blogging is spreading its wings rapidly. Your write up is a good example of it.

  29. Hrmm that was weird, my comment got eaten. Anyway I wanted to say that it’s good to be aware that somebody else also mentioned that as I had trouble finding the exact same info elsewhere. That was the first place that told me the answer. Thanks.

  30. I simply want to say I am just new to blogging and site-building and certainly liked this blog. Most likely I’m planning to bookmark your blog post . You amazingly have incredible writings. Regards for revealing your blog.

  31. Can I just say what a aid to seek out someone who actually knows what theyre talking about on the internet. You undoubtedly know the way to carry an issue to light and make it important. Extra folks need to read this and understand this facet of the story. I cant believe youre not more well-liked since you positively have the gift.

  32. Having read this I thought it was really enlightening. I appreciate you taking the time and effort to put this short article together. I once again find myself personally spending a lot of time both reading and posting comments. But so what, it was still worthwhile!

  33. Howdy! I know this is kinda off topic nevertheless I’d figured I’d ask. Would you be interested in exchanging links or maybe guest authoring a blog article or vice-versa? My blog goes over a lot of the same topics as yours and I believe we could greatly benefit from each other. If you are interested feel free to shoot me an e-mail. I look forward to hearing from you! Terrific blog by the way!

  34. An outstanding share! I’ve just forwarded this onto a colleague who had been doing a little homework on this. And he in fact bought me dinner because I discovered it for him… lol. So allow me to reword this…. Thanks for the meal!! But yeah, thanx for spending the time to discuss this topic here on your web page.

  35. I was very pleased to seek out this web-site.I wanted to thanks for your time for this wonderful learn!! I positively having fun with every little little bit of it and I have you bookmarked to check out new stuff you weblog post.

  36. You decided not to enter into great detail, nevertheless, you presented the essentials I desired to get me through. If you are trying to find started out with a task this is often the type of details that’s needed. Having more writers be part of the dialogue might be a great thing.

  37. Howdy very nice blog!! Guy .. Beautiful .. Amazing .. I will bookmark your site and take the feeds additionally…I’m glad to find numerous helpful info here in the post, we want develop extra techniques on this regard, thank you for sharing.

  38. Undeniably imagine that that you stated. Your favorite reason appeared to be at the internet the simplest thing to be aware of. I say to you, I definitely get irked whilst people consider concerns that they plainly don’t recognise about. You controlled to hit the nail upon the top and outlined out the whole thing with no need side-effects , people can take a signal. Will probably be back to get more. Thanks!

  39. I am extremely impressed with your writing skills as well as with the layout on your blog. Is this a paid theme or did you customize it yourself? Anyway keep up the excellent quality writing, it’s rare to see a great blog like this one these days..

  40. I’m really enjoying the theme/design of your website. Do you ever run into any web browser compatibility issues? A few of my blog visitors have complained about my website not operating correctly in Explorer but looks great in Opera. Do you have any solutions to help fix this problem?

  41. Hi there just wanted to give you a quick heads up. The words in your post seem to be running off the screen in Ie. I’m not sure if this is a format issue or something to do with internet browser compatibility but I figured I’d post to let you know. The design and style look great though! Hope you get the issue resolved soon. Kudos

댓글 남기기