示例#1
0
        static void Main(string[] args)
        {
            //murder console window
            var handle = ExternalAPIs.GetConsoleWindow();

#if !DEBUG
            // Hide
            ExternalAPIs.ShowWindow(handle, ExternalAPIs.SW_HIDE);
#else
            // Show
            ExternalAPIs.ShowWindow(handle, ExternalAPIs.SW_SHOW);
#endif

            Console.WriteLine("It starts.");
            Application.Run(new TrayApp());

            Console.WriteLine("Press Enter to Exit...");
        }
示例#2
0
        public TrayApp()
        {
            m_hWnd = ExternalAPIs.GetConsoleWindow();
            Console.WriteLine("Hello from the TrayApp:{0}", Thread.CurrentThread.ManagedThreadId);
            MenuItem exitMenuItem   = new MenuItem("Exit", new EventHandler(Exit));
            MenuItem KickThreadItem = new MenuItem("Race!", new EventHandler(Walk));
            MenuItem GetSpriteItem  = new MenuItem("Get Sprite", new EventHandler(Get));
            MenuItem PauseItem      = new MenuItem("Pause", new EventHandler(Pause));
            MenuItem OrderItem      = new MenuItem("List O' Windows", new EventHandler(WindowOrder));

            notifyIcon.Icon        = OnIcon;
            notifyIcon.ContextMenu = new ContextMenu(new MenuItem[]
#if DEBUG
                                                     { OrderItem, PauseItem, GetSpriteItem, KickThreadItem, exitMenuItem });
            //Events Handlers
            MouseHook.Start();
            MouseHook.MouseAction += new EventHandler(TrayApp_Click);
#else
                                                     { PauseItem, GetSpriteItem, KickThreadItem, exitMenuItem });
示例#3
0
        static public void KickWalkerThread(SpriteImporter.SPRITE sprite)
        {
            Console.WriteLine("Before the Thread starts.");
            new Thread(() =>
            {//The sprites run on this thread.
                Console.WriteLine("Hello from Thread:{0}", Thread.CurrentThread.ManagedThreadId);
                Form form          = new Form();
                form.StartPosition = FormStartPosition.Manual;
                hWnd = ExternalAPIs.GetConsoleWindow();

                #region Finding Screen Area
                form.Bounds           = GetFormRectangle(sprite.bitmap);
                List <Screen> screens = GetScreenArea();
                int leftSide          = MostLeft(screens);//Strong side
                int rightSide         = MostRight(screens);
                #endregion

                #region Adding PictureBox
                form.FormBorderStyle = FormBorderStyle.None;
                form.BackColor       = Color.DodgerBlue;
                form.TransparencyKey = Color.FromArgb(0, Color.DodgerBlue);
                form.Icon            = TrayApp.OnIcon;

                PictureBox pic = new PictureBox()
                {
                    Left = form.Right, SizeMode = PictureBoxSizeMode.AutoSize
                };
                if (sprite.bitmap == null)
                {
                    pic.Load(sprite.filename);
                }
                else
                {
                    pic.Image = sprite.bitmap;
                }
                pic.Top  = 0;
                pic.Left = 0;
                form.Controls.Add(pic);
                #endregion

                #region Animation
                System.Windows.Forms.Timer timeout = new System.Windows.Forms.Timer();

                var top   = ExternalAPIs.GetTopWindow((IntPtr)null);
                var local = hWnd;

                System.Windows.Forms.Timer animation = new System.Windows.Forms.Timer();
                animation.Tick += new System.EventHandler((sender, e) =>
                {
                    var templocal = ExternalAPIs.GetConsoleWindow();
                    if (templocal != local)
                    {
                        local = templocal;
                        Console.WriteLine("\tTop most window: {0}", top);
                        Console.WriteLine("\tLocal Window local: {0}", local);
                    }
                    var temptop = ExternalAPIs.GetTopWindow((IntPtr)null);
                    if (temptop != top)
                    {
                        top = temptop;
                        Console.WriteLine("\tTop most window: {0}", top);
                        Console.WriteLine("\tLocal Window local: {0}", local);
                    }
                    Thread.BeginCriticalRegion();
                    try
                    {
                        if (pic.Right < leftSide || form.Right < leftSide)
                        {
                            form.TopMost = false; form.TopLevel = false; form.Visible = false; form.Close();
                        }
                        form.Left -= pic.Width / sprite.jumpDiv;
                    }
                    catch (Exception ex) { Debug.WriteLine(ex.Message); }
                    Thread.EndCriticalRegion();
                });
                animation.Interval = sprite.tickSpeed;
                animation.Enabled  = true;
                #endregion

                location              = new Point(rightSide, Screen.PrimaryScreen.Bounds.Bottom - pic.Height - TASKBAR_HEIGHT);
                form.LocationChanged += new System.EventHandler(locationChangeEvent);

                form.TopMost      = true;
                form.FormClosing += new FormClosingEventHandler((sender, e)
                                                                => { animation.Stop(); timeout.Stop(); });
                Thread.BeginCriticalRegion();
                Console.WriteLine("Show Dialog");
                form.ShowDialog();
                Thread.EndCriticalRegion();
                //Application.Run(f);
            }).Start();
        }