sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    ⚠️ Important | Libfredo 15.6b introduces important bugfixes for Fredo's Extensions Update

    [C\C++] SketchUp window handle

    Scheduled Pinned Locked Moved Developers' Forum
    12 Posts 3 Posters 966 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • thomthomT Offline
      thomthom
      last edited by

      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.

      Thomas Thomassen β€” SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund

      1 Reply Last reply Reply Quote 0
      • Dan RathbunD Offline
        Dan Rathbun
        last edited by

        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

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • thomthomT Offline
          thomthom
          last edited by

          @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.

          Thomas Thomassen β€” SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

          1 Reply Last reply Reply Quote 0
          • T Offline
            tomasz
            last edited by

            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...

            Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

            1 Reply Last reply Reply Quote 0
            • Dan RathbunD Offline
              Dan Rathbun
              last edited by

              The current pid in Ruby is the global $$, or a call to: Process.pid()

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • thomthomT Offline
                thomthom
                last edited by

                GetTopWindow(0)

                What does this actually do?

                Thomas Thomassen β€” SketchUp Monkey & Coding addict
                List of my plugins and link to the CookieWare fund

                1 Reply Last reply Reply Quote 0
                • T Offline
                  tomasz
                  last edited by

                  @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.

                  Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

                  1 Reply Last reply Reply Quote 0
                  • thomthomT Offline
                    thomthom
                    last edited by

                    How fast is it to search through all the windows and do string comparison?

                    Thomas Thomassen β€” SketchUp Monkey & Coding addict
                    List of my plugins and link to the CookieWare fund

                    1 Reply Last reply Reply Quote 0
                    • T Offline
                      tomasz
                      last edited by

                      @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. πŸ˜„

                      Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

                      1 Reply Last reply Reply Quote 0
                      • thomthomT Offline
                        thomthom
                        last edited by

                        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.


                        win32_sketchup_window.rb

                        Thomas Thomassen β€” SketchUp Monkey & Coding addict
                        List of my plugins and link to the CookieWare fund

                        1 Reply Last reply Reply Quote 0
                        • 1 / 1
                        • First post
                          Last post
                        Buy SketchPlus
                        Buy SUbD
                        Buy WrapR
                        Buy eBook
                        Buy Modelur
                        Buy Vertex Tools
                        Buy SketchCuisine
                        Buy FormFonts

                        Advertisement