Gabriel Hardy
Gabriel Hardy

Reputation: 31

AlwaysOnTop property not behaving properly

For some reason, the AlwaysOnTop attribute for a form's design isn't properly working.

Here's the context: we are trying to have a form that stays on top of every other one when opened. Simple no? Also, we don't want to set the WindowType to Popup according to my superior for some other reason (if you have any idea why, please let me know).

So my question is, is there any parameter/security feature somewhere that somehow restricts the forms to be on top at any time?

Even WinApi's setForegroundWindow returns false with the form's hWnd. Any ideas?

Oh, also we're running on Dynamics AX 4.0.

Upvotes: 3

Views: 1490

Answers (3)

j.a.estevan
j.a.estevan

Reputation: 3097

I managed this case long time ago with the lostFocus event and the setFocus method. I didn't find a proper way to make a form stay on top (I think AX prevents this specifically to avoid locking a terminal) but it worked fine this way: When the form lost focus, set the focus on the form.

I don't have the code as it was on an old project. It was for a PDA project but I think you can't ever avoid user on changing form with Alt+Tab.

This is an interesting point, please keep us updated.

EDIT:

Someome in twitter got an cute solution for modal forms. I'm pretty sure it will make the trick for you. In the init method of the form:

public void run()
{
    super();
    element.wait(true);
    // Execution will resume at this point, only after
    // the user has closed the form.
} 

Source: http://gotdax.blogspot.com.es/2013/08/modal-forms-in-dynamics-ax.html

Upvotes: 1

Jan B. Kjeldsen
Jan B. Kjeldsen

Reputation: 18061

If you want your form to have modal behavior, then call the wait method from the form itself!

public void run()
{
    super();
    this.wait(true);
}

The true parameter triggers the modal mode. This works on all versions of AX.

The wait may be called from the caller instead, but that is less attractive as most forms are called through menu items.

formRun.init();
formRun.run();
formRun.wait(true);

Upvotes: 1

Kenny Saelen
Kenny Saelen

Reputation: 894

What I did to solve this was by making the form modal through WinAPI. The code below is a copy from a saved text so it might need some polishing. (Also keep in mind that it might not be working as of AX2009.)

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);

local_enableWHND(_getParent.call(_thisHWND));
}

Upvotes: 0

Related Questions