|
Thanks Nish, will check it out.
Giles
|
|
|
|
|
Hio again.. I have a class (CCompanyHandler) which loads and saves a CObArray which is full of CObjects. The load file function calls the CObject constructors, and I'm trying to figure out how to destruct all of these objects created when loaded. I figure if I can overload the CCompanyHandler destructor then I should be able to have it destruct all of the CObjects, but I still have some sort of memory leak. Here is a trace:
CCompanyHandler:Constructor
CCompanyHandler:LoadFile
CCompany:Contructor <+ 1
CCompanyHandler:Constructor
CCompanyHandler:LoadFile
CCompany:Contructor <+ 2
CCompanyHandler:Constructor
CCompanyHandler:LoadFile
CCompany:Contructor <+ 3
CCompanyHandler:LoadFile
CCompany:Contructor <+ 4
CCompanyHandler:Destructor
CCompany:Destructor <- 3
CCompanyHandler:Destructor
CCompany:Destructor <- 2
CCompanyHandler:Destructor
CCompany:Destructor <- 1
As you can see the LoadFile() function of CCompanyHandler is what calls the constructors for the objects as it reads them.
TRACE("CCompanyHandler:LoadFile\n");
try
{
CFile fileMyFile(m_strFileName,CFile::modeRead + CFile::modeNoTruncate); //open file for reading
CArchive arRead(&fileMyFile, CArchive::load); //open archive for loading
m_oaCompanies.Serialize(arRead); //call serialize function to populate m_oaCompanies
arRead.Close(); // close archive
fileMyFile.Close(); // close file
return 1;
}
My problem is that if I call the loadfile() function multiple times it will keep creating instances of CCompany, and then my destructor doesn't get rid of it.. here is what my destructor does:
TRACE("CCompanyHandler:Destructor\n");
if (GetSize() > 0)
for (int i = 0; i < GetSize(); i++)
((CCompany*)m_oaCompanies[i])->~CCompany();
As you can see this only calls the destructor for each of the objects in the CObArray, not all of the objects which were actually made by the loadfile() function..
basicly i am clueless on proper destruction right now, and I'm getting tons of memory leaks when I debug, any suggestions on proper destruction of pointers and such will be MOST appreciated.
-dz
|
|
|
|
|
hi i connected an access database thru classwizard by creating a recordset class and connecting the database thru the following dialog. how do i run executesql command to acess related tables since i cannot find an automatically generated CDatabase class
|
|
|
|
|
Do you want to run a Query or execute a SQL Statement?;)
Regards
Carlos Antollini.
Sonork ID 100.10529 cantollini
|
|
|
|
|
|
Hi all:
Do you know which software, service pack updates WinNT from older version of MSVCRT.DLL to newer ? (e.g MSVCRT.DLL 5.00.70220 -> 6.00.8797)
Thanks.
Hoang Le
|
|
|
|
|
|
I have a wrapper around the IPicture interface for drawing Gifs and jpegs that it is then used in an extended CStatic class. The code below shows the wrapper Render function which is called from the CStatic-derived OnPaint handler (also shown):
void CPictureCtrlSSL::OnPaint()
{
CPaintDC dc(this);
if (m_pict) {
CRect rcClient;
GetClientRect(&rcClient);
CRect rcImage(CPoint(0,0),m_pict.GetImageSize());
CRect rc;
rc.IntersectRect(&rcImage, &rcClient);
m_pict.Render(&dc, rc);
}
}
BOOL CPictureSSL::Render(CDC* pDC, CRect rc, LPCRECT prcMFBounds) const
{
ASSERT(pDC);
if (rc.IsRectNull()) {
CSize sz = GetImageSize(pDC);
rc.right = sz.cx;
rc.bottom = sz.cy;
}
long hmWidth,hmHeight;
GetHIMETRICSize(hmWidth, hmHeight);
m_spIPicture->Render(*pDC, rc.left, rc.top, rc.Width(), rc.Height(),
0, hmHeight, hmWidth, -hmHeight, prcMFBounds);
return TRUE;
}
This all works fine, my question is: How can I get the CPictureSSL::Render function to paint a specified colour as transparent? I though if I did m_spIPicture->Render() to a different DC I could then do the necessary bit blits to get the right effect, but I don't know enough to make it work. Any ideas?
Derek Lakin.
I wish I was what I thought I was when I wished I was what I am.
Salamander Software Ltd.
|
|
|
|
|
can i write a games like tetris or pacman using MFC or do i have to write it in windows API using C????
|
|
|
|
|
You can use MFC. You'd be better to use DirectDraw than GDI, and there's not much POINT in using MFC if your program is going to mainly be worried about drawing your game, but there is no reason you can't do so if you desire.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm thinking of getting married for companionship and so I have someone to cook and clean." - Martin Marvinski, 6/3/2002
|
|
|
|
|
There is an sample code in CP,I thing it was in DirectX or OpenGL part,its tetris game.
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
How do i set it so that i enter a number in one edit box and then have it add to or subtract from a read-only. I am trying to write a program for a class that is sort of like a jeopardy game with questions and answers and i cant get the score keeper to work.
Please E-mail me
|
|
|
|
|
Use GetWindowText to get the string, atoi to turn it into a number, ostringstream or sprintf (yuck) to convert back into a string and SetWindowText to put it back into an edit box.
If you bothered to set up an account, you'd GET an email when someone replied to your post.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm thinking of getting married for companionship and so I have someone to cook and clean." - Martin Marvinski, 6/3/2002
|
|
|
|
|
Is there a trick to get the function SetViewportOrgEx to work with a metafile? I am creating a metafile in memory (MapMode is MM_ANISOTROPIC), then I am loading metafiles (WMF) off disk an using PlayMetaFile to play the loaded metafile into the new metafile (I am essentially creating 1 metafile from a combination of parts for a detail drawing). The problem is I need to place the loaded metafiles in various locations however I do not seem to be able to get the xy offset to move, although I have been able to scale the images using ScaleViewportExtEx. I have tried to convert the WMF files to Enhanced metafiles (EMF) - In memory then using then using the Enhanced metafile functions - I haven't had any luck this way either.
Any suggestions?
|
|
|
|
|
I think that you actually want to use SetWindowOrgEx , this is the function that has the effect of shifting the origin.
|
|
|
|
|
I read an Nov. 2001 interview of Stanley Lippman, the VC++ architect, that mentioned future support for Winforms along the lines of C#/VB (RAD).
I further read an Feb. 2002 interview of Nick Hodapp, the VC++ proj. mgr., that (ominously in my view) did not seem to specifically mention support for Winforms/IDE/RAD/C++.
Does anyone (Chris Maunder?) have any idea how MS plans to move forward on this topic?
|
|
|
|
|
Anyone know how to do that ?
Thanks
Zindine
|
|
|
|
|
Hmm, I can't find an API. But that information can be found in the registry under HKLM\Hardware\...
However, I bet it would be different for each OS version.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
I am creating a thread in the OnCreate function of a view
CDocument * pDoc = GetDocument();AfxBeginThread(RxDataProc, pDoc);
The simplified thread function looks like (don't be concerned about what it does, that's not the real problem)
UINT RxDataProc(LPVOID param){
CLOPCDoc* pDoc = (CLOPCDoc*)param;
ASSERT_VALID(pDoc);
pDoc->LoadConnParameters();
bool running = true;
while(running)
{
if(int result = ::WaitForSingleObject(g_evThreadEnd.m_hObject, 0) == WAIT_OBJECT_0)running = false;
else
{
try{
if ( !myFile.Open( pszFileName, CFile::modeCreate|CFile::modeNoTruncate|CFile::modeReadWrite ), &fileException ){
TRACE( "Can't open file %s, error = %u\n", pszFileName, fileException.m_cause );
}
CSerialPort port;
port.Open(pDoc->nComPort_DU, pDoc->nBps_DU, (CSerialPort::Parity)pDoc->nParity_DU,
pDoc->nDataBits_DU,(CSerialPort::StopBits)pDoc->nStopBits_DU,
(CSerialPort::FlowControl)pDoc->nFlowControl_DU);
char sRxBuf[23];
DWORD dwRead = port.Read(sRxBuf, 23);
UNUSED(dwRead);
myFile.SeekToEnd();
myFile.Write( sRxBuf, sizeof( sRxBuf ) );
myFile.Close();
port.Close();
}
catch(CSerialException* pEx){
TRACE(_T("Handle Exception, Message: %s\n"), pEx->GetErrorMessage());
pEx->Delete();
}
}
}
return 0;
}
Anyway, my problem is I am getting an access violation when the program runs and upon debugging I found that it is coming from accessing member variables of the Document class via pDoc.
I get no compile errors. What's the problem here?? Is it even possible to access member variables and functions from a thread??
|
|
|
|
|
It is perfectly possible to access member variables of your CDocument -derived object. The code seems fine to me, and I suspect the error must lie elsewhere. Possibilities:- the document is being
delete d prematurely in the main thread. LoadConnParameters needs to run in the context of the main thread rather than in the secondary (non UI) thread. You can easily check this out by moving the call to LoadConnParameters to the main thread (just before calling AfxBeginThread , for instance).
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks a bunch!
I put LoadConnParameters outside the thread and now it works fine.
Thanks again.
- Merle
|
|
|
|
|
Hi,
I'd like to know how to use the HTMLView Navigate2 method with HTML files that are contained as resources in the .exe in which the HTMLView is located. Anyone have some sample code? Something like:
Navigate2("res://??????")
Or something like this?
Thanks,
Aaron
|
|
|
|
|
You mean this???:
Navigate2(_T("D:\\MyPage.htm") ,NULL,NULL);
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
|
The syntax is res://sFile[/sType]/sID ( check MSDN / Internet development SDK for samples ).
|
|
|
|