MDI(Multi Document Interface)로 개발하기(완료)

imageimage

MDI 와 SDI의 차이를 설명하고
자주 사용하게 되는 Frame형태 또는 Architecture를 미리 만들어 놓는 과정을 설명 하였습니다.

이제 제가 사용하는 Frame의 최종 형태가 완성이 되었습니다.
이렇게 기본적인 형태를 준비 해놓고 프로젝트를 수행할 때 필요한 부분만 수정하여 사용할 목적으로 기본형태를 만들었습니다.

개발 방법이 궁금하시면 이전 단계 MDI(Multi Document Interface)로 개발하기1~5 까지를 참조 하시기 바랍니다.

이번에 다루는 주제는 사이즈 변경 가능한 유연한 도킹컨트롤 바 입니다.

Resizable Docking Window 또는 SizingControlBar 정도로 이름을 붙이면 될 것 같습니다.
첨부된 소스의 “CDynamicCtrlBar”클래스 입니다.

MFC로 작업하다 보면 CDialogBar를 사용하다 보면 상당히 불편한 부분이 많습니다.
CDynamicCtrlBar는 CDialog를 직접 도킹 시킬 수 있게 만들어 져 있습니다.

기능과 사용법을 살펴 보겠습니다.

MainFrame.h에 #include “DynaCtrlBar.h”를 선언합니다.그리고 도킹된 윈도우를 관리하는 클래스를 변수로 잡습니다 CSCBArray m_dynar; #include “DynaCtrlBar.h
class CMainFrame : public baseFRAME
{
     DECLARE_DYNCREATE(CMainFrame)  
public:
    CMainFrame();  
    CSCBArray    m_dynar;//동적바를 쉽게 추가 하고 제어하기 위해 Array로 만듦

 

윈도우 도킹

    Window를 직접 도킹시키기 위해서 m_dynar에 CDynamicWNDBarCF를 할당합니다.
    아래 소스는 CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) 에 코딩된 내용 입니다
.

     ///////////////////////////////////////////////////
    ///  동적 컨트롤바 생성 Default   
    //동적 BAR를 만들어 Frame에 붙인다
    int pos=0;
    pos=m_dynar.GetSize();
    m_dynar.Add(new CDynamicWNDBarCF());//생성자에서 바로 추가
    if (!m_dynar[0]->Create(_T(“Window Add”), this,CSize(460,100),FALSE, ID_VIEW_CTRLBAR+pos /* control*= Id*/))
    {
        TRACE0(“Failed to create instant bar\n”);
        return -1;        // fail to create
    }
    m_dynar[pos]->SetBarStyle(m_dynar[pos]->GetBarStyle() |
        CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC|SCBS_SIZECHILD);
    m_dynar[pos]->EnableDocking(CBRS_ALIGN_ANY);
    DockControlBar(m_dynar[pos], AFX_IDW_DOCKBAR_TOP);//default로 최상단에 고정

    CDlgSetItem* p_dlg=new CDlgSetItem();
    p_dlg->Create(IDD_DIALOG_SET,m_dynar[pos]);
    ((CDynamicWNDBarCF*)m_dynar[pos])->AddWnd(p_dlg,”Test1″);

CDialog클래스인 CDlgSetItem를 Modaless로 생성하여 도킹 시킨 것 입니다.

CDialog  도킹

CDialog클래스는
((CDynamicWNDBarCF*)m_dynar[pos])->AddDialog(new CDlgSetItem(),IDD_DIALOG_SET,”Test1″);
와 같이 사용하여 직접 도킹이 가능합니다.

CRichEditCtrl 도킹

   StatusControl 클래스는 CDynamicCtrlBarCF를 상속받아서 도킹 시킨 것입니다.
    유산한 방법으로 상속 받아서 도킹 시켜도 됩니다.  

   //동적 BAR를 만들어 Frame에 붙인다 좌측에 자동 고정    
    pos=m_dynar.GetSize();
    m_dynar.Add(p_App->p_statuslog);
    if (!m_dynar[pos]->Create(_T(“Status”), this,CSize(160,100),FALSE, ID_VIEW_CTRLBAR+pos /* control*= Id*/))
    {
        TRACE0(“Failed to create instant bar\n”);
        return -1;        // fail to create
    }
    m_dynar[pos]->SetBarStyle(m_dynar[pos]->GetBarStyle() |
        CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC|SCBS_SIZECHILD);
    m_dynar[pos]->EnableDocking(CBRS_ALIGN_ANY);
    DockControlBar(m_dynar[pos], AFX_IDW_DOCKBAR_LEFT);//default로 좌측  고정

도킹 컨트롤을 메뉴 제어하기(동적 메뉴 만들기)

도킹된 메뉴를 숨겼을 때 이를 다시 보여주기 위한 메뉴를 자동적으로 만듧니다.
CMainFrame::OnInitMenu(CMenu* pMenu) 에서 메뉴가 만들어 질 때  메뉴를 추가 합니다.

void CMainFrame::OnInitMenu(CMenu* pMenu)
{
    baseFRAME::OnInitMenu(pMenu);   
    CreateBarShowMenu();//MAin Frame이 활성화 될때 마다 동적 Bar View 메뉴 최적하 하도록    
}

///////////////////////////////////////////////////////////////////////////////////////

void CMainFrame::CreateBarShowMenu()
{
    CMenu* p_menu=AfxGetMainWnd()->GetMenu();
    UINT sz=p_menu->GetMenuItemCount();
    if(sz<0) return;
    if(m_dynar.GetSize()<=0)return;//컨트롤 할 것이 없으면 return
    BOOL b_Find=FALSE;
    CString m_text,m_comp;
    UINT i=0,j=0,sz_fnc=0,mID=0;        
    MENUITEMINFO m_menuinf;      
    CMenu* menu =NULL;
    CMenu* p_smenu=NULL;
    CMenu* p_third=NULL;
    memset(&m_menuinf,0,sizeof(MENUITEMINFO));
    m_menuinf.cbSize=sizeof(MENUITEMINFO);
    m_menuinf.fMask=MIIM_TYPE|MIIM_SUBMENU|MIIM_ID|MIIM_DATA;
    m_menuinf.fType=MFT_STRING;
    for(i=0; (p_third==NULL) && (i&
lt;sz) ;i++)//메뉴에서 찾고자 하는 항목을 찾아서 …
    {
       p_smenu=p_menu->GetSubMenu(i); //Sub Menu를 불러 와럿
       sz_fnc=p_smenu->GetMenuItemCount();//Sub Menu의 갯수를 확인
       for(j=0;j<sz_fnc;j++)
       {
           mID=p_smenu->GetMenuItemID(j);
           if(mID==ID_VIEW_STATUS_BAR)
           {               
               p_third=p_smenu;//상태바가 있는 위치 일 경우
               break;
           }
       }      
    }
    if(p_third==NULL)//View Menu가 없으므로 메뉴 추가
    {
        p_menu->AppendMenu(MF_STRING,MF_STRING,”View”);
    }
    //찾은 메뉴의 하단에 메뉴를 추가, 동적 메뉴 추가
    if(p_third)
    {     
      m_dynar[0]->GetWindowText(m_comp);//찾을 메뉴의 이름 가져 오기 즉 첫번째 메뉴
      sz=p_third->GetMenuItemCount();
      for(j=0;j<sz;j++)//추가 할 메뉴가 있는지 확인
      {
         p_third->GetMenuString(j,m_text,MF_BYPOSITION);
         if(m_text==m_comp)b_Find=TRUE;
      }
      if(!b_Find) //등록해야할 메뉴를 잧지 못한 경우
      {
      p_smenu->InsertMenu (sz,MF_BYPOSITION,MF_SEPARATOR);    //메뉴 구분선 추가 하기
      sz_fnc=m_dynar.GetSize();
      for(i=0;i<sz_fnc;i++)//메뉴에 자동 추가
      {
        m_dynar[i]->GetWindowText(m_text);
        p_smenu->InsertMenu (sz+i+1,MF_BYPOSITION,ID_VIEW_CTRLBAR+i,m_text);
        //p_menu->ModifyMenu(m_menuinf.wID, MF_BYCOMMAND, m_menuinf.wID,m_text);
      }
      }
    }
    sz_mnu=sz_mnu+m_dynar.GetSize();//Show 메뉴으 Click Command를 수행할 갯수 설정    
}

도킹 컨트롤의 최종상태 가져오기

도킹컨트롤의 사이즈 변경 또는 숨기기 도킹위치 변경 정보를 레지스트리에서 불러와  마지마 상태와 똑같이  복원합니다.

#ifdef _SCB_REPLACE_MINIFRAME
      m_pFloatingFrameClass = RUNTIME_CLASS(CSCBMiniDockFrameWnd);
    #endif //_SCB_REPLACE_MINIFAME
    CRuntimeClass* prt = GetRuntimeClass();
    CString sProfile = _T(prt->m_lpszClassName);
    TRY
    {
     if (VerifyBarState(sProfile))
     {
        CDynamicCtrlBar::GlobalLoadState(this, sProfile);
        LoadBarState(sProfile);
     }
    }
    CATCH(CException, e)
    {
      puts(“in except”);
    }
    END_CATCH  

도킹 컨트롤의 최종상태 저장하기

도킹컨트롤의 사이즈 변경 또는 숨기기 도킹위치 변경 정보를 레지스트리에 저장합니다.

void CMainFrame::OnDestroy()
{
    //Save Bar Status before MainFrame Closed
    CRuntimeClass* prt = GetRuntimeClass();
    CString sProfile = _T(prt->m_lpszClassName);
    CDynamicCtrlBar::GlobalSaveState(this, sProfile);
    SaveBarState(sProfile);      

    baseFRAME::OnDestroy();   
    // TODO: Add your message handler code here   
}

 

CRichEditCtrl을 파일로 저장하기

  CRichEditCtrl요 있는 내용을 파일로 저장합니다.

void StatusControl::SaveRtf()
{
       CString m_FullFile;
    CString s_file=AfxGetApp()->m_pszHelpFilePath ;
    int    p=s_file.ReverseFind(‘\\’);
    s_file=s_file.Left(p);
   
    m_FullFile.Format(“%s\\%s.rtf”,s_file,CTime::GetCurrentTime().Format(“%Y%m%d%H”));   
   
    CFile cFile(m_FullFile, CFile::modeCreate|CFile::modeWrite);
   
    EDITSTREAM es;
    es.dwCookie = (DWORD) &cFile;
    es.pfnCallback = MyStreamOutCallback;
    m_RichEdit.StreamOut(SF_RTF, es);
   
}

 

위의 과정까지 모두 구현 하고 나서 파일을 보관 하고 나면
다음에 작업할 땐 휠씬 쉽게 작업이 가능 할 것입니다.

“MDI(Multi Document Interface)로 개발하기(완료)”의 86개의 댓글

  1. I simply want to say I’m new to blogging and site-building and really savored this blog site. Very likely I’m going to bookmark your site . You actually come with really good articles. Appreciate it for sharing with us your web page.

  2. When I initially commented I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get three emails with the same comment. Is there any way you can remove me from that service? Thank you!

  3. obviously like your web-site but you have to check the spelling on quite a few of your posts. Several of them are rife with spelling issues and I find it very bothersome to tell the truth nevertheless I’ll certainly come back again.

  4. The next time I read a blog site, I really hope that it doesn’t dissatisfy me as much as this. I indicate, I understand it was my selection to check out, yet I actually believed youd have something fascinating to state. All I listen to is a lot of whimpering about something that you might deal with if you werent too busy trying to find interest.

  5. I uncovered your blog website on google as well as inspect a few of your very early messages. Remain to maintain the very good operate. I just additional up your RSS feed to my MSN News Reader. Seeking onward to learning more from you later!?

  6. The next time I read a blog, I really hope that it does not dissatisfy me as much as this. I mean, I know it was my option to check out, however I in fact believed youd have something intriguing to state. All I hear is a bunch of grumbling regarding something that you can take care of if you werent also busy searching for focus.

  7. An excellent share, I just given this onto a coworker who was doing a little evaluation on this. And he as a matter of fact acquired me breakfast due to the fact that I found it for him. smile. So let me rephrase that: Thnx for the reward! But yeah Thnkx for spending the moment to review this, I really feel strongly about it and love finding out more on this topic. Preferably, as you end up being proficiency, would certainly you mind upgrading your blog with even more information? It is highly helpful for me. Big thumb up for this blog post!

  8. Having read this I thought it was really informative.

    I appreciate you finding the time and effort to
    put this content together. I once again find myself personally spending a lot of time both reading and posting comments.

    But so what, it was still worthwhile!

  9. After study a few of the article on your internet site currently, and I really like your way of blog writing. I bookmarked it to my bookmark website listing as well as will be inspecting back quickly. Pls check out my internet site as well and also let me recognize what you think.

  10. This may be the appropriate blog for everyone who is would like to find out about this topic. You realize a whole lot its virtually tricky to argue on hand (not that I personally would want…HaHa). You definitely put a fresh spin on the topic thats been revealed for a long time. Wonderful stuff, just great!

  11. This is the ideal blog site for anyone who wishes to find out about this subject. You understand a lot its practically hard to say with you (not that I in fact would want?HaHa). You definitely placed a new spin on a subject thats been covered for years. Wonderful things, simply wonderful!

  12. I simply want to say I’m newbie to blogging and site-building and honestly liked you’re web site. More than likely I’m likely to bookmark your website . You amazingly have wonderful stories. Appreciate it for sharing your web site.

  13. I just want to tell you that I am beginner to blogs and truly loved this web site. More than likely I’m likely to bookmark your site . You amazingly come with wonderful well written articles. With thanks for sharing with us your blog site.

  14. Thank you for the sensible critique. Me & my neighbor were just preparing to do a little research about this. We got a grab a book from our area library but I think I learned more clear from this post. I am very glad to see such great info being shared freely out there.

  15. Hi there just wanted to give you a quick heads up. The words in your post seem to be running off the screen in Opera. I’m not sure if this is a format issue or something to do with browser compatibility but I thought I’d post to let you know. The design look great though! Hope you get the problem solved soon. Thanks

  16. Greetings from Los angeles! I’m bored to tears at work so I decided to check out your website on my iphone during lunch break. I really like the information you provide here and can’t wait to take a look when I get home. I’m surprised at how fast your blog loaded on my cell phone .. I’m not even using WIFI, just 3G .. Anyhow, good blog!

  17. I’m impressed, I need to say. Really not often do I encounter a weblog that’s each educative and entertaining, and let me tell you, you may have hit the nail on the head. Your concept is excellent; the difficulty is something that not enough individuals are speaking intelligently about. I’m very pleased that I stumbled throughout this in my seek for something regarding this.

  18. I’ve observed that in the world the present moment, video games are classified as the latest popularity with kids of all ages. Often times it may be not possible to drag your son or daughter away from the games. If you want the best of both worlds, there are numerous educational games for kids. Great post.

  19. I was just looking for this info for some time. After six hours of continuous Googleing, at last I got it in your web site. I wonder what is the lack of Google strategy that do not rank this type of informative sites in top of the list. Usually the top web sites are full of garbage.

  20. An impressive share! I’ve just forwarded this onto a colleague who has been conducting a little homework on this. And he in fact bought me dinner because I stumbled upon it for him… lol. So allow me to reword this…. Thanks for the meal!! But yeah, thanx for spending some time to talk about this subject here on your web site.

  21. hello!,I really like your writing very a lot! percentage we keep up a correspondence extra about your article on AOL? I need a specialist on this space to solve my problem. May be that’s you! Looking forward to see you.

  22. I just want to say I am just newbie to blogging and certainly savored your web page. Almost certainly I’m going to bookmark your website . You actually come with fabulous articles. Cheers for sharing your blog.

  23. I have realized some new items from your web site about pcs. Another thing I have always believed is that computers have become an item that each family must have for several reasons. They provide convenient ways in which to organize households, pay bills, shop, study, tune in to music and perhaps watch tv series. An innovative technique to complete these types of tasks is by using a notebook computer. These desktops are portable ones, small, highly effective and convenient.

  24. There are a handful of interesting points with time in this article but I do not determine if I see every one of them center to heart. There’s some validity but I am going to take hold opinion until I investigate it further. Good article , thanks so we want a lot more! Added to FeedBurner likewise

  25. I do enjoy the way you have framed this problem and it does give us some fodder for thought. However, coming from what precisely I have seen, I only trust as the reviews stack on that people today continue to be on point and in no way embark on a tirade associated with the news of the day. Yet, thank you for this superb piece and though I can not necessarily concur with it in totality, I regard the viewpoint.

  26. Hello there! This post couldn’t be written much better! Looking through this post reminds me of my previous roommate! He constantly kept preaching about this. I most certainly will forward this article to him. Fairly certain he will have a great read. Many thanks for sharing!

  27. Hi there, just became aware of your blog through Google, and found that it’s truly informative. I am gonna watch out for brussels. I will be grateful if you continue this in future. Numerous people will be benefited from your writing. Cheers!

  28. I have realized that online education is getting popular because getting your degree online has become a popular choice for many people. Numerous people have not really had a chance to attend a conventional college or university however seek the increased earning possibilities and a better job that a Bachelor Degree gives you. Still some others might have a college degree in one discipline but would wish to pursue some thing they now have an interest in.

  29. Hello, I think your blog may be having internet browser compatibility problems. When I look at your site in Safari, it looks fine however, when opening in I.E., it has some overlapping issues. I merely wanted to give you a quick heads up! Other than that, excellent site.

  30. I blog quite often and I truly thank you for your information. Your article has truly peaked my interest. I’m going to take a note of your website and keep checking for new details about once a week. I subscribed to your RSS feed too.

  31. I’ll immediately grasp your rss feed as I can not find your e-mail subscription hyperlink or newsletter service. Do you have any? Kindly let me recognise so that I may just subscribe. Thanks.

  32. I truly love your website.. Great colors & theme. Did you create this amazing site yourself? Please reply back as I’m hoping to create my own personal site and would love to know where you got this from or what the theme is called. Kudos!

  33. I have to show thanks to the writer just for bailing me out of this type of problem. After surfing around throughout the world wide web and seeing notions that were not beneficial, I figured my entire life was gone. Existing devoid of the approaches to the problems you’ve fixed through your write-up is a crucial case, and the kind which may have adversely affected my entire career if I hadn’t encountered your blog post. Your main mastery and kindness in maneuvering every aspect was precious. I’m not sure what I would’ve done if I hadn’t encountered such a stuff like this. I can at this moment relish my future. Thanks so much for this reliable and results-oriented guide. I will not hesitate to propose your blog post to anyone who should have tips on this subject matter.

  34. Can I just say what a relief to find somebody that actually knows what they are talking about on the internet. You actually realize how to bring an issue to light and make it important. More people should check this out and understand this side of your story. I was surprised you aren’t more popular because you surely have the gift.

  35. I do agree with all of the ideas you have presented in your post. They are really convincing and will definitely work. Still, the posts are very short for beginners. Could you please extend them a bit from next time? Thanks for the post.

댓글 남기기