Solved

Question on user-interface thread

Posted on 1998-10-07
2
216 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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
Add content to output file 4 72
Looking for a specific application/software 2 124
withoutTen challenge 14 140
How to convert MFC::CString to UTF8 wchar_t* 10 456
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Suggested Courses

734 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