private void TranslationForm_Activated(object sender, EventArgs e) { moveBackgroundForm(); //oppan window style if (TextHook.instance.isConnected) { try { IntPtr gameWindow = TextHook.instance.currentProcess.MainWindowHandle; if (gameWindow != Winapi.INVALID_HANDLE_VALUE) { int wstyle = Winapi.GetWindowLong(gameWindow, Winapi.GWL_EXSTYLE); if ((wstyle & Winapi.WS_EX_TOPMOST) != 0) { Winapi.SetWindowPos(gameWindow, Winapi.HWND_NOTOPMOST, 0, 0, 0, 0, Winapi.SWP_NOACTIVATE | Winapi.SWP_NOMOVE | Winapi.SWP_NOSIZE); /*wstyle = wstyle & ~Winapi.WS_EX_TOPMOST; * Logger.log("Unsetting TOPMOST style"); * Winapi.SetWindowLong(gameWindow, Winapi.GWL_EXSTYLE, wstyle);*/ } } } catch (Exception ex) { Logger.logException(ex); } } }
public static void InvertScreenRect(IntPtr hwnd, Rectangle rect) { Winapi.RECT rect2; var loc = Winapi.GetWindowRect(hwnd).Location; rect.Offset(-loc.X, -loc.Y); var hdc = Winapi.GetWindowDC(hwnd); //top edge rect2 = new Winapi.RECT(rect.Left, rect.Top, rect.Right, rect.Top + INVERT_BORDER); InvertRect(hdc, ref rect2); //left edge rect2 = new Winapi.RECT(rect.Left, rect.Top + INVERT_BORDER, rect.Left + INVERT_BORDER, rect.Bottom - INVERT_BORDER); InvertRect(hdc, ref rect2); //right edge rect2 = new Winapi.RECT(rect.Right - INVERT_BORDER, rect.Top + INVERT_BORDER, rect.Right, rect.Bottom - INVERT_BORDER); InvertRect(hdc, ref rect2); //bottom edge rect2 = new Winapi.RECT(rect.Left, rect.Bottom - INVERT_BORDER, rect.Right, rect.Bottom); InvertRect(hdc, ref rect2); Winapi.ReleaseDC(hwnd, hdc); }
internal void updatePos() { Rectangle bounds = mainForm.DesktopBounds; Winapi.SetWindowPos(Handle, mainForm.Handle, bounds.Left, bounds.Top, bounds.Width, bounds.Height, 16); WindowState = mainForm.WindowState; }
public static QtProcess FromWindow(IntPtr w) { uint pid; Winapi.GetWindowThreadProcessId(w, out pid); if (nonQtProcesses.Contains(pid)) { return(null); } if (qtProcesses.ContainsKey(pid)) { return(qtProcesses[pid]); } try { var proc = Process.GetProcessById((int)pid); foreach (var m in proc.Modules.Cast <ProcessModule>().Where( m => m.ModuleName.Equals("QtGui4.dll", StringComparison.InvariantCultureIgnoreCase))) { var qproc = new QtProcess { Process = proc, QtVersion = m.FileVersionInfo, }; qtProcesses.Add(pid, qproc); return(qproc); } } catch { } nonQtProcesses.Add(pid); return(null); }
private void picturePicker_MouseMove(object sender, MouseEventArgs e) { if (!Searching) { return; } var w = Winapi.WindowFromPoint(Cursor.Position); uint pid; Winapi.GetWindowThreadProcessId(w, out pid); if (pid == CurrentPid) { return; } var json = GetWidgetData(w, false); var rect = GetWidgetRect(json); if (LastWindow != w || LastRect != rect) { // unhilite old InvertLast(); LastWindow = w; LastRect = rect; // hilite new InvertLast(); // also update window title Text = TitlePrefix + string.Format(" [{0:X8}, {1}, {2}]", w, json.TryGet <string>("class"), json.TryGet <string>("text")); } }
public TranslationForm() { InitializeComponent(); hintForm = new HintForm(); hintForm.setMainForm(this); backgroundForm = new BackgroundForm(); backgroundForm.setMainForm(this); FormUtil.restoreLocation(this); TopMost = Settings.app.stayOnTop; webBrowser1.ObjectForScripting = new BrowserInterop(webBrowser1, new InteropMethods(this)); webBrowser1.Url = Utils.getUriForBrowser("translation.html"); TranslationService.instance.onTranslationRequest += (id, raw, src) => { var translators = Settings.app.getSelectedTranslators(!Atlas.instance.isNotFound); if (translators.Count == 1 && Settings.session.po != null) { // trying .po translation var poTrans = PoManager.instance.getTranslation(raw); if (!string.IsNullOrEmpty(poTrans)) { webBrowser1.callScript("newTranslationResult", id, Utils.toJson(new TranslationResult(poTrans, false))); return; } } webBrowser1.callScript("translate", id, raw, src, Utils.toJson(translators)); }; TranslationService.instance.onEdictDone += (id, parse) => { lastParseResult = parse; if (id == waitingForId) { waitingForId = -1; return; } lastParseOptions = null; submitParseResult(parse); }; if (OptionsForm.instance.Visible) { this.SuspendTopMostBegin(); } OptionsForm.instance.VisibleChanged += (sender, e) => { if ((sender as Form).Visible) { this.SuspendTopMostBegin(); } else { this.SuspendTopMostEnd(); } }; SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged; //Utils.setWindowNoActivate(this.Handle); Winapi.RegisterHotKey(Handle, 0, (int)Winapi.KeyModifier.Control, (int)Keys.Oemtilde); }
private void redraw(object sender, EventArgs e) { UpdateLogic(); // clean opengl to draw Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT); //draws the entire scene control.DrawScene(); //change buffers Winapi.SwapBuffers(hdc); //tell opengl to drop any operation he is doing and to prepare for a new frame Gl.glFlush(); }
private Delegate loadFunc(IntPtr module, string name, Type T) { IntPtr addr = Winapi.GetProcAddress(module, name); if (addr != IntPtr.Zero) { return(Marshal.GetDelegateForFunctionPointer(addr, T)); } else { throw new MyException("Failed to find method " + name + "!"); } }
public void close() { try { if (destroyEngine != null) { destroyEngine(); } if (atlecont != null && atlecont != IntPtr.Zero) { Winapi.FreeLibrary(atlecont); } } catch { } }
private void MainForm_Deactivate(object sender, EventArgs e) { if (isSelectWindow) { isSelectWindow = false; webBrowser1.callScript("selectWindowEnd"); Task.Factory.StartNew(() => { IntPtr newWindow = Winapi.GetForegroundWindow(); if (newWindow != IntPtr.Zero) { uint pid; Winapi.GetWindowThreadProcessId(newWindow, out pid); setDefaultProcess((int)pid); } else { Thread.Sleep(100); newWindow = Winapi.GetForegroundWindow(); if (newWindow != IntPtr.Zero) { uint pid; Winapi.GetWindowThreadProcessId(newWindow, out pid); setDefaultProcess((int)pid); } else { Thread.Sleep(500); newWindow = Winapi.GetForegroundWindow(); if (newWindow != IntPtr.Zero) { uint pid; Winapi.GetWindowThreadProcessId(newWindow, out pid); setDefaultProcess((int)pid); } else { } } } }); } }
private void hotKeyPressed() { IntPtr handle = Winapi.WindowFromPoint(Cursor.Position); if (handle != Winapi.INVALID_HANDLE_VALUE) { string txt = Winapi.GetWindowTextRaw(handle); if (!string.IsNullOrWhiteSpace(txt)) { if (txt.Length > 1000) { txt = txt.Substring(0, 1000); } TranslationService.instance.update(txt); /*if (TextUtils.containsJapanese(txt)) { * * }*/ } } }
private IntPtr loadLibrary(string name) { string path = Path.Combine(installPath, name); return(Winapi.LoadLibraryEx(path, IntPtr.Zero, Winapi.LOAD_WITH_ALTERED_SEARCH_PATH)); }
internal void sendSysCommand(uint command) { Winapi.ReleaseCapture(webBrowser1.Handle); Winapi.DefWindowProc(this.Handle, Winapi.WM_SYSCOMMAND, (UIntPtr)command, IntPtr.Zero); }
public bool getAero() { return(Utils.isWindowsVistaOrLater() && Winapi.DwmIsCompositionEnabled()); }
public void showNoActivate() { Winapi.ShowWindow(this.Handle, Winapi.SW_SHOWNOACTIVATE); Winapi.SetWindowPos(this.Handle, new IntPtr(-1), 0, 0, 0, 0, 19); isVisible = true; }
public static void InvertWindow(IntPtr hwnd, bool fShowHidden) { Winapi.RECT rect2; var border = INVERT_BORDER; //window rectangle (screen coords) var rect = Winapi.GetWindowRect(hwnd); //client rectangle (screen coords) var rectc = Winapi.GetClientRect(hwnd); var tmp = Winapi.ClientToScreen(hwnd, rectc.Location); rectc.Left = tmp.X; rectc.Top = tmp.Y; var x1 = rect.Left; var y1 = rect.Top; OffsetRect(ref rect, -x1, -y1); OffsetRect(ref rectc, -x1, -y1); if (rect.Bottom - border * 2 < 0) { border = 1; } if (rect.Right - border * 2 < 0) { border = 1; } if (fShowHidden) { hwnd = IntPtr.Zero; } var hdc = Winapi.GetWindowDC(hwnd); //top edge SetRect(out rect2, 0, 0, rect.Right, border); if (fShowHidden) { OffsetRect(ref rect2, x1, y1); } InvertRect(hdc, ref rect2); //left edge SetRect(out rect2, 0, border, border, rect.Bottom); if (fShowHidden) { OffsetRect(ref rect2, x1, y1); } InvertRect(hdc, ref rect2); //right edge SetRect(out rect2, border, rect.Bottom - border, rect.Right, rect.Bottom); if (fShowHidden) { OffsetRect(ref rect2, x1, y1); } InvertRect(hdc, ref rect2); //bottom edge SetRect(out rect2, rect.Right - border, border, rect.Right, rect.Bottom - border); if (fShowHidden) { OffsetRect(ref rect2, x1, y1); } InvertRect(hdc, ref rect2); Winapi.ReleaseDC(hwnd, hdc); }