Solved

Question on user-interface thread

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Macro to save highlighted rows as a separate file 5 41
ORA-01403: no data found 43 90
Fibonacci challenge 11 111
Is there a simple front-end menu system. 9 72
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…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

867 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

24 Experts available now in Live!

Get 1:1 Help Now