Solved

Question on user-interface thread

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Whole sheet autoscrub still needed 19 51
wait notify demo infinite loop 3 114
post4 challenge 28 102
Updating statistics with error notification email in SQL server 4 96
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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…
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.

832 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