You could also use GetWindowRect, but this function is not DpiAware (and a bit old :), it may return a wrong size in specific conditions. ► Here, I'm using DwmGetWindowAttribute, specifying DWMWA_EXTENDED_FRAME_BOUNDS as the attribute, to retrieve the Window rectangle. Win32 Declarations and implementation of the RenderWindow method: PictureBox1.Image = RenderWindow(proc.MainWindowHandle, True) See here: How to obtain task bar Notification Area width for a simple use of the FindWindowEx function.Īssuming you have a WinForms app, you can call the method like this, to show a Bitmap of the rendered Window in a PictureBox: Dim proc = Process.GetProcessesByName("WINWORD").FirstOrDefault(Function(p) p.MainWindowHandle IntPtr.Zero) Or FindWindowEx, or EnumWindows, or EnumDesktopWindows, depending on the context. Process.GetProcessesByName("processName").FirstOrDefault(.) or Process.GetProcessById(id), if you know the Process Id. To get the Handle of the Window you care about, you have many options. UPDATE: in this case, it's what gets the job done. The optional tryGetFullContent argument sets the PW_RENDERFULLCONTENT flag, which is available from Windows 8.1+. You should try to pass True as the clientAreaOnly argument, to set PW_CLIENTONLY as the nFlags option, because many WPF apps are designed to hide the default Window Frame, while WinForms Windows usually don't, so try to pass False in this case. The static ( Shared) RenderWindow method shown here, returns a Bitmap object generated by the PrintWindow function. The Window has to process the message, though. ► The Window can be completely obscured by another, it doesn't matter, it's not a screenshot. This function issues a WM_PRINT or WM_PRINTCLIENT message (depending on the flags specified), so the Window that receives and processes the message prints itself to the hDC passed in the function call.
0 Comments
Leave a Reply. |