Advertisement
Lirbo

Form1

Apr 16th, 2020
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.50 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Runtime.InteropServices;
  11. using System.Threading;
  12. using System.Diagnostics;
  13.  
  14. namespace MapleLegends_Overlay
  15. {
  16.     public partial class Form1 : Form
  17.     {
  18.  
  19.         [DllImport("user32.dll")]
  20.         static extern IntPtr SetParent(IntPtr hwc, IntPtr hwp);
  21.  
  22.         // Define the FindWindow API function.
  23.         [DllImport("user32.dll", EntryPoint = "FindWindow",
  24.             SetLastError = true)]
  25.         static extern IntPtr FindWindowByCaption(IntPtr ZeroOnly,
  26.             string lpWindowName);
  27.  
  28.         // Define the SetWindowPos API function.
  29.         [DllImport("user32.dll")]
  30.         [return: MarshalAs(UnmanagedType.Bool)]
  31.         static extern bool SetWindowPos(IntPtr hWnd,
  32.             IntPtr hWndInsertAfter, int X, int Y, int cx, int cy,
  33.             SetWindowPosFlags uFlags);
  34.  
  35.         // Define the SetWindowPosFlags enumeration.
  36.         [Flags()]
  37.         private enum SetWindowPosFlags : uint
  38.         {
  39.             SynchronousWindowPosition = 0x4000,
  40.             DeferErase = 0x2000,
  41.             DrawFrame = 0x0020,
  42.             FrameChanged = 0x0020,
  43.             HideWindow = 0x0080,
  44.             DoNotActivate = 0x0010,
  45.             DoNotCopyBits = 0x0100,
  46.             IgnoreMove = 0x0002,
  47.             DoNotChangeOwnerZOrder = 0x0200,
  48.             DoNotRedraw = 0x0008,
  49.             DoNotReposition = 0x0200,
  50.             DoNotSendChangingEvent = 0x0400,
  51.             IgnoreResize = 0x0001,
  52.             IgnoreZOrder = 0x0004,
  53.             ShowWindow = 0x0040,
  54.         }
  55.  
  56.         [DllImport("user32.dll", SetLastError = true)]
  57.         static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint processId);
  58.  
  59.         Overlay frm = new Overlay();
  60.         public Form1()
  61.         {
  62.             InitializeComponent();
  63.         }
  64.  
  65.         private void checkBox1_CheckedChanged(object sender, EventArgs e)
  66.         {
  67.             if(checkBox1.Checked == true)
  68.             {
  69.  
  70.                 frm.Show();
  71.             }
  72.             else
  73.             {
  74.                 frm.Hide();
  75.             }
  76.         }
  77.  
  78.         private void button1_Click(object sender, EventArgs e)
  79.         {
  80.             //Process p = Process.Start("c:/MapleLegendsHD/MapleLegends.exe");
  81.             int pidint = Convert.ToInt32(PID.Text);
  82.             Process p = Process.GetProcessById(pidint);
  83.             Thread.Sleep(1000);
  84.             p.WaitForInputIdle();
  85.             SetParent(p.MainWindowHandle, GamePanel.Handle);
  86.             SetFullScreen(true);
  87.             // Find (the first-in-Z-order) Notepad window.
  88.         }
  89.  
  90.         private void Form1_Layout(object sender, LayoutEventArgs e)
  91.         {
  92.             button1.BringToFront();
  93.         }
  94.  
  95.         private void timer1_Tick(object sender, EventArgs e)
  96.         {
  97.             if(this.WindowState == FormWindowState.Maximized)
  98.             {
  99.                 GamePanel.Size = new Size(this.Width, this.Height);
  100.             }
  101.             else
  102.             {
  103.                 GamePanel.Size = new Size(728, 246);
  104.             }
  105.  
  106.             if(MouseInfo.Checked == true)
  107.             {
  108.                 MouseInfoLabel.Visible = true;
  109.                 Point p = GamePanel.PointToClient(Cursor.Position);
  110.                 //MouseInfoLabel.Location = p;
  111.                 MouseInfoLabel.Text = p.ToString();
  112.             }
  113.             else
  114.             {
  115.                 MouseInfoLabel.Visible = false;
  116.             }
  117.         }
  118.  
  119.         private void Form1_Load(object sender, EventArgs e)
  120.         {
  121.            
  122.         }
  123.  
  124.         private void FullScreen_Click(object sender, EventArgs e)
  125.         {
  126.             if (FullScreen.Text == "X")
  127.                 SetFullScreen(false);
  128.  
  129.             else
  130.                 SetFullScreen(true);
  131.         }
  132.  
  133.         private bool SetFullScreen(bool ans)
  134.         {
  135.             if(ans == true)
  136.             {
  137.                 this.FormBorderStyle = FormBorderStyle.None;
  138.                 this.TopMost = true;
  139.                 this.WindowState = FormWindowState.Maximized;
  140.                 FullScreen.Text = "X";
  141.                 FullScreen.ForeColor = Color.Red;
  142.                 ControlPanel.Visible = false;
  143.             }
  144.             else
  145.             {
  146.                 this.FormBorderStyle = FormBorderStyle.Sizable;
  147.                 this.TopMost = false;
  148.                 this.WindowState = FormWindowState.Normal;
  149.                 FullScreen.Text = "+";
  150.                 FullScreen.ForeColor = Color.Green;
  151.                 ControlPanel.Visible = true;
  152.             }
  153.             return false;
  154.         }
  155.  
  156.         private void button2_Click(object sender, EventArgs e)
  157.         {
  158.             /*int pidint = Convert.ToInt32(PID2.Text);
  159.             Process p = Process.GetProcessById(pidint);
  160.             Thread.Sleep(1000);
  161.             p.WaitForInputIdle();
  162.             SetParent(p.MainWindowHandle, Game2Panel.Handle);*/
  163.         }
  164.  
  165.         private void MouseInfo_CheckedChanged(object sender, EventArgs e)
  166.         {
  167.             Bitmap bitmap = Screenshot(GamePanel);
  168.             bitmap.Save("test.bmp");
  169.             Process.Start("test.bmp");
  170.         }
  171.  
  172.         private static Bitmap Screenshot(Control control)
  173.         {
  174.             Bitmap bmpScreenshot = new Bitmap(control.Width, control.Height);
  175.             Graphics g = Graphics.FromImage(bmpScreenshot);
  176.             Rectangle r = control.RectangleToScreen(control.ClientRectangle);
  177.             Point p = new Point(212, 760);
  178.             Size s = new Size(350, 45);
  179.             g.CopyFromScreen(r.Location, Point.Empty, control.Size);
  180.             return bmpScreenshot;
  181.         }
  182.  
  183.         /*private void button3_Click(object sender, EventArgs e)
  184.         {
  185.             IntPtr hWnd = this.Handle;
  186.             UInt32 pidint = Convert.ToUInt32(PID2.Text, 16);
  187.             uint processid = pidint;
  188.             uint threadid = GetWindowThreadProcessId((IntPtr)hWnd, out processid);
  189.             if (hWnd == IntPtr.Zero)
  190.             {
  191.                 MessageBox.Show("Could not find this process.");
  192.                 return;
  193.             }
  194.  
  195.             // Set the window's position.
  196.             int width = int.Parse(txtWidth.Text);
  197.             int height = int.Parse(txtHeight.Text);
  198.             int x = int.Parse(txtX.Text);
  199.             int y = int.Parse(txtY.Text);
  200.             SetWindowPos(hWnd, IntPtr.Zero, x, y, width, height, 0);
  201.         }*/
  202.     }
  203. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement