|
You could try to protect the adding of the image list with a bool variable:
In your dialog, add a bool variable firstTime , set to true in constructor.
Modify the part where you add the imagelist to look like this:
if (firstTime)
{
m_Tree.SetImageList(&m_TreeImageList, TVSIL_NORMAL);
firstTime = false;
} Additionally, I think you can drop the calls to detach(), as this will be done automagically when the tree goes away.
Who is 'General Failure'? And why is he reading my harddisk?!?
|
|
|
|
|
Hi,
Thanks for your reply.
I tried doing what you said.
But, in this case also if I try to move my dialog box, I keep getting the same error (debug assertions failed)
I'm including call stack and part of code with this:
Call stack: shows line 140 which is shown in the code.
L! 77f9180c()
_CrtDbgReport(int 2, const char * 0x5f4cd0c0 THIS_FILE, int 1202, const char * 0x00000000, const char * 0x00000000) line 353
AfxAssertFailedLine(const char * 0x5f4cd0c0 THIS_FILE, int 1202) line 39 + 20 bytes
CImageList::Attach(_IMAGELIST * 0x00141e70) line 1202 + 24 bytes
CImageList::Create(unsigned int 131, int 13, int 1, unsigned long 16777215) line 1183
CMfcTree::OnInitDialog() line 140
AfxDlgProc(HWND__ * 0x01f31c2e, unsigned int 272, unsigned int 18619602, unsigned int 18619602) line 35 + 14 bytes
USER32! 77e3a244()
USER32! 77e28b4b()
USER32! 77e2d2b2()
USER32! 77e16b21()
USER32! 77e16b44()
CWnd::DefWindowProcA(unsigned int 272, unsigned int 18619602, long 0) line 1000 + 32 bytes
CWnd::Default() line 249
CDialog::HandleInitDialog(unsigned int 18619602, unsigned int 18619602) line 624 + 8 bytes
CWnd::OnWndMsg(unsigned int 272, unsigned int 18619602, long 0, long * 0x001294b4) line 1815 + 17 bytes
CWnd::WindowProc(unsigned int 272, unsigned int 18619602, long 0) line 1585 + 30 bytes
AfxCallWndProc(CWnd * 0x00129838, HWND__ * 0x01f31c2e, unsigned int 272, unsigned int 18619602, long 0) line 215 + 26 bytes
AfxWndProc(HWND__ * 0x01f31c2e, unsigned int 272, unsigned int 18619602, long 0) line 368
AfxWndProcBase(HWND__ * 0x01f31c2e, unsigned int 272, unsigned int 18619602, long 0) line 220 + 21 bytes
USER32! 77e3a244()
USER32! 77e16362()
USER32! 77e29c20()
USER32! 77e2caa8()
USER32! 77e2ca6b()
CWnd::CreateDlgIndirect(const DLGTEMPLATE * 0x00437c30, CWnd * 0x002f70e8 {CTempWnd hWnd=0x03541c1c}, HINSTANCE__ * 0x00400000) line 327 + 36 bytes
CDialog::DoModal() line 531 + 32 bytes
CMyTreeView::OnDraw(CDC * 0x00129b30) line 61 + 11 bytes
CView::OnPaint() line 185
CWnd::OnWndMsg(unsigned int 15, unsigned int 0, long 0, long * 0x00129ca4) line 1825
CWnd::WindowProc(unsigned int 15, unsigned int 0, long 0) line 1585 + 30 bytes
AfxCallWndProc(CWnd * 0x002f4fc8, HWND__ * 0x09c71a58, unsigned int 15, unsigned int 0, long 0) line 215 + 26 bytes
AfxWndProc(HWND__ * 0x09c71a58, unsigned int 15, unsigned int 0, long 0) line 368
AfxWndProcBase(HWND__ * 0x09c71a58, unsigned int 15, unsigned int 0, long 0) line 220 + 21 bytes
USER32! 77e3a244()
USER32! 77e14730()
USER32! 77e1558a()
NTDLL! 77f91a7f()
USER32! 77e1a792()
USER32! 77e43ed5()
USER32! 77e33f6a()
USER32! 77e34306()
USER32! 77e337fb()
USER32! 77e34091()
USER32! 77e3322c()
__crtMessageBoxA(const char * 0x0012a3ec, const char * 0x102579a0 `string', unsigned int 73746) line 65
CrtMessageWindow(int 2, const char * 0x5f4cd0c0 THIS_FILE, const char * 0x0012b520, const char * 0x00000000, const char * 0x0012d544) line 520 + 22 bytes
_CrtDbgReport(int 2, const char * 0x5f4cd0c0 THIS_FILE, int 1202, const char * 0x00000000, const char * 0x00000000) line 419 + 76 bytes
AfxAssertFailedLine(const char * 0x5f4cd0c0 THIS_FILE, int 1202) line 39 + 20 bytes
CImageList::Attach(_IMAGELIST * 0x0013f750) line 1202 + 24 bytes
CImageList::Create(unsigned int 131, int 13, int 1, unsigned long 16777215) line 1183
CMfcTree::OnInitDialog() line 140
AfxDlgProc(HWND__ * 0x00da1d1e, unsigned int 272, unsigned int 15998044, unsigned int 15998044) line 35 + 14 bytes
USER32! 77e3a244()
USER32! 77e28b4b()
USER32! 77e2d2b2()
USER32! 77e16b21()
USER32! 77e16b44()
CWnd::DefWindowProcA(unsigned int 272, unsigned int 15998044, long 0) line 1000 + 32 bytes
CWnd::Default() line 249
CDialog::HandleInitDialog(unsigned int 15998044, unsigned int 15998044) line 624 + 8 bytes
CWnd::OnWndMsg(unsigned int 272, unsigned int 15998044, long 0, long * 0x0012e894) line 1815 + 17 bytes
CWnd::WindowProc(unsigned int 272, unsigned int 15998044, long 0) line 1585 + 30 bytes
AfxCallWndProc(CWnd * 0x0012ec18, HWND__ * 0x00da1d1e, unsigned int 272, unsigned int 15998044, long 0) line 215 + 26 bytes
AfxWndProc(HWND__ * 0x00da1d1e, unsigned int 272, unsigned int 15998044, long 0) line 368
AfxWndProcBase(HWND__ * 0x00da1d1e, unsigned int 272, unsigned int 15998044, long 0) line 220 + 21 bytes
USER32! 77e3a244()
USER32! 77e16362()
USER32! 77e29c20()
USER32! 77e2caa8()
USER32! 77e2ca6b()
CWnd::CreateDlgIndirect(const DLGTEMPLATE * 0x00437c30, CWnd * 0x0012f858, HINSTANCE__ * 0x00400000) line 327 + 36 bytes
CDialog::DoModal() line 531 + 32 bytes
CMyTreeView::OnDraw(CDC * 0x0012ef10) line 61 + 11 bytes
CView::OnPaint() line 185
CWnd::OnWndMsg(unsigned int 15, unsigned int 0, long 0, long * 0x0012f084) line 1825
CWnd::WindowProc(unsigned int 15, unsigned int 0, long 0) line 1585 + 30 bytes
AfxCallWndProc(CWnd * 0x002f4fc8, HWND__ * 0x09c71a58, unsigned int 15, unsigned int 0, long 0) line 215 + 26 bytes
AfxWndProc(HWND__ * 0x09c71a58, unsigned int 15, unsigned int 0, long 0) line 368
AfxWndProcBase(HWND__ * 0x09c71a58, unsigned int 15, unsigned int 0, long 0) line 220 + 21 bytes
USER32! 77e3a244()
USER32! 77e14730()
USER32! 77e1558a()
NTDLL! 77f91a7f()
USER32! 77e2917a()
USER32! 77e2d2b2()
USER32! 77e16b21()
USER32! 77e16b44()
CWnd::DefWindowProcA(unsigned int 274, unsigned int 61458, long 328197) line 1000 + 32 bytes
CWnd::WindowProc(unsigned int 274, unsigned int 61458, long 328197) line 1586 + 26 bytes
AfxCallWndProc(CWnd * 0x0012f858, HWND__ * 0x01d519fa, unsigned int 274, unsigned int 61458, long 328197) line 215 + 26 bytes
AfxWndProc(HWND__ * 0x01d519fa, unsigned int 274, unsigned int 61458, long 328197) line 368
AfxWndProcBase(HWND__ * 0x01d519fa, unsigned int 274, unsigned int 61458, long 328197) line 220 + 21 bytes
USER32! 77e3a244()
USER32! 77e14730()
USER32! 77e1558a()
NTDLL! 77f91a7f()
USER32! 77e2917a()
USER32! 77e2d2b2()
USER32! 77e16b21()
USER32! 77e16b44()
CWnd::DefWindowProcA(unsigned int 161, unsigned int 2, long 328197) line 1000 + 32 bytes
CWnd::WindowProc(unsigned int 161, unsigned int 2, long 328197) line 1586 + 26 bytes
AfxCallWndProc(CWnd * 0x0012f858, HWND__ * 0x01d519fa, unsigned int 161, unsigned int 2, long 328197) line 215 + 26 bytes
AfxWndProc(HWND__ * 0x01d519fa, unsigned int 161, unsigned int 2, long 328197) line 368
AfxWndProcBase(HWND__ * 0x01d519fa, unsigned int 161, unsigned int 2, long 328197) line 220 + 21 bytes
USER32! 77e3a244()
USER32! 77e145e5()
USER32! 77e15b51()
CWnd::RunModalLoop(unsigned long 4) line 3478 + 19 bytes
CDialog::DoModal() line 539 + 12 bytes
CMyTreeView::OnDraw(CDC * 0x0012fb50) line 61 + 11 bytes
CView::OnPaint() line 185
CWnd::OnWndMsg(unsigned int 15, unsigned int 0, long 0, long * 0x0012fcc4) line 1825
CWnd::WindowProc(unsigned int 15, unsigned int 0, long 0) line 1585 + 30 bytes
AfxCallWndProc(CWnd * 0x002f4fc8, HWND__ * 0x09c71a58, unsigned int 15, unsigned int 0, long 0) line 215 + 26 bytes
AfxWndProc(HWND__ * 0x09c71a58, unsigned int 15, unsigned int 0, long 0) line 368
AfxWndProcBase(HWND__ * 0x09c71a58, unsigned int 15, unsigned int 0, long 0) line 220 + 21 bytes
USER32! 77e3a244()
USER32! 77e14730()
USER32! 77e1558a()
NTDLL! 77f91a7f()
CTreeApp::InitInstance() line 96
AfxWinMain(HINSTANCE__ * 0x00400000, HINSTANCE__ * 0x00000000, char * 0x00132a08, int 1) line 39 + 11 bytes
WinMain(HINSTANCE__ * 0x00400000, HINSTANCE__ * 0x00000000, char * 0x00132a08, int 1) line 30
WinMainCRTStartup() line 330 + 54 bytes
KERNEL32! 77ea847c()
code:
BOOL CMfcTree::OnInitDialog()
{
CDialog::OnInitDialog();
m_ImageList.Create(IDB_BITMAP1, 13, 1, RGB(255,255,255));
if ( firstTime ) //line 140
{
m_nTree.SetImageList(&m_ImageList, TVSIL_NORMAL);
firstTime = false;
}
HTREEITEM hItem = m_nTree.InsertItem( "Root", 0,2,TVI_ROOT );
m_nTree.SelectItem (hItem);
for (int count =0 ; count <15 ; count ++)
{
OnBUTTONAddA() ;
m_nTree.SelectItem (hItem);
}
m_nTree.SelectItem (hItem);
showRoot();
m_nAddA.ShowWindow ( SW_HIDE );
//XML
//XML
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
Binayak Bhattacharyya
|
|
|
|
|
Hmm.
Seems like your imagelist creation is failing?
Please check the return value of m_ImageList.Create(..) .
Nonzero is signaling an error.
Who is 'General Failure'? And why is he reading my harddisk?!?
|
|
|
|
|
I have checked the return value of Create(...)
It's true.
any other suggestions?
|
|
|
|
|
Hello,
Sorry for my c++ stupid question but i really forgot to get the size of an array in a func
typedef struct<br />
{<br />
char *item;<br />
int top;<br />
int bottom;<br />
} Item;<br />
<br />
<br />
void Draw( Item* item )<br />
{<br />
<br />
int nSize = sizeof(*item) / sizeof(Item);<br />
<br />
}<br />
<br />
main()<br />
{<br />
Item array[] = { ... };<br />
Draw( array );<br />
}
Any idea ?
Best Regards,
Hadi
|
|
|
|
|
You can't do that. The array is actually passed into the function as a pointer, not as an array. This means that sizeof(item) will always be 4. Instead you should either pass through the size of the array as a separate parameter, or even better, use an STL container such as a vector, which includes its size within the container itself.
Dave
http://www.cloudsofheaven.org
|
|
|
|
|
Thanks alot for reply Dave
|
|
|
|
|
Here is my thought about your array:
The elements can be linked together,so it is a link list, is it
Maximal index of your array can be used to count the array's size
why do you want to count it in that way?
Here are two ways to find the size of the array
1.Add a function to count the size by using the property of link list like the following:
CountSize(Ietm array)
{
int count=1;
while(array->item!=NULL)
{
count++;
array->item=array->item->item;
}
return count;
}
2.Get the size directly by its maximal index
Maybe it is not very OK.
|
|
|
|
|
The best advice one can give is to call std::vector::size().
[plugSTL]
This would mean that you need to switch to the STL-vectors, but that would be a good idea anyway.
[/plugSTL]
Who is 'General Failure'? And why is he reading my harddisk?!?
|
|
|
|
|
Could someone please tell me how to make the background of a dialog a bitmap? I am using MFC on VC++ 6.0.
<marquee>Hosam Aly Mahmoud
|
|
|
|
|
Take a look at this.
HPS HwndSpy - GUI developer's aid to visually
locate and inspect windows. For the month of August
only, use coupon code CP-81239 for 30% off.
|
|
|
|
|
Thank you very much!
<marquee behavior="alternate">Hosam Aly Mahmoud
|
|
|
|
|
like this:
void CAaDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CRect rect;
GetClientRect(&rect);
CPaintDC dc(this);
CBitmap bitmap;
BITMAP Bitmap;
bitmap.LoadBitmap(IDB_BITMAP1);
bitmap.GetObject(sizeof(BITMAP),&Bitmap);
CDC dcMem;
dcMem.CreateCompatibleDC(&dc);
CBitmap* poldbitmap=dcMem.SelectObject(&bitmap);
dc.StretchBlt(0,0,rect.Width(),rect.Height(),
&dcMem,0,0,Bitmap.bmWidth,Bitmap.bmHeight,SRCCOPY);
dcMem.SelectObject(poldbitmap);
dcMem.DeleteDC();
}
}
void CAaDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
Invalidate(TRUE);
}
may be useful!
|
|
|
|
|
Thank you for your reply. But shouldn't this be handled in the WM_ERASEBKGND message (or the corresponding OnEraseBkgnd function)? Which one is better?
Thank you again.
<marquee behavior="alternate">Hosam Aly Mahmoud
|
|
|
|
|
Could you please tell me how to know how much free physical RAM exists on a system at a certain time? Also, if I have a process that allocates RAM using new, is there a way to guarantee that the allocated RAM does not go into the virtual memory, but rather stay in the physical RAM until I delete it (or the process ends)?
Sorry for my language, and thanks for your help.
<marquee behavior="alternate">Hosam Aly Mahmoud
|
|
|
|
|
GlobalMemoryStatus() and VirtualLock()
John
|
|
|
|
|
Thank you very much. The GlobalMemoryStatus() is great. But I could not understand VirtualLock() . Could you kindly help me with it?
<marquee behavior="alternate">Hosam Aly Mahmoud
|
|
|
|
|
|
Thank you for your reply, and sorry for my late reply. I read the two links, and thanks a lot for the second one. The first one, however, made me rethink about using VirtualLock() . But I think that if my application does not lose focus, then it will keep my application fast. Is that right? Now I have another problem: how can I keep my application in the foreground? Should I make my process' priority "Real Time"? How can I do that?
Thank you very much.
<marquee behavior="alternate">Hosam Aly Mahmoud
|
|
|
|
|
Hosam Aly Mahmoud wrote:
But I think that if my application does not lose focus, then it will keep my application fast.
Yes it will. As long as the application is not minimized it will not page out unless another process needs memory. When the application is minimized windows sets the working set size to zero thus paging out your application. Different windows versions will handle this alittle differently. I think NT4 will page all of your applicaton out immediatly causing a long delay. I am a little unsure of this. I worked on this two years ago for an application that needed to hold 256MB of images in memory at a time.
Hosam Aly Mahmoud wrote:
how can I keep my application in the foreground?
Don't allow the main window to be minimized. I made the minimize button hide the window instead of minimize and it fixed the problem.
John
|
|
|
|
|
Thanks for your efforts and time.
John M. Drescher wrote:
I made the minimize button hide the window instead of minimize and it fixed the problem
I think I will disable the minimize button. That should be enough.
John M. Drescher wrote:
As long as the application is not minimized it will not page out unless another process needs memory.
So what if another process does need memory? How can I delay all other processes and make them wait until I am finished?
Hosam Aly Mahmoud
|
|
|
|
|
Hosam Aly Mahmoud wrote:
So what if another process does need memory? How can I delay all other processes and make them wait until I am finished?
If another process needs memory it may affect the working set of your process. When all the physical memory of the system is exausted the cpu will trim the working set of all processes (other than the one requesting additional memory).
Hosam Aly Mahmoud wrote:
How can I delay all other processes and make them wait until I am finished?
Maybe setting the process priority to real time may solve your problem.
John
|
|
|
|
|
Thank you very much for your help John! I do not know how I could thank you, but here is a try:
John M. Drescher wrote:
Maybe setting the process priority to real time may solve your problem.
I thought it would, but I do not know how to do it. Could you please tell me (or give me a link)? I would very much appreciate it.
Thank you for all your help!
Hosam Aly Mahmoud
|
|
|
|
|
Not sure about how to tell how much RAM is free off the top of my head, but you can probably find out by looking at the memory management functions in MSDN.
Regarding locking allocated memory into physical memory, take a look at the VirtualLock() and VirtualUnlock() functions. These allow you to do exactly what you want.
Dave
http://www.cloudsofheaven.org
|
|
|
|
|
Thank you for your reply. I am sorry, but I could not use VirtualLock() . I am still a beginner, so I do not understand what is meant by a "memory page". Second, do I have to use VirtualAlloc() or can I allocate using new ? What is the difference?
<marquee behavior="alternate">Hosam Aly Mahmoud
|
|
|
|
|