I am trying to create a simple application that captures the desktop screen, however, not able to find much information about how to do this. I have been looking for some time and have had no luck. Please help. Please see the code below.
import winim
let window = FindWindow("Window Title", nil) let rect = GetWindowRect(window) let screenshot = captureWindow(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top) let filename = "window_screenshot.png" var file = File.open(filename, "wb") file.write_png(screenshot.width, screenshot.height, screenshot.pixels) file.close()
Error -
C:UsersuserDocumentsnimcodetest6.nim(4, 25) Error: type mismatch: got <HWND> but expected one of:
expression: GetWindowRect(window)
Hey Naterlarsen, looks like you are new to the forums so Welcome!
Just for future posts you can use code blocks to format your code so that it is easier for people to read your code to help you out. You can use three back ticks and then the short name of the language to do so like
```nim
your code
```
for your problem it is because GetWindowRect is a function that doesn't return the rect that you want. It returns a bool which tells you if the func was successful. lpRect is the param where the func saves the rect so you will need to do something like
let window = FindWindow("Window Title", nil)
var lpRect: LPRECT
if (GetWindowRect(window, lpRect) == false):
echo "failed to get window"
return # quit the application
echo lpRect