Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C#] Macro wont stop when form is closed

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Sneak
Grandmaster Cheater Supreme
Reputation: 0

Joined: 05 Nov 2008
Posts: 1895

PostPosted: Sun Sep 27, 2009 3:10 pm    Post subject: [C#] Macro wont stop when form is closed Reply with quote

Code:
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;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;


namespace AFKBot

{
    public partial class Form1 : Form
    {
        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers,
           uint vk);
        [DllImport("user32.dll")]
        private static extern bool UnregisterHotKey(IntPtr hWnd, int id);

        [DllImport("user32.dll", SetLastError = true)]
        static extern IntPtr FindWindow(
            string lpClassName,
            string lpWindowName);
           


        [DllImport("user32.dll")]
        public static extern bool PostMessage(
            IntPtr hWnd,
            uint Msg,
            int wParam,
            int lParam
            );
        const int WM_KEYDOWN = 0x100;
        IntPtr hWnd = FindWindow(
            null,
            "Combat_Arms");

        [DllImport("user32.dll")]
        public static extern uint MapVirtualKey(uint uCode, uint uMapType);
           

       


        [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);

        [DllImport("user32.dll")]
        public static extern short VkKeyScan(char ch);

        [DllImport("user32.dll", EntryPoint = "SetCursorPos")]
        internal extern static int SetCursorPos(int x, int y);
        private const int MOUSEEVENTF_LEFTDOWN = 0x02;
        private const int MOUSEEVENTF_LEFTUP = 0x04;
        private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
        private const int MOUSEEVENTF_RIGHTUP = 0x10;

       

        public Form1()
        {
            Thread myThread = new Thread(MyClick);
            InitializeComponent();
            RegisterHotKey(this.Handle, 10, 0, 0x70);//F1
        }

        private Thread m_ClickThread;

        void MyClick()
        {
            while (true)
            {
                System.Threading.Thread.Sleep(5000);
                Cursor.Position = new Point((int)800, (int)500);
                int X = Cursor.Position.X;
                int Y = Cursor.Position.Y;
                mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0);
            }
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
           
            if (checkBox1.Checked)
            {
                m_ClickThread = new Thread(MyClick);
                m_ClickThread.Start();
            }
            else
            {
                m_ClickThread = new Thread(MyClick);
                m_ClickThread.Abort();
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {

        }

        private void Form1_Load_1(object sender, EventArgs e)
        {
           
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            PostMessage(hWnd, WM_KEYDOWN, 0x10, 0x2a0001);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Process.Start(@"C:\Documents and Settings\Administrator\Desktop\Head Shot.exe");
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            m_ClickThread = new Thread(MyClick);
            m_ClickThread.Abort();
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            m_ClickThread = new Thread(MyClick);
            m_ClickThread.Abort();
        }
    }
}


when I check checkbox1, the only way the macro stops is if I end the process

_________________
Back to top
View user's profile Send private message
XiO
Newbie cheater
Reputation: 0

Joined: 27 Sep 2009
Posts: 22

PostPosted: Sun Sep 27, 2009 3:35 pm    Post subject: Reply with quote

Idea Your so brilliant! I would have never thought to put a new thread when I'm trying to abort! Rolling Eyes
Back to top
View user's profile Send private message
Sneak
Grandmaster Cheater Supreme
Reputation: 0

Joined: 05 Nov 2008
Posts: 1895

PostPosted: Sun Sep 27, 2009 3:46 pm    Post subject: Reply with quote

:O, idk if I should say thanks, or fuck off, you person with a high concentration of pigment in his skin!
_________________
Back to top
View user's profile Send private message
XiO
Newbie cheater
Reputation: 0

Joined: 27 Sep 2009
Posts: 22

PostPosted: Sun Sep 27, 2009 4:39 pm    Post subject: Reply with quote

If you wanna be like the rest of CEF, go with the latter. Besides, I am not a person with a high concentration of pigment in his skin.
Back to top
View user's profile Send private message
Jesper
Grandmaster Cheater Supreme
Reputation: 9

Joined: 21 Feb 2007
Posts: 1156

PostPosted: Sun Sep 27, 2009 4:40 pm    Post subject: Reply with quote

Try putting this.close(); or form1.close(); in the FormClosed.
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Sun Sep 27, 2009 5:31 pm    Post subject: Reply with quote

Processes don't end until all the threads have stopped executing, which means making a new thread just to kill it in the next line doesn't do anything (read: seven different shades of completely useless).

Unless of course your objective was to make yourself look like a fool. Mission complete.
Back to top
View user's profile Send private message
Sneak
Grandmaster Cheater Supreme
Reputation: 0

Joined: 05 Nov 2008
Posts: 1895

PostPosted: Sun Sep 27, 2009 7:10 pm    Post subject: Reply with quote

xD thx y'all. Got it fixed
_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites