几何尺寸与公差论坛

 找回密码
 注册
查看: 940|回复: 0

【转帖】model 3d space in winforms

[复制链接]
发表于 2009-4-12 21:48:15 | 显示全部楼层 |阅读模式
model 3d space in winforms
hello all,
i was developing windows application in usnig c#.net winforms.
i could start the solidworks from windows application, at the same time is it possible to add the 3d space [model space] of solidworks to windows application.
so that whe whole application looks totally intergated with solidworks.
thanks
ravi belkhindi
ravi belkhindi
clydeunion
automation engineer
get the process id of the model window you want to capture then call the setparent invoke method.
[dllimport("user32.dll", setlasterror=true)]
static extern intptr setparent(intptr child, intptr newparent);
intptr win = system.diagnostics.process.getprocessbyid(pidhere).mainwindowhandle;
setparent(win, yourform.handle);
where pidhere is the pid of the model space, and yourform is a form or panel or wherever you want to capture the handle too.
then to release it back:
setparent(win, new intptr(0));
thank you luke,
i experimented on the idea you have given. it worked fine
to add solidworks main frame in winform i used the below code
swapp = new sldworksclass();
swapp.visible = true;
modeldoc2 doc;
doc =(modeldoc2)swapp.opendoc("c:\\fan.sldprt", (int)swdocumenttypes_e.swdocpart);
frame myframe = (frame)swapp.frame();
int winhandle = myframe.gethwnd();
setparent((intptr)winhandle, this.handle);
similarly i tried including only the model window in winform. for this i have written the following code.
swapp = new sldworksclass();
swapp.visible = true;
modeldoc2 doc;
doc =(modeldoc2)swapp.opendoc("c:\\fan.sldprt", (int)swdocumenttypes_e.swdocpart);
frame myframe = (frame)swapp.frame();
object modwindows = myframe.modelwindows; //get array of all open documents
modelwindow modelwin = (modelwindow)((object[])(modwindows))[0]; // get first model window
intptr err = setparent((intptr)winhandle1, this.handle);
when i run the program it gives err=o and the solidworks got hanged and prompted for restart. i have attached the snap of the error.
in first case i am attaching main frame to my winform - this worked fine
in second case
model window which is the child window of main frame [solidworks] and am trying to attach the child to my winform - is that the right approach.
thanks in advance
ravi b
ravi belkhindi
clydeunion
automation engineer
edited: 03/26/2009 at 04:23 am by ravi belkhindi
click for full image
in that case it is not possible. you are taking the model away from its parent, and so the parent and model can no longer communicate in their message pumps or access modifiers. you would have to capture the entire window, or clone the handle instead, deferring all messages to the real handle pump when the user interacts with it. not exactly a 2 minute code example i am afraid.
thanks,
well, why the solidworks object model gives the option to get the handle of each models.
how can this be utilized in the programs.
greatefull of you could throw some light on this.
thanks
ravi
ravi belkhindi
clydeunion
automation engineer
answer there is a lot more you can do with handles, callbacks, message pumps, bitblts, referencing, setting styles, custom message handling... its endless. but moving its parent means communication is lost, its like taking a fish out of a pond, it dies without its required surroundings to call upon.
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|几何尺寸与公差论坛

GMT+8, 2024-12-23 10:00 , Processed in 0.034892 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表