Click here to Skip to main content
15,914,163 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
General2 Questions Pin
mvworld23-Nov-01 3:07
mvworld23-Nov-01 3:07 
GeneralRe: 2 Questions Pin
Joaquín M López Muñoz23-Nov-01 3:35
Joaquín M López Muñoz23-Nov-01 3:35 
GeneralChanging System Icon in Dialog Window Pin
John Clump22-Nov-01 22:04
John Clump22-Nov-01 22:04 
GeneralRe: Changing System Icon in Dialog Window Pin
Nish Nishant22-Nov-01 22:16
sitebuilderNish Nishant22-Nov-01 22:16 
QuestionA question about bitmap ? Pin
Leesen22-Nov-01 21:57
Leesen22-Nov-01 21:57 
AnswerRe: A question about bitmap ? Pin
Nish Nishant22-Nov-01 22:27
sitebuilderNish Nishant22-Nov-01 22:27 
GeneralA bug concerning 2 threads in my program Pin
22-Nov-01 21:13
suss22-Nov-01 21:13 
GeneralRe: A bug concerning 2 threads in my program Pin
Joaquín M López Muñoz22-Nov-01 22:21
Joaquín M López Muñoz22-Nov-01 22:21 
There are several little flaws in your code. The main problem is that the downloading thread does not provide any method for premature cancellation, so when you press cancel the program starts closing before it is safe to close the dialog.
I propose you follow this schema: Add a BOOL variable to indicate the thread to exit (m_bTimeToDie for instance), and have the downloading loop check for it. Then, change things according to this:
LRESULT CUpdateDlg::OnThreadFinished(WPARAM wParam, LPARAM /*lParam*/)
{
  m_bSafeToClose = TRUE;
  EndDialog(IDCANCEL);
  return 0L;
}

CString CUpdateDlg::DownloadFile(const char *url, const char *filename)
{
  ... // remember to check for m_bTimeToDie

  PostMessage(WM_HTTPDOWNLOAD_THREAD_FINISHED);
  return (Cause);
}

void CUpdateDlg::OnCancel() 
{
    if(m_pThread){
      m_bTimeToDie=TRUE; // thread termination will 
      GetDlgItem(IDCANCEL)->EnableWindow(FALSE); // no more cancels, we already know
    }
    else EndDialog(IDCANCEL);
}

void CUpdateDlg::OnDestroy() 
{
  if(m_pThread){
    ::WaitForSingleObject(m_pThread->m_hThread,INFINITE);
    delete m_pThread;
    m_pThread=NULL;
  }

  CDialog::OnDestroy();
}

void CUpdateDlg::OnClose() 
{
  if(m_bSafeToClose)CDialog::OnClose();
  else{ //like OnCancel()
    if(m_pThread){
      m_bTimeToDie=TRUE;	
      GetDlgItem(IDCANCEL)->EnableWindow(FALSE);
    }
    else EndDialog(IDCANCEL);
  }
}

Hope this helps.

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
GeneralHandle of one window. Pin
22-Nov-01 21:01
suss22-Nov-01 21:01 
GeneralRe: Handle of one window. Pin
Nish Nishant22-Nov-01 21:26
sitebuilderNish Nishant22-Nov-01 21:26 
GeneralRe: Handle of one window. Pin
25-Nov-01 21:15
suss25-Nov-01 21:15 
GeneralCustom control for displaying status Pin
Christopher Lord22-Nov-01 18:32
Christopher Lord22-Nov-01 18:32 
GeneralRe: Custom control for displaying status Pin
Michael Dunn22-Nov-01 19:47
sitebuilderMichael Dunn22-Nov-01 19:47 
GeneralRe: Is CSocket "secure"? Pin
Nish Nishant22-Nov-01 19:08
sitebuilderNish Nishant22-Nov-01 19:08 
GeneralRe: Is CSocket "secure"? Pin
Rashid Thadha22-Nov-01 22:34
Rashid Thadha22-Nov-01 22:34 
GeneralText Processing Pin
Nick Parker22-Nov-01 18:07
protectorNick Parker22-Nov-01 18:07 
GeneralRe: Text Processing Pin
Michael Dunn22-Nov-01 19:50
sitebuilderMichael Dunn22-Nov-01 19:50 
GeneralRe: Text Processing Pin
Nick Parker23-Nov-01 4:09
protectorNick Parker23-Nov-01 4:09 
GeneralRe: Text Processing Pin
Michael Dunn23-Nov-01 8:14
sitebuilderMichael Dunn23-Nov-01 8:14 
GeneralRe: Text Processing Pin
Nick Parker23-Nov-01 10:57
protectorNick Parker23-Nov-01 10:57 
GeneralRe: Text Processing Pin
Michael Dunn23-Nov-01 11:17
sitebuilderMichael Dunn23-Nov-01 11:17 
GeneralRe: Text Processing Pin
Nick Parker24-Nov-01 1:54
protectorNick Parker24-Nov-01 1:54 
GeneralEnumPrinters function Pin
Brett G.22-Nov-01 16:49
Brett G.22-Nov-01 16:49 
QuestionHow to display a bitmap of 24 bits correctly?? Pin
Leesen22-Nov-01 16:23
Leesen22-Nov-01 16:23 
AnswerRe: How to display a bitmap of 24 bits correctly?? Pin
Christian Graus22-Nov-01 16:38
protectorChristian Graus22-Nov-01 16:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.