PDA

View Full Version : Function for getting the Hwnd of a viewport


PEN
11-04-2009, 03:27 PM
Just thought that I would post this if any one else is interested. Let me know if you see any faster methods for doing this.

/*HeaderStart*******************************************************
:Created By: Paul Neale
:Company: PEN Productions Inc.
:Site: http://paulneale.com
:Email: info@paulneale.com
:Client: PEN Productions

:Purpose: Retuns the HWND for the active viewport.

:History:
Oct 04 2009
Created.

:Todo:

:Bugs:
None Known

:Tests:
for x in windows.getChildrenHWND #max do format "%\n" x

-->Use this to create a dotNet handle for the viewport.
p = DotNetObject "System.IntPtr" ( (getViewportHwnd()) [1])
maxHwnd = DotNetObject "MaxCustomControls.Win32HandleWrapper" p
*******************************************************HeaderEnd*/


/*FnStart*******************************************************
:Function: getActiveViewportName
:Usage: getActiveViewportName()
:Todo:
:Notes:
Called by getViewportHwnd
*******************************************************FnEnd*/
fn getActiveViewportName=
(
local viewName=viewport.getType()
case of
(
(viewName==#view_top): "Top"
(viewName==#view_bottom): "Bottom"
(viewName==#view_right): "Right"
(viewName==#view_left): "Left"
(viewName==#view_back): "Back"
(viewName==#view_persp_user): "Perspective"
(viewName==#view_iso_user): "Orthographic"
(viewName==#view_camera): (viewport.getCamera index:viewport.activeViewport).name
(viewName==#view_spot): (viewport.getCamera index:viewport.activeViewport).name
(viewName==#view_shape): "Shape"
(viewName==#view_grid): "Grid" --Will need to search for "Grid" in the name here.
)
)

/*FnStart*******************************************************
:Function: getViewportHwnd
:Usage: getViewportHwnd()
:Todo:
:Notes:
Calls getActiveViewportName and returns the HWND array for the active viewport.
*******************************************************FnEnd*/
fn getViewportHwnd=
(
local viewPortName=getActiveViewportName()
local returnHwnd=undefined
if viewPortName!=undefined do
(
for wHwnd in windows.getChildrenHWND #max do
(
if wHwnd[4]=="D3DWindow" and findString wHwnd[5] viewPortName!=undefined do
(
returnHwnd=wHwnd
exit
)
)
)
returnHwnd
)

Light
11-04-2009, 10:04 PM
Hey Paul,

It's not a killer but I would use this instead of using exit:

for wHwnd in windows.getChildrenHWND #max while returnHwnd == undefined do
(
if wHwnd[4]=="D3DWindow" and findString wHwnd[5] viewPortName!=undefined do
(
returnHwnd=wHwnd
)
)





Light

biddle
11-04-2009, 10:18 PM
Crazy, because it is so simple in the SDK:

::GetCOREInterface()->GetActiveViewport()->GetHWND()

PEN
11-05-2009, 02:59 AM
Right, exit is slow as well isn't it. I'll make the change, turns out I'm not using it now anyways.

Ya Mike there didn't appear to be an easy way.

CGTalk Moderation
11-05-2009, 02:59 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.