Solved

Question on user-interface thread

Posted on 1998-10-07
2
202 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Need Help INsttalling wget on Mavericks OS X 3 84
repeatEnd java challenge 42 83
Define unique primary key 9 81
haveThree challenge 22 101
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now