2012-11-09 4 views
3

오버레이를 만들고 있습니다. 나는이 코드를 여기에 가지고있다.폼의 부모를 "FindWindow"로 설정하십시오.

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) 
    { 

    } 



} 

    } 

투명하고 항상 온다 (ontop) 형태로 타원을 그린다. 문제는 전체 화면에서 작동하지 않는다는 것입니다.

내가 오류를 얻을 제외하고이

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

를 사용하여 시도했다. 누군가 제발 도와 줄 수 있니?

+0

을 당신이지고있는 오류에 대한 궁금 ... –

+0

오류는 다음과 같습니다 인수 1 : 'System.IntPtr 이름'에서 INT '로 변환 할 수 없습니다 INT '이 광고에 '에서 'System.IntPtr 이름' 2 인수로 변환 할 수없는 ' 는, setParent (this.Handle,를 FindWindow (NULL, "")); –

답변

3

나는 당신의 오류 그것은 int을 입력 IntPtr의 두 개의 인수를하지 기대하고 있어요 바로 여기

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

이라고 생각하고 그것은 IntPtr 아닌 int 반환합니다.

MSDN은 더 많은 정보를 제공합니다. 좋은 C# 예제를 보려면 맨 아래쪽에있는 사용자 기여도를 참조하십시오.

DllImport과 함께 사용되는 extern은 비 관리 코드에 대한 참조입니다. user32.dll에 SetParent()이라는 메서드가 두 개의 int을 매개 변수로 허용하는 정의를 가지고 있지 않습니다.

그래서 블록을 읽어야합니다

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