Click here to Skip to main content
15,889,216 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: What CWinThread is pointed to by AfxGetApp Pin
Richard MacCutchan10-Jun-12 7:55
mveRichard MacCutchan10-Jun-12 7:55 
GeneralRe: What CWinThread is pointed to by AfxGetApp Pin
ForNow10-Jun-12 9:02
ForNow10-Jun-12 9:02 
GeneralRe: What CWinThread is pointed to by AfxGetApp Pin
ForNow10-Jun-12 9:08
ForNow10-Jun-12 9:08 
GeneralRe: What CWinThread is pointed to by AfxGetApp Pin
Richard MacCutchan10-Jun-12 22:01
mveRichard MacCutchan10-Jun-12 22:01 
AnswerRe: What CWinThread is pointed to by AfxGetApp Pin
Erudite_Eric10-Jun-12 9:15
Erudite_Eric10-Jun-12 9:15 
GeneralRe: What CWinThread is pointed to by AfxGetApp Pin
ForNow10-Jun-12 18:26
ForNow10-Jun-12 18:26 
GeneralRe: What CWinThread is pointed to by AfxGetApp Pin
Erudite_Eric11-Jun-12 0:58
Erudite_Eric11-Jun-12 0:58 
AnswerRe: What CWinThread is pointed to by AfxGetApp Pin
Aescleal10-Jun-12 13:11
Aescleal10-Jun-12 13:11 
There is only 1 object of a class derived from CWinApp in an MFC application. Any program with more than one object of a CWinApp derived class won't even compile. As CWinApp is derived from CWinThread that means the app object is a thread as well.

AfxGetApp (as generated by the code generator) always returns that one object. Always, no exceptions.

Now... Windows has two types of threads. We've been over that in other questions. If you want to use them in MFC you do one of the following:

- Worker threads are kicked off by AfxBeginThread. Call that with a pointer to the function you want it execute, it gives you a CWinThread, and off you go, woo hoo! CAVEAT if you call a USER function in your worker thread it gets a message queue BUT you won't be able to do anything with it as MFC doesn't know that it's changed. It's still just scheduling that single function (which could include a message loop but please don't try it...).

- UI threads are slightly harder - you have to derive your own class from CWinThread. Override InitInstance to create the window for your UI thread. Don't try and be clever and use an existing window - if you do messages for that window will be processed by whatever thread created the window, not what you want. Then call AfxBeginThread passing it a pointer to your derived class's RUNTIME_CLASS. You can't just assign an arbitary window pointer to m_pMainWnd and expect it to work - it won't.
QuestionCallback (capAVI) and MFC doc/view Pin
Vaclav_10-Jun-12 6:17
Vaclav_10-Jun-12 6:17 
QuestionExample of CONSTRUCTOR and DESTRUCTOR in derived class ? ? ? Pin
likescr79-Jun-12 19:41
likescr79-Jun-12 19:41 
AnswerRe: Example of CONSTRUCTOR and DESTRUCTOR in derived class ? ? ? Pin
Richard MacCutchan9-Jun-12 22:17
mveRichard MacCutchan9-Jun-12 22:17 
AnswerRe: Example of CONSTRUCTOR and DESTRUCTOR in derived class ? ? ? Pin
Aescleal9-Jun-12 22:22
Aescleal9-Jun-12 22:22 
GeneralRe: Example of CONSTRUCTOR and DESTRUCTOR in derived class ? ? ? Pin
likescr713-Jun-12 3:27
likescr713-Jun-12 3:27 
QuestionRe: Example of CONSTRUCTOR and DESTRUCTOR in derived class ? ? ? Pin
CPallini10-Jun-12 21:06
mveCPallini10-Jun-12 21:06 
AnswerRe: Example of CONSTRUCTOR and DESTRUCTOR in derived class ? ? ? Pin
Eytukan11-Jun-12 4:42
Eytukan11-Jun-12 4:42 
AnswerRe: Example of CONSTRUCTOR and DESTRUCTOR in derived class ? ? ? Pin
Eytukan11-Jun-12 4:44
Eytukan11-Jun-12 4:44 
AnswerRe: Example of CONSTRUCTOR and DESTRUCTOR in derived class ? ? ? Pin
jschell11-Jun-12 8:02
jschell11-Jun-12 8:02 
QuestionData Encapsulation Pin
pix_programmer8-Jun-12 21:12
pix_programmer8-Jun-12 21:12 
AnswerRe: Data Encapsulation Pin
Richard MacCutchan8-Jun-12 22:07
mveRichard MacCutchan8-Jun-12 22:07 
AnswerRe: Data Encapsulation Pin
Aescleal9-Jun-12 9:40
Aescleal9-Jun-12 9:40 
QuestionMy assignment aggregation, composition and inheritance Pin
David96378-Jun-12 19:23
David96378-Jun-12 19:23 
AnswerRe: My assignment aggregation, composition and inheritance Pin
Richard MacCutchan8-Jun-12 22:02
mveRichard MacCutchan8-Jun-12 22:02 
GeneralRe: My assignment aggregation, composition and inheritance Pin
David96379-Jun-12 0:13
David96379-Jun-12 0:13 
GeneralRe: My assignment aggregation, composition and inheritance Pin
Richard MacCutchan9-Jun-12 0:20
mveRichard MacCutchan9-Jun-12 0:20 
AnswerRe: My assignment aggregation, composition and inheritance Pin
Aescleal9-Jun-12 10:09
Aescleal9-Jun-12 10:09 

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.