private void BtnCaptureCam_Click(object sender, EventArgs e) { // Get DroidCam video window IntPtr hwndCaptureWindow = WinApi.User32.User32Methods.FindWindow(null, "DroidCam Video"); if (hwndCaptureWindow != null) { // Get dimensions of the capture window NetCoreEx.Geometry.Rectangle rect = new NetCoreEx.Geometry.Rectangle(); GetWindowRect(hwndCaptureWindow, out rect); // Do fancy DC bitblit IntPtr hdcFrom = GetDC(hwndCaptureWindow); IntPtr hdcTo = CreateCompatibleDC(hdcFrom); IntPtr bitmapTo = CreateCompatibleBitmap(hdcFrom, rect.Width, rect.Height); SelectObject(hdcTo, bitmapTo); BitBlt(hdcTo, 0, 0, rect.Width, rect.Height, hdcFrom, 0, 0, WinApi.Gdi32.BitBltFlags.SRCCOPY); // Create the image Bitmap image = Image.FromHbitmap(bitmapTo); // Release resources DeleteObject(bitmapTo); DeleteDC(hdcTo); ReleaseDC(hwndCaptureWindow, hdcFrom); // Apply the image ApplyImageFilters(image); } }
public void Init(string title, int width, int height, bool vsync, bool fullscreen) { if (m_Info != null) { throw new InvalidOperationException("application already initialized"); } m_Info = new ApplicationInfo { Title = title, Width = width, Height = height, VSync = vsync, FullScreen = fullscreen }; IntPtr hInstance = Kernel32Methods.GetModuleHandle(IntPtr.Zero); m_WindowProc = WindowProc; var wc = new WindowClassEx { Size = (uint)Marshal.SizeOf <WindowClassEx>(), ClassName = "MainWindow", CursorHandle = User32Helpers.LoadCursor(IntPtr.Zero, SystemCursor.IDC_ARROW), IconHandle = User32Helpers.LoadIcon(IntPtr.Zero, SystemIcon.IDI_APPLICATION), Styles = WindowClassStyles.CS_HREDRAW | WindowClassStyles.CS_VREDRAW | WindowClassStyles.CS_OWNDC, BackgroundBrushHandle = new IntPtr((int)StockObject.WHITE_BRUSH), WindowProc = m_WindowProc, InstanceHandle = hInstance }; if (User32Methods.RegisterClassEx(ref wc) == 0) { throw new ExternalException("window registration failed"); } NetCoreEx.Geometry.Rectangle size = new NetCoreEx.Geometry.Rectangle(0, 0, width, height); User32Methods.AdjustWindowRectEx(ref size, WindowStyles.WS_OVERLAPPEDWINDOW | WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS, false, WindowExStyles.WS_EX_APPWINDOW | WindowExStyles.WS_EX_WINDOWEDGE); m_hWnd = User32Methods.CreateWindowEx(WindowExStyles.WS_EX_APPWINDOW | WindowExStyles.WS_EX_WINDOWEDGE, wc.ClassName, title, WindowStyles.WS_OVERLAPPEDWINDOW | WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS, (int)CreateWindowFlags.CW_USEDEFAULT, (int)CreateWindowFlags.CW_USEDEFAULT, size.Right + (-size.Left), size.Bottom + (-size.Top), IntPtr.Zero, IntPtr.Zero, hInstance, IntPtr.Zero); if (m_hWnd == IntPtr.Zero) { throw new ExternalException("window creation failed"); } User32Methods.ShowWindow(m_hWnd, ShowWindowCommands.SW_SHOWNORMAL); User32Methods.UpdateWindow(m_hWnd); Context.Instance.Init(m_hWnd, m_Info); Renderer.Instance.Init(); Script.LuaEngine.Instance.Init(); }
private Point ScreenToClient(Point point) { var client = new Rectangle(); User32Methods.AdjustWindowRectEx(ref client, GetStyles(), User32Methods.GetMenu(Handle) != IntPtr.Zero, GetExStyles()); GetWindowRect(out Rectangle window); return(new Point(point.X - window.Left + client.Left, point.Y - window.Top + client.Top)); }