|
Do you want to know if the user tried to activate the disabled button? If so, trap mouse messages like WM_MOUSEMOVE and WM_LBUTTONUP (not WM_LBUTTONDOWN - normal buttons activate on the release of the mouse button).
If you are worried about some other application sending you artificial button click messages (like the application that automatically dismisses the Outlook "something is trying to send email on your behalf" dialog), look for WM_COMMAND messages for that button, and if you know button's state when you last set it, you can determine if the message is real or not.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
thanks
... is a good idea...
now i try....
thanks
Raiz
|
|
|
|
|
Hi,
i create a Frame within a TabWnd. In the different Tabs, i place a View.
If i click on button on the view, i create dynammicaly a new View and replace it.
If the user wishes to close this new View, the old view returns.
The changing works nice, but i have trouble to close and delete the view.
I send a WM_CLOSE to the view and after this a delete :
LRESULT ViewTabWnd::CloseOld(WPARAM w, LPARAM l)
{
CWnd* Old = (CWnd*)w;
Old->SendMessage(WM_CLOSE);
delete Old;
return TRUE;
}
But at "delete Old" i have the error :
Last Trace : (<<<<<<< indicates the debug-trace )
void PASCAL CObject::operator delete(void* p)
{
#ifdef _AFX_NO_DEBUG_CRT
free(p);
#else
_free_dbg(p, _AFX_CLIENT_BLOCK); <<<<<<<<<
#endif
}
if (pHead->nBlockUse == _IGNORE_BLOCK)
{
_ASSERTE(pHead->nLine == IGNORE_LINE && pHead->lRequest == IGNORE_REQ);
/* fill the entire block including header with dead-land-fill */
memset(pHead, _bDeadLandFill,
sizeof(_CrtMemBlockHeader) + pHead->nDataSize + nNoMansLandSize);
_free_base(pHead); <<<<<<<<<<<<<<<<<
RTCCALLBACK(_RTC_FuncCheckSet_hook,(1));
return;
}
Does anyone knows this problem ?
I'm confused
Thanks
|
|
|
|
|
Looks like pointer you are deleting is already deleted and dangled .
baerten wrote: LRESULT ViewTabWnd::CloseOld(WPARAM w, LPARAM l)
How this message/function is called ?
|
|
|
|
|
thanks
via a PostMessage
LRESULT ViewTabWnd::CloseOld(WPARAM w, LPARAM l)
{
CWnd* Old = (CWnd*)w;
Old->SendMessage(WM_CLOSE);
delete Old; << I step here, then via F10 i step into the destructor and then the error is launched
return TRUE; << i never step here
}
|
|
|
|
|
I found the error ...
It's a variable which has a wrong syntax, i wrote bool at place of BOOL
5 hours of recherche for nothing
Thanks anyway
|
|
|
|
|
baerten wrote: It's a variable which has a wrong syntax, i wrote bool at place of BOOL
Nice to see, your error is solved.
But, really cant understand how it affects your code. Can you show changes , you needed to make.
|
|
|
|
|
i changed only bool to BOOL.
bool isn't a MFC Datatype, but however it could create it ( bool is used in .NET )
But at the destruction of this datatype he had the error.
But only if i create the view dynamicaly. If i created the same view with a Frame via CreateView
the error doesn't occur.
So, i could step into the Destructor and after the destructor all variables will be destroyed
and there, he had the error
That was an error of kind "too fast typing and too much thinking in the C#-Way" LOL
|
|
|
|
|
baerten wrote: bool isn't a MFC Datatype
Its keyword in C++, so that should not be problem. Still confused. .
Why it was so ?
|
|
|
|
|
Hi,
I need to change the font size of CStatic ctrl.
How can do this ?
Thanks.
|
|
|
|
|
You can use of CreateFont and then use of SetFont And also see Nibu babu thomas answer to super_ttd (Strange Font bolding)
|
|
|
|
|
Look for LOGFONT-->lfHeight while creating font for static window.
|
|
|
|
|
See here.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hi all,
I have made a worker thread like this
UINT workerThread(LPVOID pParam)
{
return 0;
}
i want to pass a CString parameter to my thread
how to do it n how to do AfxBeginThread for passing CString parameter.......
thanxs in advance
|
|
|
|
|
why not just calling like this :
CString str = _T("hello CP");
workerThread(&str);
from within the function, if you know you'll always get a CString, then use it like that :
UINT workerThread(LPVOID lpParam) {
CString str = *(static_cast<CString*>(lpParam));
return 0;
}
|
|
|
|
|
toxcct wrote: CString str = _T("hello CP"); workerThread(&str);
str is a local object right? Passing local objects to thread function is a bad practice and leads to disaster.
|
|
|
|
|
Nibu babu thomas wrote: str is a local object right?
not necessarily... i wrote it like that to show that it was defined first, but you're right, it wasn't clear enough
|
|
|
|
|
As your earler response suggests, you may race on the CString going out of scope before the worker thread starts and can use it.
This would have to be an instance of CString that would not go out of scope so quickly (static, member, global, dynamically allocated, etc. - whatever works best given the requirements).
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
You can to it if you dynamically allocate the CString object and then free it in the worker thread. Be careful doing this if you are doing things like per-thread custom memory allocation routines, or if you pass the pointer across DLL or COM boundaries and then try to deallocate it - the DLL or COM object implementation may not use the same allocation/deallocation routines you are.
Something like the following should work (may contain errors, and has no error handling...):
CString *pString = new CString( _T( "Why Do You Need A CString?" ) );
AfxBeginThread( workerThread, (LPVOID)pString, ..... );
{
CString *pString = (CString*)pParam;
delete pString;
}
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
thanxs to all
my problem got solved ..
but can anybody tell me if i have to pass two parameters one CString n One int then how will i do it....
|
|
|
|
|
&nhsp;&nhsp; Create a struct for all of the data you need, and pass a pointer to the struct across to the worker thread.
&nhsp;&nhsp; Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
thanku for ur reply..
i have created a structure having
CString and int values like this
struct test
{
CString str;
int item;
};
created its object like this
test *obj;
obj = new test;
and in that object passed the values
like
obj->str = "neha";
obj->item = 1;
After that i have started thread like this
Ping = AfxBeginThread(PingThread,obj);
in thread i have retrieved first Cstring value like this
cstrHost = *(static_cast<cstring*>(pParam));
but in my integer value i m getting garbage value..
int_val = *(static_cast<int*>(pParam));
How to correct it.....
|
|
|
|
|
test *pStruct = (test*)pParam;
cstrHost = pStruct -> str;
int_val = pStruct -> item; Just like with candy, you have to first get to the outer portion (i.e. the wrapper) in order to get to the good stuff inside.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Hi all,
I've just tried to bold the font in a particular static in one of my dialogs.
for this i have done this :
I Have 2 statics left aligned, containing exactly the same string (the upper one is for comparison purpose).
The static I modify has a control variable of type CStatic on it.
here is the code i put in the dialog's OnInitDialog() :
HDC hdc = (HDC)(*m_myStatic.GetDC());
TEXTMETRIC tm;
::GetTextMetrics(hdc, &tm);
int n = ::GetTextFace(hdc, 0, NULL);
TCHAR* pszFontName = new TCHAR[n];
::GetTextFace(hdc, n, pszFontName);
CFont nf;
nf.CreateFont(tm.tmHeight,
tm.tmAveCharWidth,
0,
0,
tm.tmWeight,
FALSE,
tm.tmUnderlined,
tm.tmStruckOut,
tm.tmCharSet,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
tm.tmPitchAndFamily,
pszFontName);
delete[] pszFontName;
m_myStatic.SetFont(&nf);
as you can see, i merely duplicate the original font without bolding it, but what a surprise, the static is bold anyway
can anyone explain me why the font (Tahoma) is acting like this ?
|
|
|
|
|
super_ttd wrote: CFont nf; nf.CreateFont(tm.tmHeight, tm.tmAveCharWidth, 0, 0, tm.tmWeight, FALSE, tm.tmUnderlined, tm.tmStruckOut, tm.tmCharSet, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, tm.tmPitchAndFamily, pszFontName);
You are creating a local CFont object. Hence the CFont object get's destroyed. This is the reason for this wierd behavior, might be since the font object got destroyed it's using DEFAULT_GUI_FONT.
From MSDN:
Specifically, do not destroy the specified CFont object until after the CWnd control has been destroyed.
Windows does not copy the font specified in a SetFont() call.
If the font is destroyed before the control is destroyed, unpredictable results can occur. "new" the font object and see the difference...
And by the way you don't have to write this much code for modifying an existing font object...
Here is the code snippet that does this...
CFont* pFont = m_cstc.GetFont();
LOGFONT lfLogFont = { 0 };
pFont->GetLogFont( &lfLogFont );
lfLogFont.lfWeight = FW_BOLD;
CFont pNewFont = new CFont;
pNewFont->CreateFontIndirect( &lfLogFont );
m_cstc.SetFont( pNewFont );
|
|
|
|