Splitter Wnd Issues with Stidio .Net

From Visual Basic to GNU C, this is the place to talk programming.

Moderators: SecretSquirrel, just brew it!

Splitter Wnd Issues with Stidio .Net

Postposted on Thu Feb 26, 2004 1:42 pm

Ok here's my first snippet of code:

BOOL fRet = FALSE;

CRect cr;
GetWindowRect(&cr);

if(!m_wndSplit.CreateStatic(this, 2, 1, WS_CHILD | WS_VISIBLE, AFX_IDW_PANE_FIRST))
goto bail;

m_wndSplit.SetRowInfo(0, 13*(cr.Height())/16, 10);
m_wndSplit.SetRowInfo(1, 3*(cr.Height())/16, 10);

if(!m_wndSplit.CreateView(1, 0, RUNTIME_CLASS(CDirCmdView), CSize(0, cr.Height()/2), pContext))
goto bail;

if(!m_wndSplit2.CreateStatic(&m_wndSplit, 1, 2, WS_CHILD | WS_VISIBLE | WS_BORDER, m_wndSplit.IdFromRowCol(0, 0)))
goto bail;

if(!m_wndSplit2.CreateView(0, 0, RUNTIME_CLASS(CMapView), CSize(cr.Width()/2, cr.Height()/2), pContext))
goto bail;

m_wndSplit2.SetColumnInfo(0, 7*(cr.Width())/8, 10);

if(!m_wndSplit2.CreateView(0, 1, RUNTIME_CLASS(CStatusView), CSize(cr.Width()/2, cr.Height()/2), pContext))
goto bail;

m_wndSplit2.SetColumnInfo(1, cr.Width()/8, 10);

m_wndSplit.RecalcLayout();
m_wndSplit2.RecalcLayout();

fRet = TRUE;
bail:
return fRet;


This works peachy until I add the OnSize message handler, and add this code:

CRect cr;
GetWindowRect(&cr);

m_wndSplit.SetRowInfo(0, 13*(cr.Height())/16, 10);
m_wndSplit.SetRowInfo(1, 3*(cr.Height())/16, 10);

m_wndSplit2.SetColumnInfo(0, 7*(cr.Width())/8, 10);
m_wndSplit2.SetColumnInfo(1, cr.Width()/8, 10);

m_wndSplit.RecalcLayout();
m_wndSplit2.RecalcLayout();

Then I get an access violation error on the very first CreateStatic function. What gives? All I want to do is take my top portion of code, and make it so whenever the window is resize that the aspect ratio of all the childviews stays the same...

Thanks in advance.
OutlawTornNMT
Gerbil First Class
 
Posts: 148
Joined: Sun Jul 21, 2002 5:30 pm

Postposted on Wed Mar 10, 2004 11:43 am

Well, I am not entirely sure why you get the access violation error as I have done something similar in the past. Here is a link to the tutorial I used to learn how to create splitter windows:

http://www.gamedev.net/reference/articl ... le1358.asp
Veritas
Gerbil First Class
 
Posts: 113
Joined: Wed Dec 26, 2001 7:00 pm
Location: Houston, TX

Postposted on Thu Mar 11, 2004 2:30 am

Are you verifying that you're got a non-zero sized rect before you go passing its width and height into other calls? Some of those calls may barf (that's the technical term) if you pass zeros in as args. Be careful about assuming the order of events, and also be careful about assuming your window is always some non-zero size. I can't tell you how many times I've crashed somebody's app because they had a ton of resize code that worked fine until the window was minimized (oops, how many controls can you tile in a zero sized window?)
UberGerbil
Gerbil Khan
 
Posts: 9976
Joined: Thu Jun 19, 2003 3:11 pm


Return to Developer's Den

Who is online

Users browsing this forum: No registered users and 3 guests