zoukankan      html  css  js  c++  java
  • 修改工作区标题

    修改主窗体标题

    Configuration in title bar


    Configuration in title bar

    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:
    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.

    ALTERNATIVE AX 3.0 SOLUTION

    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.
    // Classes\Info\startupPost
    void startupPost()
    {
        // Needs delay until idle to allow Axapta to initialize fully
        this.setTimeOut(identifierStr(UpdateWindowTitle), 1, true);
    }
    The actual function in question is pretty straight forward:
    // 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);
    }


    ORIGINAL AX 3.0 SOLUTION

    from AxForum
    \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;
    }
  • 相关阅读:
    python logging模块
    python 面向对象进阶之对象内置方法
    Python基于Socket实现简易多人聊天室
    Pypi项目包发布
    Unable to locate package python3 错误解决办法
    Invalid operation updata 错误解决方法
    测试用例组合生成工具
    Python GUI之Tkiner实战
    Python爬虫实现翻译功能
    免费AWS云服务器一键搭建Trojan详细教程
  • 原文地址:https://www.cnblogs.com/perock/p/2619577.html
Copyright © 2011-2022 走看看