Uzman Üye
Çoğu Kod Videodan Bakılmıştır Diğerleri Yardım Alınarak.
Edit:en aşşağıdaki top most kodu biraz sıkıntılıdır nedenini bilmiyorum
-------------------------------------------------------------------------------
Edit:en aşşağıdaki top most kodu biraz sıkıntılıdır nedenini bilmiyorum
-------------------------------------------------------------------------------
PHP:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace projeadı
{
public partial class formadı : Form
{
RECT rect;
public const string WINDOW_NAME = "oyun adı";
IntPtr handle = FindWindow(null, WINDOW_NAME);
public struct RECT
{
public int left, top, right, bottom;
}
[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
[DllImport("user32.dll", SetLastError = true)]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr FindWindow(string ipClassName, string ipWindowName);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetWindowRect(IntPtr hwnd, out RECT lpRect);
[DllImport("user32.dll")]
static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);
private void formadı_Load(object sender, EventArgs e)
{
this.BackColor = Color.Wheat; //System.Drawing.Color.Black; Daha iyi Gözükür
this.TransparencyKey = Color.Wheat; //System.Drawing.Color.Black; Daha iyi Gözükür
this.TopMost = true; //açıldığında devamlı önde kalmasını sağlar
this.FormBorderStyle = FormBorderStyle.None; //programın penceri kısmını siler
this.ShowInTaskbar = false; //görev çubuğunda gözükmemesini sağlar
this.DoubleBuffered = true; //titrememesini sağlar
int initialStyle = GetWindowLong(this.Handle, -20);
SetWindowLong(this.Handle, -20, initialStyle | 0x80000 | 0x20); //mousenin formun içinde geçmesini sağlar
private string GetActiveWindowTitle()
{
const int nChars = 256;
StringBuilder Buff = new StringBuilder(nChars);
IntPtr handle = GetForegroundWindow();
if (GetWindowText(handle, Buff, nChars) > 0)
{
return Buff.ToString();
}
return null;
}
//bunuda timere yazıcaksınız bu kod oyun penceresinin kordinatını alıp formu devamlı orda tutar ayrıca timerin intervalını 1 yapmayı unutmayın
{
GetWindowRect(handle, out rect);
this.Top = rect.top;
this.Left = rect.left;
}
//buda timere yazılacak eğer oyun kapalıysa otomatikmen program kapanır
Process[] p = Process.GetProcessesByName("oyun ismi);
// If Notting Found (Length = 0)
if (p.Length == 0)
{
Application.Exit();
}
//timere yazılacak kod ,bu kod oyun öndeyse formu devamlı önde tutar arkadaysa arkada tutar
if (GetActiveWindowTitle() == "oyunun ismi")
{
this.TopMost = true;
}
else
{
this.TopMost = false;
}
Son düzenleme: