Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CMFCToolBarComboBoxButton::GetByCmd returns NULL

CMFCToolBarComboBoxButton::GetByCmd returns NULL

Scheduled Pinned Locked Moved C / C++ / MFC
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    joliet
    wrote on last edited by
    #1

    I created a CMFCToolBarComboBoxButton in a CMFCToolBar as following:

    afx_msg LRESULT CMainFrame::OnToolbarReset(WPARAM wp, LPARAM lp)
    {
    UINT uiToolBarId = (UINT) wp;
    if (uiToolBarId == IDR_TOOLBAR_FILES)
    {
    CMFCToolBarComboBoxButton omboButton1(IDC_SRC_PRO_LIST, GetCmdMgr ()->GetCmdImage(IDC_SRC_PRO_LIST, FALSE), CBS_DROPDOWNLIST);

        comboButton1.EnableWindow(FALSE);
        comboButton1.SetCenterVert();
        comboButton1.SetDropDownHeight(200);
        comboButton1.SetFlatMode();
        m\_wndFilesBar.ReplaceButton (IDC\_SRC\_PRO\_LIST, comboButton1);
     }
    

    }

    It runs well. But when I want to add some content into it from another thread.I defined a function:

    int CMainFrame::CBAddItem(LPCTSTR lpszItem, DWORD_PTR dwData)
    {
    int r = -1;
    CMFCToolBarComboBoxButton* pSrcCombo = CMFCToolBarComboBoxButton::GetByCmd (IDC_SRC_PRO_LIST);
    if(pSrcCombo)
    {
    r = pSrcCombo->AddItem(lpszItem, dwData);
    }
    return r;
    }

    The function CMFCToolBarComboBoxButton::GetByCmd always return NULL. And I traced this function, found:

    int __stdcall CMFCToolBar::GetCommandButtons(UINT uiCmd, CObList& listButtons)
    {
    .....
    for (POSITION posTlb = afxAllToolBars.GetHeadPosition(); posTlb != NULL;)
    {
    CMFCToolBar* pToolBar = (CMFCToolBar*) afxAllToolBars.GetNext(posTlb);
    ENSURE(pToolBar != NULL);

        if (CWnd::FromHandlePermanent(pToolBar->m\_hWnd) != NULL)
    

    CWnd::FromHandlePermanent(pToolBar->m_hWnd) always return NULL. So why?

    J 1 Reply Last reply
    0
    • J joliet

      I created a CMFCToolBarComboBoxButton in a CMFCToolBar as following:

      afx_msg LRESULT CMainFrame::OnToolbarReset(WPARAM wp, LPARAM lp)
      {
      UINT uiToolBarId = (UINT) wp;
      if (uiToolBarId == IDR_TOOLBAR_FILES)
      {
      CMFCToolBarComboBoxButton omboButton1(IDC_SRC_PRO_LIST, GetCmdMgr ()->GetCmdImage(IDC_SRC_PRO_LIST, FALSE), CBS_DROPDOWNLIST);

          comboButton1.EnableWindow(FALSE);
          comboButton1.SetCenterVert();
          comboButton1.SetDropDownHeight(200);
          comboButton1.SetFlatMode();
          m\_wndFilesBar.ReplaceButton (IDC\_SRC\_PRO\_LIST, comboButton1);
       }
      

      }

      It runs well. But when I want to add some content into it from another thread.I defined a function:

      int CMainFrame::CBAddItem(LPCTSTR lpszItem, DWORD_PTR dwData)
      {
      int r = -1;
      CMFCToolBarComboBoxButton* pSrcCombo = CMFCToolBarComboBoxButton::GetByCmd (IDC_SRC_PRO_LIST);
      if(pSrcCombo)
      {
      r = pSrcCombo->AddItem(lpszItem, dwData);
      }
      return r;
      }

      The function CMFCToolBarComboBoxButton::GetByCmd always return NULL. And I traced this function, found:

      int __stdcall CMFCToolBar::GetCommandButtons(UINT uiCmd, CObList& listButtons)
      {
      .....
      for (POSITION posTlb = afxAllToolBars.GetHeadPosition(); posTlb != NULL;)
      {
      CMFCToolBar* pToolBar = (CMFCToolBar*) afxAllToolBars.GetNext(posTlb);
      ENSURE(pToolBar != NULL);

          if (CWnd::FromHandlePermanent(pToolBar->m\_hWnd) != NULL)
      

      CWnd::FromHandlePermanent(pToolBar->m_hWnd) always return NULL. So why?

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      Check if you met the requirements described at the MSDN page Multithreading: Programming Tips[^]. A common solution to access MFC objects from other threads is posting user defined messages. Then the manipulation of the object occurs inside the thread that owns the MFC object. If your thread is a worker thread see the CP article Using Worker Threads[^] for examples.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups