How to cancel long time drawing
-
I am writing a code to do a long time draw like:
void MyDialog::DoSlowDraw(DWORD tDelay){
while(notFinished){
DrawNextLine(); // like LineTo()....
Sleep(tDelay);
}
}And it's better to have a "cancel button" because it may take a long time according to tDelay. --------------------- :(( My try: To handle "cancle button clicked Message" , Drawing must be done by another thread.
UINT DrawProc( LPVOID pParam )
{
CMyDialog* pform = (CMyDialog*)pParam;
int timeDelay = pform->timeD;
Line_list* pLines = pform->m_pLines;
CClientDC cdc(pform);
//Draw....It's worked, but as far as I know 1. Work thread should not touch the GUI ---- (Do the drawing). 2. MFC object should not passed to another thread ---- (passing drawing data by CMyDialog*) :confused:Is there a good way to cancle long time drawing.
-
I am writing a code to do a long time draw like:
void MyDialog::DoSlowDraw(DWORD tDelay){
while(notFinished){
DrawNextLine(); // like LineTo()....
Sleep(tDelay);
}
}And it's better to have a "cancel button" because it may take a long time according to tDelay. --------------------- :(( My try: To handle "cancle button clicked Message" , Drawing must be done by another thread.
UINT DrawProc( LPVOID pParam )
{
CMyDialog* pform = (CMyDialog*)pParam;
int timeDelay = pform->timeD;
Line_list* pLines = pform->m_pLines;
CClientDC cdc(pform);
//Draw....It's worked, but as far as I know 1. Work thread should not touch the GUI ---- (Do the drawing). 2. MFC object should not passed to another thread ---- (passing drawing data by CMyDialog*) :confused:Is there a good way to cancle long time drawing.
fitatc wrote:
Is there a good way to cancle long time drawing.
See here.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
fitatc wrote:
Is there a good way to cancle long time drawing.
See here.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
May be You misunderstanding my qustion because of my poor english. My Question is "How to do multiThread thing in one GUI thread." in another word. But by your advise, I did find the answer from old Qustions By another guy: http://www.codeproject.com/script/Forums/View.aspx?fid=1647&msg=570370[^]
-
May be You misunderstanding my qustion because of my poor english. My Question is "How to do multiThread thing in one GUI thread." in another word. But by your advise, I did find the answer from old Qustions By another guy: http://www.codeproject.com/script/Forums/View.aspx?fid=1647&msg=570370[^]
fitatc wrote:
May be You misunderstanding my qustion because of my poor english.
I understood you perfectly. If you are drawing in a worker thread and you need to cancel that thread, my advice is the way to go. Using a message pump is an antiquated and largely unused 16-bit Windows solution.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
fitatc wrote:
May be You misunderstanding my qustion because of my poor english.
I understood you perfectly. If you are drawing in a worker thread and you need to cancel that thread, my advice is the way to go. Using a message pump is an antiquated and largely unused 16-bit Windows solution.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
Sorry for my late response,(I am in a busy work now) You are right, but before that, :confused:Do you think it is OK to draw in the work thread? I mean, a good design? because drawing is touching the GUI I thought, maybe I was wrong.
fitatc wrote:
Do you think it is OK to draw in the work thread?
I would think not. Have the worker thread post a message to the main thread (that owns the UI).
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons