|
Post a user defined message with PostThreadMessage and exit the thread on receiving this message.
<bold>- Nilesh
<italics>"Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw
|
|
|
|
|
Can you give me a sample of this mechanism.
by calling PostThreadMessage( )
how can i implement the CWinThread so that it can catch the message?
i have ever tried this way:
threadRoute()
{
GetMessage(.....)
}
but is not what i want, because i need a loop inside the thread fucntion. it is keep looping until i want to terminate.
Thanx!
|
|
|
|
|
Simpler way out could be checking a flag in your thread's loop and this flag be changed by your application before exiting.
<bold>- Nilesh
<italics>"Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw
|
|
|
|
|
have you created a worker thread or UI thread using CWinthread
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
Actually i am not sur
i create a dlg which has a control list. when this dlg is created by calling domodal(), a CWinThread is created in OnInit funtion. The thread will keep reading the log files and display the contents on the control list.
User will click cancel of the dlg to exit the dlg. problem is if i don't kill the Thread, it may still hold the handle to the log file. so further writing to the log file will cause problem.
|
|
|
|
|
could you show me your coding of OnInitDialog Function?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
There is several way to terminate your thread. Let me suppose that you understand about synchronisation.
And also to make thing more easier,
define a static member variable of type: static BOOL m_endLoop for your dialog class CYourDLG;
and also define a static member of type: static CEvent m_EventExit for your dialog class CYourDLG.
in the CYourDLG::OnInit() function initialize m_endLoop=0; and call m_EventExit.SetEvent().
And in your function OnCancel and OnOk at before to exit, call
WaitForSingleObject(EventExit,INFINITE); and in the first line in those 2 functions set
m_endLoop =TRUE;
and now in your loop function that terminate the thread, inside the loop insert this code:
if(CYourDLG::m_endLoop==TRUE)
{
// first to some cleaning and close all opened file or whatelse
...........
//and call
CYourDLG::m_EventExit.SetEvent();
return 0;
}
================== BUT when your start the thread insert this line at the begin of the thread function
CYourDLG::m_EventExit.ResetEvent();
That is.
You will have no access violation.
This solution must help.
Let me know if you have more questions
Perre Kande
|
|
|
|
|
a_du wrote:
Actually i am not sur
How can you not know? You call AfxBeginThread() in one of two ways. One way creates a worker (has no message pump) thread. The other creates a UI (has a message pump) thread.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Hello,
I think that you have a worker thread problem. Read here[^] about threads.
As stated in the article, you can kill your thread by calling ::TerminateThead((HANDLE)YourWinThreadObject); , but this is not safe, since your resources will not be cleaned up nicely...
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
See here for termination methods.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
is it normal that CEdit::SetSel(-1, -1); donnot erase my EditBox ?
from the MSDN, i read this :
void SetSel(
int nStartChar,
int nEndChar,
BOOL bNoScroll = FALSE
);
nStartChar
Specifies the starting position. If nStartChar is 0 and nEndChar is –1, all the
text in the edit control is selected. If nStartChar is –1, any current selection is removed.
i so thought that calling say m_peMyEdit->SetSel(-1, -1); (where m_peMyEdit is declaredas as a CEdit* and well initialized also) would clear the content of my Control.
should i feedback this to Microsoft ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
It does not clear the content of the control.
It removes the selection.
(e.g. if you press shift you can select chars in an edit control by pressing arrow keys) calling the setsel with -1 as startchar removes the selection... The text is still there completely, only any text that was 'selected', appears as normal now...
Hope this helps you,
Davy
|
|
|
|
|
effectively, now you say it, i realize i didn't read it right...
thanks a lot
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Hi Tox,(Long time no see)
Why don't you use CEdit::SetWindowText("") for clearing the Edit Control
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
ThatsAlok wrote:
Hi Tox,(Long time no see)
yeah, i'm here, but with a lot of work, so no much time to be connected (moreover, our servers are still cuting off during the morning and the afternoon...).
ThatsAlok wrote:
Why don't you use CEdit::SetWindowText("") for clearing the Edit Control
yes, that's what i do, but i wondered why i could not do this actually...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
One of my article is waiting for you comment, hope you find some time for it from your busy Schedule. BOB and other already commented on it
here is link Article[^]
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
|
there any wizard in MFC for creating a Windows Service?
If not, Please help me with a complete code for developing a Windows Service
I need it very much and immediately
|
|
|
|
|
Yes, assuming you're running VS 2003.
- Shift+Ctrl+N to invoke New Project dialog box
- Expand Visual C++ Projects folder
- Select ATL folder
- Select the ATL Project type
- Specify name and location
- Click enter
- When the ATL Project Wizard displays, select the Application Settings tab
- Specify Server type of Service
- Click Finish
Voila! You now have a service with the guts of communicating with the SCM and a worker thread done for you.
|
|
|
|
|
Check here[^]
<bold>- Nilesh
<italics>"Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw
|
|
|
|
|
Tank you very much for your Help.
But I need a Source code for crete and develop a Windows Service because
I`m not a professional programmer in VisualC++ and I do`nt have much information about Windows Service
|
|
|
|
|
|
Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
|
|
|
|
|
Thank you for your help!
There is a good code in item "Five Steps to Writing Windows Services in C".
But some links are not enabled.(Such as "Listing 1, Listing 2, Figure 1, Figure 2"
I want to see this links and figures.What shude I do?
Please guide me immediately.
|
|
|
|
|
Hi,
How to get the sectors/clusters of a particular file?
I am working on Windows 2000.
Hoping to get a reply soon.
TIA.
regards,
Jahfer V P.
|
|
|
|