Click here to Skip to main content
16,017,608 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Global objects in MFC Pin
Achim Klein15-Aug-05 12:07
Achim Klein15-Aug-05 12:07 
GeneralRe: Global objects in MFC Pin
Bob Stanneveld15-Aug-05 6:05
Bob Stanneveld15-Aug-05 6:05 
GeneralRe: Global objects in MFC Pin
TOlivier15-Aug-05 11:26
TOlivier15-Aug-05 11:26 
GeneralRe: Global objects in MFC Pin
Achim Klein15-Aug-05 13:52
Achim Klein15-Aug-05 13:52 
GeneralRe: Global objects in MFC Pin
Achim Klein15-Aug-05 13:56
Achim Klein15-Aug-05 13:56 
GeneralRe: Global objects in MFC Pin
Achim Klein15-Aug-05 14:36
Achim Klein15-Aug-05 14:36 
GeneralRe: Global objects in MFC Pin
TOlivier16-Aug-05 4:31
TOlivier16-Aug-05 4:31 
GeneralRe: Global objects in MFC Pin
Emilio Garavaglia15-Aug-05 22:14
Emilio Garavaglia15-Aug-05 22:14 
Ouch .. NOOOOOOO ...
MFC apps are WINDOWS apps, not console apps.

The idea of an infinite loop in main cannot be used in a windows app, since a windows app is itself a loop.
You'll stuck your app, whith an infinite loop, pushing the CPU at 100% for ever, with the only chance, to the user, to kill it.
I suspect your real problem is that you're trying to do with MFC what you ususally do with traditional console application. That's not the way to go, with windows programming.

With MFC, consider this as starting points:
- CYourApp: public CWinApp has global linkage and exist for all the application life. Make its instance (usially a CYuourApp theApp varialble) to have global scope (by declaring it as external in a header included by all files - stdafx.h is good) and you can put any member in it and access it from everywhere.
- virtual CWinApp::Initinstance is called by the MFC embedded WinMain (like the main of traditional consoles) BEFORE the windows message looop is started. Any initialization code can be placed in the Initinstance override.
- Once the messageloop is started, the input devices (keyboard and mouse) are read by the system, and actions are sent as message to the active application's main window where are dispatched to the implementing C++ class member functions through a message map. You can respond to a message by doing any sort of calculation, but NEVER with an infinite loop, or the application will stuck.
- If you need to perform a lengthy operation through a loop, implement a loop like
whiile(your exit condition)
{
    ::MSG msg;
    if (::PeekMessage(&msg, 0,0,0, PM_REMOVE) &&
            !::TranslateMessage(&msg))
       ::DispatchMessage(&msg);
    //your instruction goes here
    //your eventual break statement
}

That is: give the system a chanche to manipulate input! (and remenber that input cannot be accessed with functions like getch() or cin::get etc. Input becomes messages deliveret to the main window)

(Another more sophisticated way is use a woker thread ... but if you're new to windows programming, multithreaduing is certinly not the starting point!)

- Output cannot be sent to any "stream": you must store it somewhere in your program, and them display it in the window by handling WM_PAINT (ususally with OnPaint)

- if you need a sort of "draw forever" program, you can instantiate a timer (::SetTimer)and respond to it in your main wiandow (OnTimer) with your loop's body (note BODY, not LOOP: the loop is in Windows, issuing the timer message)

Hope all this may help.
____________


2 bugs found.
> recompile ...
65534 bugs found.
D'Oh! | :doh:

GeneralPlay Audio CD via Soundcard Pin
Storm-blade15-Aug-05 3:10
professionalStorm-blade15-Aug-05 3:10 
GeneralRe: Play Audio CD via Soundcard Pin
M.Mehrdad.M15-Aug-05 3:51
M.Mehrdad.M15-Aug-05 3:51 
GeneralRe: Play Audio CD via Soundcard Pin
Storm-blade15-Aug-05 4:35
professionalStorm-blade15-Aug-05 4:35 
GeneralProblem with "Create a FrameWnd inside a thread" Pin
Stephan Pilz15-Aug-05 2:41
Stephan Pilz15-Aug-05 2:41 
GeneralRe: Problem with "Create a FrameWnd inside a thread" Pin
khan++15-Aug-05 2:47
khan++15-Aug-05 2:47 
GeneralRe: Problem with "Create a FrameWnd inside a thread" Pin
Stephan Pilz15-Aug-05 3:44
Stephan Pilz15-Aug-05 3:44 
GeneralRe: Problem with "Create a FrameWnd inside a thread" Pin
HumanOsc15-Aug-05 4:51
HumanOsc15-Aug-05 4:51 
GeneralRe: Problem with "Create a FrameWnd inside a thread" Pin
Stephan Pilz15-Aug-05 20:08
Stephan Pilz15-Aug-05 20:08 
GeneralRe: Problem with "Create a FrameWnd inside a thread" Pin
Stephan Pilz15-Aug-05 20:52
Stephan Pilz15-Aug-05 20:52 
GeneralRe: Problem with "Create a FrameWnd inside a thread" Pin
Sheng Jiang 蒋晟15-Aug-05 15:49
Sheng Jiang 蒋晟15-Aug-05 15:49 
GeneralRe: Problem with "Create a FrameWnd inside a thread" Pin
Stephan Pilz15-Aug-05 20:14
Stephan Pilz15-Aug-05 20:14 
GeneralRe: Problem with "Create a FrameWnd inside a thread" Pin
Sheng Jiang 蒋晟15-Aug-05 20:20
Sheng Jiang 蒋晟15-Aug-05 20:20 
GeneralRe: Problem with "Create a FrameWnd inside a thread" Pin
Stephan Pilz15-Aug-05 20:51
Stephan Pilz15-Aug-05 20:51 
GeneralRe: Problem with "Create a FrameWnd inside a thread" Pin
HumanOsc16-Aug-05 1:22
HumanOsc16-Aug-05 1:22 
GeneralLocation of strcmp Pin
rottencheese15-Aug-05 2:17
rottencheese15-Aug-05 2:17 
GeneralRe: Location of strcmp Pin
Chris Losinger15-Aug-05 2:28
professionalChris Losinger15-Aug-05 2:28 
GeneralRe: Location of strcmp Pin
Tim Smith15-Aug-05 3:40
Tim Smith15-Aug-05 3:40 

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.