ARKBreedingStats.Win32Stuff.SetForegroundWindow C# (CSharp) Method

SetForegroundWindow() private method

private SetForegroundWindow ( IntPtr hWnd ) : int
hWnd IntPtr
return int
        public static extern int SetForegroundWindow(IntPtr hWnd);

Usage Example

Example #1
0
        public float[] doOCR(out string OCRText, out string dinoName, string useImageFilePath = "", bool changeForegroundWindow = true)
        {
            string finishedText = "";

            dinoName = "";
            float[] finalValues = new float[1] {
                0
            };

            Bitmap screenshotbmp = null;// = (Bitmap)Bitmap.FromFile(@"D:\ScreenshotsArk\Clipboard12.png");
            Bitmap testbmp;

            debugPanel.Controls.Clear();

            if (System.IO.File.Exists(useImageFilePath))
            {
                screenshotbmp = (Bitmap)Bitmap.FromFile(useImageFilePath);
            }
            else
            {
                // grab screenshot from ark
                screenshotbmp = Win32Stuff.GetSreenshotOfProcess("ShooterGame");
                //screenshotbmp.Save(@"D:\ScreenshotsArk\Clipboard02.png");
            }
            if (screenshotbmp == null)
            {
                OCRText = "Error: no image for OCR. Is ARK running?";
                return(finalValues);
            }
            if (!calibrate(screenshotbmp))
            {
                OCRText = "Error while calibrating: probably game-resolution is not supported by this OCR";
                return(finalValues);
            }
            finalValues = new float[statPositions.Count];

            AddBitmapToDebug(screenshotbmp);
            if (changeForegroundWindow)
            {
                Win32Stuff.SetForegroundWindow(Application.OpenForms[0].Handle);
            }

            int count = -1;

            foreach (String statName in statPositions.Keys)
            {
                count++;
                testbmp = SubImage(screenshotbmp, statPositions[statName].X, statPositions[statName].Y, 500, 30); // 300 is enough, except for the name
                AddBitmapToDebug(testbmp);

                bool onlyNumbers = coordsAfterDot; // hack for 1050, position just for coordinates

                string statOCR = "";

                if (statName == "NameAndLevel")
                {
                    statOCR = readImage(testbmp, true, false);
                }
                else
                {
                    statOCR = readImage(testbmp, true, onlyNumbers);
                }

                if (statName == "Oxygen" && statOCR == "")
                {
                    continue;
                }

                lastLetterositions[statName] = new Point(statPositions[statName].X + lastLetterPosition(removePixelsUnderThreshold(GetGreyScale(testbmp), whiteThreshold)), statPositions[statName].Y);

                finishedText += "\r\n" + statName + ": " + statOCR;

                // parse the OCR String

                Regex r;
                if (onlyNumbers)
                {
                    r = new Regex(@"((\d*[\.,']?\d?)\/)?(\d*[\.,']?\d?)");
                }
                else
                {
                    r = new Regex(@"([a-zA-Z]*)[:;]((\d*[\.,']?\d?)\/)?(\d*[\.,']?\d?)");
                }
                if (statName == "NameAndLevel")
                {
                    r = new Regex(@"(.*)-?Lv[liI](\d*)Eq");
                }

                MatchCollection mc = r.Matches(statOCR);

                if (mc.Count == 0)
                {
                    if (statName == "NameAndLevel")
                    {
                        continue;
                    }
                    else
                    {
                        OCRText = finishedText + "error reading stat " + statName;
                        return(finalValues);
                    }
                }

                String testStatName = mc[0].Groups[1].Value;
                float  v            = 0;
                float.TryParse(mc[0].Groups[mc[0].Groups.Count - 1].Value.Replace('\'', '.').Replace(',', '.').Replace('O', '0'), System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.GetCultureInfo("en-US"), out v); // common substitutions: comma and apostrophe to dot,

                if (statName == "NameAndLevel")
                {
                    if (testStatName.EndsWith("-"))
                    {
                        dinoName = testStatName.Substring(0, testStatName.Length - 1);
                    }
                    else
                    {
                        dinoName = testStatName;
                    }
                }
                // TODO: test here that the read stat name corresponds to the stat supposed to be read
                finalValues[count] = v;
            }

            OCRText = finishedText;

            return(finalValues);

            Bitmap grab = Win32Stuff.GetSreenshotOfProcess("ShooterGame");

            AddBitmapToDebug(grab);

            //grab.Save("E:\\Temp\\Calibration8.png", ImageFormat.Png);
            if (changeForegroundWindow)
            {
                Win32Stuff.SetForegroundWindow(Application.OpenForms[0].Handle);
            }
        }
All Usage Examples Of ARKBreedingStats.Win32Stuff::SetForegroundWindow