How can we create thread in MFC framework?
Answers were Sorted based on User's Feedback
MFC support two type of thread : Worker Thread & UI thread.
There is an overloaded function called AfxBeginThread()for
creating threads in MFC but at APT level you can't
differentaite.
At implementation level you can find the difference:-
For worker thread:
AfxBeginThread(); It takes 6 parameters, first param as
address of thread controlling function(must),2nd as
parameter passed to threadfn(must),3'rd thread priority
level(optional), 4'th as stack size(Optional),5'th as
create_flag(optional),6'th security class(optional)etc.
For UI(User Interface) thread:
Derive a class from CWinThread;
class CMyThread:public CWinThread
{
.....
.....
.....
}
Override the InitInstance() function in this class.
Then use the function
AfxBeginThread()and pass the parameter in RUNTIME_CLASS
macro in this func.
i.e. AfxBeginThread(RUNTIME_CLASS(CMyThread));
It takes 5 parameters ...rest of last four params are same
as worker thread which are optional.
So in this you can create the Worker and User Interface
threads.
| Is This Answer Correct ? | 5 Yes | 2 No |
Answer / jianhua wang
For worker thread:
AfxBeginThread();
for user interface thread:
Derive a class from CWinThread;
AfxBeginThread(); (Another version)
//if the thread is created in a suspended state, you must call
CWinThread::ResumeThread();
| Is This Answer Correct ? | 3 Yes | 1 No |
What is the difference between OnInitialUpdate and OnUpdate?
What is the difference between the ASSERT and VERIFY macros?
1)To Remove WS_MINIMIZEBOX in a Frame ?
What is Thread ?(VC++)What is the difference between Cmutex and Csemaphone?
How to handle dynamic menus in mfc? What happens when client calls cocreateinstance?
What interface must be supported by an ActiveX control?
1)does Frame Thickness in MFC?
What four types of properties are supported by an ActiveX control?
what is the use of CWinApp class?
What are the differences between MFC Exception macros and C++ exception keywords?
What is a message map, and what is the advantage of a message map over virtual functions?
Q1. A. What is unary operator? List out the different operators involved in the unary operator. B. What is an adjust field format flag? Q2. A. Distinguish between a # include and #define. B. Can a list of string be stored within a two dimensional array? Q3. A. Explain how a pointer to function can be declared in C++? B. List the merits and demerits of declaring a nested class in C++? Q4. A. What are the syntactic rules to be avoid ambiguity in multiple inheritence? B. Explain the operation of overloading of an assignment operator. Q5. A. Explain how the virtual base class is different from the conventional base classes of the opps. B. Explain how an exception handler is defined and invoked in a Program. Q6. A. What is a binary file? List the merits and demerits of the binary file usagein C++. B. Write short notes on Text Manipulation Routines. C. Write bites in Turbo c++ Header ("Include") Files.