Axaptapedia is now maintained by AgileCadence For more information please click here.
Configuration in title bar
Configuration in title bar[edit]
One common complaint 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:
<xpp> 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()));
} </xpp>
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.
<xpp> 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())); }
} </xpp>
The details for these fixes came originally from posts to the microsoft public axapta newsgroup.
Alternative AX 3.0 Solution[edit]
The original solution for AX 3 used onEventGoingIdle to adapt the Window title. This is not optimal since this is called many thousands of times during the lifetime of an Axapta session. Unfortunalety, one can't simply use Info::startupPost() to set the title, as the Ax Client set the final title only after the startup cycle has completed. One workaround for this is to defer the execution of the title update using the setTimeOut() method with the idle flag set to true. This will delay the execution of the method in question to the point, where Axapta goes idle for the first time:
Addendum: It seems, that Axapta 3 resets the title bar now and again. I have not yet found the root cause of this. However, if you experience this problem, working around it is rather easy. Reschedule the CANUpdateWindowTitle to run every thirty seconds or so. This is not as stressfull as running it over and over again like the original solution did.
<xpp> // Classes\Info\startupPost void startupPost() {
// Needs delay until idle to allow Axapta to initialize fully this.setTimeOut(identifierStr(UpdateWindowTitle), 1, true);
} </xpp>
The actual function in question is pretty straight forward:
<xpp> // Classes\Info\UpdateWindowTitle void CANUpdateWindowTitle() {
Session session; SQLSystem SQLSystem; #define.WM_SETTEXT(0x0c)
int setWindowText(str title) { 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
ret = _defwproc.call(infolog.hWnd(), #WM_SETTEXT, 0, title); return ret; } ;
session = new Session(); SQLSystem = new SQLSystem();
if (isAOS()) setWindowText(strfmt("Axapta - %1", session.AOSName())); else setWindowText(strfmt("Axapta 2T - DB %1 on %2 ", SQLSystem.loginDatabase(), SQLSystem.loginServer()));
// In case you experience Problems: Enable this to rerun every 30 Seconds if Axapta changes // the title back to the default now and then. // this.setTimeOut(identifierStr(CANUpdateWindowTitle), 30000);
} </xpp>
Original AX 3.0 solution[edit]
from AxForum
\Classes\Info\onEventGoingIdle <xpp> //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();
} </xpp>
TitleChanger::changeTitle: <xpp> 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);
} </xpp>
StrUtils::startsWith: <xpp> // string _s begins with _suffix static boolean startsWith(str _s, str _prefix) {
return strLen(_s)>=strLen(_prefix) && subStr(_s, 1, strLen(_prefix))==_prefix;
} </xpp>