void FillTree(IntPtr hwnd, TreeViewItem root) { TreeViewItem tvi = new TreeViewItem() { Header = GetWindowToString(hwnd), HeaderTemplate = hwndtree.ItemTemplate, Tag = WinUser.IsWindowVisible(hwnd), }; if (root == null) { hwndtree.Items.Add(tvi); } else { root.Items.Add(tvi); } List <IntPtr> childs = new List <IntPtr>(); FindWindow(hwnd, IntPtr.Zero, childs); foreach (var i in childs) { FillTree(i, tvi); } }
private void hwndText_TextChanged(object sender, TextChangedEventArgs e) { IntPtr hwnd; if (IsIntPtr(hwndText.Text, 16) && (hwnd = Hwnd) != IntPtr.Zero && WinUser.IsWindow(hwnd) && hwnd != Handle) { s_hButton.IsEnabled = true; s_hButton.IsChecked = WinUser.IsWindowVisible(hwnd); e_dButton.IsEnabled = true; e_dButton.IsChecked = WinUser.IsWindowEnabled(hwnd); gotoNextButton.IsEnabled = NextWindow(hwnd) != IntPtr.Zero ? true : false; gotoPrevButton.IsEnabled = PrevWindow(hwnd) != IntPtr.Zero ? true : false; AddHandle(hwnd); StringBuilder strb = new StringBuilder(256); WinUser.GetWindowText(hwnd, strb, 256); string title = strb.ToString(); this.Title = string.Format("{0} - {1}", assemblyName.Name, title); } else { WhenNullHandle(); } }
private void GoToWindow(IntPtr owner, GoToNavigation gotoNav) { var hwnd = owner; switch (gotoNav) { case GoToNavigation.Next: hwnd = NextWindow(owner); break; case GoToNavigation.Previous: hwnd = PrevWindow(owner); break; case GoToNavigation.Ancestor: hwnd = WinUser.GetAncestor(owner, 1); break; case GoToNavigation.Child: hwnd = WinUser.FindWindowEx(owner, IntPtr.Zero, null, null); break; } if (hwnd != IntPtr.Zero) { hwndText.Text = hwnd.ToString("X8"); } var item = GetWindowToString(hwnd); hwndlist.SelectedItem = item; hwndlist.BringIntoView(); }
private string GetWindowToString(IntPtr hwnd) { //if (!WinUser.IsWindow(hwnd)) // return null; //StringBuilder strb = new StringBuilder(256); //WinUser.GetWindowText(hwnd, strb, 256); //string title = strb.ToString(); string title = GetControlText(hwnd); StringBuilder sb = new StringBuilder(256); WinUser.GetClassName(hwnd, sb, 256); string className = sb.ToString(); string str_hwnd = Convert.ToString(hwnd.ToInt32(), 16).ToUpper(); while (str_hwnd.Length < 8) { str_hwnd = "0" + str_hwnd; } string item = string.Format("{0} \"{1}\" {2}", str_hwnd, title, className); return(item); }
private void AddHandle(IntPtr hwnd) { if (!WinUser.IsWindow(hwnd) || hwnd == Handle) { return; } string item = GetWindowToString(hwnd); if (WinUser.IsWindow(hwnd)) { var source = HwndSource.FromHwnd(hwnd); if (source != null) { dynamic WpfWindow = source.RootVisual; item = "WPF " + item; } } if (!hwndlist.Items.Contains(item)) { hwndlist.Items.Add(item); } hwndlist.SelectedItem = item; hwndlist.BringIntoView(); }
private void HighlightedWindow(IntPtr hwnd) { wm = new HighlightedWindow() { Width = 0, Height = 0, Left = int.MaxValue, Top = int.MaxValue, Background = Brushes.Transparent,// new SolidColorBrush(Color.FromArgb(0xa2, 0x12, 0x0a, 0xd0)), BorderBrush = System.Windows.Media.Brushes.Red, BorderThickness = new Thickness(2), }; wm.Show(); WinUser.Rect rect; WinUser.GetWindowRect(hwnd, out rect); int width = rect.Right - rect.Left; int height = rect.Bottom - rect.Top; wm.Left = rect.Left; wm.Top = rect.Top; wm.Width = rect.Right - rect.Left; wm.Height = rect.Bottom - rect.Top; if (WinUser.IsMaximize(hwnd)) { wm.Left = 0; wm.Top = 0; wm.Width = rect.Right + rect.Left; wm.Height = rect.Bottom + rect.Top; } Thread.Sleep(200); wm.Close(); }
public static void MouseButtonCallback(IntPtr hWnd, InputManager inputManager, uint button, uint x, uint y) { bool down = false; switch (button) { case WinUser.WM_LBUTTONDOWN: WinUser.SetCapture(hWnd); button = Input.SP_MOUSE_LEFT; down = true; break; case WinUser.WM_LBUTTONUP: WinUser.ReleaseCapture(); button = Input.SP_MOUSE_LEFT; down = false; break; case WinUser.WM_RBUTTONDOWN: WinUser.SetCapture(hWnd); button = Input.SP_MOUSE_RIGHT; down = true; break; case WinUser.WM_RBUTTONUP: WinUser.ReleaseCapture(); button = Input.SP_MOUSE_RIGHT; down = false; break; case WinUser.WM_MBUTTONDOWN: WinUser.SetCapture(hWnd); button = Input.SP_MOUSE_MIDDLE; down = true; break; case WinUser.WM_MBUTTONUP: WinUser.ReleaseCapture(); button = Input.SP_MOUSE_MIDDLE; down = false; break; } inputManager.mouseButtons[button] = down; inputManager.mousePosition.x = x; inputManager.mousePosition.y = y; Log.Assert(() => inputManager.eventCallback != null); if (down) { inputManager.eventCallback(new MousePressedEvent(button, x, y)); } else { inputManager.eventCallback(new MouseReleasedEvent(button, x, y)); } }
public void SetMousePosition(Vector2 position) { POINT pt = new POINT { x = (int)position.x, y = (int)position.y }; WinUser.ClientToScreen(Window.GetWindowClass().GetHWND(), ref pt); WinUser.SetCursorPos(pt.x, pt.y); }
private void Notify_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e) { if (e.Clicks == 0 && e.Button == System.Windows.Forms.MouseButtons.Right) { menu.IsOpen = true; HwndSource hwnd = PresentationSource.FromVisual(menu) as HwndSource; WinUser.SetForegroundWindow(hwnd.Handle); hwnd.AddHook(WindowFilterMessage); } }
private void FindWindow(IntPtr parent, IntPtr prev, List <IntPtr> list) { var child = WinUser.FindWindowEx(parent, prev, null, null); if (child == IntPtr.Zero) { return; } list.Add(child); FindWindow(parent, child, list); }
private IntPtr PrevWindow(IntPtr owner) { var list = GetChildsWindows(WinUser.GetAncestor(owner, 1)); int indx = list.IndexOf(owner); if (indx > 0) { return(list[indx - 1]); } return(IntPtr.Zero); }
private void TextBlock_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { var item = ((FrameworkElement)sender).DataContext.ToString(); var str_hwnd = Regex.Match(item, "[0-9A-F]{8}").Value; if (WinUser.IsWindow(new IntPtr(Convert.ToInt32(str_hwnd, 16)))) { hwndText.Text = str_hwnd; } else { hwndlist.Items.Remove(item); } }
//保存用户 protected void BtnSave_Click(object sender, DirectEventArgs e) { userinfoMgr mgr = new userinfoMgr(); if (Hid.Text.Length > 0) {//Update User userinfo user = mgr.FindById_userinfo(int.Parse(Hid.Text)); user.roleid = int.Parse(cboRole.SelectedItem.Value); user.telephone = TxtTel.Text.Trim(); user.email = TxtEmail.Text.Trim(); user.address = TxtAddress.Text.Trim(); if (mgr.Update_userinfo(user)) { WinUser.Hide(); X.Msg.Notify("成功", "用户修改成功").Show(); GridPanel1.Reload(); } else { MsgShow("失败", "用户修改失败,请重试"); } } else {//ADD User if (mgr.FindById_userinfo(TxtUserName.Text.Trim()) != null) { MsgShow("提示", "该用户已存在,请使用其他用户名"); return; } userinfo user = new userinfo(); user.username = TxtUserName.Text.Trim(); user.roleid = int.Parse(cboRole.SelectedItem.Value); user.telephone = TxtTel.Text.Trim(); user.password = CJ_DBOperater.CJ.PwdSecurity("123456"); user.logintime = DateTime.Now.ToString(); user.createtime = DateTime.Now.ToString(); user.email = TxtEmail.Text.Trim(); user.address = TxtAddress.Text.Trim(); if (mgr.Add_userinfo(user)) { WinUser.Hide(); X.Msg.Notify("成功", "<font color='green'>用户添加成功,默认密码123456</font>").Show(); GridPanel1.Reload(); } else { MsgShow("失败", "用户添加失败,请重试"); } } }
public void PlatformUpdate() { POINT mouse = new POINT(); WinUser.GetCursorPos(ref mouse); WinUser.ScreenToClient(Window.GetWindowClass().GetHWND(), ref mouse); Vector2 mousePos = new Vector2(mouse.x, mouse.y); if (mousePos != mousePosition) { // TPDP Put left eventCallback(new MouseMovedEvent(mousePos.x, mousePos.y, mouseButtons[0])); mousePosition = mousePos; } }
//双击Grid的列,弹出修改框 protected void GridDBClick(object sender, DirectEventArgs e) { userinfoMgr mgr = new userinfoMgr(); userinfo user = mgr.FindById_userinfo(int.Parse(e.ExtraParams["id"])); if (user != null) { TxtUserName.Text = user.username; TxtTel.Text = user.telephone; TxtEmail.Text = user.email; cboRole.Value = user.roleid; TxtAddress.Text = user.address; Hid.Text = user.userid.ToString(); WinUser.Show(); } }
public void SetMouseCursor(uint cursor) { if (cursor == Input.SP_NO_CURSOR) { WinUser.SetCursor(new IntPtr(Input.SP_NO_CURSOR)); while (WinUser.ShowCursor(false) >= 0) { ; } } else { WinUser.SetCursor(WinUser.LoadCursorW(IntPtr.Zero, WinUser.IDC_ARROW)); WinUser.ShowCursor(true); } }
private void PlatformUpdate() { MSG message = new MSG(); while (WinUser.PeekMessageW(ref message, IntPtr.Zero, 0, 0, WinUser.PM_REMOVE)) { if (message.message == WinUser.WM_QUIT) { closed = true; return; } WinUser.TranslateMessage(ref message); WinUser.DispatchMessageW(ref message); } inputManager.PlatformUpdate(); Renderer.Present(); }
/// <summary> /// This is the hook to HwndSource that is called when window messages related to /// this window occur. /// </summary> /// <param name="hwnd"></param> /// <param name="msg"></param> /// <param name="wParam"></param> /// <param name="lParam"></param> /// <param name="handled"></param> /// <returns></returns> private IntPtr WindowFilterMessage(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { IntPtr retInt = IntPtr.Zero; WindowMessage message = (WindowMessage)msg; // // we need to process WM_GETMINMAXINFO before _swh is assigned to // b/c we want to store the max/min size allowed by win32 for the hwnd // which is later used in GetWindowMinMax. WmGetMinMaxInfo can handle // _swh == null case. switch (message) { case WindowMessage.WM_APP: AddHandle(WinUser.GetForegroundWindow()); break; } return(retInt); }
public GLContext(WindowProperties properties, object deviceContext) { hDc = WinUser.GetDC((IntPtr)deviceContext); IntPtr hrc = WinGDI.wglCreateContext(hDc); if (hrc.ToInt32() != 0) { if (!WinGDI.wglMakeCurrent(hDc, hrc)) { Log.Error("Failed setting OpenGL context!"); Log.Assert(() => false); } } else { Log.Error("Failed creating OpenGL context!"); Log.Assert(() => false); } }
public string GetControlText(IntPtr hWnd) { StringBuilder title = new StringBuilder(256); // Get the size of the string required to hold the window title. Int32 size = WinUser.SendMessage(hWnd, (int)WindowMessage.WM_GETTEXTLENGTH, 0, 0); // If the return is 0, there is no title. if (size > 0) { title = new StringBuilder(size + 1); WinUser.SendMessage(hWnd, (int)WindowMessage.WM_GETTEXT, title.Capacity, title); } else { WinUser.GetWindowText(hWnd, title, title.Capacity); } return(title.ToString()); }
public Base(string fullname, List <Credential> tmpCredentials, PluginManager pluginManager, List <string> appSet, WinUser winUser, STATUS isDeleted, String username, String SID, List <WinUser> users, Licenser licenser, bool isLocalAdmin) { this.Fullname = fullname; this.Credentials = tmpCredentials; this.appSet = appSet; this.winUser = winUser; this.SID = SID; this.Status = isDeleted; this.Username = username; this.PluginManager = pluginManager; this.Users = users; this.IsLocalAdmin = isLocalAdmin; Licenser = licenser; if (winUser != null) { /// Translate string representation of login Type into XMLDB_LoginType if (winUser.Identification == XmlDB.LOGIN_STRING[(int)XmlDB.LOGIN_TYPE.BIO]) { this.LoginType = XmlDB.LOGIN_TYPE.BIO; } else if (winUser.Identification == XmlDB.LOGIN_STRING[(int)XmlDB.LOGIN_TYPE.MIXED]) { this.LoginType = XmlDB.LOGIN_TYPE.MIXED; } else { this.LoginType = XmlDB.LOGIN_TYPE.PASS; } this.Password = winUser.Password; this.isEnrolled = true; } else { this.isEnrolled = false; this.LoginType = XmlDB.LOGIN_TYPE.MIXED; this.Password = ""; } InitializeComponent(); }
private void hwndtree_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { var tvi = e.NewValue as TreeViewItem; if (tvi.Header == null) { return; } var item = tvi.Header.ToString(); var str_hwnd = Regex.Match(item, "[0-9A-F]{8}").Value; if (str_hwnd == "") { return; } if (WinUser.IsWindow(new IntPtr(Convert.ToInt32(str_hwnd, 16)))) { hwndText.Text = str_hwnd; } else { hwndlist.Items.Remove(item); } }
private bool PlatformInit() { WNDCLASS winClass = new WNDCLASS(); winClass.style = WinUser.CS_HREDRAW | WinUser.CS_VREDRAW | WinUser.CS_OWNDC; proc = WndProc; winClass.lpfnWndProc = Marshal.GetFunctionPointerForDelegate(proc); winClass.lpszClassName = "Sparky Win32 Window"; winClass.hCursor = WinUser.LoadCursorW(IntPtr.Zero, WinUser.IDC_ARROW); winClass.hIcon = WinUser.LoadIconW(IntPtr.Zero, WinUser.IDI_WINLOGO); if (WinUser.RegisterClassW(ref winClass) == 0) { Log.Error("Could not register Win32 class!"); return(false); } RECT size = new RECT(0, 0, (int)properties.width, (int)properties.height); WinUser.AdjustWindowRectEx(ref size, WinUser.WS_OVERLAPPEDWINDOW | WinUser.WS_CLIPSIBLINGS | WinUser.WS_CLIPCHILDREN, false, WinUser.WS_EX_APPWINDOW | WinUser.WS_EX_WINDOWEDGE); hWnd = WinUser.CreateWindowExW(WinUser.WS_EX_APPWINDOW | WinUser.WS_EX_WINDOWEDGE, winClass.lpszClassName, title, WinUser.WS_OVERLAPPEDWINDOW | WinUser.WS_CLIPSIBLINGS | WinUser.WS_CLIPCHILDREN, (int)(WinUser.GetSystemMetrics(WinUser.SM_CXSCREEN) / 2 - properties.width / 2), (int)(WinUser.GetSystemMetrics(WinUser.SM_CYSCREEN) / 2 - properties.height / 2), (int)(size.right + (-size.left)), (int)(size.bottom + (-size.top)), IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero ); if (hWnd.ToInt32() == 0) { Log.Error("Could not create window!"); return(false); } RegisterWindowClass(hWnd, this); hDc = WinUser.GetDC(hWnd); PIXELFORMATDESCRIPTOR pfd = GetPixelFormat(); int pixelFormat = WinGDI.ChoosePixelFormat(hDc, ref pfd); if (pixelFormat != 0) { if (!WinGDI.SetPixelFormat(hDc, pixelFormat, ref pfd)) { Log.Error("Failed setting pixel format!"); return(false); } } else { Log.Error("Failed choosing pixel format!"); return(false); } Context.Create(properties, hWnd); WinUser.ShowWindow(hWnd, WinUser.SW_SHOW); WinUser.SetFocus(hWnd); return(true); }
private void ShowHideClick(object sender, RoutedEventArgs e) { WinUser.ShowWindow(Hwnd, WinUser.IsWindowVisible(Hwnd) == true ? 0 : 1); s_hButton.IsChecked = WinUser.IsWindowVisible(Hwnd); }
private IntPtr NextWindow(IntPtr owner) { return(WinUser.FindWindowEx(WinUser.GetAncestor(owner, 1), owner, null, null)); }
private void search_PreviewMouseMove(object sender, MouseEventArgs e) { if (isSearching) { var p = GlobalMouse.Position; last_p = p; IntPtr _hwnd = WinUser.WindowFromPoint(new MS.Interop.WinUser.POINT() { x = (int)p.X, y = (int)p.Y }); if (GetControlText(_hwnd).Contains("SVG Code")) { int t = 1; } if (WinUser.GetAncestor(_hwnd, 1) != DesktopHandle) { var next = NextWindow(_hwnd); while (next != IntPtr.Zero && WinUser.IsWindowVisible(next)) { WinUser.Rect _rect; WinUser.GetWindowRect(next, out _rect); if (p.X >= _rect.Left && p.X <= _rect.Right && p.Y >= _rect.Top && p.Y <= _rect.Bottom) { _hwnd = next; } next = NextWindow(next); } } WinUser.Rect rect; WinUser.GetWindowRect(_hwnd, out rect); int width = rect.Right - rect.Left; int height = rect.Bottom - rect.Top; int x_rel = (int)(p.X - rect.Left); int y_rel = (int)(p.Y - rect.Top); if (last_hwnd == _hwnd || _hwnd == wmHandle || _hwnd == cpHandle) { return; } last_hwnd = _hwnd; status.Text = string.Format("({0}, {1})-({2}, {3}) {4}x{5}", rect.Left, rect.Top, rect.Right, rect.Bottom, rect.Right - rect.Left, rect.Bottom - rect.Top); wm.Left = rect.Left; wm.Top = rect.Top; wm.Width = rect.Right - rect.Left; wm.Height = rect.Bottom - rect.Top; if (WinUser.IsMaximize(_hwnd)) { wm.Left = 0; wm.Top = 0; wm.Width = rect.Right + rect.Left; wm.Height = rect.Bottom + rect.Top; } string str_hwnd = Convert.ToString(_hwnd.ToInt32(), 16).ToUpper(); while (str_hwnd.Length < 8) { str_hwnd = "0" + str_hwnd; } this.hwndText.Text = str_hwnd; } }
private void EnableDisableClick(object sender, RoutedEventArgs e) { WinUser.EnableWindow(Hwnd, !WinUser.IsWindowEnabled(Hwnd)); e_dButton.IsChecked = WinUser.IsWindowEnabled(Hwnd); }
public void SetTitle(string title) { this.title = title + " | " + Application.GetApplication().GetBuildConfiguration() + " " + Application.GetApplication().GetPlatform() + " | Renderer: " + Renderer.GetTitle(); WinUser.SetWindowTextW(hWnd, this.title); }
public static IntPtr WndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam) { IntPtr result = new IntPtr(); Window window = Window.GetWindowClass(); if (window == null) { return(WinUser.DefWindowProcW(hWnd, msg, wParam, lParam)); } InputManager inputManager = window.GetInputManager(); switch (msg) { case WinUser.WM_ACTIVATE: { if (wParam.ToInt32().HighWord() != 0) { // active } else { // inactive } return(new IntPtr(0)); } case WinUser.WM_SYSCOMMAND: { switch (wParam.ToInt32()) { case WinUser.SC_SCREENSAVE: case WinUser.SC_MONITORPOWER: return(new IntPtr(0)); } result = WinUser.DefWindowProcW(hWnd, msg, wParam, lParam); } break; case WinUser.WM_SETFOCUS: FocusCallback(window, true); break; case WinUser.WM_KILLFOCUS: FocusCallback(window, false); break; case WinUser.WM_CLOSE: case WinUser.WM_DESTROY: WinUser.PostQuitMessage(0); break; case WinUser.WM_KEYDOWN: case WinUser.WM_KEYUP: case WinUser.WM_SYSKEYDOWN: case WinUser.WM_SYSKEYUP: InputManager.KeyCallback(inputManager, (uint)lParam.ToInt32(), (uint)wParam.ToInt32(), msg); break; case WinUser.WM_LBUTTONDOWN: case WinUser.WM_LBUTTONUP: case WinUser.WM_RBUTTONDOWN: case WinUser.WM_RBUTTONUP: case WinUser.WM_MBUTTONDOWN: case WinUser.WM_MBUTTONUP: InputManager.MouseButtonCallback(hWnd, inputManager, msg, (uint)lParam.ToInt32().LowWord(), (uint)lParam.ToInt32().LowWord()); break; case WinUser.WM_SIZE: ResizeCallback(window, lParam.ToInt32().LowWord(), lParam.ToInt32().HighWord()); break; default: result = WinUser.DefWindowProcW(hWnd, msg, wParam, lParam); break; } return(result); }