Solved

Question on user-interface thread

Posted on 1998-10-07
2
212 Views
Last Modified: 2013-11-20
Hi All,

I would like to create a user inerface thread in my application. And I would to know if can  I create a
Frame derived from CFrameWnd, a document derived from CDocument and a view CFormView
attach to that thread.

 
This is what I done:

1) I derived a new class   from CWinThread :

    class CMyNewThredApp : public CWinThread
    {
        public:
         CMyNewThredApp();
         virtual ~CMyNewThredApp();
        public:
         virtual BOOL InitInstance();
        protected:
         DECLARE_DYNCREATE(CMyNewThredApp)

    };

    BOOL CMyNewThredApp::InitInstance()
    {

         m_pMainWnd = new CMyNewThredFrame;
         m_pMainWnd->ShowWindow(SW_SHOW);
         m_pMainWnd->UpdateWindow();

         return TRUE;
    }

2) I derived a new class   from CFrameWnd:
 

    class CMyNewThredFrame : public CFrameWnd
    {

     DECLARE_DYNCREATE(CMyNewThredFrame)
    public:
     CMyNewThredFrame();
     virtual ~CMyNewThredFrame();

    protected:
     afx_msg int OnCreate( LPCREATESTRUCT lpCreateStruct);

     DECLARE_MESSAGE_MAP()
    };

    int CMyNewThredFrame::OnCreate( LPCREATESTRUCT lpCreateStruct )
    {

             if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
              return -1;

             CMyNewThredView* ptrView = new CMyNewThredView;
     
          ptrView->Create( NULL, NULL, WS_CHILD | WS_VISIBLE, CRect( 0, 0, 0, 0), this,
          AFX_IDW_PANE_FIRST, NULL);
     
         return 0;
    }

3) I derived a new class   from CDocument:
 
 

    class CMyNewThredDoc : public CDocument
    {

     DECLARE_DYNCREATE(CMyNewThredDoc)
    public:
     CMyNewThredDoc();
     virtual ~CMyNewThredDoc();
    protected:
     virtual BOOL OnNewDocument();

    public:
     BOOL b_variable;
    };

3) I derived a new class   from CFormView:
 

    class CMyNewThredView : public CFormView
    {
         DECLARE_DYNCREATE(CMyNewThredView)
        public:
         CMyNewThredView();
         virtual ~CMyNewThredView();
        public:
         CMyNewThredViewDoc* GetDocument(){ return (CMyNewThredDoc*)m_pDocument; };
        protected:
         virtual void OnInitialUpdate(); // called first time after construct
         afx_msg void OnRButtonDown( UINT, CPoint );
         DECLARE_MESSAGE_MAP()
    };

    void CMyNewThredView::OnInitialUpdate()
    {
         GetDocument()->b_variable = FALSE;
         CFormView::OnInitialUpdate();
    }
     


////////////////////////////////////////////////////////////
    my problems:
    1)
       When the thread is executed, the member function OnInitialeUpDate of the class CMyNewThredView
       attched to the thread it's not called at all. That mean that the view it's never constructed. But
       when I execute the thread I still have a frame and a view. That same very strange :-).

    2)
          And the  m_pDocument allways return a NULL (thats mean that the document was not created or was                 destroyed).

         I like to know how can I link together CMyNewThredDoc, CMyNewThredView and CMyNewThredFrame. And          how can creat a new document and a view when the thread start.

Thanks
0
Comment
Question by:kkuu
2 Comments
 

Author Comment

by:kkuu
ID: 1323050
Edited text of question
0
 
LVL 3

Accepted Solution

by:
plaroche earned 50 total points
ID: 1323051
You can create a user-interface thread like you did, and the problems you report do not come from that thread which seems to be all right.

I invite you to check in a classwizard MDI generated app. In the CMainFrame's OnCreate you will not find the creation of a view. This is a not a coincidence, it's really not there the "normal" way to create a view and/or a document.

One of the easiest way to create your document/view/mdi child frame is to call CDocTemplate::OpenDocumentFile().  This is the way MFC does it internally.  You can do that at anytime after creating your mainframe in InitInstance.

Note: Your OnInitialUpdate was never called because when you dynamically create a view like you did YOU have to call it. Again, internally MFC does it.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sum67 challenge 35 115
haveThree challenge 22 123
Dell Alienware Graphics Amplifier Driver for non-Alienware systems 18 454
Work with App store 7 89
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question