3

オーバーレイを作成しています。私はここにこのコードを持っています

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;


    namespace HyperBox
    {

public partial class Form1 : Form
{

    public Form1()
    {
        InitializeComponent();

        this.TopMost = true; // make the form always on top
        this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; // hidden border
        this.WindowState = FormWindowState.Maximized; // maximized
        this.MinimizeBox = this.MaximizeBox = false; // not allowed to be minimized
        this.MinimumSize = this.MaximumSize = this.Size; // not allowed to be resized
        this.TransparencyKey = this.BackColor = Color.Red; // the color key to transparent, choose a color that you don't use

        // Set the form click-through
        int initialStyle = GetWindowLong(this.Handle, -20);
        SetWindowLong(this.Handle, -20, initialStyle | 0x80000 | 0x20);
    }

    [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
    static extern int GetWindowLong(IntPtr hWnd, int nIndex);

    [System.Runtime.InteropServices.DllImport("user32.dll")]
    static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
    [System.Runtime.InteropServices.DllImport("user32.dll")]
    static extern bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha,         uint dwFlags);
    [System.Runtime.InteropServices.DllImport("user32.dll")]
    static extern int SetParent(int hWndChild, int hWndNewParent);


    protected override void OnPaint(PaintEventArgs e)
    {
        base.OnPaint(e);
        // draw what you want
        e.Graphics.FillEllipse(Brushes.Blue, 30, 30, 100, 100);

    }
    private void Form1_MouseMove(object sender, MouseEventArgs e)
    {

    }

    private void Form1_Paint(object sender, PaintEventArgs e)
    {

    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }



}

    }

透明で常に上にあるフォームに楕円を描画します。問題は、フルスクリーンでは機能しないことです。

これを使ってみました

    SetParent(this.handle, FindWindow(null, "<parent window title here>"));

エラーが発生することを除いて。誰か助けてもらえますか?

4

1 に答える 1

3

あなたの間違いはここにあると思います

[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern int SetParent(int hWndChild, int hWndNewParent);

not型の2つの引数を期待しており、 IntPtrnotをint返します。IntPtrint

MSDNはより多くの情報を提供します。いくつかの良いC#の例については、下部にあるユーザーの貢献を参照してください。

externは、と一緒に使用するとDllImport、アンマネージコードへの参照になることに注意してください。user32.dllで呼び出されるメソッドには、パラメーターとしてSetParent()2つのを受け入れる定義がありません。int

そのため、そのブロックは次のようになります。

[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
于 2012-11-10T03:39:23.780 に答える