I apologize if the question is too easy for experienced programmers. I just got started with the basics of windows with the Petzold but have experience programming in Mathematica and some C and Labview.
What i dont understand about the message loop in windows, which appears implemented as a While loop, seems that in "normal" C programs a while loop runs as long as the condition stays true, then the program goes to the next instruction until the program ends. I visualize that like a sequence of events in time that lead to the execution and end of the program, not the same philosophy of a Labview program where time and sequences matter less and the program may never ever end unless interrumpted by the user.
As far as i understand in windows the message loop keeps going forever unless you interrupt the program. Almost behaving as an infinite loop, always active. If the true/false condition on the message loop changes, given by the boolean result of GetMessage, then how come once you get a false, the program doesnt just end right there?
In Labview programs there is not a strong concept of time or of sequence of operations, any condition could change at any given moment, like the true/false condition of a While loop, and then the loop would start executing a block of code or stop without it implying that the program is somehow closer to its end. Is that how it works in windows too?
All i say is that with a program that looks like this:
WinMain()
{....
while(condition)
{execute code}
....}
I would think it would just execute the block of code and end right there. But in windows it keeps "waiting" for the condition to be true in order to execute the code. I believe i am not getting this right which is why i am asking for anyone to clear up this mechanism for me.
Actions occur in a Windows loop based on a condition. Usually that condition is due to the fact that a window object (button, checkbox, radio button, selection in a listbox, etc) sends a message due to a condition that has occurred. In the case of a button, the button was pressed; in the case of a listbox something was entered or selected.
You need a windows loop that has a case statement containing both the event type and the id of the window object that generated the event.
Without more detailed code posted, it's hard to help you beyond that. From my ancient knowledge of Windows, there is a main Windows loop that keeps waiting for events to occur and then processing code based on those events occurring. Processing an exit program would also be one of those conditions.
The condition saying "stpp program" would be caught, and the code written would break out of the main windows processing loop. That would allow the program to exit.