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

먼저 Formview를 수정하여 화면에 출력 할 수 있도록 ID를 수정하자

“AppFrame.h”를 수정하여 붉은색으로 표시된 부분과 같이 추가하자.

 

#include <afxtempl.h> // 추가

class CAppFrameApp : public CWinApp

{

public:

struct st_view //윈도우 개수를 정하기 위한 구조체

    {

        UINT max;

        UINT sz;

    };

    CMap<CString,LPCSTR,st_view*,st_view*> m_arDoc;//

CAppFrameApp();

………………..

DECLARE_MESSAGE_MAP()

protected:

void CreateView();

};

“AppFrame.cpp”부분을 수정하여 윈도우를 새로 생성하는 부분을 만들어 보자.

CAppFrameApp::CAppFrameApp()

{

// TODO: add construction code here,

// Place all significant initialization in InitInstance

st_view* p_view=NULL;

m_arDoc.SetAt(“AppFrame”,new st_view);

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

// 각각의 DOC Type에 대한 윈도우 갯수

p_view=m_arDoc[“AppFrame”];

p_view->max=4;

p_view->sz=0;

}

BOOL CAppFrameApp::InitInstance()

{

AfxEnableControlContainer();

………………

CSingleDocTemplate* pDocTemplate;

pDocTemplate = new CSingleDocTemplate(

IDR_MAINFRAME,

RUNTIME_CLASS(CAppFrameDoc),

RUNTIME_CLASS(CMainFrame), // main SDI frame window

RUNTIME_CLASS(CAppFrameView));

AddDocTemplate(pDocTemplate);

// Parse command line for standard shell commands, DDE, file open

CCommandLineInfo cmdInfo;

ParseCommandLine(cmdInfo);

// Dispatch commands specified on the command line

if (!ProcessShellCommand(cmdInfo))

return FALSE;

CreateView();//FileNew 이전에 View를 생성하기

// The one and only window has been initialized, so show and update it.

m_pMainWnd->ShowWindow(SW_SHOW);

m_pMainWnd->UpdateWindow();

return TRUE;

}

//View를 임의로 만들기

void CAppFrameApp::CreateView()

{

UINT nID=IDD_APPFRAME_FORM;

POSITION pos =NULL;

CRect mRect;

CView* pNewView = NULL;

CString m_Fmt;

CRuntimeClass *pNewViewClass=RUNTIME_CLASS(CAppFrameView);

CView* pOldView = ((CFrameWnd*)m_pMainWnd)->GetActiveView();//View 이미 생성되어 있음

CDocument* pDoc = ((CFrameWnd*)m_pMainWnd)->GetActiveDocument();

st_view* p_view=m_arDoc[“AppFra”];//창의 최대 개수와 생성된 개수 지정되어 있음

m_Fmt.Format(“Window %d”,p_view->sz);

If(pOldView)

    pOldView->GetClientRect(&mRect);

mRect.top+=130;

mRect.right=200;

mRect.bottom-=10;

pOldView->MoveWindow(mRect);

pOldView->SetDlgItemText(IDC_STATIC_CNT,m_Fmt);

for(p_view->sz=1;p_view->sz<p_view->max;p_view->sz++)

{

    CCreateContext context;

    context.m_pCurrentDoc = pDoc;

m_Fmt.Format(“Window %d”,p_view->sz);

    pNewView = (CView*)pNewViewClass->CreateObject();

    pNewView->Create(NULL, NULL, 0,

    mRect/*CFrameWnd::rectDefault*/,

m_pMainWnd, nID, &context);

pNewView->OnInitialUpdate();

pNewView->SetDlgItemText(IDC_STATIC_CNT,m_Fmt);

pNewView->ShowWindow(SW_SHOW);

mRect.OffsetRect(mRect.Width(),0);

}

}

F5를 눌러 실행시켜보면 그림과 같은 화면이 보입니다다.

그리고 하나의 View만 정상적으로 활성화(Active) 되어 있는 것을 볼 수 있을 것입니다.

SDI에 대해서는 자세한 설명을 하지 않겠습니다.

대략 적으로 둘러 볼 내용은 SDI는 하나의 Document에 접근하고 IDR_MAINFRAME 및 CMainFrame, CAppFrameView 및 Document가 하나의 그룹으로 이루어져 있고 하나의 View만

Active되 어 사용된다고 이해 만 하고 지나 가겠습니다.


자 이제 지금까지 코딩 한 것을 MDI로 만들고 특징을 분석해 보기로 합니다.

먼저 현재 까지 작업한 내용 중 몇 군데를 수정 하겠습니다.

“MainFrame.h”를 열어서

#if _MSC_VER > 1000

#pragma once

#endif // _MSC_VER > 1000

//#define FRAME_SDI

#ifdef FRAME_SDI

#define baseFRAME CFrameWnd //SDI

#else

#define baseFRAME CMDIFrameWnd //MDI

#endif

를 추가하고 클래스 상속을 변경합니다, 내용을 간단히 살펴보면

CMainFrame 이 CFrameWnd 또는 CMDIFrameWnd 둘 중 어느 하나를 상속받게 만든 것 입니다.

필요에 따라 //#define FRAME_SDI 를 주석으로 처리하면 MDI가 되고 주석을 없애면 SDI가 되도록 구성한 것입니다.

CMainFrame 는 SDI일 때 CFrameWnd 를 MDI일 때 는 CMDIFrameWnd 상속 받기 때문 입니다.

class CMainFrame : public baseFRAME

{

…..

}

컴파일 해보면 “MainFrame.cpp” 부분에 다수의 에러를 발견하게 될 텐데

CFrameWnd-> baseFRAME. 로 변경하는 작업을 해야 합니다.

  1. IMPLEMENT_DYNCREATE(CMainFrame, baseFRAME)
  2. BE
    GIN_MESSAGE_MAP(CMainFrame, baseFRAME)
  1. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)

{

if (baseFRAME::OnCreate(lpCreateStruct) == -1)

return -1;

  1. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)

{

if( !baseFRAME::PreCreateWindow(cs) )

return FALSE;

  1. void CMainFrame::AssertValid() const

{

baseFRAME::AssertValid();

}

  1. void CMainFrame::Dump(CDumpContext& dc) const

{

baseFRAME::Dump(dc);

}

그 다음은 BOOL CAppFrameApp::InitInstance()에서 아래와 같이 변경하여 SDI를

MDI로 전환 시킵니다.

LoadStdProfileSettings(); // Load standard INI file options (including MRU)

// Register the application’s document templates. Document templates

// serve as the connection between documents, frame windows and views.

#ifdef FRAME_SDI

CSingleDocTemplate* pDocTemplate;

pDocTemplate = new CSingleDocTemplate(

IDR_MAINFRAME,

RUNTIME_CLASS(CAppFrameDoc),

RUNTIME_CLASS(CMainFrame), // main SDI frame window

RUNTIME_CLASS(CAppFrameView));

AddDocTemplate(pDocTemplate);

#else

//// MDI 1

CMultiDocTemplate* pDocTemplate;

pDocTemplate = new CMultiDocTemplate(

IDR_MAINFRAME,

RUNTIME_CLASS(CAppFrameDoc),

RUNTIME_CLASS(CMainFrame), // custom MDI child frame

RUNTIME_CLASS(CAppFrameView));

AddDocTemplate(pDocTemplate);

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

// create main MDI Frame window

baseFRAME* pMainFrame = new baseFRAME;

if (!pMainFrame->LoadFrame(IDR_MAINFRAME))

return FALSE;

m_pMainWnd = pMainFrame;

#endif

// Parse command line for standard shell commands, DDE, file open

CCommandLineInfo cmdInfo;

ParseCommandLine(cmdInfo);

// Dispatch commands specified on the command line

if (!ProcessShellCommand(cmdInfo))

return FALSE;

그리고 다시 실행 시켜봅니다.아직 정상동작이 되지 않을 것입니다.

void CAppFrameApp::CreateView()부분을 디버깅 해보면

CView* pOldView = ((CFrameWnd*)m_pMainWnd)->GetActiveView(); 부터 에러가 발생 되는 것을 볼 수 있을 것입니다.

이하 부분

for(p_view->sz=1;p_view->sz<p_view->max;p_view->sz++)

{

    CCreateContext context;

    context.m_pCurrentDoc = pDoc;

m_Fmt.Format(“Window %d”,p_view->sz);

    pNewView = (CView*)pNewViewClass->CreateObject();

…….

}

에서 정상 실행이 되었는데도 아무런 창이 뜨지 않는 것을 확인 할 수 있을 것 입니다.

CAppFrameApp::InitInstance() 의 아래 부분에서 CreateView(); 부분은 SDI에서도 별다른

역할을 하지 못하고 MDI에서도 정상 동작 하지 않으므로 MDI에서만 동작 하도록 변경하고.

#ifndef FRAME_SDI //MDI일때만

CreateView();//FileNew 이전에 View를 생성하기

#endif

CreateView()를 수정합니다.

void CAppFrameApp::CreateView()

{

    CString strDocName;

    CDocTemplate* pSelect=NULL;

    st_view* p_view=NULL;

    POSITION pos=GetFirstDocTemplatePosition();

    while(pos!=NULL)

    {

        pSelect=GetNextDocTemplate(pos);

        pSelect->GetDocString(strDocName,CDocTemplate::docName);

        pSelect->SaveAllModified();

        if(!strDocName.IsEmpty())

        {

         p_view=m_arDoc[strDocName];

         if(p_view)

         {

         for(p_view->sz=0;p_view->sz<p_view->max;p_view->sz++)//미리 정의 해둔 갯수 만큼 윈도우 만들기

            {

             pSelect->OpenDocumentFile(NULL);

            }

         }

        }

    }

}

일단 한번 실행시켜보면 pSelect->GetDocString(strDocName,CDocTemplate::docName);

에서 Doc Type 을 가져오지 못하는 것을 볼 수 있습니다.

이 문제의 비밀은

String Table의 IDR_MAINFRAME 과 관계가 있습니다.

SDI 일 때 IDR_MAINFRAME 의 내용


MDI 차이를 보이는 것을 알 수 있습니다. 이는 MDI에서 여러 개의 Document Type에 접근 할 때 문서의 확장자를 결정하는 중요한 요소가 됩니다.

MDI형태로 String Table의 내용을 변경하고 일단 한번 구동 시켜 봅니다.

여러 개의 창이 생성된 것을 볼 수 있습니다. 정확히 말하면 View가 없이 MainFrame이 여러 개 생성 되어 있는 것입니다.


지문이 너무 길어져서 다음에 설명 하기로 합니다.

다음

이전글

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

  1. I just want to tell you that I am very new to blogging and site-building and definitely liked this page. Very likely I’m going to bookmark your website . You certainly come with amazing article content. Thanks a lot for sharing your blog.

  2. Great ¡V I should definitely pronounce, impressed with your web site. I had no trouble navigating through all the tabs as well as related information ended up being truly easy to do to access. I recently found what I hoped for before you know it at all. Quite unusual. Is likely to appreciate it for those who add forums or anything, web site theme . a tones way for your client to communicate. Excellent task..

  3. Thanks for your valuable post. As time passes, I have come to understand that the symptoms of mesothelioma cancer are caused by this build up connected fluid relating to the lining on the lung and the breasts cavity. The illness may start inside the chest spot and pass on to other limbs. Other symptoms of pleural mesothelioma cancer include losing weight, severe inhaling and exhaling trouble, nausea, difficulty taking in food, and inflammation of the face and neck areas. It must be noted that some people with the disease tend not to experience any serious signs and symptoms at all.

  4. I simply want to tell you that I’m newbie to weblog and absolutely liked this page. Probably I’m likely to bookmark your blog post . You absolutely have remarkable articles. Bless you for sharing with us your website.

  5. I am now not sure the place you are getting your information, however great topic. I needs to spend a while studying more or working out more. Thank you for fantastic information I used to be on the lookout for this info for my mission.

  6. I was recommended this blog by my cousin. I’m not sure whether this post is written by him as no one else know such detailed about my difficulty. You’re incredible! Thanks!

  7. Hey very nice web site!! Man .. Beautiful .. Amazing .. I will bookmark your site and take the feeds also…I’m happy to find a lot of useful information here in the post, we need develop more strategies in this regard, thanks for sharing. . . . . .

  8. With havin so much written content do you ever run into any issues of plagorism or copyright violation? My website has a lot of exclusive content I’ve either written myself or outsourced but it seems a lot of it is popping it up all over the internet without my agreement. Do you know any solutions to help prevent content from being stolen? I’d really appreciate it.

  9. Hello just wanted to give you a quick heads up and let you know a few of the images 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.

  10. A lot of thanks for your whole hard work on this web page. My mother enjoys setting aside time for internet research and it is easy to understand why. All of us know all regarding the powerful tactic you provide simple suggestions through the blog and improve contribution from some other people about this idea and our own simple princess is certainly studying so much. Take pleasure in the remaining portion of the new year. Your performing a pretty cool job.

  11. Hi, Neat post. There’s a problem along with your site in web explorer, could test this… IE nonetheless is the marketplace leader and a good portion of people will omit your excellent writing because of this problem.

  12. Hi, I do think this is a great web site. I stumbledupon it 😉 I am going to return once again since i have book-marked it. Money and freedom is the greatest way to change, may you be rich and continue to guide others.

  13. I discovered your blog site web site on the search engines and appearance a few of your early posts. Preserve the excellent operate. I simply extra your Feed to my MSN News Reader. Seeking forward to reading much more from you afterwards!…

  14. naturally like your web site but you need to check the spelling on quite a few of your posts. A number of them are rife with spelling problems and I find it very troublesome to tell the truth nevertheless I will surely come back again.

  15. Definitely believe that which you said. Your favorite justification seemed to be on the internet the simplest thing to be aware of. I say to you, I definitely get annoyed while people think about worries that they plainly do not know about. You managed to hit the nail upon the top as well as defined out the whole thing without having side-effects , people can take a signal. Will likely be back to get more. Thanks

  16. We’re a group of volunteers and opening a new scheme in our community. Your website provided us with valuable information to work on. You have done a formidable job and our entire community will be thankful to you.

  17. Thanks for the sensible critique. Me and 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 from this post. I am very glad to see such great info being shared freely out there.

  18. I’m amazed, I have to admit. Rarely do I encounter a blog that’s both educative and engaging, and without a doubt, you’ve hit the nail on the head. The problem is something too few people are speaking intelligently about. Now i’m very happy I found this in my hunt for something concerning this.

  19. Today, I went to the beach front with my children. I found a sea shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She put the shell to her ear and screamed. There was a hermit crab inside and it pinched her ear. She never wants to go back! LoL I know this is totally off topic but I had to tell someone!

  20. Fantastic beat ! I would like to apprentice while you amend your web site, how could i subscribe for a blog website? The account aided me a acceptable deal. I had been a little bit acquainted of this your broadcast offered bright clear idea

  21. With havin so much content do you ever run into any issues of plagorism or copyright infringement? My blog has a lot of completely unique content I’ve either written myself or outsourced but it appears a lot of it is popping it up all over the web without my agreement. Do you know any methods to help prevent content from being stolen? I’d certainly appreciate it.

  22. The next time I learn a weblog, I hope that it doesnt disappoint me as much as this one. I imply, I do know it was my choice to learn, however I actually thought youd have something attention-grabbing to say. All I hear is a bunch of whining about something that you could possibly fix should you werent too busy looking for attention.

  23. Intriguing article. I know I’m a little late in posting my comment even so the article were to the and merely the information I was searching for. I can’t say i trust all you could mentioned nonetheless it was emphatically fascinating! BTW…I found your site by having a Google search. I’m a frequent visitor for your blog and can return again soon.

  24. Excellent blog right here! Additionally your site a lot up fast! What host are you the use of? Can I am getting your associate link on your host? I want my website loaded up as fast as yours lol

  25. It’s a pity you don’t have a donate button! I’d most certainly donate to this superb blog! I suppose for now i’ll settle for bookmarking and adding your RSS feed to my Google account. I look forward to fresh updates and will talk about this site with my Facebook group. Talk soon!

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

  27. Thanks so much for giving everyone an extraordinarily breathtaking opportunity to check tips from this blog. It is often very fantastic plus packed with fun for me and my office fellow workers to visit your website at a minimum thrice in 7 days to read the latest tips you will have. And of course, we are always pleased with your mind-boggling solutions you serve. Certain two ideas in this posting are particularly the most suitable we have had.

  28. Have you ever considered about adding a little bit more than just your articles? I mean, what you say is valuable and all. But imagine if you added some great visuals or video clips to give your posts more, “pop”! Your content is excellent but with images and clips, this site could certainly be one of the most beneficial in its field. Superb blog!

  29. Have you ever considered writing an ebook or guest authoring on other blogs? I have a blog centered on the same ideas you discuss and would love to have you share some stories/information. I know my audience would appreciate your work. If you are even remotely interested, feel free to send me an e-mail.

  30. Excellent website you have here but I was wondering if you knew of any message boards that cover the same topics talked about in this article? I’d really love to be a part of online community where I can get suggestions from other experienced individuals that share the same interest. If you have any suggestions, please let me know. Cheers!

  31. Good post. I study one thing more difficult on completely different blogs everyday. It’s going to all the time be stimulating to learn content material from different writers and practice a little bit something from their store. I’d favor to use some with the content on my weblog whether or not you don’t mind. Natually I’ll offer you a hyperlink on your net blog. Thanks for sharing.

  32. you are really a good webmaster. The website loading speed is incredible. It seems that you’re doing any unique trick. Moreover, The contents are masterpiece. you’ve done a excellent job on this topic!

  33. Hi there! I know this is kinda off topic but I was wondering which blog platform are you using for this website? I’m getting tired of WordPress because I’ve had problems with hackers and I’m looking at options for another platform. I would be great if you could point me in the direction of a good platform.

  34. Its like you read my thoughts! You seem to understand a lot about this, such as you wrote the book in it or something. I feel that you simply could do with some p.c. to drive the message home a little bit, but instead of that, this is fantastic blog. A fantastic read. I will certainly be back.

  35. I loved as much as you’ll receive carried out right here. The sketch is attractive, your authored material stylish. nonetheless, you command get bought an nervousness over that you wish be delivering the following. unwell unquestionably come more formerly again as exactly the same nearly very often inside case you shield this hike.

  36. I simply desired to thank you very much all over again. I’m not certain what I would’ve done without the solutions provided by you concerning such a field. It had been the hard setting in my view, nevertheless being able to view a specialised tactic you resolved the issue took me to jump with joy. I will be grateful for this advice and as well , expect you really know what a great job you are always providing educating people today thru your blog. Most probably you haven’t met all of us.

  37. Hey there this is kind of of off topic but I was wanting to know if blogs use WYSIWYG editors or if you have to manually code with HTML. I’m starting a blog soon but have no coding experience so I wanted to get guidance from someone with experience. Any help would be greatly appreciated!

  38. Hello there! Quick question that’s entirely off topic. Do you know how to make your site mobile friendly? My website looks weird when viewing from my apple iphone. I’m trying to find a theme or plugin that might be able to correct this issue. If you have any suggestions, please share. Cheers!

  39. Throughout the great scheme of things you’ll secure an A+ with regard to effort. Where exactly you actually lost me was first in all the particulars. You know, people say, details make or break the argument.. And it couldn’t be more accurate right here. Having said that, let me tell you just what exactly did do the job. Your article (parts of it) can be pretty powerful and that is possibly why I am taking the effort in order to comment. I do not really make it a regular habit of doing that. 2nd, even though I can notice a jumps in reasoning you make, I am definitely not confident of just how you seem to connect your details that make the actual final result. For now I shall yield to your point however hope in the near future you connect the dots much better.

  40. Great goods from you, man. I’ve understand your stuff previous to and you’re just extremely great. I really like what you’ve acquired here, really like what you are saying and the way in which you say it. You make it entertaining and you still take care of to keep it wise. I cant wait to read much more from you. This is really a great website.

  41. An impressive share, I simply given this onto a colleague who was doing a little analysis on this. And he in truth purchased me breakfast as a result of I found it for him.. smile. So let me reword that: Thnx for the treat! But yeah Thnkx for spending the time to debate this, I feel strongly about it and love studying extra on this topic. If possible, as you change into experience, would you mind updating your blog with more details? It is extremely useful for me. Big thumb up for this blog put up!

  42. Good blog! I truly love how it is simple on my eyes and the data are well written. I am wondering how I could be notified when a new post has been made. I have subscribed to your RSS which must do the trick! Have a great day!

  43. You really make it seem so easy with your presentation but I find this matter to be really something which I think I would never understand. It seems too complicated and very broad for me. I am looking forward for your next post, I will try to get the hang of it!

  44. This design is spectacular! You most certainly know how to keep a reader amused. Between your wit and your videos, I was almost moved to start my own blog (well, almost…HaHa!) Fantastic job. I really loved what you had to say, and more than that, how you presented it. Too cool!

  45. hello there and thank you for your info – I’ve certainly picked up something new from right here. I did however expertise several technical issues using this web site, since I experienced to reload the website a lot of times previous to I could get it to load correctly. I had been wondering if your hosting is OK? Not that I’m complaining, but sluggish loading instances times will often affect your placement in google and could damage your quality score if ads and marketing with Adwords. Anyway I am adding this RSS to my e-mail and can look out for a lot more of your respective exciting content. Ensure that you update this again soon..

  46. I’m really enjoying the design and layout of your blog. It’s a very easy on the eyes which makes it much more pleasant for me to come here and visit more often. Did you hire out a developer to create your theme? Exceptional work!

  47. Hey very nice site!! Guy .. Beautiful .. Superb .. I will bookmark your site and take the feeds additionally…I am happy to seek out so many useful info here within the submit, we’d like work out more strategies on this regard, thanks for sharing. . . . . .

  48. There are some attention-grabbing points in time on this article but I don’t know if I see all of them middle to heart. There may be some validity however I will take hold opinion till I look into it further. Good article , thanks and we would like extra! Added to FeedBurner as well

  49. After I originally commented I seem to have clicked the -Notify me when new comments are added- checkbox and now whenever a comment is added I get 4 emails with the same comment. Is there an easy method you can remove me from that service? Thank you.

  50. Its like you read my mind! You seem to know so much about this, like you wrote the book in it or something. I think that you could do with a few pics to drive the message home a little bit, but instead of that, this is great blog. A fantastic read. I will certainly be back.

  51. Hi, Neat post. There’s an issue along with your website in internet explorer, could test this… IE still is the market leader and a good component of folks will omit your magnificent writing due to this problem.

  52. Today, with all the fast way of living that everyone is having, credit cards get this amazing demand throughout the market. Persons out of every discipline are using the credit card and people who are not using the credit cards have made up their minds to apply for one in particular. Thanks for revealing your ideas in credit cards.

  53. Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point. You definitely know what youre talking about, why throw away your intelligence on just posting videos to your site when you could be giving us something informative to read?

  54. Do you mind if I quote a few of your articles as long as I provide credit and sources back to your site? My blog is in the very same niche as yours and my users would truly benefit from some of the information you present here. Please let me know if this ok with you. Many thanks!

  55. Howdy just wanted to give you a quick heads up and let you know a few of the pictures aren’t loading correctly. I’m not sure why but I think its a linking issue. I’ve tried it in two different web browsers and both show the same outcome.

  56. This is the right blog for anybody who would like to find out about this topic. You realize a whole lot its almost tough to argue with you (not that I really will need to횜HaHa). You certainly put a fresh spin on a topic which has been discussed for many years. Great stuff, just great!

  57. I blog frequently and I really thank you for your content. This article has really peaked my interest. I am going to book mark your website and keep checking for new details about once a week. I subscribed to your Feed too.

댓글 남기기