|
I don't think you have to declare a global variable.
This should do the trick (and if not, I'll need to see more of your code):
LRESULT CALLBACK MainWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
...
hwnddlg = CreateDialog(app_instance, "PARAMETER_WINDOW_DATA", hwnd, (DLGPROC) Parameter_Window_Data);
}
-------------------------------------------
BOOL CALLBACK Parameter_Window_Data(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
...
DestroyWindow(hWnd);
hwnddlg = CreateDialog(app_instance, EXPER_INTRO_DIALOG, hWnd, (DLGPROC) Parameter_Window_Exper);
}
-------------------------------------------
You see, just give it the handle to the parent in stead of using NULL (which means the desktop)
Don't think you are, know you are...
|
|
|
|
|
I did so as you posted, but the child dialog (EXPER_INTRO_DIALOG) can't be displayed. I wonder if the problem now(not display at all) is because DestroyWindow(hWnd) has killed the parent dialog.
Anyway, I guess I can get my program done under your help.
Regards,
Sean
|
|
|
|
|
Hello gurus,
I have a similar question to what was discussed
here
Suppose I have a function to split a text file into 10 parts like (The first 9 parts are 90% of the total text and the last part contains whatever remaining).
When the dialog closes I have a memory leak problem related to pBuffer which I'm not releasing, as is expected. How and where do I free pBuffer?
the code goes like(not too commented)
BOOL CReadPercentDlg::ReadPercent(LPCTSTR strFileName)<br />
{<br />
HANDLE hTheFile;<br />
hTheFile = CreateFile(strFileName,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);<br />
if(!hTheFile)<br />
return FALSE;<br />
DWORD dwFileSize = ::GetFileSize(hTheFile, NULL );<br />
DWORD dw10Percent = (DWORD)( dwFileSize *.10 );<br />
BYTE *pBuffer = new BYTE[ dw10Percent ];<br />
<br />
if( !pBuffer )<br />
{<br />
TRACE("Not enough mmemory");<br />
return FALSE;
}<br />
<br />
DWORD dwStatus = 0;<br />
DWORD dwRead = 0;<br />
DWORD dwTotalRead = 0;<br />
for(int i=0;i<9;i++)<br />
{<br />
<br />
dwStatus = ::ReadFile( hTheFile, pBuffer, dw10Percent, &dwRead, NULL );<br />
if( dwStatus != ERROR_SUCCESS )<br />
{<br />
<br />
} <br />
<br />
pBuffer[dw10Percent] = '\0';<br />
OutputDebugString((LPSTR)pBuffer);<br />
dwTotalRead+=dw10Percent;<br />
}<br />
<br />
pBuffer[0] = '\0'; <br />
pBuffer = NULL;<br />
DWORD dwLeft = 0;<br />
dwLeft = dwFileSize - dwTotalRead;<br />
if(dwLeft!=0)<br />
{<br />
TRACE("\nLeft %u",dwLeft);<br />
<br />
pBuffer = new BYTE[dwLeft];<br />
if(pBuffer==NULL)<br />
return FALSE;<br />
<br />
dwStatus = ::ReadFile( hTheFile, pBuffer, dwLeft, &dwRead, NULL );<br />
if( dwStatus != ERROR_SUCCESS )<br />
{<br />
<br />
<br />
<br />
} <br />
pBuffer[dwLeft] = '\0';<br />
TRACE("\nLast :\n");<br />
TRACE((LPSTR)pBuffer);<br />
<br />
}<br />
<br />
pBuffer = NULL;<br />
return TRUE;<br />
<br />
}
Also, is there any better way to read in such percents of text files?
Thanks a lot in advance.
Looking for a lurking sig!
|
|
|
|
|
smartptr wrote:
(The first 9 parts are 90% of the total text and the last part contains whatever remaining).
smartptr wrote:
Also, is there any better way to read in such percents of text files?
If you used C++ file handling ( iostreams ), you could read into std::strings, which would clean up after themselves. Otherwise, you need to delete [] the buffer at the end of this function. There is no-where else to do it, you create it on the heap within this function, therefore once you leave this function, the pointer has leaked, you no longer have a reference to it.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Thanks for your reply.
Can I make the buffer a member variable of the dialog class?(and when the dialog is closing:
delete pBuffer;<br />
pBuffer = NULL; )
to avoid a memory leak?
|
|
|
|
|
Sure - no problems at all, except that you need to delete [] pBuffer, not delete it, it is an array.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
smartptr wrote:
//where do we free pBuffer?
//following line again causes
//memory check error at 0x004228B7 = 0x00, should be 0xFD.
// delete[] pBuffer;
//but if I do not release pBuffer by now, I get a memory leak.
It could be that there is a memory problem elsewhere inthe code that is trashing something and causing the delete to fail. This line looks suspicious:
<br />
pBuffer[dw10Percent] = '\0';<br />
It looks like you are accessing the array beyond its end. You allocated it as having dw10Percent items, which means the highest index it can have is (dw10Percent - 1).
There may be other things like that, too, that are causing problems.
Even a broken clock is right twice a day.
|
|
|
|
|
I have an MDI application and I implement the serialize function to read data in . In case the File read is not a trusted file , how do i abort the process of displaying the view. i want the document to not show the view but to just display an error message. Thank you .
|
|
|
|
|
I'm french, so I hope you will excuse me for my poor english.
I have an MFC application which load lot of DLL. In this Dll I make allocation with new, so It use the MFC checking system for leak memory.
And when I terminate my application, I free all my librairies with function 'FreeLibrary()'. But If I have some leak memory in a DLL the MFC Dumping Leak will display to me :
Dumping Object->
#File Error#, etc....
I don't have the FileName.
MFC can't find the name of the File (__FILE__) because the memory where the FileName where store was allocate in the DLL where the 'new' is made. So when I call the function 'FreeLibrary()' on my DLL, all memory which containt '__FILE__' were release.
So how can I do to see my memory leak even if i have call FreeLibrary ? (I must call function FreeLibrary() otherwise I will have lot of problems with my application).
Thanks you for reading my question.
|
|
|
|
|
leander wrote:
So how can I do to see my memory leak even if i have call FreeLibrary ? (I must call function FreeLibrary() otherwise I will have lot of problems with my application).
I am not biblically familiar with MFC as I had to lookup exactly what FreeLibrary() does. Anytime you use the new operator to allocate memory on the heap you will need to release it with the delete operator. It appears that the FreeLibrary *only* handles ref counting and will unmap the module from the address space itself, I would belive that you still need to handle the internal allocation/deallocation of memory yourself. Hope this helps.
Nick Parker
Not everything that can be counted counts, and not everything that counts can be counted. - Albert Einstein
|
|
|
|
|
Cant you turn off FreeLibrary, only for so long as to find the memory leak?
Also, Are the DLLs in debug mode? To completely debug the application, both your application and DLLs should be built in Debug mode.
|
|
|
|
|
I try to turn off the call() to FreeLibrary() to Debug my leak, but it's little complicate to do it, because I have static object how make allocation with a memory manager (only for malloc and free, not for new and delete). So if I don't call the FreeLibrary the destructor off my static object is not call, and i have some crash when I free my memory manager.
So for the moment, to debug leak, I remove the Freeliberary() and I don't release my memory manager to see the leak.
But I hope to find an other solution without changing some code to with memory leak.
My application and my DLL are compile in Debug with option "Multithread DLL"
|
|
|
|
|
I don't understand why failing to call FreeLibrary causes a lot of problems in your app. But that's what I would do: comment out the FreeLibrary calls (temporarily) and see if you can get a better reading on where the leaks are occurring.
If that doesn't work, let me know and I'll help you find the leaks the hard way.
Regards,
Alvaro
Well done is better than well said. -- Benjamin Franklin
(I actually prefer medium-well.)
|
|
|
|
|
Hello,
I have created a dll in c that can draw on a picture box. But the problem is that i need to be able to place new lines or rect or ellipses... using the mouse and also be able to move or resize them (using the mouse) after placement. Any ideas???
Thank you in advance
Nicolas Siatras
|
|
|
|
|
Is there any way to create a device context that will let me draw on a bitmap that isn't necessarily the same format as the display device?
For example, if I created a 640 x 480 8-bit bitmap wit CreateDIBSection, could I somehow create a device context to draw text on the bitmap even if the primary display is 24-bit?
|
|
|
|
|
You need a DIBSection. To be honest, there is no reason I can see ever to use anything else. A DIBSection is a DIB, but it can be selected into a DC and drawn on with GDI functions as if it was a DDB.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
When you create a DC with ::CreateCompatibleDC, it basically creates a DC that is ready to support a monochromatic display. It does not create a display that matches the same color format as the display. When you select a bitmap into the memDC, the color depth of the DC is set to the same as what is set in the bitmap.
Then when you use bitblt or stretchblt, the GDI does all of the color conversions for you if you are drawing from a 24 bit color DC to an 8-bit DC.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Hi everyone,
my knowledge of VC++ is slightly over basic so please be gentle with any responses.
My problem is that I have a generated image array (300x300) of 8-bit data (gray levels) stored in an unsigned char called imagedata (ironically).
I want to display this image on the screen of a dialogue based application but have been failing miserably.
If anyone can let me know what classes and routines I need to use, or even any sample code I can get my hands on, would be much appreciated.
Thanks in advance,
Rooster76
|
|
|
|
|
for a start, have a look at CBitmap::CreateBitmap.
Max.
|
|
|
|
|
you first need to convert that image into a DIB. this is Window's native image type.
1. a DIB is vertically flipped (first pixel is bottom-left)
2. all pixel rows in a DIB must be a multiple of four bytes wide. this may mean you have to add padding bytes to the end of the rows
3. a DIB starts with a BITMAPINFOHEADER struct
4. in an 8-bit DIB, the palette (256 entries in this case) immediately follows the header struct
5. the pixel bytes immediately follow the palette
so, to turn that image of yours in to a DIB:
find out how wide the pixel rows will be (accounting for the row padding), multiple that by the height. add 256 * sizeof(RGBQUAD) for the palette and sizeof(BITMAPINFOHEADER) for the header. allocate that much memory. then, fill in the header, copy the palette, copy the pixel rows (accounting for padding! and the vertical flip), and you're done!
-c
There's one easy way to prove the effectiveness of 'letting the market decide' when it comes to environmental protection. It's spelt 'S-U-V'.
--Holgate, from Plastic
|
|
|
|
|
Its sooooo eaaassyyyy.....
But then you write graphic apps all the time don't you?
Roger Allen
Sonork 100.10016
In case you're worried about what's going to become of the younger generation, it's going to grow up and start worrying about the younger generation. - Roger Allen, but not me!
|
|
|
|
|
Roger Allen wrote:
But then you write graphic apps all the time don't you?
yep. but i wrote the ISColormappedToDIB function just once.
-c
There's one easy way to prove the effectiveness of 'letting the market decide' when it comes to environmental protection. It's spelt 'S-U-V'.
--Holgate, from Plastic
|
|
|
|
|
In CMainFrame file,
I defined CSplitterWnd m_wndSplitter;
and Split a Docounment into two View.
here is code:
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) <br />
{<br />
m_wndSplitter.CreateStatic(this,1,2);<br />
<br />
m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CMyFindDialogView),CSize(400,400),pContext);<br />
m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CMyFindDialogView),CSize(400,400),pContext);<br />
<br />
return 1;<br />
}
In A NEW CLASS ,
I am do :
#include "MainFrm.h" in it's cpp header.
and
i want to do :
<br />
CWnd* m_pHexWnd = CMainFrame::m_wndSplitter.GetPane(0,1);<br />
but faied.
how to do it?
explain: i want get the CWnd* of SplitterWnd'CWnd.
because ,i want use it in a Create(,parameters,A CWnd*) Function.
i feel good.
|
|
|
|
|
Consider GetParent() and AfxGetMainWnd().
Kuphryn
|
|
|
|
|
Don't know it exactly.
can give a example?
Study Together!
|
|
|
|
|