Hello all. I have a question with no code because i'm a beginner at mfc and find it very confusing. I can see that there is a message loop in mfc. From what i understand it is like an event in windows form applications.

In my mfc application i want to have a function run, on a click of a button in my mfc. When this happens i want to run the function in my programs main thread. This is because the function has values that incriment every cycle and i need this function to continue running even after the onclick has taken place. I also need to avoid using a loop on button click because this will no doubt freeze the program.

Is this the right course of action for what i want to do. If so where might i find this code or what other alternatives are there. Thank you all and goodbye.

The button is running in the main thread. MFC doesn't create new threads for individual objects (buttons and windows) but has the same message pump that every MS-Windows has.

Which MFC class contains the function you want to run on button click? One way to handle that is in the Button's OnClick event handler post another private message which can be caught by the function you want to run. Or, just simply execute it from OnClick, assuming the function doesn't take long to execute.

I want a task to continue to execute after i have clicked the button. The function contains a mail list, and i want it to send one message after another. Normally i would do this in a loop, but the ui of mfc will freeze, is there a way to do this?

Put the function in another thread which would be started when the button is clicked. providing the function doesn't need access to any of the MFC windows or controls. That function (thread) would continuously post messages to the MFC main thread so that it can update windows/objects.

This article has been dead for over six months. Start a new discussion instead.