Using a thread in a dialog project
-
Hi, I need to use the same thread for several Dialogs. I do it for one dialog and it works, because I associate it with this dialog. But If I want to use it in another dialog, ¿How can I do it? How can I associate it with several dialogs? Another question: How Can I use a member class dialog variable in another Dialog code? Thanks. Regards, Javier
-
Hi, I need to use the same thread for several Dialogs. I do it for one dialog and it works, because I associate it with this dialog. But If I want to use it in another dialog, ¿How can I do it? How can I associate it with several dialogs? Another question: How Can I use a member class dialog variable in another Dialog code? Thanks. Regards, Javier
That may be a questionable programming practice. Isn't there any other place where you can put that variable that is accessible to all dialogs? Regards, João Paulo Figueira Embedded MVP
-
That may be a questionable programming practice. Isn't there any other place where you can put that variable that is accessible to all dialogs? Regards, João Paulo Figueira Embedded MVP
Yes, sorry, I only need two variables managed in the thread that they could be accessible from all dialogs, and I need to resume or to stop the thread from a button in any dialog. How can I do it? I only need to know to make accessibles threads variables(or member variables) or something else. Regards. Regards, Javier
-
Yes, sorry, I only need two variables managed in the thread that they could be accessible from all dialogs, and I need to resume or to stop the thread from a button in any dialog. How can I do it? I only need to know to make accessibles threads variables(or member variables) or something else. Regards. Regards, Javier
Try a global object. Not a clean solution, but works. Regards, João Paulo Figueira Embedded MVP
-
Try a global object. Not a clean solution, but works. Regards, João Paulo Figueira Embedded MVP
-
ok, what is the clean solution? If I do it like global object, how can i define it?Any sample or code for learn it? Thank you. Regards, Javier
illidan99 wrote: ok, what is the clean solution? Language purists don't like globals... that's all. I regularly use globals and it's very easy to do. I create two files, one named "globals.h" that is included in all cpp files that need to access the global variables. For instance:
#ifndef __GLOBALS__
#define __GLOBALS__extern int g_nInteger;
extern HANDLE g_hThread;#endif
Now, you include in your project a cpp file named "globals.cpp":
#include "stdafx.h"
#include "globals.h"int g_nInteger = 0;
HANDLE g_hThread = NULL;And that's all you need. Regards, João Paulo Figueira Embedded MVP
-
illidan99 wrote: ok, what is the clean solution? Language purists don't like globals... that's all. I regularly use globals and it's very easy to do. I create two files, one named "globals.h" that is included in all cpp files that need to access the global variables. For instance:
#ifndef __GLOBALS__
#define __GLOBALS__extern int g_nInteger;
extern HANDLE g_hThread;#endif
Now, you include in your project a cpp file named "globals.cpp":
#include "stdafx.h"
#include "globals.h"int g_nInteger = 0;
HANDLE g_hThread = NULL;And that's all you need. Regards, João Paulo Figueira Embedded MVP