Cum salvez pozitia a doua toolbar-uri ?

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

Cum salvez pozitia a doua toolbar-uri ?

Post by mesajflaviu » 05 Jun 2012, 12:08

Intr-o aplicatie MDI, pe langa toolbar-ul standard, mai am unul :

Code: Select all

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if(CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)return -1;

	if(! m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP 
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || 
		! m_wndToolBar.LoadToolBar(IDR_MAINFRAME2))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}

	if(! m_wndEditToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_BOTTOM 
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || 
		! m_wndEditToolBar.LoadToolBar(IDR_TOOLBAREDIT))
	{
		TRACE0("Failed to create edit toolbar\n");
		return -1;      // fail to create
	}

	// TODO: Delete these three lines if you don't want the toolbar to
	//  be dockable

	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
	EnableDocking(CBRS_ALIGN_ANY);
	DockControlBar(&m_wndToolBar);

	LoadBarState(_T("BarState"));

	m_wndEditToolBar.EnableDocking(CBRS_ALIGN_ANY);
	EnableDocking(CBRS_ALIGN_ANY);
	DockControlBar(&m_wndEditToolBar);

	LoadBarState(_T("EditBarState"));
...
}
intrebarea mea este, cum salvez cu LoadBarState(...) pozitia fiecaruia toolbar ?
Am incercat asa, dar e o prostie :

Code: Select all

void CMainFrame::OnDestroy() 
{
	SaveBarState(_T("BarState"));
	SaveBarState(_T("EditBarState"));

	CMDIFrameWnd::OnDestroy();

	// TODO: Add your message handler code here
...
}



User avatar
Marius Bancila
Fondator
Fondator
Posts: 2344
Joined: 11 Jul 2007, 11:45
Judet: Timiş
Location: Timisoara
Contact:

Re: Cum salvez pozitia a doua toolbar-uri ?

Post by Marius Bancila » 05 Jun 2012, 13:57

SaveBarState iti salveaza pozitia fiecarei bare de control detinuta de frame. Acel parametru e doar numele unei sectiuni din fisierul de initializare sau cheie in Registry unde informatia e stocata.

Ar trebui sa fie suficient sa salvezi odata si sa incarci odata. Intrebarea e ce se intampla, nu-ti merge? Ce nu merge? Ce cod mai ai dupa LoadBarState?
Marius Bancila
Fondator Codexpert, Microsoft MVP VC++
Site personal | Blog

User avatar
Marius Bancila
Fondator
Fondator
Posts: 2344
Joined: 11 Jul 2007, 11:45
Judet: Timiş
Location: Timisoara
Contact:

Re: Cum salvez pozitia a doua toolbar-uri ?

Post by Marius Bancila » 05 Jun 2012, 14:01

Ia uite ce zice cineva aici http://www.itlisting.org/5-windows/9ff8 ... 8fce5.aspx:
When I create the toolbars in the frame window's OnCreate, they must be given a control ID explicitely in the Create call. Otherwise SaveBarState and LoadBarState will not be able to figure out which control is which. So, initially my code was:

Code: Select all

        if (!m_wndZoomBar.Create(this) || 
              !m_wndZoomBar.LoadToolBar(IDR_ZOOMBAR)) 
        { 
                TRACE0("Failed to create zoom toolbar\n"); 
                return -1; 
        } 
I changed it to

Code: Select all

        UINT flags = WS_CHILD | WS_VISIBLE | CBRS_TOP; 
        if (!m_wndZoomBar.Create(this, flags, IDR_ZOOMBAR) || 
              !m_wndZoomBar.LoadToolBar(IDR_ZOOMBAR)) 
        { 
                TRACE0("Failed to create zoom toolbar\n"); 
                return -1; 
        } 
and now everything works perfectly.
Incearca si tu acelasi lucru.
Marius Bancila
Fondator Codexpert, Microsoft MVP VC++
Site personal | Blog

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

Re: Cum salvez pozitia a doua toolbar-uri ?

Post by mesajflaviu » 05 Jun 2012, 15:17

O sa incerc acum ...

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

Re: Cum salvez pozitia a doua toolbar-uri ?

Post by mesajflaviu » 05 Jun 2012, 16:15

Asta era, am pus in CreateEx(...) ID-ul toolbar-ului (fiecarui toolbar) si totul merge brici ! Multumesc !

Post Reply