Configuration in Title bar

Configuration in title bar

One common complain with Dynamics Ax 4.0 is that it is not possible for the user to determine in which environment they are working.

Particularly for consultants/developers who often have multiple Ax applications open at one time, this is very frustrating and can easily lead to errors (developing in the wrong application). In Axapta 3.0 information was displayed in the title bar allowing users to determine the application, but this is missing in Ax 4.0

This simple fix will display the configuration name in the main Dynamics Ax window title bar. You need to simply override the workspaceWindowCreated() method in the info() class (special class nearly at the bottom of the Classes node in the AOT) and add a single line of code. After the change, the method should appear as follows:

void workspaceWindowCreated(int _hWnd)
{
;
    // Put workspace window specific initialization here.
    // Show config in title bar
    WinAPI::setWindowText(_hWnd, strFmt("%1 - %2", WinAPI::getWindowText(_hWnd), xInfo::configuration()));
}

Another option is shown below. This will put the current AOS and server name, as well as the logged in development layer, after the standard title bar text.

void workspaceWindowCreated(int _hWnd)
{
    SqlSystem       sqlSystem = new SqlSystem();
    LoginProperty   loginProperty = sqlSystem.createLoginProperty();
    ;

    // Put workspace window specific initialization here.

    // Show application details in title bar
    if (loginProperty)
    {
        WinAPI::setWindowText(_hWnd, strFmt("%1 - %2@%3 (%4)", WinAPI::getWindowText(_hWnd), loginProperty.getDatabase(), loginProperty.getServer(), this.currentAOLayer()));
    }
}

The details for these fixes came originally from posts to the microsoft public axapta newsgroup.

Ax 3.0 solution

\Classes\Info\onEventGoingIdle

//Event fired by kernel when the client goes idle.
//It is not fired during CTRL-Break dialog.
void onEventGoingIdle()
{
    this.operationProgressClear();
    this.endLengthyOperation(true);
    // there should be a user who will work if error occured
    if(strLwr(curUserID())!='admin')
        TitleChanger::changeTitle();
}

TitleChanger::changeTitle:

static void changeTitle()
{
    #define.WM_SETTEXT(0x000C)
    str         caption;
    str prefix=new Session().AOSName()+": ";
    int  defWindowProc(
                               int              _handle,
                               int              _msg,
                               int              _wParam,
                               str              _lParam )
    {
        int         ret;
        DLL         _DLL             = new DLL('USER32');
        DLLFunction _defwproc        = new DLLFunction(_DLL, 'DefWindowProcA');
        ;

        _defwproc.returns(ExtTypes:: DWord); // LRESULT
        _defwproc.arg(ExtTypes:: DWord);     // handle window
        _defwproc.arg(ExtTypes:: DWord);     // message
        _defwproc.arg(ExtTypes:: DWord);     // wparm
        _defwproc.arg(ExtTypes::String);     // lparm

        return  _defwproc.call(_handle, _msg, _wParam, _lParam);
    }
    ;
    caption = winapi::getWindowText(infolog.hWnd());
    if(!StrUtils::startsWith(caption, prefix))
        defWindowProc(infolog.hWnd(), #WM_SETTEXT, 0, prefix + caption);
}

StrUtils::startsWith:

// string _s begins with _suffix
static boolean startsWith(str _s, str _prefix)
{
    return
        strLen(_s)>=strLen(_prefix)
        &&
        subStr(_s, 1, strLen(_prefix))==_prefix;
}
Advertisements

One Response to Configuration in Title bar

  1. A great and very useful hack.
    Thanks a mill.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: