|
You can remove WM_TIMER messages like this at the end of your data polling function:
// Look for WM_TIMER messages
MSG msg;
while ( ::PeekMessage(&msg, NULL, WM_TIMER, WM_TIMER, PM_NOREMOVE) )
{
// m_nTimerID contains holds the ID of your timer... if you're using
// more than one timer, this removal procedure won't be fool proof.
if ( msg.wParam == (UINT)m_nTimerID )
{
// Remove the message
::PeekMessage(&msg, NULL, WM_TIMER, WM_TIMER, PM_REMOVE);
}
else break;
};
However, I wouldn't implement it like this, but instead create a worker thread that uses a Waitable Timer object (cf. CreateWaitableTimer in the Platform SDK). This way you needn't worry about removing messages from the queue, and you can change the worker thread's priority if you like. You will need to synchronize access to the variables you will be updating, but it isn't that hard.
HANDLE hWait = ::CreateWaitableTimer(...);
for ( ;; ) {
::SetWaitableTimer(...);
// You might want to use a "Quit" event object as well, created and signaled from the main thread, so you know when to exit the thread. If that's the case, use WaitForMultipleObjects instead.
DWORD dwWaitRet = ::WaitForSingleObject(hWait,...);
switch (dwWaitRet)
{
// cases...
}
}
CloseHandle(hWait);
|
|
|
|
|
|
For really tiny wait intervals such as a few ms, there are no obvious advantages, and Sleep might in fact be a better solution than creating a kernel object. However, for longer intervals the thread would remain locked until the timeout value expires, which would cause the application to look as if it was hung (and you don't want to use the dangerous TerminateThread API, since it doesn't allow for object cleanup among other unwanted side effects). In this case, it's always better to implement a solution such as the one I suggested.
|
|
|
|
|
Carl Berg wrote:
In this case, it's always better to implement a solution such as the one I suggested.
With WaitForMultipleObjects?
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Yes, exactly, one will have to use WaitForMultipleObjects in order to be able to wait on both the timer and a quit/exitthread event (and possibly other objects as well, depending on design).
If the update processing is a lengthy operation, it might be a good thing to check if the quit event has been set at a few checkpoints. This can be done using WaitForSingleObject with a zero timeout value: WaitForSingleObject(hQuitEvent, 0). If the event is set, the return value will be WAIT_OBJECT_0 (cancel update and exit thread), else it will be WAIT_TIMEOUT (continue the update process).
|
|
|
|
|
Hello,
INTRODUCTION:
First of all let me thank you very much for your help.
I think that using a thread in order to read and another one in order to write (with different priorities) will be a great solution for me.
As I had written down in the Subject of my first message I'm very novice, but I've bought a Jeffrey Richter book that talks widely about threads and I think that, with this book, I will learn how to manage and use correctly threads.
But I have a doubt:
QUESTION:
OK, I will have a thread that will get all the needed data from the XProgram, and I'll have another thread that will write data to that program too (I think that I'll need some kind of "transfer stack" that I'll will have to modify from outside the threads in order to make them work (one for each thread)...) but, now that it seems that I will simplify the fact of getting and setting data to the XProgram, I would like to know how to send that data to the place where it have to go.
Let me explain better:
>> I'll have a transfer stack for reading from the XProgram.
>> This transfer stack will contain all the variables that I have to read from the XProgram.
>> I will use some kind of filters that will avoid reading groups of variables that I don't need by the moment.
>> I will know wich group of variables have suffered a change in the XProgram.
>> I want to send all the variable groups (those in which some var. have changed) to the dialog that use that information.
-----------------------------------------------------------------------------
Which would be the best solution?
ID: 01
DESCRIPTION: Sending messages to the main application window passing the first parameter as a mask of the variables group that has been modified in order to be able to call the right update function (in other dialogs that I'll need acces to (ths is not a problem from the main window)).
COMMENT: Wouldn't be a slow method due to the messages queue?
ID: 02
DESCRIPTION: Calling an updateGUI function in each dialog that need it.
COMMENT: Does is this possible? and moreover I will need access to all those functions in all the dialogs...
ID: 03
DESCRIPTION: having the same timers that allow me to update the GUI?.
COMMENT: why do I use the two threads then?
-----------------------------------------------------------------------------
Of course I have not still readed all about threads that is in that Jeff. Richter book, but could you give me an advice about this?
Thank you again, and let me promise you that I wont annoy you again with questions without reading all about threading in the Richter's book.
|
|
|
|
|
You should probably read this article:
http://www.codeproject.com/system/simpletime.asp
|
|
|
|
|
Hello
I would like to know how we can get all sub keys under a parent key.
Say , i want to get the list of all keys in \HKEY_CURRENT_USER\SOFTWARE.Ultimately i want find the software installed in a machine.So how can i proceed?
Is there any other way like doing the same opreations using INI files?
Please do reply.
Thanks in Advance
Uday
|
|
|
|
|
udayakumar wrote:
I would like to know how we can get all sub keys under a parent key.
Use RegEnumKeyEx.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Use Instalshield .. it ll do all these kinds of job , with a predefine standard interface.
Abhishek Narula
"Learn to appreciate others ... World would appreciate you"
|
|
|
|
|
Oh I am Sorry .. I didnt read the question correctly .
RegEnumKey is the right answer.
Infact enumerate the following key
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
you ll get the list of all Uninstable Softwares
Hope that serves
Abhishek Narula
"Learn to appreciate others ... World would appreciate you"
|
|
|
|
|
I tried with this still i could not make out.
If you dont mind can u tell me where can i get the install shield code.
If you have any cah i get that.
Regards
Uday
|
|
|
|
|
hi,
i need the solution for disabling audio port, so that
if any audio format is playing i can stop it.
if anyone have idea , discuss with me.
thanks in advance.
regards
Halid
|
|
|
|
|
The problem given to me is to build a MFC app , which should have multiple child windows same as in a typical MDI , but all the views should be connected to single instance of Document class,
Something you can give a name Multiple Views Application,
that is one document and multiple views.
I am not suppose to use splitters where in I can create multiple views in CFrameWnd::OnCreateClien().
Does some one has a clue about how to go about >?
Abhishek Narula
"Learn to appreciate others ... World would appreciate you"
|
|
|
|
|
Override CMultiDocTemplate::OpenDocumentFile. This method is called when your app opens file from disk or creates new file. Before calling original implementation, check if any document is open and close it.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
No you didnt get the problem ,
I have to have 4 views opened simultaneously , in a different windows.
but all 4 view are supposed to be connected to same Doc class .
Am I able to explain it now ?
Abhishek Narula
"Learn to appreciate others ... World would appreciate you"
|
|
|
|
|
Abhishek Narula wrote:
No you didnt get the problem ,
I think I got it.
Create MDI app. When user opens/creates new document, you have to do the following:
1) ensure that previously active document is closed.
2) open additional 3 views (or whatever number is needed)
Overriden CMultiDocTemplate::OpenDocumentFile is the perfect place to put this functionality.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
When creating an active document container application, is it possible to display an active document server's menu icons? The default MFC implementation does not do this, so I'm wondering if it would be possible to (re)implement some OLE interface to achieve this. Any hints would be greatly appreciated!
|
|
|
|
|
Hi
I'm creating a window in a specific position and need to write some text in that window area. I've used TextOut() for the same. Window is created, but the Text is not written over there.
Herez the code snippet I'm using.
/*hWnd1 = CreateWindowEx(WS_EX_TOOLWINDOW,"HelpClass",NULL,WS_POPUPWINDOW,466,140,320,94,hWnd,NULL,ghInst, NULL);
hDC=GetDC(hWnd1);
hFont = CreateFont(14,0,0,0,FW_BOLD,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,PROOF_QUALITY,DEFAULT_PITCH | FF_SWISS,"Century New");
hOldFont=SelectObject(hDC,hFont);
SetTextColor(hDC,BLACK);
TextOut(hDC,0,0,"Title",5);
DeleteObject(SelectObject(hDC,hOldFont));
ReleaseDC(hWnd1,hDC);
Any Help is appreciated.
TIA
Venky
|
|
|
|
|
|
Just a hunch, but you probably need to perform the Textout call in the window's WM_PAINT handler.
"There's a slew of slip 'twixt cup and lip"
|
|
|
|
|
Thanks a lot for the same
With Best Regards
Venky
|
|
|
|
|
How to get the left string of the caret in richeditview, if the caret is visible?
I'm amumu, and you?
|
|
|
|
|
I saw somebody said " draw a new line and delete the old one",
but how to "delete the old one"?
thanks a lot!
i ma realfly
|
|
|
|
|
realfly wrote:
draw a new line and delete the old one
I think he/she meant draw white(background color) on the old one.
Also for painting with GDI+ check this
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|