Hi,
I have a problem with resizing CTreeCtrl on VC++ 7.0. I am not sure where I went wrong but it give access violation message upon running.
Judging from the values on the debugger, I am thinking the problem might be that GetWindowRect() fails to get the proper CRect dimension (although I can't figure out why). Below are the values on the debugger:
Below is the snapshot of the relevant codes. I highlighted the relevant section in blue for easy reading.
Any help, any insight, any information is appreciated. Thanks.
Zech.
I have a problem with resizing CTreeCtrl on VC++ 7.0. I am not sure where I went wrong but it give access violation message upon running.
Judging from the values on the debugger, I am thinking the problem might be that GetWindowRect() fails to get the proper CRect dimension (although I can't figure out why). Below are the values on the debugger:
File: winocc.cpp
void CWnd::MoveWindow(int x, int y, int nWidth, int nHeight, BOOL bRepaint)
{
ASSERT:IsWindow(m_hWnd) || (m_pCtrlSite != NULL));
...
}
Values:
(I don't think that these numbers should be so large and negative)
x = -842150451
y = -842150451
nWidth = -842150464
nHeight = 842150848
bRepaint = 1
Below is the snapshot of the relevant codes. I highlighted the relevant section in blue for easy reading.
Code:
void CClientView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
contactList=treeCtrl.InsertItem("Group 1");
internet=treeCtrl.InsertItem("Group 2");
[blue]getDim()[/blue];
}
void CClientView::OnSize(UINT nType, int cx, int cy)
{
CFormView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
[green]//get the form rect
//This is a CTreeCtrl on CFormView[/green]
[blue]CRect formRect;
GetWindowRect(&formRect);
[green]//get the tree ctrl[/green]
CWnd* tree = GetDlgItem(IDC_TREE);
[green]//calculate the width and height[/green]
float width=treeWidth;
float height=(float)formRect.Height()-(float)treeHeight;
tree->MoveWindow(anchorPoint.x,anchorPoint.y,(long)width,(long)height,TRUE);[red]//Stopped: ACCESS VIOLATION[/red]
tree->RedrawWindow();
[/blue]
}
[blue]
void CClientView::getDim(void)
{
[green]//get the form dimensions[/green]
CRect formRect;
GetWindowRect(&formRect);
[green]//get the tree control dimensions[/green]
CRect treeRect;
CWnd* tree=GetDlgItem(IDC_TREE);
tree->GetWindowRect(&treeRect);
[green]//set the anchor point[/green]
anchorPoint=treeRect.TopLeft();
ScreenToClient(&anchorPoint);
[green]//store and calculate the height and width[/green]
treeWidth=(long)treeRect.Width();
treeHeight=(long)((float)formRect.Height()-(float)treeRect.Height());
[green]//anchorPoint, treeWidth and treeHeight are protected class variables.[/green]
}[/blue]
Any help, any insight, any information is appreciated. Thanks.
Zech.