[C\C++] SketchUp window handle
-
I'm doing this: http://www.thomthom.net/software/sketchup/tt_lib2/doc/TT/Win32.html#get_sketchup_window-class_method
<span class="syntaxdefault"><br />def self</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">get_sketchup_window<br /> hwnd </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> GetActiveWindow</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">call<br /> return nil if hwnd </span><span class="syntaxkeyword">== </span><span class="syntaxdefault">0<br /> </span><span class="syntaxcomment"># In case the SketchUp window was not the active one - get the ancestor.<br /></span><span class="syntaxdefault"> GetAncestor</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">call</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">hwnd</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> GA_ROOTOWNER</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">end<br /></span>
Guessing the name of the Window - what if you have multiple windows, or your browser has an article of SketchUp open?
I used GetActiveWindow because it returns a window for the current process. Then I get the ancestor because that will be the SketchUp window. However, it only work if SketchUp or any of its child windows has focus. If the function is called when another application has focus you get nil.
Maybe it can be obtained from the process id?@unknownuser said:
Will a procedure be much different on MAC?
I'd like to know how to do this. The method above is using the Win32 API - and no Googling has lead me to any solution for OSX.
-
Here's a stack overflow thread I made earlier trying to work out how to get the window handle: http://stackoverflow.com/questions/4548354/win32-can-one-enumerate-the-windows-belonging-to-the-calling-thread
I've not implemented it yet though.
-
a note that on the C side of things, the constant NULL is set to the integer 0, which is what C will return for many Win API functions that are unsuccessful.
Win32API.so I don't think converts a C NULL into a Ruby
nil
-
@dan rathbun said:
Win32API.so I don't think converts a C NULL into a Ruby
nil
You're right. That was a wee bug in my code there. I compare against 0 elsewhere. Thanks for spotting that.
-
I have succeeded to find SU hwnd in a following way (pseudo-Ruby \ C++ code):
curr_proc_id = GetCurrentProcessId(); h = GetTopWindow(0); while ( h ) { pid=GetWindowThreadProcessId( h ); if ( pid == curr_proc_id ) { class_name=GetClassName( h ); if (class_name[0..2]=='Afx' && class_name[13]=='b') su_hwnd=h; } h = GetNextWindow( h ); } return su_hwnd;
p.s. I am a spoiled child. I want my Ruby back!!!
I hate defining almost every single byte in memory!
Mac OSX now...
-
The current pid in Ruby is the global
$$
, or a call to:Process.pid()
-
GetTopWindow(0)
What does this actually do?
-
@thomthom said:
GetTopWindow(0)
What does this actually do?
It gets "top most" window.
@unknownuser said:
If this parameter is NULL (0), the function returns a handle to the window at the top of the Z order.
The z-order of a window indicates the window's position in a stack of overlapping windows. This window stack is oriented along an imaginary axis, the z-axis, extending outward from the screen. The window at the top of the z-order overlaps all other windows. The window at the bottom of the z-order is overlapped by all other windows.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633514(v=vs.85).aspx
GetNextWindow
gets a window beneath.. till all windows examined. -
How fast is it to search through all the windows and do string comparison?
-
@thomthom said:
How fast is it to search through all the windows and do string comparison?
I haven't learned yet how to measure time in C (whole function is written in C), but I guess it is very fast.
-
Here's a way that doesn't iterate every windows there is. It enumerates the windows of the calling thread. Cuts down the searching and ensure that you don't get the wrong window.
Advertisement