Click here to Skip to main content
15,915,600 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: private instance of a public struct Pin
elephantstar15-Oct-04 10:57
elephantstar15-Oct-04 10:57 
GeneralRe: private instance of a public struct Pin
Maximilien15-Oct-04 14:53
Maximilien15-Oct-04 14:53 
GeneralRe: private instance of a public struct Pin
elephantstar19-Oct-04 6:33
elephantstar19-Oct-04 6:33 
GeneralLinking Unicode and non-Unicode DLLs in same .EXE Pin
EurekaJim15-Oct-04 8:31
EurekaJim15-Oct-04 8:31 
GeneralRe: Linking Unicode and non-Unicode DLLs in same .EXE Pin
Blake Miller15-Oct-04 9:30
Blake Miller15-Oct-04 9:30 
GeneralRe: Linking Unicode and non-Unicode DLLs in same .EXE Pin
EurekaJim15-Oct-04 9:50
EurekaJim15-Oct-04 9:50 
GeneralRe: Linking Unicode and non-Unicode DLLs in same .EXE Pin
Blake Miller15-Oct-04 9:59
Blake Miller15-Oct-04 9:59 
GeneralSafer Timer Thread termination Pin
15-Oct-04 8:26
suss15-Oct-04 8:26 
I was experimenting on a worker thread to do a timer which posts a message each second and the thread is created in the CView constructor
(MY APP is SDI)

class CMyView:public CView
{
//consturctor ...

public:
static UINT RunTimer(LPVOID p);
void Run();
public:
volatile BOOL m_bRunTimer;

//other stuff



};


CMyView::CMyView()
{
m_bRunTimer=TRUE;
//Initialize Stuff
AfxBeginThread(RunTimer,this); //Get A Thread To Post A Message Every Second
}

the Run Timer Function is used in This Way

/////////////////////////////////////////////////
UINT CMyView::RunTimer(LPVOID p)
{
((CMyView*)p)->Run ();
return 0;
}

void CMyView::Run ()
{
while (m_bRunTimer)
{
::Sleep (1000);
PostMessage (UWM_TIMER_SECOND);
/*Note Here that UWM_TIMER_MESSAGE IS user Defined Message*/
}

}

every thing works great till this point and the thread posts a message each second and the message handling is doin great the problem arises when the window(program) is closed then a debug assertion failure dialog box is displayed saying the when we are Posting a message we are posting a message to a window that no longer exists.
I tried adding The line m_bRunTimer=FALSE; in ~CMyView() but no change then i wrote some code in the


void CMyView::OnDestroy()
{
m_bRunTimer=FALSE;
::Sleep(4000);//Simply Added to Elapse the Time Slice of Main Thread
CView::OnDestroy();
}

After Doing i finally got safe with removing the thread and returns value i used TRACE() that my thread is safley removed and everything but i think my way of getting rid of the thread is kind of not portable and clean is there any other way that i can do this safley.
GeneralRe: Safer Timer Thread termination Pin
Doug Mitchell15-Oct-04 9:05
Doug Mitchell15-Oct-04 9:05 
GeneralRe: Safer Timer Thread termination Pin
Blake Miller15-Oct-04 9:38
Blake Miller15-Oct-04 9:38 
Generalconversion operator not being called for both objects Pin
lino_i15-Oct-04 6:53
lino_i15-Oct-04 6:53 
GeneralRe: conversion operator not being called for both objects Pin
David Crow15-Oct-04 8:09
David Crow15-Oct-04 8:09 
GeneralRe: conversion operator not being called for both objects Pin
lino_i15-Oct-04 8:37
lino_i15-Oct-04 8:37 
GeneralRe: conversion operator not being called for both objects Pin
David Crow15-Oct-04 9:03
David Crow15-Oct-04 9:03 
GeneralRe: conversion operator not being called for both objects Pin
lino_i15-Oct-04 9:25
lino_i15-Oct-04 9:25 
GeneralRe: conversion operator not being called for both objects Pin
David Crow15-Oct-04 9:46
David Crow15-Oct-04 9:46 
GeneralRe: conversion operator not being called for both objects Pin
lino_i15-Oct-04 9:50
lino_i15-Oct-04 9:50 
GeneralRe: conversion operator not being called for both objects Pin
David Crow15-Oct-04 9:59
David Crow15-Oct-04 9:59 
GeneralSkinned dialogs Pin
mtzlplyk15-Oct-04 6:14
mtzlplyk15-Oct-04 6:14 
Generalanalyzing the return value Pin
lino_i15-Oct-04 5:56
lino_i15-Oct-04 5:56 
GeneralRe: analyzing the return value Pin
mtzlplyk15-Oct-04 6:11
mtzlplyk15-Oct-04 6:11 
GeneralRe: analyzing the return value Pin
David Crow15-Oct-04 8:01
David Crow15-Oct-04 8:01 
QuestionHow do I gray out a radio button? Pin
tpbzdw15-Oct-04 5:13
tpbzdw15-Oct-04 5:13 
AnswerRe: How do I gray out a radio button? Pin
David Crow15-Oct-04 5:38
David Crow15-Oct-04 5:38 
GeneralRe: How do I gray out a radio button? Pin
tpbzdw15-Oct-04 5:41
tpbzdw15-Oct-04 5:41 

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.