Click here to Skip to main content
15,885,216 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Can not create object of DirectorySearcher class with Visual C++ with project reference of System.DirectoryServices.dll Pin
Alex Banar2-Apr-22 2:01
Alex Banar2-Apr-22 2:01 
GeneralRe: Can not create object of DirectorySearcher class with Visual C++ with project reference of System.DirectoryServices.dll Pin
Victor Nijegorodov2-Apr-22 2:55
Victor Nijegorodov2-Apr-22 2:55 
GeneralRe: Can not create object of DirectorySearcher class with Visual C++ with project reference of System.DirectoryServices.dll Pin
Alex Banar2-Apr-22 10:08
Alex Banar2-Apr-22 10:08 
GeneralRe: Can not create object of DirectorySearcher class with Visual C++ with project reference of System.DirectoryServices.dll Pin
Richard MacCutchan3-Apr-22 23:12
mveRichard MacCutchan3-Apr-22 23:12 
GeneralRe: Can not create object of DirectorySearcher class with Visual C++ with project reference of System.DirectoryServices.dll Pin
Richard Andrew x644-Apr-22 6:49
professionalRichard Andrew x644-Apr-22 6:49 
GeneralRe: Can not create object of DirectorySearcher class with Visual C++ with project reference of System.DirectoryServices.dll Pin
Dave Kreskowiak2-Apr-22 4:46
mveDave Kreskowiak2-Apr-22 4:46 
GeneralRe: Can not create object of DirectorySearcher class with Visual C++ with project reference of System.DirectoryServices.dll Pin
Alex Banar2-Apr-22 10:08
Alex Banar2-Apr-22 10:08 
QuestionSwitching a toolbar from Docked to Floating without restarting app? Pin
kittmaster31-Mar-22 11:59
kittmaster31-Mar-22 11:59 
So my app works using MFC toolbar creation without issue. If I set a flag, I can make it Dock or Float when the program is started using m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);. The code that does it lives in the OnCreate which of course can only be called once. What I'm looking to do is use my property sheet to allow the user to select the mode of the toolbars Docked or Floating which requires a method outside of the OnCreate. So I have two buttons for testing, one to destroy the toolbar (working) and create which "rebuilds" the toolbar....

I start off with the app in the Docked mode, then I test by destroying the toolbar and then rebuilding it. The rebuild is where my issue is. On the rebuild, it is "adding" some blank space equivalent to the two toolbars (Menu and Button) and the toolbars float....I can drag it out of where it was docked.....and the floating bar works.....but it "leaves behind" the a non functional version of the floating toolbar where it was once docked. If I double click the floating bar, it jumps back to its previously docked location.

So I'm trying to figure out what is needed to correct my code that partially does what I want.....and fix the artifacts.

The code to destroy:
C++
int CMainFrame::OnToolBarDestroy()
{

    //if (!m_wndToolBar)
    //{
    //  m_wndOutput.AddStringStatusTab(_T("Error: Icon toolbar is already removed, action cancelled"));
    //  m_wndOutput.AddStringDebugTab(_T("Debug: MainFrame--Error: Icon toolbar is already removed, action cancelled"));
    //  return -1;
    //}

    //m_wndToolBar.Invalidate();
    //m_wndMenuBar.DestroyWindow();
    //m_wndToolBar.DestroyWindow();
    //m_wndToolBar.AdjustDockingLayout();
    //RecalcLayout();
    //OnToolBarCreate();

    //return 0;

    //CRect rcClientOld;
    //CRect rcClientNew;
    //GetClientRect(rcClientOld);
    //RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0, reposQuery, rcClientNew);

    //m_wndToolBar.ShowPane(FALSE, FALSE, TRUE); // Hide toolbar
    //RecalcLayout();

    CDockingManager myPane;
    myPane.RemovePaneFromDockManager(&m_wndToolBar, TRUE, TRUE, TRUE, NULL);
    m_wndToolBar.Invalidate();
    m_wndToolBar.DestroyWindow();

    myPane.SaveState();

    CPaneContainer myContainer;
    myContainer.RemoveNonValidPanes();

    RecalcLayout();

    return 0;
}

The code to rebuild the toolbar:
C++
int CMainFrame::OnToolBarCreate()
{
    if (m_wndToolBar)
    {
        m_wndOutput.AddStringStatusTab(_T("Error: Icon toolbar is already active, action cancelled"));
        m_wndOutput.AddStringDebugTab(_T("Debug: MainFrame--Error: Icon toolbar is already active, action cancelled"));
        return -1;
    }

    CMFCPopupMenu::SetForceMenuFocus(FALSE);
    //CMDIChildWndEx::m_bEnableFloatingBars = TRUE;

    // Create ToolBar toolbar
    if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_ALIGN_TOP
        | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
        !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
    {
        TRACE0("Failed to Create Dialog ToolBar\n");
        return -1;
    }

    CMFCToolBar myTools;
    myTools.IsFloating();

    //m_wndMenuBar.EnableDocking(CBRS_ALIGN_ANY);
    m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); // ------- The problem starts with this line...
    EnableDocking(CBRS_ALIGN_ANY);
    //DockPane(&m_wndMenuBar);
    DockPane(&m_wndToolBar);
    //  DockPaneLeftOf(&m_wndToolBar);
    //CDockingManager::SetDockingMode(DT_SMART);
    EnableAutoHidePanes(CBRS_ALIGN_ANY);

    CRect rcClientOld;
    CRect rcClientNew;
    GetClientRect(rcClientOld);
    RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0, reposQuery, rcClientNew);

    m_wndOutput.AddStringStatusTab(_T("I'm created 1 times"));

    //m_wndToolBar.ResetAll();

    //CPaneContainer myContainer;
    //myContainer.RemoveNonValidPanes();

    //CDockingManager myPane;
    //myPane.AdjustDockingLayout();

    m_wndToolBar.ShowPane(TRUE, FALSE, TRUE); // Show toolbar
    RecalcLayout(); 
    //m_wndToolBar.ShowPane(TRUE, FALSE, TRUE); // Show toolbar
    return 0;
}

In the rebuild, note the comment of where the problem begins.....If I comment out that line.....I can destroy and rebuild the toolbar with no issue, it is once I enable that line of code which creates the "float" of the toolbar action. I thought by destroying the toolbar and rebuilding it with the same options as the OnCreate function with the float line mentioned above would do it.....but I get weird issues with the toolbar.

Here are images showing:

Docked Menu:

http://kittmaster.com/imagedump/codeproject/Toolbar1.png

Destroyed Toolbar:

http://kittmaster.com/imagedump/codeproject/Toolbar2.png

Rebuilt Toolbar with issues described:

http://kittmaster.com/imagedump/codeproject/Toolbar3.png

Any ideas how I can solve this issue?

I can't find any code examples anywhere the float option isn't done outside of the OnCreate function.

Hopefully someone can guide me?

You can see with all the commented code of things I've tried to see if I could fix it...

Thanks in advance!
Chris
AnswerRe: Switching a toolbar from Docked to Floating without restarting app? Pin
Randor 1-Apr-22 4:26
professional Randor 1-Apr-22 4:26 
GeneralRe: Switching a toolbar from Docked to Floating without restarting app? Pin
kittmaster1-Apr-22 6:06
kittmaster1-Apr-22 6:06 
GeneralRe: Switching a toolbar from Docked to Floating without restarting app? Pin
Randor 1-Apr-22 6:32
professional Randor 1-Apr-22 6:32 
GeneralRe: Switching a toolbar from Docked to Floating without restarting app? Pin
kittmaster1-Apr-22 9:37
kittmaster1-Apr-22 9:37 
GeneralRe: Switching a toolbar from Docked to Floating without restarting app? Pin
Randor 1-Apr-22 10:13
professional Randor 1-Apr-22 10:13 
GeneralRe: Switching a toolbar from Docked to Floating without restarting app? Pin
kittmaster1-Apr-22 12:34
kittmaster1-Apr-22 12:34 
QuestionMfc Pin
D Sirisha29-Mar-22 6:52
D Sirisha29-Mar-22 6:52 
GeneralRe: Mfc Pin
David Crow29-Mar-22 7:04
David Crow29-Mar-22 7:04 
AnswerRe: Mfc Pin
CPallini29-Mar-22 20:30
mveCPallini29-Mar-22 20:30 
QuestionThere are NN people standing on a line, exactly one of them (we don’t know who) is infected with a virus. The virus spreads from one person to another if their distance is at most 2. If the infected person is chosen optimally, find the minimum (bes Pin
099_Rohan29-Mar-22 4:33
099_Rohan29-Mar-22 4:33 
AnswerRe: There are NN people standing on a line, exactly one of them (we don’t know who) is infected with a virus. The virus spreads from one person to another if their distance is at most 2. If the infected person is chosen optimally, find the minimum Pin
Victor Nijegorodov29-Mar-22 4:55
Victor Nijegorodov29-Mar-22 4:55 
AnswerRe: There are NN people standing on a line, exactly one of them (we don’t know who) is infected with a virus. The virus spreads from one person to another if their distance is at most 2. If the infected person is chosen optimally, find the minimum Pin
jeron129-Mar-22 4:58
jeron129-Mar-22 4:58 
AnswerRe: There are NN people standing on a line, exactly one of them (we don’t know who) is infected with a virus. The virus spreads from one person to another if their distance is at most 2. If the infected person is chosen optimally, find the minimum Pin
Dave Kreskowiak29-Mar-22 5:29
mveDave Kreskowiak29-Mar-22 5:29 
QuestionWhat MS SDK do you use and why? Pin
charlieg28-Mar-22 14:08
charlieg28-Mar-22 14:08 
AnswerRe: What MS SDK do you use and why? Pin
Richard MacCutchan29-Mar-22 1:26
mveRichard MacCutchan29-Mar-22 1:26 
GeneralRe: What MS SDK do you use and why? Pin
charlieg29-Mar-22 2:43
charlieg29-Mar-22 2:43 
QuestionLinked List Cleanup Pin
Calin Negru22-Mar-22 11:03
Calin Negru22-Mar-22 11:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.