sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    [Code] Win32 - Get SketchUp Window Handle (WIP)

    Scheduled Pinned Locked Moved Developers' Forum
    40 Posts 5 Posters 10.1k Views 5 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.
    • Dan RathbunD Offline
      Dan Rathbun
      last edited by

      Here's some interesting info:

      #
      #  some Sketchup window properties;
      #
      #  AutomationId  =  ""
      #
      #  CLASS   =  "Afx;00400000;b;00010011;00000006;00790557"
      #  *** the last octet changes each time Sketchup is run,
      #  examples;  "Afx;00400000;b;00010011;00000006;0012077F"
      #             "Afx;00400000;b;00010011;00000006;000E0699"
      #
      #  ControlType           =  "ControlType.Window"
      #  LocalizedControlType  =  "window"
      #
      

      The main application window is the only one with a classname like this, and also the only one with a LocalizedControlType that equals "window".

      ALL dialogs including WebDialogs, are:

      #
      #  ClassName             =  "#32770"
      #  ControlType           =  "ControlType.Window"
      #  LocalizedControlType  =  "Dialog"
      #
      

      I'm not here much anymore.

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

        @thomthom said:

        I have produced a code which appear to return the handle for the SketchUp window of the calling thread.

        Are you planning on distibuting a pre-compiled win-api as part of TT_Lib2 ??

        I have a few issues with this.
        (1) It's not in the correct folder. What if a person already has it (and possibly a newer version,) installed ?

        require will not recognize the path string you have in that example, and would load the older version down under your TT_Lib2 folder. That would overwrite the newer classes that might be loaded, if they were loaded first.

        OR.. since "T" comes before "W" your version would get loaded first, and when a normal version gets loaded after... your code might get broken. (I say "might" as newer versions are usually better.)

        So? I like the idea of someone precompiling Berger's WinUtils, and zipping them for manual install by the community (and/or creating a one-click-installer for dummies.) But they should be in the proper folder ... and likely a path to them appended to the $LOAD_PATH array.

        How much of Berger's suite would the distro have? the bare bones min or the whole thing?

        I'm not here much anymore.

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

          @dan rathbun said:

          Here's some interesting info:

          I get Afx:00A50000:b:00010005:00000006:0A7C0E3B during one session,
          and the next I get Afx:00ED0000:b:00010005:00000006:5CCC0D4F - seems to be more than just the last bit that changes...

          SU8 - Win7...

          I don't understand where that name is from - other apps, like Notepad++ has a fixed classname.

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

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

            @dan rathbun said:

            Are you planning on distibuting a pre-compiled win-api as part of TT_Lib2 ??

            I'm looking into it. If license allows it.

            @dan rathbun said:

            (1) It's not in the correct folder. What if a person already has it (and possibly a newer version,) installed ?

            That is a thing that was on my to-look-into list. What if I placed it into a folder, say: TT_Lib2/win32api/win32/api.so - and then added the TT_Lib2/win32api/ path to $LOAD_PATH so one load it as the examples says require 'win32/api'?

            @dan rathbun said:

            OR.. since "T" comes before "W" your version would get loaded first, and when a normal version gets loaded after... your code might get broken. (I say "might" as newer versions are usually better.)

            We have that potential issue with Win32API already, though it often lies in the root of the plugins folder, you can't be sure what version was copied into there last.

            @dan rathbun said:

            How much of Berger's suite would the distro have? the bare bones min or the whole thing?

            Atm I only have use of api.so - but there was some interesting stuff he had.

            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

              @thomthom said:

              @dan rathbun said:

              Here's some interesting info:

              I get Afx:00A50000:b:00010005:00000006:0A7C0E3B during one session,
              and the next I get Afx:00ED0000:b:00010005:00000006:5CCC0D4F - seems to be more than just the last bit that changes...

              SU8 - Win7...

              I don't understand where that name is from- other apps, like Notepad++ has a fixed classname.

              @unknownuser said:

              (http://en.wikipedia.org/wiki/Application_Framework_eXtensions)":35xuu8cn]One interesting quirk of MFC is the use of "Afx" as the prefix for many functions, macros and the standard precompiled header name "stdafx.h". During early development what became MFC was called "Application Framework Extensions" and abbreviated "Afx". The name Microsoft Foundation Classes (MFC) was adopted too late in the release cycle to change these references.

              @unknownuser said:

              Just few words about AFX:XXXXX:XXX like windows..... Dont confuse with this type of class names, these are just class names and actually MFC generates class names for its windows this way. Some of those numbers are an HINSTANCE and a process ID (to make sure the class name is unique). I'm not sure what the others are - if you really want to know, you can probably find it in 'MFC source code. -MAHESH

              @unknownuser said:

              (http://www.autohotkey.com/forum/topic633.html), Chris, in his reply, ":35xuu8cn]Below are quotes from the only relevant link discovered on Google at:

              @unknownuser said:

              Those Afx window classes were custom classes distributed with early versions of MFC, before the "Common Controls" concept was introduced.

              Many people have tried to "read" text from them but you CAN'T, not with messages anyway!

              They're almost certainly owner-drawn - the text is not delivered by messages, it's "hand-drawn" into the window's DC

              ...

              Apparently legacy from the early days ... there are many things I see (about Sketchup UI objects,) poking about with MS Tools that don't look quite right.

              I'm not here much anymore.

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

                So, many of what looks like system UI elemens is not drawn by the system - but emulated by the AFX/MFC framework?

                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

                  There are several GUI frameworks a coder can choose to use ... WTL sounds very interesting.

                  Link Preview Image
                  Windows Template Library - Wikipedia

                  favicon

                  (en.wikipedia.org)

                  I'm not here much anymore.

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

                    @dan rathbun said:

                    I've also read that the DL library is 'on the outs', and they are planning to deprecate it and replace it with something else.

                    OK.. now I remember what the next generation (after DL,) was supposed to move to, (the Foriegn Function Interface):
                    Wikipedia: libffi
                    and the github site for Ruby FFI is:
                    https://github.com/ffi/ffi

                    It is not yet included with Ruby as of v1.9.1-p429

                    I'm not here much anymore.

                    1 Reply Last reply Reply Quote 0
                    • A Offline
                      Anton_S
                      last edited by

                      Here is my way to find sketchup window.
                      I used it in SU Window Settings plugin.

                      Parts of ClassName change After restarting SU
                      ~sample: "Afx:00400000:b:00010011:00000006:0574025D"
                      From my testing:

                      • On windows XP, the last set of values, separated by ":" change.
                        Afx:00400000:b:00010011:00000006:0574025D
                      • On windows 7, all even parts, separated by ":" change. The odd parts are always the same, including on both 32 and 64 -bit processors.
                        Afx:00400000:b:00010011:00000006:0574025D

                      So, the only parts of class that are reliable to locate main SU window are, Afx, b and 00000006. Plus to get the current sketchup window, you could add the Process.pid. The code below does all of that work 😄

                      @main_window = Hash.new
                      @find_main_window = Win32;;API;;Callback.new('IP', 'I'){|hwnd, lParam|
                        p = 0.chr*4
                        threadID = GetWindowThreadProcessId.call(hwnd, p)
                        pid = p.unpack('l')[0]
                        next true if (pid != Process.pid)
                        cname = 0.chr*50
                        GetClassName.call(hwnd, cname, cname.size)
                        cname = cname.strip
                        if (cname[0,3] == "Afx") and (cname[13,1] == "b") and (cname[24,8] == "00000006")
                          @threadID = threadID
                          @main_window["hwnd"] = hwnd
                          next false
                        end
                        true
                      }
                      EnumWindows.call(@find_main_window, nil)
                      

                      Note, this example was only tested on Windows XP and On Win7.

                      What vous think?

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

                        You neglect to show the require() staement that loads Dan Berger's win32-api extensions. (This example does not use the Win32API.so file, that comes "out-of-the-box" with Ruby.)

                        I'm not here much anymore.

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

                          I find it much simplier.. to use a KNOWN child window (sometimes I use the Console window, sometimes I create a hidden child window with a caption that is unique, like perhaps I insert a time-stamp and the current Sketchup pid, returned with $$, into my child window caption.)

                          Then find the handle to that unique window, and get it's owner.

                          I'm not here much anymore.

                          1 Reply Last reply Reply Quote 0
                          • A Offline
                            Anton_S
                            last edited by

                            @dan rathbun said:

                            You neglect to show the require() staement that loads Dan Berger's win32-api extensions. (This example does not use the Win32API.so file, that comes "out-of-the-box" with Ruby.)

                            Thanks for pointing that out. Yep, the code above requires win32-api

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

                            Advertisement