Пример #1
0
 public static void FullscreenOff()
 {
     if (fullscreen)
     {
         try
         {
             windowPosition.FullscreenPosition = WindowPosition.Serialize(Form1.thisForm);
             fullscreen = false;
             if (dxDevice != null)
             {
                 dxDevice.RestoreDisplayMode();
             }
             WindowPosition.Deserialize(Form1.thisForm, Global.windowPosition.MainFormPosition, true);
             if (Form1.thisForm.formOptions != null)
             {
                 WindowPosition.Deserialize(Form1.thisForm.formOptions, Global.windowPosition.OptionsFormPosition, true);
             }
             if (FormMonitor.isCreated())
             {
                 WindowPosition.Deserialize(FormMonitor.instance, Global.windowPosition.MonitorFormPosition, true);
             }
             Form1.thisForm.TopMost = Global.isTopMost();
             PInvokeFunc.SetWindowPos(gameWindow, IntPtr.Zero, oldGameLocation.X, oldGameLocation.Y, 0, 0, 21);
         }
         catch (Exception)
         {
         }
     }
 }
Пример #2
0
 public static string Translate(string source)
 {
     if (string.IsNullOrEmpty(source))
     {
         return(source);
     }
     mutex.WaitOne();
     try
     {
         byte[] inp  = MecabEncoding.GetBytes(source);
         IntPtr outp = mecab_sparse_tostr(mecab, inp);
         string result;
         if (outp != IntPtr.Zero)
         {
             result = MecabEncoding.GetString(PInvokeFunc.ByteArrayFromPtr(outp));
         }
         else
         {
             result = null;
         }
         return(result);
     }
     finally
     {
         mutex.ReleaseMutex();
     }
 }
Пример #3
0
        public void UpdatePos()
        {
            int border = (Form1.thisForm.Width - Form1.thisForm.ClientSize.Width) / 2;

            PInvokeFunc.SetWindowPos(Handle, Form1.thisForm.Handle, Form1.thisForm.Left + border, Form1.thisForm.Top + (Form1.thisForm.Height - border - Form1.thisForm.ClientSize.Height), Form1.thisForm.ClientSize.Width, Form1.thisForm.ClientSize.Height, 16);
            WindowState = Form1.thisForm.WindowState;
        }
Пример #4
0
        private static IntPtr LoadLibrary(string name)
        {
            string path = Path.Combine(InstallPath, name);

            return(PInvokeFunc.LoadLibraryEx(path, IntPtr.Zero, PInvokeFunc.LOAD_WITH_ALTERED_SEARCH_PATH));
            //return PInvokeFunc.LoadLibraryEx("C:\\RarExt.dll", IntPtr.Zero, PInvokeFunc.LOAD_WITH_ALTERED_SEARCH_PATH);
        }
Пример #5
0
 public void UpdateWindowsList(IntPtr[] all)
 {
     listBox1.Items.Clear();
     foreach (IntPtr hwnd in all)
     {
         string s = PInvokeFunc.GetWindowText(hwnd);
         listBox1.Items.Add(new AppRecord(s, hwnd));
     }
 }
Пример #6
0
        public static string Translate(string source)
        {
            if (source == null)
            {
                return(source);
            }
            bool haveLetters = false;

            foreach (char ch in source)
            {
                if (char.IsLetter(ch))
                {
                    haveLetters = true;
                    break;
                }
            }
            if (!haveLetters)
            {
                return(source);
            }
            //long before = DateTime.Now.Ticks;
            mutex.WaitOne();
            try
            {
                IntPtr outp;
                IntPtr tmp;
                uint   size;
                byte[] inp = Encoding932.GetBytes(source);
                TranslatePair(inp, out outp, out tmp, out size);
                string result;
                if (outp != IntPtr.Zero)
                {
                    result = Encoding932.GetString(PInvokeFunc.ByteArrayFromPtr(outp));
                    FreeAtlasData(outp, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
                }
                else
                {
                    result = null;
                }
                if (tmp != IntPtr.Zero)
                {
                    /*if (result != null)
                     * {
                     *  string s = Encoding932.GetString(PInvokeFunc.ByteArrayFromPtr(tmp));
                     *  result += " [" + s + "]";
                     * }*/
                    FreeAtlasData(tmp, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
                }
                return(result);
            }
            finally
            {
                mutex.ReleaseMutex();
                //Form1.Debug(((double)(DateTime.Now.Ticks - before) / 10000000).ToString());
            }
        }
Пример #7
0
 private static bool UnloadLibrary(IntPtr handle)
 {
     if (handle != IntPtr.Zero)
     {
         return(PInvokeFunc.FreeLibrary(handle));
     }
     else
     {
         return(false);
     }
 }
Пример #8
0
        //private delegate int AwuWordDelType(int x1, byte[] type, int x3, byte[] word);
        //private static AwuWordDelType AwuWordDel;

        private static Delegate LoadFunc(IntPtr module, string name, Type T)
        {
            IntPtr addr = PInvokeFunc.GetProcAddress(module, name);

            if (addr != IntPtr.Zero)
            {
                return(Marshal.GetDelegateForFunctionPointer(addr, T));
            }
            else
            {
                throw new Exception("Cannot load function " + name + "!");
            }
        }
Пример #9
0
        private static IntPtr[] GetPossibleWindows()
        {
            List <IntPtr> result = new List <IntPtr>();

            IntPtr[] all = PInvokeFunc.GetDesktopWindowHandles(IntPtr.Zero);
            uint     pid = 0;

            try
            {
                if (agth.CurrentApp != null)
                {
                    Process p = GetProcessByFullName(agth.CurrentApp);
                    if (p != null)
                    {
                        pid = (uint)p.Id;
                    }
                }
            }
            catch (Exception)
            {
            }
            foreach (IntPtr hwnd in all)
            {
                if (hwnd == Form1.thisForm.Handle)
                {
                    continue;
                }
                if (pid != 0)
                {
                    uint curPid;
                    PInvokeFunc.GetWindowThreadProcessId(hwnd, out curPid);
                    if (pid != curPid)
                    {
                        continue;
                    }
                }
                string s = PInvokeFunc.GetWindowText(hwnd);
                if (s == null || s == "")
                {
                    continue;
                }
                Rectangle rect = PInvokeFunc.GetWindowRect(hwnd);
                if (rect.Width >= 640 && rect.Width < 1300)
                {
                    result.Add(hwnd);
                }
            }
            return(result.ToArray());
        }
Пример #10
0
        public static void FullscreenOn()
        {
            if (gameWindow == IntPtr.Zero)
            {
                IntPtr[] possibleWindows = GetPossibleWindows();
                if (possibleWindows.Length == 0)
                {
                    return;
                }
                else if (possibleWindows.Length == 1)
                {
                    gameWindow = possibleWindows[0];
                }
                else
                {
                    FormSelectApp.instance.UpdateWindowsList(possibleWindows);
                    if (FormSelectApp.instance.ShowDialog() == DialogResult.OK)
                    {
                        gameWindow = FormSelectApp.instance.GetSelectedWindow();
                        if (gameWindow == IntPtr.Zero)
                        {
                            return;
                        }
                    }
                    else
                    {
                        return;
                    }
                }
            }
            Rectangle rect  = PInvokeFunc.GetWindowRect(gameWindow);
            int       w     = rect.Width;
            int       h     = rect.Height;
            int       fullX = -1;
            int       fullY = -1;

            int[,] sizes = { {  640, 480 }, {  800,  600 }, { 1024,  768 }, { 1152,  720 }, { 1152, 864 }, { 1280, 720 },
                             { 1280, 768 }, { 1280,  800 }, { 1280,  960 }, { 1280, 1024 }, { 1360, 768 }, { 1440, 900 },
                             { 1600, 900 }, { 1600, 1024 }, { 1600, 1200 } };
            int minD = int.MaxValue;

            for (int i = 0; i <= sizes.GetUpperBound(0); ++i)
            {
                int dx = w - sizes[i, 0];
                int dy = h - sizes[i, 1];
                int d  = dx * dx + dy * dy;
                if (d <= minD)
                {
                    minD  = d;
                    fullX = sizes[i, 0];
                    fullY = sizes[i, 1];
                }
            }

            Global.windowPosition.MainFormPosition = WindowPosition.Serialize(Form1.thisForm);
            if (Form1.thisForm.formOptions != null)
            {
                Global.windowPosition.OptionsFormPosition = WindowPosition.Serialize(Form1.thisForm.formOptions);
            }
            if (FormMonitor.isCreated())
            {
                Global.windowPosition.MonitorFormPosition = WindowPosition.Serialize(FormMonitor.instance);
            }
            oldGameLocation = new Point(rect.Left, rect.Top);
            fullscreen      = true;
            try
            {
                if (dxDevice == null)
                {
                    dxDevice = new Device();
                }
                dxDevice.SetDisplayMode(fullX, fullY, 32, 0, true);
                int border = (rect.Width - fullX) / 2;
                PInvokeFunc.SetWindowPos(gameWindow, IntPtr.Zero, -border, fullY - rect.Height + border, 0, 0, 5);
                WindowPosition.Deserialize(Form1.thisForm, Global.windowPosition.FullscreenPosition);
                if (Form1.thisForm.Width > fullX)
                {
                    Form1.thisForm.Width = fullX;
                }
                if (Form1.thisForm.Height > fullY)
                {
                    Form1.thisForm.Height = fullY;
                }
                if (Form1.thisForm.Left + Form1.thisForm.Width > fullX)
                {
                    Form1.thisForm.Left = fullX - Form1.thisForm.Width;
                }
                if (Form1.thisForm.Top + Form1.thisForm.Height > fullY)
                {
                    Form1.thisForm.Top = fullY - Form1.thisForm.Height;
                }
                Form1.thisForm.TopMost = true;
            }
            catch (Exception)
            {
                FullscreenOff();
            }
        }
Пример #11
0
 public void _Show()
 {
     PInvokeFunc.ShowWindow(this.Handle, PInvokeFunc.SW_SHOWNOACTIVATE);
     PInvokeFunc.SetWindowPos(this.Handle, new IntPtr(-1), 0, 0, 0, 0, 19);
 }