|
hi!
i've encountered serious problem, which couldnt solve for hours.
i've got a couple of views splitted by CSplitterWnd
in one of this views (ParentView) i dynamically create CWnd-derived object (SpinEdit) that holds CEdit and CSpinButtonCtrl (analogously to CInPlaceEdit by Chris Maunder).
the problem is:
i cant handle WM_KILLFOCUS message in SpinEdit window. Spy++ shows that this message isnt sent to SpinEdit window than user clicks mouse button on ParentView.
maybe problem is in ParentView? it is completely owner drawn and has no more child-controls except this dynamically created SpinEdit.
any help will be greatly appreciated
nobody is perfect
|
|
|
|
|
This may be of help http://www.codeproject.com/dialog/killfocus.asp[^]
Roger Allen
Sonork 100.10016
I think I need a new quote, I am on the prowl, so look out for a soft cute furry looking animal, which is really a Hippo in disguise. Its probably me.
|
|
|
|
|
Hello,
I have learned a ton in the past few days.. Having never programmed UI Threads (with the help of articles on Code Project and all of you) I have implemented a UI thread that contains a CSocket for file transfer.. The server works perfect except when I close the server I have a memory leak.. This is how I start the UI Thread and how I close the UI thread.. what am I doing wrong??
Here is the creation inside CMainFrame
CFtThread* pThread = (CFtThread*)AfxBeginThread(RUNTIME_CLASS(CFtThread),
THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
pThread->m_nPort = 21;
pThread->ResumeThread();
pThread->OnStartListening();
Here is how I am trying to close the thread.. it's in CMainFrame::OnClose()
void CMainFrame::OnClose()
{
..... code
CFtThread* pThread = (CFtThread*)AfxGetThread();
pThread->ExitInstance();
..... code
CFrameWnd::OnClose();
}
In my int CFtThread::ExitInstance() I try to close the socket and remove any connected sockets...
int CFtThread::ExitInstance()
{
m_sSocket.ShutDown(2);
m_sSocket.Close();
POSITION pos, temp;
pos = m_pEpList.GetHeadPosition();
while(!m_pEpList.IsEmpty())
{
temp = pos;
CFtSocket* pSocket = (CFtSocket*)m_pEpList.GetNext(pos);
pSocket->Close();
m_pEpList.RemoveAt(temp);
}
return CWinThread::ExitInstance();
}
Any ideas on why I still have a memory leak?
Thanks,
Rob Jones
|
|
|
|
|
u are emtying the list, but are u deleting the pointers if any??
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Yes I delete all Socket pointers.. It's in a different function.. 99% of the time the pointers are gone and the pointer list is empty.. I just empty it on close "just incase"..
|
|
|
|
|
AfxGetThread() returns a CWinThread pointer to the thread that makes the call. From your chunks of code it looks like you are trying to close your main thread from the OnClose() event handler for it, and thus not actually closing your CFtThread object.
I don't know what would happen if you cast a CWinThread pointer to CFtThread; I would have thought something more significant than a memory leak would happen when you try to call members of CFtThread.m_sSocket.
You get given a pointer to your CFtThread as a return from AfxBeginThread(). Try using that to close the thread.
Signature space for rent. Apply by email to....
|
|
|
|
|
I set a member pointer to CFtThread (in CMainFrame) and tried to use that pointer (from AfxBeginThread()) to close the thread.. seems that maybe the app closes before the thread does.. is there a way to wait for the thread to close before closing the app?
|
|
|
|
|
Thats cool. Just these two lines in your sample code made me suspicious:-
CFtThread* pThread = (CFtThread*)AfxGetThread();
pThread->ExitInstance();
Anyway. Only your CFtThread thread can terminate itself safely. You need to devise a mechanism for signaling to it that it needs to terminate. For a suitable signalling mechanism, see CWinThread::PostThreadMessage. You could use a custom message for it.
When your thread receives the message, it should call AfxEndThread().
for detailed info, see msdn "multithread programming | with mfc"
Signature space for rent. Apply by email to....
|
|
|
|
|
Dumping objects ->
strcore.cpp(118) : {93} normal block at 0x01222E40, 52 bytes long.
Data: < ' ' C:\C> 01 00 00 00 27 00 00 00 27 00 00 00 43 3A 5C 43
C:\Code\FtServer\FtThread.cpp(17) : {91} client block at 0x01222F40, subtype 0, 168 bytes long.
a CFtThread object at $01222F40, 168 bytes long
Object dump complete.
I'm unsure what strcore.ccp is... not sure if this helps.
Any ideas?
|
|
|
|
|
strcore.cpp needn't concern you:- MFC internals. The useful part of that dump is the line:-
a CFtThread object at $01222F40, 168 bytes long
tells you what it was.
Signature space for rent. Apply by email to....
|
|
|
|
|
strcore.cpp is the guts of CString.
As you can see, the leaked memory even contains fragments of your string.
But this is not CStrings fault, it simply gets no opportunity to clean up.
|
|
|
|
|
The best way to kill a thread is asking it to finish and wait for its end. A way to to this could be to implement a specific message send by the app to the thread.
(m_pMyThread is the pointer you get from AfxBeginThread
WM_STOPTHREAD defined as WM_APP + 1)
In the application:
<code>
// asking the thread to end
m_pMyThread->PostThreadMessage(WM_STOPTHREAD, 0, 0);
MsgWaitForMultipleObjects(1, &(m_pMyThread->m_hThread), TRUE, INFINITE, QS_ALLEVENTS);</code>
In the thread
<code>BEGIN_MESSAGE_MAP(CMyThread, CWinThread)
ON_THREAD_MESSAGE(WM_STOPTHREAD, OnStopThread)
END_MESSAGE_MAP()</code>
<code>LRESULT CMyThread::OnStopThreadClip(WPARAM wParam, LPARAM lParam)
{
// cleaning data here
AfxEndThread(1);
return 0L;
}</code>
HTH,
K.
<font size=0>
Some of those that work forces
Are the same that burn crosses !
Killing In The Name/Rage Against The Machine
</a>
</font>
|
|
|
|
|
How can I find out if I'm in print preview mode in my main frames OnClose()?
I've tried checking the DC IsKindOf for CPreviewDC, but couldn't get a positive result (am I using the DC incorrectly?) like this:
CDC* pDC = GetDC();
if (pDC && pDC->IsKindOf(RUNTIME_CLASS(CPreviewDC)))
if (pDC)
ReleaseDC(pDC); And I've also tried checking for difference's in the hDC's without joy:
CDC* pDC = GetDC();
if (pDC && pDC->m_hDC != pDC->m_hAttribDC)
if (pDC)
ReleaseDC(pDC); Anyone know how I can find out if I'm in print preview in my CMainFrame::OnClose() ??
Dylan Kenneally
London, UK
|
|
|
|
|
From the top of my head: override CFrameWnd::OnSetPreviewMode. Never did that, however
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|
|
Works a treat, thanks very much
Dylan Kenneally
London, UK
|
|
|
|
|
I am doing my win32 application.How to dynamically increase scroll bar size
of a window.
|
|
|
|
|
Do you create your scrollbars by adding WS_HSCROLL or WS_VSCROLL window style, or it's a child control?
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|
|
Hi,
I have 2 Tables on MS-Access and I use 1 class CRecordSet because these tables are joined. I have no problem to read a recordset like this:
rsMsg.m_strFilter.Format("CLE = %d", lCle );
rsMsgExp.Open( CRecordset::snapshot,_T("Proc"));
if(!(rsMsgExp.IsEOF() && rsMsgExp.IsBOF()))
{
rsMsgExp.MoveFirst();
csToto = rsMsgExp.m_TOTO;
But when I don't want to write (Add or Update a record), it's not possible, the Exception is "Record is on Read Only Mode", why ???????
Thanks a lot ....
|
|
|
|
|
Snapshots are not updateable. BTW: why don't you use CDaoRecordset instead of ODBC-based CRecordset if you're using Access?
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|
|
|
So use CDaoRecordset and open it as 'dynaset', not 'snapshot' - pass dbOpenDynaset to CDaoRecordset::Open.
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|
|
Hi,
I have a problem with the COleDateTime class. I have no idea how to do subtraction and addition for two COleDateTime objects. I am used to the VB type of time and date addition and subtraction. Is there a way to do subtraction and addition as in VB date/time?
By the way is there an equalvalent date/time method in VC that is similar to the one in VB?
Your help is greatly appreciated.
leonwoo
|
|
|
|
|
Look at the COleDateTimeSpan class and operators +,-,+= and -= defined in COleDateTime.
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|
|
Im using dinput.h's GetDeviceState to retrieve the
current mouse cursor position.
Why do I get coordinates returned in the billions???
I get the same result using ints and longs for x&y.
All I want are pixel coordinates within the
range of my window app.
Any help would be much appreciated
Thanks,
Rob
|
|
|
|
|
Says MSDN-
> The mouse is a relative-axis device, so the absolute axis positions for mouse axes are simply accumulated relative motion. Therefore, the value of the absolute axis position is not meaningful except in comparison with other absolute axis positions.
Why don't you just handle WM_MOUSEMOVE events instead? Potentially with a SetCapture() first.
Signature space for rent. Apply by email to....
|
|
|
|