Creating a UI thread without using RUNTIME_CLASS 
Author Message
 Creating a UI thread without using RUNTIME_CLASS

does anybody know of a way to create a user interface
thread, ie a CWinThread with a message loop without using
the AfxBeginThread that requires the use of RUNTIME_CLASS?

There are 2 versions of AfxBeginThread:
CWinThread* AfxBeginThread( AFX_THREADPROC pfnThreadProc,
LPVOID pParam, int nPriority = THREAD_PRIORITY_NORMAL,
UINT nStackSize = 0, DWORD dwCreateFlags = 0,
LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL );

CWinThread* AfxBeginThread( CRuntimeClass* pThreadClass,
int nPriority = THREAD_PRIORITY_NORMAL, UINT nStackSize =
0, DWORD dwCreateFlags = 0, LPSECURITY_ATTRIBUTES
lpSecurityAttrs = NULL );

... the first for worker threads and the second for UI
threads. I would much prefer a UI thread because of it
message handling capabilities.

I've tried creating a CWinThread on the heap then calling
CreateThread on this but the constructor is protected.
Changing the contructor to public in my derived class does
fix the problem, you rightly just get unresolved external
reference.

So is there a way of creating a UI thread without using
RUNTIME_CLASS????

cheers,

KK.



Sat, 31 Jul 2004 23:30:20 GMT  
 Creating a UI thread without using RUNTIME_CLASS
I'm just curious, but why do you need to do this?
Jeff...


Quote:

> does anybody know of a way to create a user interface
> thread, ie a CWinThread with a message loop without using
> the AfxBeginThread that requires the use of RUNTIME_CLASS?

> There are 2 versions of AfxBeginThread:
> CWinThread* AfxBeginThread( AFX_THREADPROC pfnThreadProc,
> LPVOID pParam, int nPriority = THREAD_PRIORITY_NORMAL,
> UINT nStackSize = 0, DWORD dwCreateFlags = 0,
> LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL );

> CWinThread* AfxBeginThread( CRuntimeClass* pThreadClass,
> int nPriority = THREAD_PRIORITY_NORMAL, UINT nStackSize =
> 0, DWORD dwCreateFlags = 0, LPSECURITY_ATTRIBUTES
> lpSecurityAttrs = NULL );

> ... the first for worker threads and the second for UI
> threads. I would much prefer a UI thread because of it
> message handling capabilities.

> I've tried creating a CWinThread on the heap then calling
> CreateThread on this but the constructor is protected.
> Changing the contructor to public in my derived class does
> fix the problem, you rightly just get unresolved external
> reference.

> So is there a way of creating a UI thread without using
> RUNTIME_CLASS????

> cheers,

> KK.



Sat, 31 Jul 2004 23:54:47 GMT  
 Creating a UI thread without using RUNTIME_CLASS

Quote:

> So is there a way of creating a UI thread without using
> RUNTIME_CLASS????

> cheers,

> KK.

I suggest you explain your real problem.

--
Scott McPhillips [VC++ MVP]



Sun, 01 Aug 2004 11:30:46 GMT  
 Creating a UI thread without using RUNTIME_CLASS
Ok.

I've written a template class which is a derived class
from CWinThread:

template<typename TP>
class TInterfaceThread : public CWinThread.

In order to do this, I've used some macros (from
www.jetbyte.com) that enable you to write MFC derived
template classes. However, there is no support for the
RUNTIME_CLASS macro which is needed in order to start the
thread ie TInterfaceThread.

I've designed a templated threadpool class, but in order
to avoid future threading problems, I would like to have
my new templated thread class IInterfaceThread (as the
name suggests) to act as an interface to the threadpool
class. Instead of clients calling methods on the
threadpool, they will instead call methods on the
InterfaceThread. The InterfaceThread will then post itself
a message; there by making the clients interaction with
the threadpool, asynchronous.

But to acheive this, my InterfaceThread has to be
templated because my threadpool is also templated. The
parameter to my TInterfaceThread is the thread pool class.

But at the moment, I can't find a way to start my
interface thread. I am currently working on writing new
macros to replace the RUNTIME_CLASS macro, but in the mean
time I'm also trying to determine if it is possible to
start a UI thread without RUNTIME_CLASS.

Any hints????

cheers,

KK.

Quote:
>-----Original Message-----

>> So is there a way of creating a UI thread without using
>> RUNTIME_CLASS????

>> cheers,

>> KK.

>I suggest you explain your real problem.

>--
>Scott McPhillips [VC++ MVP]
>.



Sun, 01 Aug 2004 23:06:45 GMT  
 Creating a UI thread without using RUNTIME_CLASS

Quote:

> Ok.

> I've written a template class which is a derived class
> from CWinThread:

> template<typename TP>
> class TInterfaceThread : public CWinThread.

> In order to do this, I've used some macros (from
> www.jetbyte.com) that enable you to write MFC derived
> template classes. However, there is no support for the
> RUNTIME_CLASS macro which is needed in order to start the
> thread ie TInterfaceThread.

> I've designed a templated threadpool class, but in order
> to avoid future threading problems, I would like to have
> my new templated thread class IInterfaceThread (as the
> name suggests) to act as an interface to the threadpool
> class. Instead of clients calling methods on the
> threadpool, they will instead call methods on the
> InterfaceThread. The InterfaceThread will then post itself
> a message; there by making the clients interaction with
> the threadpool, asynchronous.

> But to acheive this, my InterfaceThread has to be
> templated because my threadpool is also templated. The
> parameter to my TInterfaceThread is the thread pool class.

> But at the moment, I can't find a way to start my
> interface thread. I am currently working on writing new
> macros to replace the RUNTIME_CLASS macro, but in the mean
> time I'm also trying to determine if it is possible to
> start a UI thread without RUNTIME_CLASS.

> Any hints????

> cheers,

> KK.

The purpose of the RUNTIME_CLASS parameter is to let MFC create an
object of your thread class.  It can't do pThread = new CYourThread
because it doesn't know your thread's class name until run time.

But you know your thread's class name at compile time :)  
Untested theory: Try copying the MFC code in AfxBeginThread, adapting it
a bit to use 'new' instead of CreateObject.  That will eliminate the
need for RUNTIME_CLASS.

--
Scott McPhillips [VC++ MVP]



Mon, 02 Aug 2004 09:54:29 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Starting a UI Thread from a UI Thread.

2. Create thread message queue without creating window?

3. creating UI thread

4. how to create window in a UI thread?

5. how to create window in a UI thread ?

6. creating UI thread

7. Creating UI thread

8. Can't create and run a modeless dialog with UI thread

9. MFC UI Thread Leaks Memory if Controls are Created in It

10. Creating UI Threads in an MFC DLL

11. How create UI thread it like another application?

12. Creating a dialog box in a UI-Thread

 

 
Powered by phpBB® Forum Software