I guess I missed it somewhere in documentation that I need the message queue / pump. But I was puzzled why my CWinThread derived class was never constructed.Duh!
But I am beginning to see big flaw in my design - I need to "unload" processing time from the main thread ( I hope that is in English!) so I can click the button to stop my process. But I want to stop this process at specific location , so why am I going thru all this extra code if I can just put a global flag and set it in the worker thread?
What would be the difference between this (flag) and setting an event in worker thread and waiting for it in the main thread as suggested?
(BTW very good suggestion,thanks)
I prefer KISS methods! I was just trying to learn how to communicate between threads for future reference when the task won't be so simple.
Anyway, can someone elaborate on this: if I create worker thread variable in one thread (as I did ) how can I use that variable ( to control the thread as I wanted originaly) from another class ( object )?
Do I need a global variable? How would that appoach differ from my use of simple flag?
But I think I am getting too far into left field of what - if scenario.
Thanks again for all you suggestions, I really appreciate it.
I decided to try the UI thread to stop the process. Seems like a challenge and I like to torture myself with goofy programming techniques.
Now I cannot figure out how to execute the process I was after. This process ( used to be worker thread "function") and its 300+ lines of code is in the view main thread!
It is OK to make the view variable in the new UI thread? On first thought it seems like "circular reference". Any other way to do this “ function transfer” from the view?
Thanks for all you help.
I have managed to execute an equivalent of "worker thread function" located in the UI thread class.
1. It needs access to document and it asserts there. I am working on why.
2. The big one:
If I temporary bypass the code( won't work witout the document) and just do an infinite loop ( even with some Sleep in it) I cannot click the UI button! That means only one thing - the OS is too busy letting the main thread messages thru! That is not what I was after in the first place!
If I continue with multithreaded approach (just for kiks) I need to write some more code! Joy!?
As someone else already suggested, you can use the command "shutdown -r" which will run just as though you used it through command prompt. An example:
This will default to a 30 second timer before the computer begins to shutdown. With some effort, you should be able to find a way to decrease the timer, although I'm not positive.
EDIT: system("shutdown -r -t 10"); that will set the shutdown timer to 10 seconds, instead of the default 30. The command shutdown tells the computer what to do, "-r" is for resetting the computer, "-t xx" (-t 10) sets the time to the amount of seconds you indicate, so if your code were "system("shutdown -r -t 1");" The computer would start resetting one second after your program executes that line of code. Theoretically you can set it to 0 seconds, but I don't feel like testing that one
VS2008 does not have a "makefile" export; So, you'd better sit down and learn how to manually generate makefiles which is one of the devil created file format (IMO). You might be interested in using one of the many IDE available on linux (kdevelop, ... ) that should ease your pain by "wrapping" the makefile in a nice environment.
One the other hand, depending on how much your application is tied to Visual Studio and/or windows (API and framework) the makefile might be the least of your problem.
i am trying to make a customized Clist control. i have written my Class derived from CListCtrl. The problem is in this Vertical scroll bar are not coming when i dynamically create this list control. if i create it in resource and use DDX_Control and take it as my class variable it works fine(scroll bar comes) but if i create control dynamically scroll bars dont come. This is the creation code
I want to emulate pressing a pushbutton.
I call SendDlgItemMessage(hDlg,IDBUTTON,BM_SETSTATE,TRUE,0L);
and then I have tried calling RedrawWindow(GetDlgItem(hDlg,IDBUTTON),NULL,NULL,RDW_INVALIDATE|RDW_ERASE|RDW_FRAME|RDW_UPDATENOW|RDW_INTERNALPAINT);
with various flag combinations, but the button will not redraw.
If I call MessageBox after the RedrawWindow, the button redraws, but I don't want to do that!
What am I missing?