Uzman Üye
Kendi Penceremi Oyun Penceresine Bağlamak İstiyorum Nereye Giderse Gitsin Takip Edicek Ve Üstünde Durucak Yani Overlay Diyebiliriz.
Denediklerim:
1.
Bunda oyun penceresinin parentliğini kendi üstüme alıyorum bu sayede benim formum devamlı üstte kalıyor ayrıca takip etmesi için task.factory kullanıyorum fakat çok fazla cpu kullanıyor o yüzden cpuhelper yaptım onu kullanıncada gecikme oluyor
2.
bunu yapınca kendi formumu oyunun childi yapıyorum bu sayede gecikmesiz takip ediyor fakat oyun child formun üstüne drawlıyor bu olunca bizim form gözükmüyor.
çözüm bulanlara şimdiden teşekkürler.
Denediklerim:
1.
Kod:
public int cpuhelper = 0;
public const string gamename = "oyun";
public struct RECT
{
public int left, top, right, bottom;
}
private void Form1_Load(object sender, EventArgs e)
{
this.FormBorderStyle = FormBorderStyle.None;
this.BackColor = System.Drawing.Color.Wheat;
this.TransparencyKey = System.Drawing.Color.Wheat;
int initialStyle = GetWindowLong(this.Handle, -20);
SetWindowLong(this.Handle, -20, initialStyle | 0x80000 | 0x20);
var oyunh = Process.GetProcessesByName("oyun").FirstOrDefault();
if (oyunh != null)
{
var owner = oyunh.MainWindowHandle;
var owned = this.Handle;
var i = SetWindowLong(owned, -8 , owner);
}
reducer.CheckedChanged += reducervoid;
Gui.CheckForIllegalCrossThreadCalls = false;
showcgui();
this.SetStyle(
ControlStyles.AllPaintingInWmPaint |
ControlStyles.UserPaint |
ControlStyles.DoubleBuffer,
true);
Task t = Task.Factory.StartNew(() =>
{
allinone();
});
}
void reducervoid(object sender, EventArgs e)
{
if (reducer.Checked == true)
{
cpuhelper = 1;
}
else if (reducer.Checked == false)
{
cpuhelper = 0;
}
}
private async void allinone()
{
while (true)
{
await Task.Delay(cpuhelper);
Process[] procs = Process.GetProcessesByName("oyun");
if (procs.Length == 0)
{
Environment.Exit(0);
}
else
{
foreach (Process proc in procs)
{
RECT outrect;
GetWindowRect(handle, out outrect);
this.Top = outrect.top;
this.Left = outrect.left;
}
}
}
}
Bunda oyun penceresinin parentliğini kendi üstüme alıyorum bu sayede benim formum devamlı üstte kalıyor ayrıca takip etmesi için task.factory kullanıyorum fakat çok fazla cpu kullanıyor o yüzden cpuhelper yaptım onu kullanıncada gecikme oluyor
2.
C#:
public static uint MF_BYPOSITION = 0x400;
public static uint MF_REMOVE = 0x1000;
public static int GWL_STYLE = -16;
public static int WS_CHILD = 0x40000000;
public static int WS_BORDER = 0x00800000;
public static int WS_DLGFRAME = 0x00400000;
public static int WS_CAPTION = WS_BORDER | WS_DLGFRAME;
public static int WS_SYSMENU = 0x00080000;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Process oyun = Process.GetProcessesByName("oyun").FirstOrDefault();
if (oyun != null)
{
Hide();
FormBorderStyle = FormBorderStyle.None;
SetBounds(0, 0, 0, 0, BoundsSpecified.Location);
IntPtr oyunh = oyun.MainWindowHandle;
IntPtr formh = this.Handle;
SetWindowLong(formh, GWL_STYLE, GetWindowLong(formh, GWL_STYLE) | WS_CHILD);
SetParent(formh, oyunh);
Show();
}
}
}
}
bunu yapınca kendi formumu oyunun childi yapıyorum bu sayede gecikmesiz takip ediyor fakat oyun child formun üstüne drawlıyor bu olunca bizim form gözükmüyor.
çözüm bulanlara şimdiden teşekkürler.
Son düzenleme: