Print Page | Close Window

QuickAccessToolbar Save and Load [Solved]

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Command Bars
Forum Description: Topics Related to Codejock Command Bars
URL: http://forum.codejock.com/forum_posts.asp?TID=24308
Printed Date: 21 November 2024 at 3:57pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: QuickAccessToolbar Save and Load [Solved]
Posted By: cpede
Subject: QuickAccessToolbar Save and Load [Solved]
Date Posted: 20 July 2022 at 5:10am
I can't find any examples on how to save and load the controls in the QuickAccessToolbar.

I managed to save and load the using the code below.

Right after adding a new control to the QuickAccessToolbar using the CXTPRibbonCustomizeQuickAccessPage everyting works.

The problem is that after saving and loading the QuickAccesControls they appear correct in the QuickAccessToolbar, but the controls are not working?

void CMainWindow::LoadQuickAccessControls()
{
CXTPRibbonBar* pRibbonBar = DYNAMIC_DOWNCAST(CXTPRibbonBar, GetCommandBars()->GetMenuBar());
if (pRibbonBar == NULL) return;
CXTPRibbonQuickAccessControls *pQA = pRibbonBar->GetQuickAccessControls();
if (pQA == NULL) return;
XTP_COMMANDBARS_PROPEXCHANGE_PARAM param;
param.pCommandBars = GetCommandBars();
param.bSaveOriginalControls = FALSE;
param.bSerializeControls = TRUE;
param.bSerializeActions = TRUE;
param.bSerializeLayout = FALSE;
param.bSerializeOptions = FALSE;

HKEY hKey = NULL;
if (::RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\\My Company\\My App"), 0, KEY_READ, &hKey) != ERROR_SUCCESS)
return;
CXTPPropExchangeRegistry px(TRUE, hKey, _T("QuickAccessLayout"));
px.m_dwData = DWORD_PTR(&param);
pQA->DoPropExchange(&px);
::RegCloseKey(hKey);
}
void CMainWindow::SaveQuickAccessControls()
{
CXTPRibbonBar* pRibbonBar = DYNAMIC_DOWNCAST(CXTPRibbonBar, GetCommandBars()->GetMenuBar());
if (pRibbonBar == NULL) return;
CXTPRibbonQuickAccessControls *pQA = pRibbonBar->GetQuickAccessControls();
if (pQA == NULL) return;
XTP_COMMANDBARS_PROPEXCHANGE_PARAM param;
param.bSaveOriginalControls = FALSE;
param.bSerializeControls = TRUE;
param.bSerializeActions = TRUE;
param.bSerializeLayout = FALSE;
param.bSerializeOptions = FALSE;

HKEY hKey = NULL;
if (::RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\\My Company\\My App"), 0, KEY_WRITE, &hKey) != ERROR_SUCCESS)
return;
CXTPPropExchangeRegistry px(FALSE, hKey, _T("QuickAccessLayout"));
px.m_dwData = DWORD_PTR(&param);
pQA->DoPropExchange(&px);
::RegCloseKey(hKey);
}

This fails:
XTPCommandBar.cpp line 653:
if (!pControl->OnSetPopup(TRUE))

Since m_pCommandBar is NULL in XTPControlPopup.cpp line 295:
if (!m_pCommandBar)

Please help.


-------------
Product: Xtreme ToolkitPro (24.0.0)
Platform: Windows 10 (x64)
Language: Visual Studio 2017 (C++)



Replies:
Posted By: cpede
Date Posted: 29 July 2022 at 2:56am
Maybe a good idea to add these methods to the Codejock Ribbon MDI Sample for others to use??

void CMainFrame::LoadQuickAccessControls()
{
  CXTPRibbonBar* pRibbonBar = DYNAMIC_DOWNCAST(CXTPRibbonBar, 
          GetCommandBars()->GetMenuBar());
  if (pRibbonBar == NULL) return;
  CXTPRibbonQuickAccessControls *pQA = pRibbonBar->GetQuickAccessControls();
  if (pQA == NULL) return;

  XTP_COMMANDBARS_PROPEXCHANGE_PARAM param;
  param.pCommandBars = GetCommandBars();
  param.bSaveOnlyCustomized = FALSE;
  param.bLoadSilent = TRUE;
  param.bSaveOriginalControls = TRUE;
  param.bSerializeActions = TRUE;
  param.bSerializeControls = TRUE;
  param.bSerializeDesignerControls = TRUE;
  param.bSerializeImages = FALSE;
  param.bSerializeLayout = TRUE;
  param.bSerializeOptions = TRUE;

  HKEY hKey = NULL;
  if (::RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\\Codejock Software Sample Applications
          \\Codejock Ribbon MDI Sample"), 0, KEY_READ, &hKey) != ERROR_SUCCESS)
  {
    pRibbonBar->GetQuickAccessControls()->Reset();
    return;
  }
  ::RegCloseKey(hKey);

  if (::RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\\Codejock Software Sample Applications
          \\Codejock Ribbon MDI Sample"), 0, KEY_READ, &hKey) != ERROR_SUCCESS)
    return;

  pRibbonBar->GetQuickAccessControls()->RemoveAll();

  CXTPPropExchangeRegistry px(TRUE, hKey, _T("QuickAccessLayout"));
  px.m_dwData = DWORD_PTR(&param);
  pQA->DoPropExchange(&px);
  ::RegCloseKey(hKey);
}
void CMainFrame::SaveQuickAccessControls()
{
  CXTPRibbonBar* pRibbonBar = DYNAMIC_DOWNCAST(CXTPRibbonBar, 
          GetCommandBars()->GetMenuBar());
  if (pRibbonBar == NULL) return;
  CXTPRibbonQuickAccessControls *pQA = pRibbonBar->GetQuickAccessControls();
  if (pQA == NULL) return;

  XTP_COMMANDBARS_PROPEXCHANGE_PARAM param;
  param.pCommandBars = NULL;// GetCommandBars();
  param.bSaveOnlyCustomized = FALSE;
  param.bLoadSilent = TRUE;
  param.bSaveOriginalControls = FALSE;
  param.bSerializeActions = TRUE;
  param.bSerializeControls = TRUE;
  param.bSerializeDesignerControls = TRUE;
  param.bSerializeImages = FALSE;
  param.bSerializeLayout = TRUE;
  param.bSerializeOptions = TRUE;

  HKEY hKey = NULL;
  if (::RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\\Codejock Software Sample Applications
          \\Codejock Ribbon MDI Sample"), 0, KEY_WRITE, &hKey) != ERROR_SUCCESS)
    return;
  CXTPPropExchangeRegistry px(FALSE, hKey, _T("QuickAccessLayout"));
  px.m_dwData = DWORD_PTR(&param);
  pQA->DoPropExchange(&px);
  ::RegCloseKey(hKey);
}  


-------------
Product: Xtreme ToolkitPro (24.0.0)
Platform: Windows 10 (x64)
Language: Visual Studio 2017 (C++)


Posted By: Fredrik
Date Posted: 30 July 2022 at 7:39am
A question, why would you need to load/save Quick Access controls using separate functions? 

I just create the ribbon bar including the QAT, and then call LoadCommandBars(L"MySection", TRUE); and all previous customizations are then loaded.




-------------
Windows 10, Visual Studio 20157, Toolkit Pro 18.3.0



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net