示例#1
0
 public static extern bool ClientToScreen(IntPtr hWnd, ref PointINT lpPoint);
示例#2
0
        public static void initWOTArgs()
        {
            bool wot_alive = false;
            if (Process.GetProcessesByName("WorldOfTanks").Length > 0)
                wot_alive = true;

            if (!wot_alive)
            {
                Helper.LogInfo("world of tanks not alive");
                return;
            }
            /*
            StringBuilder b = new StringBuilder(2000);
            GetWindowText(handle, b, 2000);
            Helper.LogDebug("GetWindowText" + b.ToString());
             */

            Process[] processes = Process.GetProcessesByName("WorldOfTanks");
            if (processes.Length == 0)
            {
                Helper.LogException("There's no open worldoftanks.exe");
                MessageBox.Show("There's no open worldoftanks.exe");
                Environment.Exit(0);
            }
            Process process = processes[0];
            Helper.LogInfo("worldoftanks.exe with pid " + process.Id);
            TBConst.pid = process.Id;
            TBConst.wotHandle = process.MainWindowHandle;
            RECT rct;
            int width;
            int height;
            Helper.GetWindowRect(new HandleRef(null, TBConst.wotHandle), out rct);
            width = rct.Right - rct.Left;
            height = rct.Bottom - rct.Top;

            RECT client;

            Helper.GetClientRect(TBConst.wotHandle, out client);
            Helper.LogInfo("client.right  " + client.Right + " client.bottom " + client.Bottom);
            width += 1280 - client.Right;
            height += 768 - client.Bottom;

            PointINT p = new PointINT(0, 0);
            Helper.ClientToScreen(TBConst.wotHandle, ref p);
            // correct the window size
            if (client.Right != 1280 || client.Bottom != 768)
            {
                Helper.LogInfo("client height and width not correct. correcting it");

                Helper.MoveWindow(TBConst.wotHandle, rct.Left, rct.Top, width, height, false);
            }
            Helper.LogInfo("width " + width + " height " + height);

            Helper.GetClientRect(TBConst.wotHandle, out client);
            if (client.Right != 1280 || client.Bottom != 768)
            {
                Helper.LogException("client Height and Width is not 1280x768");
                //MessageBox.Show("client Height and Width is not 1280x768");
                //Environment.Exit(0);
            }

            Thread.Sleep(20);
            TBConst.windowX = p.X;
            TBConst.windowY = p.Y;

            TBConst.botPort = TBConst.pid % 10000 + 10000;
            Helper.LogInfo("botPort" + TBConst.botPort);
        }