How can you get a Window handle (HWND) corresponding with a window's resource id? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How can you get a Window handle (HWND) corresponding with a window's resource id?

I'm using OpenGL utility toolkit(GLUT) which gives an int to identify a window. I think the int is the resource identifier when GLUT is used in Microsoft Windows. I want to get an HWND for a screenshot. I can get the foreground window's HWND using GetForegroundWindow but I'd like to get the corresponding HWND even if it isn't in the foreground.

30th Apr 2021, 4:24 AM
Josh Greig
Josh Greig - avatar
2 Answers
+ 1
You may have to find the window by its title bar. I remember having to do that once by using a Windows API that returned a list of all open windows and searching by title to get its corresponding HWND in the structure. So I also had to make sure the title was uniquely identifiable. That was the best solution nearly a decade ago. Maybe it still applies.
30th Apr 2021, 5:33 AM
Brian
Brian - avatar
+ 1
Brian, you're probably right that hoping for a unique window title is the best I can do. It is unfortunate that GLUT can't give something more reliable or clean but maybe that's part of the price of GLUT being so OS-independent.
2nd May 2021, 4:15 PM
Josh Greig
Josh Greig - avatar