0

I am using Visual Basic to get a screenshot of, in this case, the edit control in Notepad:

Dim windowHandle = FindWindow("Notepad", Nothing)
windowHandle = FindWindowEx(windowHandle, Nothing, "Edit", Nothing)

Dim clientRect As RECT
GetClientRect(windowHandle, clientRect)

Dim windowDeviceContext = GetDC(windowHandle)
Dim memoryDeviceContext = CreateCompatibleDC(windowDeviceContext)
Dim bitmapHandle = CreateCompatibleBitmap(windowDeviceContext, clientRect.Right, clientRect.Bottom)
Dim selectObjectResult = SelectObject(memoryDeviceContext, bitmapHandle)
Dim bitBltResult = BitBlt(memoryDeviceContext, 0, 0, clientRect.Right, clientRect.Bottom, windowDeviceContext, 0, 0, TernaryRasterOperations.SRCCOPY)
Dim bmpScreen As Bitmap = Bitmap.FromHbitmap(bitmapHandle)

bmpScreen.Save(Filepath)

This works fine, but as you keep typing, eventually you will get a scrollbar in the edit control. The above code only captures the visible area of the control. Is there a way to get the FULL control area as if there are no scrollbars? I am limited to Visual Basic and Win32 API obviously.

Visual Vincent
  • 18,045
  • 5
  • 28
  • 75
John Smith
  • 965
  • 1
  • 9
  • 22
  • How is this related to C++? – tambre Jan 05 '17 at 14:26
  • Well basically all used functions are C++ WIN32 API which are imported into VB. So it's based on C++ code. But yeah maybe not the best tag. – John Smith Jan 05 '17 at 14:46
  • And why the VB6 tag? – Chris Dunaway Jan 05 '17 at 15:12
  • No, there isn't. The area hidden behind the scrollbars is not actually displayed, so it cannot be screenshotted. Why do you need a screenshot? Would it be sufficient just to get the text that the control contains? – Cody Gray - on strike Jan 05 '17 at 15:20
  • @JohnSmith There is no C++ Win32 API (I wish there was). Technically it's a C API. But your code is not written in C++ and neither is your objective, so assuming the correctness of the imports, the C++ has no relevance here. – tambre Jan 05 '17 at 15:25
  • @Cody Gray unfortunately this is not sufficient. I need a screenshot to proof a website (notepad is just an example) being in a certain style. Basically what I am asking is how does Snagit do this, because this program can capture a screenshot of the full area. – John Smith Jan 05 '17 at 15:56
  • If you want to capture a webpage contents from a webbrowser like IE for example, you might need to look at the WM_PRINT(CLIENT) message. – VuVirt Jan 05 '17 at 18:06
  • You can also check the PrintWindow API and the following links as well: https://msdn.microsoft.com/en-us/library/dd162869.aspx, http://stackoverflow.com/questions/830359/capturing-a-window-that-is-hidden-or-minimized, http://support.microsoft.com/default.aspx?scid=kb;en-us;Q161299, http://www.fengyuan.com/article/wmprint.html (Uses hooks) – VuVirt Jan 05 '17 at 18:27

0 Answers0