What I´m doing:
- Have a application with player
- The user press the “Play button”, “Download the file” or “Play and Download the file”
- It fires a thread to Download the file.
I’m developing with C++ with MFC, and the thread cannot access the internals easily. I can just pass the HI/LOWWORD.
When the thread finishes, and it come back to the main thread, how can I signal what action the thread should make?
Actually I pass in the thread construction the action, like:
Calling: StartThread(file, PLAY);
The end of the thread: pClass->SendMessage(WM_DOWNLOADVIDEOTHREADEND,(WPARAM)downloadedfile,ACTION);
And then when the application receives the DOWNLOADVIDEOTHREADEND message, it check the ACTION and do it.
But it do not look elegant, it a mess!
There some pattern for this?
There´s a better way to do this?
In my opinion you should split the UI part of your application with your logic part in the different modules. Let’s say that you wrote an module with a name player you have to provide an interface for the player listener such as Java’s swing do it for the buttons. After that you can catch your events everywhere independent of technology you using ( QT, MFC , VCL and so on). So you could implement the bridge, strategy or observer pattern in this case. I will give you an example with a bridge design patter:
In your interface declare all types of events which player can throw:
Avoid using libraries like MFC in your project, because it may generate some troubles in
future. You could move to the other platform or make the decision to use another lib like QT for your GUI.
Good luck.