[code] Win32 Moving/Showing/Hiding Toolbars and Dialogs
-
As implemented in TT_Lib2 with error checking:
<span class="syntaxdefault"><br /> </span><span class="syntaxcomment"># Call after webdialog.show to change the window into a toolwindow. Spesify the<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># window title so the method can verify it changes the correct window.<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment">#<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># @param [String] window_title<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment">#<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># @return [Nil]<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># @since 2.5.0<br /></span><span class="syntaxdefault"> def self</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">make_toolwindow_frame</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">window_title</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># Retrieves the window handle to the active window attached to the calling<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># thread's message queue. <br /></span><span class="syntaxdefault"> 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">nil</span><span class="syntaxkeyword">?<br /></span><span class="syntaxdefault"> <br /> </span><span class="syntaxcomment"># Verify window text as extra security to ensure it's the correct window.<br /></span><span class="syntaxdefault"> buf_len </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> GetWindowTextLength</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">call</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">hwnd</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> return nil if buf_len </span><span class="syntaxkeyword">==</span><span class="syntaxdefault"> 0<br /> <br /> str </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxstring">' '</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">*</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">(</span><span class="syntaxdefault">buf_len </span><span class="syntaxkeyword">+</span><span class="syntaxdefault"> 1</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> result </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> GetWindowText</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"> str</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> str</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">length</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> return nil if result </span><span class="syntaxkeyword">==</span><span class="syntaxdefault"> 0<br /> <br /> return nil unless str</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">strip </span><span class="syntaxkeyword">==</span><span class="syntaxdefault"> window_title</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">strip<br /> <br /> </span><span class="syntaxcomment"># Set frame to Toolwindow<br /></span><span class="syntaxdefault"> style </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> GetWindowLong</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"> GWL_EXSTYLE</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> return nil if style </span><span class="syntaxkeyword">==</span><span class="syntaxdefault"> 0<br /> <br /> result </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> SetWindowLong</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"> GWL_EXSTYLE</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> style </span><span class="syntaxkeyword">|</span><span class="syntaxdefault"> WS_EX_TOOLWINDOW</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> return nil if result </span><span class="syntaxkeyword">==</span><span class="syntaxdefault"> 0<br /> <br /> </span><span class="syntaxcomment"># Remove and disable minimze and maximize<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># http://support.microsoft.com/kb/137033<br /></span><span class="syntaxdefault"> style </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> GetWindowLong</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"> GWL_STYLE</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> return nil if style </span><span class="syntaxkeyword">==</span><span class="syntaxdefault"> 0<br /> <br /> style </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> style </span><span class="syntaxkeyword">&</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">~</span><span class="syntaxdefault">WS_MINIMIZEBOX<br /> style </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> style </span><span class="syntaxkeyword">&</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">~</span><span class="syntaxdefault">WS_MAXIMIZEBOX<br /> result </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> SetWindowLong</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"> GWL_STYLE</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> style</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> return nil if result </span><span class="syntaxkeyword">==</span><span class="syntaxdefault"> 0<br /> <br /> </span><span class="syntaxcomment"># Refresh the window frame<br /></span><span class="syntaxdefault"> result </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> SetWindowPos</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"> 0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> SWP_FRAMECHANGED</span><span class="syntaxkeyword">|</span><span class="syntaxdefault">SWP_NOSIZE</span><span class="syntaxkeyword">|</span><span class="syntaxdefault">SWP_NOMOVE</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> result </span><span class="syntaxkeyword">!=</span><span class="syntaxdefault"> 0<br /> end<br /></span>
-
Can we have code blocks that expand similar to when you click on images?
-
What are possible advantages of using toolwindows instead of webdialogs?
And is the communication between SU and the toolwindow still done in the same way? -
It's not different windows - it's just different window frames. The code examples changes the window frame of webdialogs to toolwindows - which takes up less space and look neater.
-
Thanks for following (and cleaning) up the example. Will some this be getting into TT_Lib at some point?
-
@jim said:
Will some this be getting into TT_Lib at some point?
TT_Lib2, yes.
I already got a wrapper to create toolwindows.
<span class="syntaxdefault"><br /> def show_toolbar<br /> options </span><span class="syntaxkeyword">= {<br /> ;</span><span class="syntaxdefault">title </span><span class="syntaxkeyword">=> </span><span class="syntaxstring">'Bezier Surface'</span><span class="syntaxkeyword">,<br /> ;</span><span class="syntaxdefault">pref_key </span><span class="syntaxkeyword">=> </span><span class="syntaxstring">"#{TT;;Plugins;;BPatch;;ID}_Toolbar"</span><span class="syntaxkeyword">,<br /> ;</span><span class="syntaxdefault">width </span><span class="syntaxkeyword">=> </span><span class="syntaxdefault">128</span><span class="syntaxkeyword">,<br /> ;</span><span class="syntaxdefault">height </span><span class="syntaxkeyword">=> </span><span class="syntaxdefault">52</span><span class="syntaxkeyword">,<br /> ;</span><span class="syntaxdefault">resizable </span><span class="syntaxkeyword">=> </span><span class="syntaxdefault">false</span><span class="syntaxkeyword">,<br /> ;</span><span class="syntaxdefault">scrollable </span><span class="syntaxkeyword">=> </span><span class="syntaxdefault">false<br /> </span><span class="syntaxkeyword">}<br /> @</span><span class="syntaxdefault">toolbar </span><span class="syntaxkeyword">||= </span><span class="syntaxdefault">TT</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">GUI</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">ToolWindow</span><span class="syntaxkeyword">.new( </span><span class="syntaxdefault">options </span><span class="syntaxkeyword">)<br /> @</span><span class="syntaxdefault">toolbar</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">show_window<br /> end<br /></span>
(Extract from a work in progress project.)
-
Wonder if one can hook into windows like this under OSX...
-
@pout said:
What are possible advantages of using toolwindows instead of webdialogs?
And is the communication between SU and the toolwindow still done in the same way?For some windows, if it is a Toolwindow it will not show up in the Alt-Tab list. But this is normal for SketchUp dialog windows anyway, so there should be no difference there.
-
@thomthom said:
I some times experience that the window automatically closes after a few seconds. it has happened only sporadically...)
It's just getting GC'd.
window
is a local variable referencing the WebDialog, and the variable no longer exists after the method exits. Since the WebDialog no longer has any references, it is GC'd.@thomthom said:
Can GWL_STYLE and GWL_EXSTYLE changes be combines into one call?
Maybe - the "styles" are just bits but at different offset (one is -16, the other -20). If you meant is there a win32api function for setting both simultaneously then I don't know.
Hehe, the php highlighter work OK on Ruby.
-
@jim said:
It's just getting GC'd. window is a local variable referencing the WebDialog, and the variable no longer exists after the method exits. Since the WebDialog no longer has any references, it is GC'd.
Oh... that's a gotcha I didn't think of. You need to keep a reference to the WD for the duration of its lifespan.
@jim said:
Maybe - the "styles" are just bits but at different offset (one is -16, the other -20). If you meant is there a win32api function for setting both simultaneously then I don't know.
The thing is - today, I don't really see any lag...
What's nice about having toolwindows is that now I can make my custom toolbar.
-
Just came across a nice API call that will be useful for creating webdialog toolbars:
http://social.msdn.microsoft.com/forums/en/csharpgeneral/thread/e7fef568-2c0b-41eb-9785-304f84d03819/#bf79c87e-ef49-456f-a485-aa767d841d20One can use
WS_EX_NOACTIVATE
to prevent a window from catching focus - but from what I understand it'll still allow interaction events. I'll try it out as soon as I get home. -
hm....
@unknownuser said:
The WS_EX_NOACTIVATE value for dwExStyle prevents foreground activation by the system. To prevent queue activation when the user clicks on the window, you must process the WM_MOUSEACTIVATE message appropriately. To bring the window to the foreground or to activate it programmatically, use SetForegroundWindow or SetActiveWindow. Returning FALSE to WM_NCACTIVATE prevents the window from losing queue activation. However, the return value is ignored at activation time.
http://msdn.microsoft.com/en-us/library/ms632680%28v=vs.85%29.aspx
"queue activation"?
-
bleh... turns out to not be so straight forwards as I though. Seems that one needs to handle some window messages:
http://www.allquests.com/question/132471/Ws-ex-noactivate.html
http://stackoverflow.com/questions/2969680/c-showing-form-with-ws-ex-noactivate-flagBut working out how to handle window messages would be a very interesting thing - as then we could recreate the roll-up/down feature of SU's toolwindows.
-
tt, most of this discussion is "over my head", but will the result permit toolbars to unfold perpendicular to the edge of a sketchup window like the menus do? If so please provide a simple version that we can use to compact our application toolbars.
-
It doesn't modify existing toolbars. I'm simply modifying the appearance of webdialogs.
@honoluludesktop said:
but will the result permit toolbars to unfold perpendicular to the edge of a sketchup window like the menus do?
You mean toolbars where you click on a button and it displays a dropdown list of more buttons?
-
Yes, Would go a long way to cleaning up our screens.
-
Interesting though - but I'm not sure if it's possible. In either case - if you start making all toolbars like that they end up having the same problem as menus - that everything is hidden in sub-menus and you need an extra operation to reveal it - to be able to explore available commands. I feel the usability would not be improved.
If one has that many toolbars open I'd rather ask if they are all required to be there on screen.
Personally I assign hotkeys to the most frequent commands I use. Then I have a few toolbars for semi-frequent command. For everything else I use the menus.
I have been toying with the idea of having a webdialog which allows you to filter out the commands you want - and make sets of tools you can switch between depending on the job.
-
@thomthom said:
...........if you start making all toolbars like that they end up having the same problem as menus - that everything is hidden in sub-menus and you need an extra operation to reveal it - to be able to explore available commands. I feel the usability would not be improved.
.........You are probably right about this.
-
I do have an experimental hack to catch all menus, commands and toolbar items that's created. I hope to tind time soon to put together a basic version of a plugin that let you quickly search and filter out available commands.
-
@thomthom said:
@honoluludesktop said:
but will the result permit toolbars to unfold perpendicular to the edge of a sketchup window like the menus do?
You mean toolbars where you click on a button and it displays a dropdown list of more buttons?
These are called "Flyout Toolbars" and have been a part of the AutoCAD GUI since at least R13 (circa 1994) and perhaps even R12 in Win16 mode.
This is one of the things on my to do list for Win32 Sketchup.
Advertisement