C++ Get the HWND for SketchUp

For my C plugin, I want to display a progress bar while it exports. To do that, I need to get the HWND of the main sketchup window. Is there a best way to do that?

The APIs have never had a method / function to get SketchUp’s application window (despite requests.)
So we’ve had to make Windows system calls using various Ruby libraries (currently Fiddle.)

But on the C side you can load a system DLL (User32.DLL) and make direct system calls.

One way might be …

  1. Get the current SketchUp process ID. (Ruby’s Process::pid module method will return it.)
  2. Enumerate the toplevel windows.
  3. Check each Window’s process ID against what you know is SketchUp’s process ID.
  4. When found keep the handle and return falsely from your EnumWindowsProc.

You might also filter by windows containing “SketchUp” in the caption, but users can have more than 1 instance of SketchUp running.

Others have used the handle of what they know is a child window (perhaps they created it as an empty HtmlDialog offscreen with a unique caption,) used FindWindow using the unique name, and then GetAncestorWindow function looking for the root owner.

1 Like