ITQuants blog

Fusion Invest v7: How to add a caption bar like the simulation bar?

Jan 25

Written by:
1/25/2016 4:26 PM  RssIcon

One client asked me to add some very visible message in Fusion Invest that permits to warn when the pricing date is not the current date. A good sample of such a message is the native toolbar that is displayed by the application when the simulation mode is selected. The expected result should be the following one:

By the way, the core code of Fusion Invest is still written in MFC/C++. Adding such a toolbar is possible by written some C++ code that uses the MFC classes. The goal of this post is to give the code that permits to activate such a functionality.

The right way to add such a class is to use at first the MFC wizard provided by Visual Studio. Using the right options (Ribbon activated) will generate an application very similar to Fusion Invest. The option that permits to generate the C++ code corresponding to the simulation bar is provided when selecting the legend bar.

In the toolkit code, the main window class is available through the MFC AfxGetMainWnd() method. We then just need to create a CMFCCaptionBar that uses the main window as parent. Such a thing is possible using the following code :

BOOL result = m_wndCaptionBar.Create(WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, AfxGetMainWnd(), 100000, -1, TRUE);

Note that the ID used (100 000) should not be taken by the menu Ids used by SophisValue.exe.

If we want to override the background color, a solution is to derivate the default class and by overriding the OnDrawBackGround method as follow:

class CBkgColorCaptionBar : public CMFCCaptionBar
{
public:
    CBkgColorCaptionBar() {};
 
protected:
    virtual void OnDrawBackground(CDC* pDC, CRect rect)
    {
        //CDrawingManager dm(*pDC);
        COLORREF clrOrange = RGB(255,127,39);
        //dm.FillGradient(rect, m_clrRibbonBarGradientDark, m_clrRibbonBarGradientLight, TRUE);
        pDC->FillSolidRect(rect,clrOrange);
    }
};

Finally, the code can be exported to C# toolkit using some C++ managed wrapper as follow:

void Global::ShowContextDateCaptionBar(bool bShow, System::DateTime^ dt, bool usePnL, bool useTheoreticals)
{
    static CBkgColorCaptionBar m_wndCaptionBar;
    if(!::IsWindow(m_wndCaptionBar.m_hWnd))
    {
        BOOL result = m_wndCaptionBar.Create(WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, AfxGetMainWnd(), 100000, -1, TRUE);
 
 
        char szBuffer[1024];
        const char* szPnL = usePnL ? "true" : "false";
        const char* szTheoreticals = useTheoreticals ? "true" : "false";
 
        _snprintf(szBuffer,sizeof(szBuffer),"Pricing date is not the current date (date=%02d/%02d/%04i, usePnL=%s, useTheoreticals=%s).",
            dt->Day,dt->Month,dt->Year,szPnL,szTheoreticals);
 
        m_wndCaptionBar.SetText(szBuffer, CMFCCaptionBar::ALIGN_LEFT);
 
        m_wndCaptionBar.SetBitmap(IDB_BITMAP1, RGB(0, 0, 0), FALSE, CMFCCaptionBar::ALIGN_LEFT);
        m_wndCaptionBar.SetImageToolTip("Important", "Pricing date.");
    }
 
    int _show = bShow ? SW_SHOW : SW_HIDE;
    m_wndCaptionBar.ShowWindow(_show);
    dynamic_cast(AfxGetMainWnd())->RecalcLayout(FALSE);
}


Tags:
Categories: Sophis, C++

Search blog