Click here to Skip to main content
15,868,151 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Function for Rename in Native APIs Pin
Ryan Binns26-Apr-06 2:22
Ryan Binns26-Apr-06 2:22 
AnswerRe: Function for Rename in Native APIs Pin
David Crow26-Apr-06 2:52
David Crow26-Apr-06 2:52 
GeneralRe: Function for Rename in Native APIs Pin
rajeevktripathi26-Apr-06 3:38
rajeevktripathi26-Apr-06 3:38 
GeneralRe: Function for Rename in Native APIs Pin
David Crow26-Apr-06 3:54
David Crow26-Apr-06 3:54 
GeneralRe: Function for Rename in Native APIs Pin
rajeevktripathi26-Apr-06 4:08
rajeevktripathi26-Apr-06 4:08 
QuestionDrag and Drop Pin
Anil_vvs25-Apr-06 23:19
Anil_vvs25-Apr-06 23:19 
QuestionMoving an ActiveX in a dialog box Pin
VogRo25-Apr-06 22:35
VogRo25-Apr-06 22:35 
QuestionShowing dialogs within a thread Pin
ilgale25-Apr-06 22:08
ilgale25-Apr-06 22:08 
I have to manage a part of my user interface (dialogs) in a separate thread.
I've created a CWinThread derived class and I've tryed to show a dialog
in the PreTranslateMessage method but when I close the dialog an
exception is fired.

This is my PreTranslateMessage:

BOOL CTest1Thread::PreTranslateMessage(MSG* pMsg) <br />
{<br />
   switch(pMsg->message)<br />
   {<br />
      case WM_START:<br />
         AfxMessageBox(_T("START EVENT"), MB_OK | MB_ICONEXCLAMATION);<br />
      break;<br />
<br />
      case WM_STOP:<br />
         AfxMessageBox(_T("STOP EVENT"), MB_OK | MB_ICONEXCLAMATION);<br />
         ::PostQuitMessage(0);<br />
      break;<br />
<br />
      case WM_SHOW_CHILD:<br />
         m_pDlgThreadChild = new CDlgThreadChild();<br />
         m_pDlgThreadChild->DoModal();<br />
         delete m_pDlgThreadChild;<br />
         m_pDlgThreadChild = NULL;<br />
      break;<br />
<br />
      default:<br />
      break;<br />
   }<br />
	<br />
   return CWinThread::PreTranslateMessage(pMsg);<br />
}


The exception is fired in WINCORE.CPP at this point:

		// should be a normal window<br />
		ASSERT(::IsWindow(m_hWnd));<br />
<br />
		// should also be in the permanent or temporary handle map<br />
		CHandleMap* pMap = afxMapHWND();<br />
		ASSERT(pMap != NULL);<br />
<br />
		CObject* p;<br />
		ASSERT((p = pMap->LookupPermanent(m_hWnd)) != NULL ||<br />
			(p = pMap->LookupTemporary(m_hWnd)) != NULL);<br />
		ASSERT((CWnd*)p == this);   // must be us<br />
<br />
		// Note: if either of the above asserts fire and you are<br />
		// writing a multithreaded application, it is likely that<br />
		// you have passed a C++ object from one thread to another<br />
		// and have used that object in a way that was not intended.<br />
		// (only simple inline wrapper functions should be used)<br />
		//<br />
		// In general, CWnd objects should be passed by HWND from<br />
		// one thread to another.  The receiving thread can wrap<br />
		// the HWND with a CWnd object by using CWnd::FromHandle.<br />
		//<br />
		// It is dangerous to pass C++ objects from one thread to<br />
		// another, unless the objects are designed to be used in<br />
		// such a manner.


So... I've seen is not easy to manage dialogs in threads...
How can I do that ?

Thanks a lot !!!
AnswerRe: Showing dialogs within a thread Pin
Cedric Moonen25-Apr-06 22:11
Cedric Moonen25-Apr-06 22:11 
GeneralRe: Showing dialogs within a thread Pin
ilgale25-Apr-06 22:35
ilgale25-Apr-06 22:35 
GeneralRe: Showing dialogs within a thread Pin
Cedric Moonen25-Apr-06 22:43
Cedric Moonen25-Apr-06 22:43 
GeneralRe: Showing dialogs within a thread Pin
ilgale25-Apr-06 23:51
ilgale25-Apr-06 23:51 
AnswerRe: Showing dialogs within a thread Pin
Nibu babu thomas25-Apr-06 22:23
Nibu babu thomas25-Apr-06 22:23 
GeneralRe: Showing dialogs within a thread Pin
ilgale25-Apr-06 22:37
ilgale25-Apr-06 22:37 
GeneralRe: Showing dialogs within a thread Pin
Nibu babu thomas25-Apr-06 23:11
Nibu babu thomas25-Apr-06 23:11 
GeneralRe: Showing dialogs within a thread Pin
ilgale26-Apr-06 0:24
ilgale26-Apr-06 0:24 
Questionwhen use a button on dialog, i get trouble Pin
samfromcn25-Apr-06 22:05
samfromcn25-Apr-06 22:05 
AnswerRe: when use a button on dialog, i get trouble Pin
Cedric Moonen25-Apr-06 22:09
Cedric Moonen25-Apr-06 22:09 
GeneralRe: when use a button on dialog, i get trouble Pin
samfromcn25-Apr-06 22:29
samfromcn25-Apr-06 22:29 
GeneralRe: when use a button on dialog, i get trouble Pin
Cedric Moonen25-Apr-06 22:34
Cedric Moonen25-Apr-06 22:34 
GeneralRe: when use a button on dialog, i get trouble Pin
samfromcn25-Apr-06 22:47
samfromcn25-Apr-06 22:47 
QuestionRe: when use a button on dialog, i get trouble Pin
David Crow26-Apr-06 3:08
David Crow26-Apr-06 3:08 
AnswerRe: when use a button on dialog, i get trouble Pin
Ryan Binns26-Apr-06 2:26
Ryan Binns26-Apr-06 2:26 
AnswerRe: when use a button on dialog, i get trouble Pin
samfromcn26-Apr-06 17:41
samfromcn26-Apr-06 17:41 
QuestionHow to use internal command of command prompt without typing it Pin
kflrei25-Apr-06 22:02
kflrei25-Apr-06 22:02 

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.