ITQuants blog

Sophis Risque: how to close specific portfolio windows

Nov 14

Written by:
11/14/2013 6:07 PM  RssIcon

In some cases, for example when changing user calculation preferences like the Delta Split, it is necessary to close the portfolio windows in order to take into account the modifications. Closing specific portfolio windows in Sophis Risque and Value is possible using the Windows SDK, MFC and the Sophis low level toolkit and standard toolkit.

In our case, since the list of underlyings is changed on the underlying view, the main portfolio extraction has to be rebuild. This is done by using the following Sophis toolkit command:

1.CSRExtraction::gMain.Rebuild();

 

Infortunately, using this command, all references used by the portfolio views are becoming obsolete and windows have to be closed. We have to iterate on the displayed windows belonging to Sophis Risque, and to detect which type of window is available.

The iteration is done using the Windows SDK function EnumChildWindows, which permits to iterate all application windows, even when closing them.

The code to close the portfolio windows will look like also something like that:

1.void CloseFolioWindows()
2.{
3.    if(AfxGetMainWnd() && AfxGetMainWnd()->m_hWnd)
4.        ::EnumChildWindows(AfxGetMainWnd()->m_hWnd,EnumCloseFolioWindow,0L);
5.}

 

The callback EnumCloseFolioWindow will be called on each windows of Sophis Risque. The portfolio views are MDI Child windows and inherit from the MFC class CMDIChildWnd.

On each MDI child window, we just have then to detect if the OS window is registered as a CSWindow in the Sophis window kernel. In order to detect it, we can use the instance gApplicationSophis and its method GetCSWindow. On portfolio views, it will correspond to the CSWindFolio, which inherits from CSWindow. GetCSWindow raises an error when the parameter does not correspond to a CSWindow. We have to catch this exception.

Finally, the code permitting the EnumChildWindows callback will be the following one:

#define NDEBUG
struct Rect;
#include
  
BOOL CALLBACK EnumCloseFolioWindow(HWND hwndChild, LPARAM lParam) 
{
    CMDIChildWnd* _wnd = dynamic_cast(CWnd::FromHandle(hwndChild));
    if(_wnd && gApplicationSophis)
    {
        try  // with a try, GetCSWindow raising a C++ exception if no CSWindow is linked to the WindowPtr parameter
        {
            CSWindow* _window = gApplicationSophis->GetCSWindow(_wnd);
            if(_window)
            {
                CSWindFolio* _wndFolio = dynamic_cast(_window);
                if(_wndFolio)
                    _wnd->DestroyWindow();
            }
        }
        catch(...)
        {
        }
    }
  
    return TRUE;
}

 

N.B.: using CSWindFolio, it is possible to detect other parameters, like the folio identifier (CSWindfolio::GetFolioID).

Search blog