Problema in CChildFrame::OnCreateClient

Intrebari legate de programarea cu biblioteci precum MFC, ATL, WTL si GDI+.
Post Reply
mesajflaviu
Membru++
Membru++
Posts: 688
Joined: 10 Sep 2008, 21:40
Judet: Cluj

Problema in CChildFrame::OnCreateClient

Post by mesajflaviu » 08 Jun 2012, 13:40

Incerc de ceva timp sa rezolv o problema aparent minora : intr-o aplicatie MDI, vreau sa impart CChildFrame in 3 view-uri : 3 coloane, iar coloana 2 in 3 randuri ... totul merge OK, dar nu reusesc sa setez latimea coloanei 2 la o valoare diferita de 0:

Code: Select all

BOOL CChildFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
{
	// TODO: Add your specialized code here and/or call the base class

	if(! m_wndSplitter.CreateStatic(this, 1, 3))return FALSE;
	if(! m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CSplittTestView), CSize(lpcs->cx / 3, 0), pContext))
	{
		m_wndSplitter.DestroyWindow();
		return FALSE;
	}
	if(! m_wndSplitter.CreateView(0,2,RUNTIME_CLASS(CTest4View),CSize(lpcs->cx / 3,0),pContext))
	{
		m_wndSplitter.DestroyWindow();
		return FALSE;
	}
	if(! m_wndSplitter2.CreateStatic(&m_wndSplitter,3,1,WS_CHILD | WS_VISIBLE | WS_BORDER,m_wndSplitter.IdFromRowCol(0,1)))
	{
		m_wndSplitter2.DestroyWindow();
		return FALSE;
	}
	if(! m_wndSplitter2.CreateView(0,0,RUNTIME_CLASS(CTest1View),CSize(lpcs->cx / 3,100),pContext))
	{
		m_wndSplitter2.DestroyWindow();
		return FALSE;
	}
	if(! m_wndSplitter2.CreateView(1,0,RUNTIME_CLASS(CTest2View),CSize(lpcs->cx / 3,100),pContext))
	{
		m_wndSplitter2.DestroyWindow();
		return FALSE;
	}
	if(! m_wndSplitter2.CreateView(2,0,RUNTIME_CLASS(CTest3View),CSize(lpcs->cx / 3,0),pContext))
	{
		m_wndSplitter2.DestroyWindow();
		return FALSE;
	}

//	return CMDIChildWnd::OnCreateClient(lpcs, pContext);
	return TRUE;
}
am incercat sa pun valori relative la parametrul sizeInit al metodei

Code: Select all

virtual BOOL CreateView( int row, int col, CRuntimeClass* pViewClass, SIZE sizeInit, CCreateContext* pContext );
adica CSize(lpcs->cx / 3,0), am pus valori absolute, am incercat sa masor view-ul cu GetClientRect si sa pun valoarea obtinuta impartita la 3, acelasi rezultat ... am atasat si un proiect de test, in care se poate vedea cum latimea coloanei 2 este intodeauna 0 ...
Attachments
SplittTest.zip
(95 KiB) Downloaded 189 times



User avatar
Ovidiu Cucu
Fondator
Fondator
Posts: 3776
Joined: 11 Jul 2007, 16:10
Judet: Iaşi
Location: Iasi
Contact:

Re: Problema in CChildFrame::OnCreateClient

Post by Ovidiu Cucu » 08 Jun 2012, 15:23

Fa asa:

Code: Select all

BOOL CChildFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
{
   VERIFY(m_wndSplitter.CreateStatic(this, 1, 3));
   const int cxIdeal = lpcs->cx / 3;
   m_wndSplitter.SetColumnInfo(0, cxIdeal, 0);
   m_wndSplitter.SetColumnInfo(1, cxIdeal, 0);
   // ...
}
MSDN
When the framework displays the splitter window, it lays out the panes in columns and rows according to their ideal dimensions, working from the upper-left to the lower-right corner of the splitter window's client area.

mesajflaviu
Membru++
Membru++
Posts: 688
Joined: 10 Sep 2008, 21:40
Judet: Cluj

Re: Problema in CChildFrame::OnCreateClient

Post by mesajflaviu » 08 Jun 2012, 15:36

Interesant ... acuma merge ... multumesc !

User avatar
Ovidiu Cucu
Fondator
Fondator
Posts: 3776
Joined: 11 Jul 2007, 16:10
Judet: Iaşi
Location: Iasi
Contact:

Re: Problema in CChildFrame::OnCreateClient

Post by Ovidiu Cucu » 08 Jun 2012, 17:24

mesajflaviu wrote:Interesant ... acuma merge ...
De ce asa si nu altfel?
Pai, luind primul splitter, cel cu o linie si trei coloane: in prima si ultima coloana creezi cate un view caruia ii dai latimea care te intereseaza (1/3 din zona client a frame-ului). Framework-ul va dimensiona prima coloana dupa latimea view-ului continut. La ultima oricum nu conteaza, pentru ca se va dimensiona cu ce mai ramane. Coloana din mijloc nu contine un view ci un alt splitter. Pentru ca nu i-am dat nici o informatie despre latimea pe care o prefer, va fi pusa pe zero.

Ca sa repar asta, ii dau ceea ce-i lipseste:

Code: Select all

   const int cxIdeal = lpcs->cx / 3;
   m_wndSplitter.SetColumnInfo(1, cxIdeal, 0);
Adica "an ideal width for the splitter window column in pixels.
De ce i-au zis "ideal"?
Pentru ca nu-i garantat ca asta va fi si latimea finala. Printre altele, cum am spus mai sus, ultima coloana se dimensioneaza oricum pe ce ramane.

Post Reply