1

matlab プログラムを C# フォームにドッキングすることになっている C# プログラムを作成しています。この理由は、私の会社が非常に複雑な計算に matlab プログラムを使用しているためです。

ドッキングすると、このプログラムは intouch wonderware 環境に統合され、HMI と matlab プログラム間のユーザー操作がより効率的になります。

次のコードを使用します。

    [DllImport("user32.dll")]
    static extern IntPtr SetFocus(IntPtr hWnd);
    [DllImport("user32.dll")]
    public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
    [DllImport("user32.dll", SetLastError = true)]
    public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
    [DllImport("user32.dll", SetLastError = true)]
    public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
    [MonitoringDescriptionAttribute("ProcessMainWindowHandle")]
    public IntPtr MainWindowHandle { get; set; }

    public void getWinHandle(int parentWidth, int parentHeight)
    {

        hWnd = IntPtr.Zero;
        hWnd = FindWindow(null, "TSplot 2.3.1 (Build: 5626)");
        matlabPTR MatlabNativeWin = new matlabPTR();
        MatlabNativeWin.AssignHandle(hWnd);
        SetParent(hWnd, formiLuring.Handle);
        MoveWindow(hWnd, -8, -33, parentWidth+16, parentHeight+41, false);

    }
public class matlabPTR : NativeWindow
{
    protected override void WndProc(ref Message message)
    {
        const int WM_SYSCOMMAND = 0x0112;
        const int SC_MOVE = 0xF010;
        const int SC_SIZING = 0x0214;

        switch (message.Msg)
        {
            case WM_SYSCOMMAND:
                int command = message.WParam.ToInt32() & 0xfff0;

                if (command == SC_MOVE)
                {
                    return;
                }

                break;
        }

        base.WndProc(ref message);
    }
}

ウィンドウ ハンドルを正常に作成し、C# フォームに追加しました。また、ユーザーがこの matlab ウィンドウを移動できないようにフリーズしました。

ただし、問題は、matlab プログラムが完全なフォーカス イベントを取得していないように見えることです。Z をキーボードで押すと、通常は matlab インターフェイス内でズームが生成されますが、どういうわけか、matlab プログラムはこれを登録しません。

この理由は、C# フォーム自体がキー プレス イベントを受け取るためだと思うかもしれませんが、C# イベントをオーバーライドしようとしましたが、matlab プログラムが強調表示されているときにこのイベントはトリガーされません。

何かを見逃したか、何か間違ったことをしているのだと思いました。

御時間ありがとうございます

4

0 に答える 0