Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using System.Runtime.InteropServices;
- using System.Threading;
- namespace diwifgc
- {
- public partial class Form1 : Form
- {
- public const string gamename = "Subnautica"; // Change this to your game's window name!!!
- //Including WINApi functions. You can find those on PInvoke.net
- [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
- static extern IntPtr FindWindowByCaption(IntPtr ZeroOnly, string lpWindowName);
- [DllImport("user32.dll")]
- static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
- [DllImport("user32.dll", SetLastError = true)]
- static extern int GetWindowLong(IntPtr window, int index);
- IntPtr handle = FindWindowByCaption(IntPtr.Zero, gamename);
- [DllImport("user32.dll")]
- static extern IntPtr GetForegroundWindow();
- [DllImport("user32.dll", SetLastError = true)]
- static extern bool GetWindowRect(IntPtr hwnd, out RECT lpRect);
- // Making basic RECT struct for GetWindowRect function.
- public struct RECT
- {
- public int left, top, right, bottom;
- }
- // Making the graphics object.
- System.Drawing.Graphics g;
- RECT outrect;
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- this.SetStyle(
- ControlStyles.AllPaintingInWmPaint |
- ControlStyles.UserPaint |
- ControlStyles.DoubleBuffer,
- true);
- this.FormBorderStyle = FormBorderStyle.None;
- this.BackColor = System.Drawing.Color.Black;
- this.TransparencyKey = System.Drawing.Color.Black;
- this.TopMost = true;
- /* Making the RECT object that will handle info from WINApi function. */
- /* Saving data to that object */
- GetWindowRect(handle, out outrect);
- /* Change the size of the form to the size of the Game window. */
- this.Size = new Size(outrect.right - outrect.left, outrect.bottom - outrect.top);
- this.Top = outrect.top;
- this.Left = outrect.left;
- /* Change the position of the form to the position of the Game window. */
- /* Change form's style to make it transparent and to remove the border */
- this.FormBorderStyle = FormBorderStyle.None;
- this.BackColor = System.Drawing.Color.Black;
- this.TransparencyKey = System.Drawing.Color.Black;
- /* Using WINApi function GetWindowLong and SetWindowLong to be able to click throught the form */
- int initialStyle = GetWindowLong(this.Handle, -20);
- SetWindowLong(this.Handle, -20, initialStyle | 0x80000 | 0x20);
- /* Make the form on top of other windows */
- this.TopMost = true;
- /* Change Form1 to your form's name if you have different.
- This is actually bad thing to do, but this will allow you to skip writing much code for our threading */
- Form1.CheckForIllegalCrossThreadCalls = false;
- Thread PrePaintThread = new Thread(new ThreadStart(prepaint));
- PrePaintThread.Start();
- //Thread stickThread = new Thread(new ThreadStart(stick));
- //stickThread.Start();
- }
- private void prepaint()
- {
- while (true)
- {
- this.Refresh();
- /* Refresh rate is 50ms */
- System.Threading.Thread.Sleep(50);
- }
- }
- /*
- public void stick()
- {
- while (true)
- {
- this.Top = outrect.top;
- this.Left = outrect.left;
- }
- }
- */
- private void Form1_Paint(object sender, PaintEventArgs e)
- {
- g = e.Graphics;
- painttext(g);
- }
- private void painttext(System.Drawing.Graphics g)
- {
- /* Make a new font object for drawing */
- Font bigFont = new Font("Arial", 20);
- /* Make a colored brush for drawing text */
- Brush mybrush = new SolidBrush(Color.White);
- /* Draw 'Hello, World' at position 50, 50 of the game window */
- g.DrawString("Hello, World!", bigFont, mybrush, 50, 50);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement