EQuestionAnswers.com Computer/Electronics Questions and Answers
C, C++, VC++, COM/DCOM, DLL and more
#Login #Sign up  Facebook Twitter TGoogle+
 

#Previous question #Index of VC++/WIN32/MFC Questions #Next question
#include <afxwin.h>
#include "resource.h"
#define ID_UITHREAD 1001
class CUIThread : public CWinThread
{
  public:
  virtual BOOL InitInstance();
10    virtual BOOL ExitInstance();
11 
12    DECLARE_DYNCREATE(CUIThrea)
13    DECLARE_MESSAGE_MAP()
14  };
15  IMPLEMENT_DYNCREATE(CUIThread, CWinThread)
16 
17  BEGIN_MESSAGE_MAP(CUIThread,CWinThread)
18  END_MESSAGE_MAP()
19 
20  BOOL CUIThread::InitInstance()
21  {
22    CDialog objThreadDlg (MAKEINTRESOURCE(IDD_DIALOG1));
23    m_pMainWnd = &objThreadDlg;
24    int nResponse = objThreadDlg.DoModal();
25    if (nResponse == IDOK)
26    {
27    }
28    return TRUE;
29  }
30  BOOL CUIThread::ExitInstance()
31  {
32    return 0;
33  }
34  class CMyWnd : public CFrameWnd
35  {
36  private:
37    CButton m_BWorker;
38    CWinThread *m_pThread;
39    bool m_bThread;
40    friend  UINT WorkerThread(LPVOID arg);
41  public:
42    CMyWnd()
43    {
44      
45      CRect rt;
46      rt.top = 10;
47      rt.left = 150;
48      rt.right = 250;
49      rt.bottom = 30;
50      Create(NULL, _T("MFC UI Thread"));
51      m_BWorker.Create("UI Thread", WS_CHILD|WS_VISIBLE, rt, this, ID_UITHREAD);
52      m_pThread = NULL;
53      m_bThread = TRUE;
54    }
55 
56    afx_msg void OnWorker();
57 
58    DECLARE_MESSAGE_MAP()
59  };
60  BEGIN_MESSAGE_MAP(CMyWnd, CFrameWnd)
61  ON_COMMAND(ID_WORKER, OnUIThread)
62  END_MESSAGE_MAP()
63 
64  afx_msg void CMyWnd::OnUIThread()
65  {
66    if(!m_pThread) {
67      m_bThread = TRUE;
68      m_pThread = AfxBeginThread(RUNTIME_CLASS(CUIThread));
69    } else {
70      m_bThread = FALSE;
71      m_pThread = NULL;
72    }
73  }
74 
75  class CMyApp : public  CWinApp 
76  {
77 
78  public:
79    virtual BOOL InitInstance()
80    {
81 
82      m_pMainWnd = new CMyWnd();
83      m_pMainWnd->ShowWindow(SW_SHOW);
84      m_pMainWnd->UpdateWindow();
85 
86         return TRUE;
87    }
88   };
89 
90 
91 
92   CMyApp app;

MFC UI Thread Demo

You have viewed 1 page out of 109. Your VC++ learning is 0.00% complete. Login to check your learning progress.

 Vote 0

Similar topics related to this section

#Programming Windows, Fifth Edition (Developer Reference)
#Programming Applications for Microsoft Windows (Microsoft Programming Series)
#Programming Windows with MFC, Second Edition
#Visual C++ Programming
#Programming Microsoft Visual C++, Fifth Edition

* #1 webmaster Wed 30 Apr/2014 02:35:19(GMT)  Like 0 Unlike 0

Dear Users,

We are pleased to inform you that a forum/blog has been incorporated with www.mybestnotes.co.in. You are welcomed to add your comments, requests, codes, solutions and feedback to it. Please login(if already a member) or signup(for free) to avail to this facility.

Regards,
Webmaster

Your message goes here:

Name:Guest
Email:anonymous@unknown.com
My Post:*
Secutiry Code: ******  *
Preview this compose before posting this in discussion forum.
 
Note:
  1. Use [Sxx] code to show smiles. Example [S02]
  2. Use [URL ], example [URL http://www.google.com/]
  3. To display code or un formatted text use [CODE] [/CODE]. Example: [CODE] printf("Hello world"); [/CODE]
 [S01]   [S02]   [S03]   [S04]   [S05]   [S06]   [S07]   [S08] 
 [S09]   [S10]   [S11]   [S12]   [S13]   [S14]   [S15]   [S16] 
 [S17]   [S18]   [S19]   [S20]   [S21]   [S22]   [S23]   [S24] 

Note: Only members are allowed, * fields are mandatory.