by Jim » Sun Sep 26, 2010 3:13 am
Not a plugin - just some example codes for manipulating the toolbar and dialog windows by name using the Win32API.so library file. The documentation for these constants and functions can be found by searching msdn. These functions are for floating toolbars and dialogs. Docked toolbars will not be changed. move_toolbar("Views", [x, y, w, h]) hide_toolbar("Standard") remove_caption("Styles") show_toolbar("Standard") restore_caption("Styles")Remove Caption679.png - Code: Select all
pw = FindWindow.call(c, name) style = GetWindowLong.call(pw, GWL_STYLE) SetWindowLong.call(pw, GWL_STYLE, style & ~WS_CAPTION)
Restore Caption- Code: Select all
pw = FindWindow.call(clss, name) style = GetWindowLong.call(pw, GWL_STYLE) SetWindowLong.call(pw, GWL_STYLE, style | WS_CAPTION) SetWindowPos.call(pw, 0, 0, 0, 0, 0, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE)
WebDialog -> ToolWindow702.png - Code: Select all
w = UI::WebDialog.new("New Web Dialog") w.show hwnd = FindWindow.call(DIALOG_CLASS, "New Web Dialog") style = GetWindowLong.call(hwnd, GWL_EXSTYLE) SetWindowLong.call(hwnd, GWL_EXSTYLE, style | WS_EX_TOOLWINDOW) SetWindowPos.call(hwnd, 0, 0, 0, 0, 0, SWP_FRAMECHANGED|SWP_NOSIZE|SWP_NOMOVE)
- Code: Select all
require 'sketchup' require 'Win32API'
# ShowWindow() flags SW_HIDE = 0 SW_SHOWNORMAL = 1 SW_SHOWDEFAULT = 1 SW_MAXIMIZE = 3 SW_SHOW = 5 SW_MINIMIZE = 6 SW_RESTORE = 9
WS_CAPTION = 0x00C00000 GWL_STYLE = -16
# SetWindowPos() flags SWP_NOSIZE = 0x0001 SWP_NOMOVE = 0x0002 SWP_DRAWFRAME = 0x0020 SWP_FRAMECHANGED = 0x0020 SWP_NOREPOSITION = 0x0200
# SketchUp Info SKETCHUP_CLASS = "Afx:00400000:b:00010011:00000006:3EFB027F" TOOLBAR_CLASS = "Afx:00400000:8:00010011:00000000:00000000" DIALOG_CLASS = "#32770" # Dialogs, WebDialogs, and everything else.
# Windows Functions FindWindow = Win32API.new("user32.dll" , "FindWindow" , ['P', 'P'] , 'N') #FindWindowEx = Win32API.new("user32.dll", "FindWindowEx" , ['N', 'N' , 'P' , 'P'], 'N') SetWindowPos = Win32API.new("user32.dll" , "SetWindowPos" , ['P', 'P' , 'N' , 'N' , 'N' , 'N', 'N'], 'N') GetClassName = Win32API.new("user32.dll" , "GetClassName" , ['P', 'P' , 'I'], 'N') GetWindowRect = Win32API.new("user32.dll" , "GetWindowRect", ['P', 'PP'], 'N') SetWindowLong = Win32API.new("user32.dll" , "SetWindowLong", ['P', 'N' , 'N'], 'N') GetWindowLong = Win32API.new("user32.dll" , "GetWindowLong", ['P', 'N'] , 'L') ShowWindow = Win32API.new("user32.dll" , "ShowWindow" , ['P', 'N'] , 'N')
# Originally in SketchyPhysic by Chris Phillips def get_window_rect(name) pw = FindWindow.call(0, name) rect = Array.new.fill(0.chr,0..4*4).join GetWindowRect.call(pw, rect); rect=rect.unpack("i*") #turn rectangle into [top, left, width, height] instead of [top, left, right, bottom] rect[2]=rect[2]-rect[0] #w=x2-x1 rect[3]=rect[3]-rect[1] #h=y2-y1 return rect end
def show_toolbar(name, sw=1) pw = FindWindow.call(TOOLBAR_CLASS, name) ShowWindow.call(pw, sw) end
def hide_toolbar(name) pw = FindWindow.call(TOOLBAR_CLASS, name) ShowWindow.call(pw, SW_HIDE) end
def move_toolbar(name, rect, flags = 0) pw = FindWindow.call(TOOLBAR_CLASS, name) return unless pw rect.flatten! x, y, w, h = rect SetWindowPos.call(pw, 0, x, y, w, h, flags) end
def move_dialog(name, rect, flags=SWP_NOSIZE) pw = FindWindow.call(DIALOG_CLASS, name) return unless pw rect.flatten! x, y, w, h = rect SetWindowPos.call(pw, 0, x, y, w, h, flags) end
Last edited by Jim on Wed Sep 29, 2010 10:40 pm, edited 2 times in total.
Hi
-
Jim
- Global Moderator
-
- Posts: 4678
- Joined: Mon Nov 12, 2007 10:13 pm
- Location: ohio
- Name: Jim
- Operating system: Windows
- SketchUp version: 2017
- License type: Pro
- SketchUp use: hobby
- Level of SketchUp: Intermediate
-
by thomthom » Sun Sep 26, 2010 11:46 am
What I wanted to do was work out what flags to change to make a WebDialog into a ToolWindow. You haven't looked into that by any chance?
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by thomthom » Sun Sep 26, 2010 4:45 pm
It can - I used to do it in Visual Basic when VB didn't offer full control over the windows. You can in fact change any window of any app - as long as you get its handle.
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by Jim » Sun Sep 26, 2010 4:50 pm
Yep, just did it. I'm just wondering of I am not writing a library that has already been written...
Hi
-
Jim
- Global Moderator
-
- Posts: 4678
- Joined: Mon Nov 12, 2007 10:13 pm
- Location: ohio
- Name: Jim
- Operating system: Windows
- SketchUp version: 2017
- License type: Pro
- SketchUp use: hobby
- Level of SketchUp: Intermediate
-
by thomthom » Sun Sep 26, 2010 4:57 pm
How quickly can you get the window handle when opening webdialogs? Can you avoid a flicker of change?
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by Jim » Sun Sep 26, 2010 5:09 pm
Good question I don't know the answer to, but wouldn't the reliable way be to have the dialog send a message back to ruby when it's ready?
Or can you change the dialog to a toolwindow before you .show() it? Will need to test.
Hi
-
Jim
- Global Moderator
-
- Posts: 4678
- Joined: Mon Nov 12, 2007 10:13 pm
- Location: ohio
- Name: Jim
- Operating system: Windows
- SketchUp version: 2017
- License type: Pro
- SketchUp use: hobby
- Level of SketchUp: Intermediate
-
by thomthom » Sun Sep 26, 2010 5:38 pm
Maybe the .show event of the dialog triggers as it's displayed? But I'm not sure if it wait for the HTML - which you do not want - as that will lag.
And can you do anything before calling show? You need a handle to the window - how are you getting that at the moment?
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by Jim » Sun Sep 26, 2010 5:58 pm
What does it mean when I get a negative value for a window style? How do I decode it into it's positive representation?
Hi
-
Jim
- Global Moderator
-
- Posts: 4678
- Joined: Mon Nov 12, 2007 10:13 pm
- Location: ohio
- Name: Jim
- Operating system: Windows
- SketchUp version: 2017
- License type: Pro
- SketchUp use: hobby
- Level of SketchUp: Intermediate
-
by thomthom » Sun Sep 26, 2010 5:59 pm
From GetWindowLong?
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by Jim » Sun Sep 26, 2010 6:06 pm
yeah.
s = get_style("Ruby Console") -1798569916
Hi
-
Jim
- Global Moderator
-
- Posts: 4678
- Joined: Mon Nov 12, 2007 10:13 pm
- Location: ohio
- Name: Jim
- Operating system: Windows
- SketchUp version: 2017
- License type: Pro
- SketchUp use: hobby
- Level of SketchUp: Intermediate
-
by thomthom » Sun Sep 26, 2010 6:14 pm
hm....
Are you receiving the data in the correct data type?
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by Jim » Mon Sep 27, 2010 12:25 am
Turns out the negative return value is not a problem - I just wasn't using it right.
Hi
-
Jim
- Global Moderator
-
- Posts: 4678
- Joined: Mon Nov 12, 2007 10:13 pm
- Location: ohio
- Name: Jim
- Operating system: Windows
- SketchUp version: 2017
- License type: Pro
- SketchUp use: hobby
- Level of SketchUp: Intermediate
-
by Jim » Mon Sep 27, 2010 12:41 am
thomthom wrote:Maybe the .show event of the dialog triggers as it's displayed? But I'm not sure if it wait for the HTML - which you do not want - as that will lag.
And can you do anything before calling show? You need a handle to the window - how are you getting that at the moment?
Using FindWindow - which is a basic search by window name and class.
Hi
-
Jim
- Global Moderator
-
- Posts: 4678
- Joined: Mon Nov 12, 2007 10:13 pm
- Location: ohio
- Name: Jim
- Operating system: Windows
- SketchUp version: 2017
- License type: Pro
- SketchUp use: hobby
- Level of SketchUp: Intermediate
-
by Jim » Mon Sep 27, 2010 6:41 pm
For a WebDialog, I couldn't find a handle until it was shown. I used EnumWindows and EnumChildWidows to locate it.
But I didn't see a lag when applying the ToolWIndow class immediately after .showing the webdialog.
Hi
-
Jim
- Global Moderator
-
- Posts: 4678
- Joined: Mon Nov 12, 2007 10:13 pm
- Location: ohio
- Name: Jim
- Operating system: Windows
- SketchUp version: 2017
- License type: Pro
- SketchUp use: hobby
- Level of SketchUp: Intermediate
-
by thomthom » Mon Sep 27, 2010 9:17 pm
Neat! 
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by Jim » Mon Sep 27, 2010 10:25 pm
The Win32API.so file does not support the use of callbacks needed by EnumWindows and EnumChildWindows. So I have had to move to win32/api.so, which does support callbacks. But this will also allow more interesting things to be done, such as finding resizing Sketchup by its drawing area, and sending values to the Measurements box via a plugin.
Hi
-
Jim
- Global Moderator
-
- Posts: 4678
- Joined: Mon Nov 12, 2007 10:13 pm
- Location: ohio
- Name: Jim
- Operating system: Windows
- SketchUp version: 2017
- License type: Pro
- SketchUp use: hobby
- Level of SketchUp: Intermediate
-
by thomthom » Wed Sep 29, 2010 2:38 pm
When there is multiple SketchUp windows open - how do you find the one you want?
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by Jim » Wed Sep 29, 2010 2:52 pm
Hopefully, the window titles are different. If not, I'm not sure.
Hi
-
Jim
- Global Moderator
-
- Posts: 4678
- Joined: Mon Nov 12, 2007 10:13 pm
- Location: ohio
- Name: Jim
- Operating system: Windows
- SketchUp version: 2017
- License type: Pro
- SketchUp use: hobby
- Level of SketchUp: Intermediate
-
by thomthom » Wed Sep 29, 2010 2:55 pm
So you look for windows with "<filename> - SketchUp (Pro)"
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by Jim » Wed Sep 29, 2010 2:57 pm
Too fast... here's how to get the exact name. (But is_pro? is for windows 7+) - Code: Select all
def su_window_name pro = Sketchup.is_pro? ? " Pro" : "" if ((title = Sketchup.active_model.title).empty?) return ("Untitled - SketchUp" + pro) else return (title += ".skp - SketchUp" + pro) end end
Hi
-
Jim
- Global Moderator
-
- Posts: 4678
- Joined: Mon Nov 12, 2007 10:13 pm
- Location: ohio
- Name: Jim
- Operating system: Windows
- SketchUp version: 2017
- License type: Pro
- SketchUp use: hobby
- Level of SketchUp: Intermediate
-
by thomthom » Wed Sep 29, 2010 2:59 pm
But when there is two untitled windows there could be problems?
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by Jim » Wed Sep 29, 2010 3:00 pm
Yes, but in that case how would any program know which one the user meant?
You can find all of the matching windows. It's just hard to know which the user meant to use.
Hi
-
Jim
- Global Moderator
-
- Posts: 4678
- Joined: Mon Nov 12, 2007 10:13 pm
- Location: ohio
- Name: Jim
- Operating system: Windows
- SketchUp version: 2017
- License type: Pro
- SketchUp use: hobby
- Level of SketchUp: Intermediate
-
by thomthom » Wed Sep 29, 2010 3:03 pm
Jim wrote:Yes, but in that case how would any program know which one the user meant?
If you'd created the window then you'd get the handle from there. (Would be nice if the API could expose the handles in the Ruby API) I suppose that if it is possible to get an array of matching windows one could filter out the window you want by checking if one of them is the active - if it's the active SU window you want. (Assuming SU is the currently active window) Or maybe by Z-Order? Assuming that the top most is the most recent - again if that is what you want...
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by thomthom » Wed Sep 29, 2010 3:13 pm
In most cases you'd get the window the user is working on, right? So how about GetForegroundWindow - then, in case one of the toolbars or webdialogs are the active window, iterate down the hierarchy using GetParent - checking for matching window title?
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by JD Hill » Fri Oct 01, 2010 2:05 pm
If you have an API which supports EnumWindows, you can use GetProcessId and GetWindowThreadProcessId to filter on windows in the current process.
-

JD Hill
- Bella Render
-
- Posts: 76
- Joined: Mon Oct 26, 2009 11:56 pm
- Name: JD Hill
by thomthom » Mon Oct 04, 2010 1:34 pm
Jim wrote:But I didn't see a lag when applying the ToolWIndow class immediately after .showing the webdialog.
You got a snippet of how you applied the ToolWindow style?
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by thomthom » Mon Oct 04, 2010 4:40 pm
'N' instead of 'L'? hm.. I'm a wee bit confused to exactly when to use what type...
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by Jim » Mon Oct 04, 2010 5:05 pm
From the pick-axe book: Strings ``n'' and ``l'' represent numbers, ``i'' represent integers, ``p'' represents pointers to data stored in a string ``v'' represents a void type (used for export parameters only). These strings are case-insensitive.
So I guessed you just use the type that is the best match to the API call parameters. In other words, your guess is as good as mine.
Hi
-
Jim
- Global Moderator
-
- Posts: 4678
- Joined: Mon Nov 12, 2007 10:13 pm
- Location: ohio
- Name: Jim
- Operating system: Windows
- SketchUp version: 2017
- License type: Pro
- SketchUp use: hobby
- Level of SketchUp: Intermediate
-
by thomthom » Mon Oct 04, 2010 9:08 pm
is N === L ? "Number" vs Integer? Number == Float?
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by Ad Machine » 5 minutes ago
-
Ad Machine
- Robot
-
- Posts: 2012
-
Return to Developers' Forum
|