CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2000
    Posts
    23

    DocTemplate Resource ID

    Is there anyway for a Child Frame Wnd to access the doc templates resource ID?
    I would like to use this id to decide how to construct the frame.
    I would like this resource id for the following reason. I create two different document templates, during execution the document will create,spawn new windows that use it(the document) these windows all share common traits and utilize splitterwnd's. Most of them don't need any additional changes, but there is one version of the frame where it needs an extra splitter and I can determine that based on the ResourceID if I can get access to it in the CChildFrame
    thx
    david


  2. #2
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: DocTemplate Resource ID

    From what you posted I understand that you have registered two different document templates. I understand that you are using the same document type in both templates. You are also using the same type of child frame.

    If some of the above is false, you are better off letting system handle two different templates.

    If all of the above is true, override virtual OnCreateClient in your child window class. CCreateContext contains m_pNewDocTemplate member and CDocumentTemplate knows about resource ID.

    Unfortunately this member (m_nIDResource) is protected.

    Now you know the rest of the story:

    Derive your own class based on CMultiDocTemplate and add function that will return this number I called it for example CMultiDocTemplateEx.

    Declare in MultiDocTemplateEx.h

    UINT GetResourceID() {return m_nIDResource;}




    In OnCreateClient:


    UINT ID = ((CMultiDocTemplateEx*)pContext->m_pNewDocTemplate)->GetResourceID();



    And you have it.


    There is no such a thing like silly question, but there are many stupid answers.

    I don't do it for ratings. However, rating tells me how my solution worked and that is important.
    Good luck in your journey in a C++ land.

    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  3. #3
    Join Date
    Nov 2000
    Posts
    23

    Re: DocTemplate Resource ID

    I thought it would come to this, but I thought I would ask just in case there was something I did not know. My fears live!
    Thanx John


  4. #4
    Join Date
    Aug 2001
    Location
    Israel
    Posts
    60

    Question

    I wish my MyApp Doc to decides which of 2 view types to open: IRC_Channel or IRC_User view type.

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

    CView* CIRCDoc::CreateNewView(LPCTSTR lpszName)
    {
    short ViewType;
    T = ((lpszName[0]=='#') ? IDR_CHANNELTYPE : IDR_USERTYPE);

    CDocTemplate* pTmp = GetDocTemplate();
    CFrameWnd* pFrame = pTmp->CreateNewFrame(this, NULL);
    ASSERT(pFrame != NULL);

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

    I implemented 2 docTemplates, but I do not really need them. All I wish is to decide, on that point, if to use type1 or type2 view. It MUST be possible somehow... Can you help me with that?
    Sincerely,
    Amit Gefen
    Senior Software Engineer
    Skype: amit.gefen
    amit.gefen@ca.com
    www.xosoft.com

  5. #5
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    I probably could’ve helped you but I will need more information about what you are trying to do:

    [list=1][*]Does your app require document view support?[*]Are you trying to display different view for the same document in different frame?[*]Are you trying to display different view for the same document in the same frame?[*]By implemented do you mean derived your own class for both templates?[*]Did you register two templates?[/list=1]
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  6. #6
    Join Date
    Aug 2001
    Location
    Israel
    Posts
    60
    2 is waht i tried to do: I want to open, on run-time, one of a 3 kinds of frame windows for the same document! according to dynamic information.

    I succed by that time somehow: I declared 2 classes inherit 1 from CDocManager & the 2nd from CMultiDocTemplate: CXDocManager & CXMultiDocTemplate. CXDocManager create an CXDocTemplate objects in AddDocTemplate(pXDocTemplate) & CXMultiDocTemplate keeps a copy of nIDResource to be available on CXDocTemplate::GetIDResource().

    So, on run-time, it become possible to iterate DocTemplates to get one according to the original ID.

    I am not sure if this is the most elegant design but it seems to me quiet OO, & I will be happy to hear your opinion about.

  7. #7
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917
    You are right; you do not need two document templates if decision what view is based on type of view.

    You don’t even need CMultiDocTemplate nor do you need CDocManager derivatives.

    I would allow App to make decision what view to show and child window to carry it out.

    • Create new variable (int for example) that will keep value for the requested view. Variable can be anything that is best for you.
    • I don’t know how decision is made as to what view to show; relevant is that you assign what view to use in this decision making block.
    • Override OnCreateClient member in CChildFrame.
    • In this function check what view was requested and replace m_pNewViewClass member of the pContext structure with runtime information of the requested view.


    In example below (for two views) I used integer set to zero if default view is used and to some other value in another view is requested.

    Code:
    BOOL CChildFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
    {
    	if(0 == theApp.m_iRequestedResID)
    	{
    		//Get the document you want to create another view for. 
    		//You may choose different way to get to a document object. 
    		//A way you manage your windows and views (controlling number 
    		//of frames/views for instance of one document is up to you.
    		CFrameWnd* pActiveFrm = ((CFrameWnd*)AfxGetMainWnd())->GetActiveFrame();
    		
    		pContext->m_pCurrentDoc = pActiveFrm->GetActiveDocument(); 
    		pContext->m_pNewViewClass = RUNTIME_CLASS(CTwoViewsOneDocFormView);
    	}
    }
    pContext structure is filled up (using information from registered template) before calling CChildFrame OnCreateClient. Child frame uses this information to create view. If you replace information about view, you just trick a frame to create view different than registered.
    Last edited by JohnCz; June 4th, 2002 at 09:14 AM.
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured