mandag den 20. juli 2009

Making a form modal i X++

Put the following code in the GLOBAL class in a new method called setFormModal:


static void setFormModal(int _thisHWND, boolean _bModal)
{
    DLL _winApiDLL;
    DLLFunction _EnabledWindow;
    DLLFunction _getTop;
    DLLFunction _getNext;
    DLLFunction _getParent;

    void local_enableWHND(int _lHWND)
    {
        int lnextWnd;
        lnextWnd = _getTop.call(_getParent.call(_lHWND));
        while (lnextWnd)
        {
            if (lnextWnd != _lHWND)
                enabledWindow.call(lnextWnd, (!_bModal));
            lnextWnd = _getNext.call(lnextWnd, 2);
        }
    }
    ;
    _winApiDLL = new DLL('user32');
    _getNext = new DLLFunction(_winApiDLL,"GetWindow");
    _EnabledWindow = new DLLFunction(_winApiDLL,"EnableWindow");
    _getTop = new DLLFunction(_winApiDLL,"GetTopWindow");
    _getParent = new DLLFunction(_winApiDLL,"GetParent");
    _getParent.returns(ExtTypes:: DWORD);
    _getParent.arg(ExtTypes:: DWORD);
    _EnabledWindow.returns(ExtTypes:: DWORD);
    _EnabledWindow.arg(ExtTypes:: DWORD, ExtTypes:: DWORD);
    _getTop.returns(ExtTypes:: DWORD);
    _getTop.arg(ExtTypes:: DWORD);
    _getNext.returns(ExtTypes:: DWORD);
    _getNext.arg(ExtTypes:: DWORD, ExtTypes:: DWORD);
    local_enableWHND(_thisHWND);
}


In the form the following methods are overridden with calls to the Global::SetformModal method:

public void run()
{
    super();
    Global::setFormModal(this.hWnd(), true);
}

public void close()
{
    super();
    Global::setFormModal(this.hWnd(), false);
}

1 kommentar:

  1. This is really BAD CODE!!, a mate implement that code, and when you go to do Debug, the session crash!! and the crash can only be solved shutting down the computer forced, because it blocks all the windows session, including the start button.

    It's dangerous call and use unmannaged code, like the COM and DLL, for that reason, this code is so dangerous!!

    Andres L.

    SvarSlet