Click here to Skip to main content
15,926,035 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Casino Game Pin
Wes Aday1-Mar-04 7:27
professionalWes Aday1-Mar-04 7:27 
GeneralRe: Casino Game Pin
John M. Drescher1-Mar-04 7:41
John M. Drescher1-Mar-04 7:41 
Questionwhere to get free PDF sdk? Pin
Xiaodi_Liu1-Mar-04 6:44
Xiaodi_Liu1-Mar-04 6:44 
AnswerRe: where to get free PDF sdk? Pin
John M. Drescher1-Mar-04 7:45
John M. Drescher1-Mar-04 7:45 
QuestionHow to display xp style button and check box. Pin
bin89221-Mar-04 5:55
bin89221-Mar-04 5:55 
AnswerRe: How to display xp style button and check box. Pin
John R. Shaw1-Mar-04 16:43
John R. Shaw1-Mar-04 16:43 
GeneralThank you very much. Pin
bin89222-Mar-04 5:47
bin89222-Mar-04 5:47 
GeneralVery simple Thread class. Pin
Quaoar1-Mar-04 5:44
Quaoar1-Mar-04 5:44 
Everything I've found to date on Thread classes are way too complex for what I want. I have a basic Thread class:

<br />
class Thread{<br />
public:<br />
    Thread( ) ;<br />
    virtual ~Thread( ) ;<br />
<br />
    static DWORD WINAPI ThreadFunc( LPVOID lpParam ) ;<br />
<br />
    void run( ) ;<br />
    void end( ) ;<br />
    void resume( ) ;<br />
    void suspend( ) ;<br />
<br />
private:<br />
    DWORD dwThreadId, dwThrdParam ;<br />
    HANDLE hThread ;<br />
<br />
    char szMsg[80];<br />
};<br />


What I need is something VERY simple that will allow me to easily extend what I already have to allow my Thread class to be inheritable such that two different classes that inherit it have their own specific critical section...

In Java, when I create a class, I can extend/inherit the Thread class. Let's say,
<br />
class Ant extends Thread{ ...<br />


The Ant class will have a 'run' method somewhere in there that will 'replace' (for want of a better term) the Thread class' own run method.

My C++ Thread class:
<br />
DWORD WINAPI Thread::ThreadFunc( LPVOID lpParam ){ <br />
    return 0; <br />
}<br />


I have an Ant class. This class should provide an 'updated' ThreadFunc. I also have a World class. This class should provide a completely different 'updated' ThreadFunc.

Let's say I want:
<br />
Ant::ThreadFunc( stuff ){<br />
    for( ; ; ){<br />
        cout << "Hi" << endl ;<br />
    }<br />
}<br />


and:
<br />
World::ThreadFunc( stuff ){<br />
    for( ; ; ){<br />
        cout << "Ih" << endl ;<br />
    }<br />
}<br />


How can I manage this?

In case it helps, or gives you any ideas as to what I've done already, my Thread constructor is pretty much:
<br />
    dwThrdParam = 1; <br />
<br />
    //	Create the thread<br />
    hThread = CreateThread( <br />
        0,								// it should be inheritable<br />
        0,								// use default stack size<br />
        ThreadFunc,						// thread function<br />
        &dwThrdParam,					// argument to thread function<br />
        CREATE_SUSPENDED,				// create the thread in a suspended state<br />
        &dwThreadId						// returns the thread identifier<br />
     ) ;<br />
<br />
    cout << "Thread " << dwThreadId << " created." << endl ;<br />
<br />
    // Check the return value for success.<br />
    if (hThread == NULL){<br />
        wsprintf( szMsg, "CreateThread failed." ); <br />
        MessageBox( NULL, szMsg, "main", MB_OK );<br />
    }<br />


My project is to do a virtual ant colony, and I stupidly put down on the project spec that I'd have the ants running as seperate threads. Having other stuff running in its own thread could prove useful, but if I don't get the thread class goin properly, I'll just have to toss that part of the project. :/

Anyhoo - Javalike Thread class in C++.
Code would be great. Smile | :)
Or a good resource on how to do it would be cool also. Smile | :)

/*    All those who believe in pshycokenesis, raise my hand.
*/
GeneralRe: Very simple Thread class. Pin
John M. Drescher1-Mar-04 9:00
John M. Drescher1-Mar-04 9:00 
GeneralRe: Very simple Thread class. Pin
Joe Woodbury1-Mar-04 18:31
professionalJoe Woodbury1-Mar-04 18:31 
GeneralRe: Very simple Thread class. Pin
Quaoar2-Mar-04 6:23
Quaoar2-Mar-04 6:23 
QuestionHow to Create a Button with Tooltip in &quot;win32 application project&quot;? Pin
akira321-Mar-04 5:18
akira321-Mar-04 5:18 
AnswerRe: How to Create a Button with Tooltip in &quot;win32 application project&quot;? Pin
rrrado1-Mar-04 5:26
rrrado1-Mar-04 5:26 
QuestionHow to remember app window's size Pin
rrrado1-Mar-04 5:16
rrrado1-Mar-04 5:16 
AnswerRe: How to remember app window's size Pin
David Crow1-Mar-04 5:45
David Crow1-Mar-04 5:45 
GeneralRe: How to remember app window's size Pin
Diddy2-Mar-04 11:27
Diddy2-Mar-04 11:27 
QuestionHow to show Window Maximized? - initially Pin
vgrigor1-Mar-04 4:04
vgrigor1-Mar-04 4:04 
AnswerRe: How to show Window Maximized? - initially Pin
Wes Aday1-Mar-04 4:14
professionalWes Aday1-Mar-04 4:14 
GeneralRe: How to show Window Maximized? - initially Pin
vgrigor1-Mar-04 4:26
vgrigor1-Mar-04 4:26 
GeneralRe: How to show Window Maximized? - initially Pin
Wes Aday1-Mar-04 4:38
professionalWes Aday1-Mar-04 4:38 
Questionhow to customize a merged menu when in-place editing Pin
Member 4855451-Mar-04 4:02
Member 4855451-Mar-04 4:02 
GeneralRe: Pointer To Dialog Pin
Caoimh1-Mar-04 3:32
Caoimh1-Mar-04 3:32 
GeneralRe: Pointer To Dialog Pin
David Crow1-Mar-04 3:49
David Crow1-Mar-04 3:49 
GeneralNeed Hyperlink on Dialog Pin
Caoimh1-Mar-04 3:26
Caoimh1-Mar-04 3:26 
GeneralRe: Need Hyperlink on Dialog Pin
Ravi Bhavnani1-Mar-04 3:42
professionalRavi Bhavnani1-Mar-04 3:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.