0

これは奇妙な質問です。コンピューター上でナビゲーション用のアプリケーションを構築することに興味があります。ユーザーが何かを達成したときに、ユーザーに「物理的な合図」を提供したいと考えています。たとえば、フォルダをクリックすると拡大する白い輪。これはC#でできますか?あるユーザーは、これをより詳細に拡張してより具体的にすることを提案しました。Kinect を使用して、ユーザーが OS をナビゲートできるようにしたいと考えています。ただし、両手を使えるようにしたいので、手をマウスポインターにだけ付けたくありません。OS とのやり取りについて、ユーザーに視覚的なフィードバックを提供したいと思います。これを行う最善の方法を考えるのに苦労しています。そのため、OS で視覚効果を作成したいのですが、ゲーム ウィンドウのような特定のウィンドウでは作成しません。

私が目にするほとんどのグラフィック チュートリアルには、ウィンドウの構築とそのウィンドウのパイプラインのレンダリングが含まれます。または、WPF と Silverlight のグラフィックスとアニメーションを使用します。これは特定のアプリケーションではなく OS 用であるため、それよりも柔軟性が必要です。どこから始めればよいのか、また .NET または Mono Framework を使用してそれが可能かどうかを判断するのに苦労しています。

この目標を達成するには、C++ を使用したほうがよいのでしょうか。これが質問のオープンエンドすぎる場合はお知らせください。このようなことを始める方法を見つけようとしています。ありがとう!

4

1 に答える 1

4

.NET WinForms は、C++ WinForms が GDI+ を使用するように、.NET はより抽象化されています。p/invoke を介してネイティブ コードに引き続きアクセスでき、抽象化された BCL で保護されたメンバーをオーバーライドすることができます。つまり、かなりのレベルの制御が可能です。したがって、特定のグラフィックス ライブラリについて話しているのでない限り、.NET WinForms が C++ より劣っているとは思いません。このコンテキストで。

あなたの仕事に関して、私はレイヤードウィンドウを研究します。申し訳ありませんが、私が学習していたときにそれらを見つけるのに苦労したため、手元にある包括的な参考文献はありませんが、レイヤード ウィンドウでの描画を開始するのに役立つクラスをまとめて集めました. FormMain フォームを派生元から派生させるのではなく、次のようにしSingleLayeredFormます。

public class SingleLayeredForm : Form
{
    public new event PaintEventHandler Paint;

    public SingleLayeredForm()
    {
        this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
        this.FormBorderStyle = FormBorderStyle.FixedSingle;
        this.StartPosition = FormStartPosition.Manual;
    }

    protected override CreateParams CreateParams
    {
        get
        {
            if (DesignMode) return base.CreateParams;
            CreateParams createParams = base.CreateParams;
            createParams.ExStyle = createParams.ExStyle | 0x80000;
            return createParams;
        }
    }

    public void SetBitmap(Bitmap bitmap)
    {
        if (!IsHandleCreated || DesignMode) return;
        IntPtr oldBits = IntPtr.Zero;
        IntPtr screenDC = WinAPI.GetDC(IntPtr.Zero);
        IntPtr hBitmap = IntPtr.Zero;
        IntPtr memDC = WinAPI.CreateCompatibleDC(screenDC);
        try
        {
            Point topLocation = new Point(this.Left, this.Top);
            Size bitmapSize = new Size(bitmap.Width, bitmap.Height);
            WinAPI.BLENDFUNCTION blendFunc = new WinAPI.BLENDFUNCTION();
            Point sourceLocation = Point.Empty;
            hBitmap = bitmap.GetHbitmap(Color.FromArgb(0));
            oldBits = WinAPI.SelectObject(memDC, hBitmap);

            blendFunc.BlendOp = WinAPI.AC_SRC_OVER;
            blendFunc.SourceConstantAlpha = 255;
            blendFunc.AlphaFormat = WinAPI.AC_SRC_ALPHA;
            blendFunc.BlendFlags = 0;

            WinAPI.UpdateLayeredWindow(Handle, screenDC, ref topLocation, ref bitmapSize, memDC, ref sourceLocation, 0, ref blendFunc, WinAPI.ULW_ALPHA);
        }
        finally
        {
            if (hBitmap != IntPtr.Zero)
            {
                WinAPI.SelectObject(memDC, oldBits);
                WinAPI.DeleteObject(hBitmap);
            }
            WinAPI.ReleaseDC(IntPtr.Zero, screenDC);
            WinAPI.DeleteDC(memDC);
        }
    }

    public new void Invalidate()
    {
        using (Bitmap bitmap = new Bitmap(this.ClientSize.Width, this.ClientSize.Height))
        {
            using (Graphics graphics = Graphics.FromImage(bitmap))
            {

                graphics.SmoothingMode = SmoothingMode.HighSpeed;
                graphics.CompositingMode = CompositingMode.SourceCopy;

                if (this.Paint != null)
                    this.Paint(this, new PaintEventArgs(graphics, Rectangle.Empty));
            }
            SetBitmap(bitmap);
        }
    }
}

public sealed class WinAPI
{
    [DllImport("user32.dll")]
    public static extern bool HideCaret(IntPtr hWnd);

    [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
    public static extern short GetKeyState(int keyCode);

    [DllImport("user32.dll")]
    public static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);

    [DllImport("user32.dll")]
    public static extern bool UnregisterHotKey(IntPtr hWnd, int id);

    [DllImport("gdi32.dll", SetLastError = true)]
    public static extern IntPtr CreateCompatibleDC(IntPtr hdc);

    [DllImport("user32.dll")]
    public static extern IntPtr GetDC(IntPtr hWnd);

    [DllImport("gdi32.dll", ExactSpelling = true, PreserveSig = true, SetLastError = true)]
    public static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj);

    [DllImport("user32.dll")]
    public static extern bool ReleaseDC(IntPtr hWnd, IntPtr hDC);

    [DllImport("gdi32.dll")]
    public static extern bool DeleteDC(IntPtr hdc);

    [DllImport("gdi32.dll")]
    public static extern bool DeleteObject(IntPtr hObject);

    [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]
    public static extern bool UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst, ref Point pptDst, ref Size psize, IntPtr hdcSrc, ref Point pptSrc, uint crKey, [In] ref BLENDFUNCTION pblend, uint dwFlags);

    [DllImport("user32.dll")]
    public static extern IntPtr GetDesktopWindow();

    [DllImport("user32.dll")]
    public static extern IntPtr GetWindowDC(IntPtr ptr);

    [DllImport("gdi32.dll")]
    public static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int nWidth, int nHeight);

    [DllImport("gdi32.dll")]
    public static extern bool BitBlt(IntPtr hdcDest, int xDest, int yDest, int wDest, int hDest, IntPtr hdcSource, int xSrc, int ySrc, CopyPixelOperation rop);

    [DllImport("user32.dll")]
    public static extern IntPtr GetForegroundWindow();

    [DllImport("user32.dll")]
    public static extern bool GetWindowRect(IntPtr hWnd, out RECT rect);

    public const byte AC_SRC_OVER = 0;
    public const byte AC_SRC_ALPHA = 1;
    public const byte ULW_ALPHA = 2;

    [StructLayout(LayoutKind.Sequential, Pack = 1)]
    public struct BLENDFUNCTION
    {
        public byte BlendOp;
        public byte BlendFlags;
        public byte SourceConstantAlpha;
        public byte AlphaFormat;
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct RECT
    {
        public int Left;
        public int Top;
        public int Right;
        public int Bottom;
    }
}
于 2012-12-23T15:21:39.720 に答える