Adding RenderWindowControl to tool box - vtk

I am trying to use Kitware ActiViz.NET. I have installed it using nuget.
But I can't seem to find RenderWindowControl on the toolbox. I have been trying to add it manually this way:
invoke "Choose Items..."
and in the following dialog click on button "Browse...",
navigate to your ActiViz.NET installation folder, browse to /bin
folder, select "Kitware.VTK.dll".
Click OK.
Now you should see in your ToolBox a new control named RenderWindowControl.
But I get "The file "C:\programfiles\activiz.net 5.8.0 Opensource Eddition\bin\kitware.vtk.DLL" is not valid".
I have tried to add the control in the code rether than the designer,and got this exception:
Could not load file or assembly 'Kitware.VTK, Version=5.8.0.607, Culture=neutral, PublicKeyToken=995c7fb9db2c1b44' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Has anyone had this problem before?
Any ideas?

For the design mode you would need to use the 32Bit version, because VS is running on 32Bit and can only load 32Bit controls.
So you could use for design time the 32Bit version and for build/release switch to the 64bit version.
But you can also add the RenderWindowControl manually.
Of course the designer will be unable to display this, so it would be
necessary to comment it out, before switching to the designer
Open your designer file e.g. Form1.Designer.cs and add the control like
private RenderWindowControl myRenderWindowControl;
private void InitalizeComponent()
{
//all other controls added by the designer
myRenderWindowControl = new RenderWindowControl();
myRenderWindowControl.SetBounds(0,0,640,480);
this.Controls.Add(this.myRenderWindowControl);
}

Adding VTK's RenderWindowControl to WPF is a little more complicated.
Assuming you installed a 64 bit VTK package, the following steps worked for me.
https://learn.microsoft.com/en-us/dotnet/framework/wpf/advanced/walkthrough-hosting-a-windows-forms-control-in-wpf
Add Project References to WindowsFormsIntegration and System.Windows.Forms
Draw a Grid on the Designer Form.
In Properties Dialog, Give it a name, then
Double Click the Loaded event.
In the loaded event handler add the code.
// Create the interop host control.
System.Windows.Forms.Integration.WindowsFormsHost host =
new System.Windows.Forms.Integration.WindowsFormsHost();
myRenderWindowControl = new RenderWindowControl();
myRenderWindowControl.SetBounds(0, 0, 30, 30); // not too big in case it disappears.
// Assign the control as the host control's child.
host.Child = myRenderWindowControl;
this.VTKGrid.Children.Add(host);

Related

VB6: Name conflicts with existing module, project, or object library

Opening a VB6 Project, I get errors like:
Errors during load. Refer to xyz.LOG
I open the log file and see these errors:
Line 42: Class Threed.SSPanel of control XYZ was not a loaded control
class.
In this case I can see the problem is due to the Sheridan 3D Controls: C:\WINDOWS\system32\THREED32.OCX
I thought the project was missing a component so, VB6 > Project > Components > tick the Sheridan 3D Controls and got this error:
---------------------- Microsoft Visual Basic ---------------------------
Name conflicts with existing module, project, or object library
--------------------------- OK Help ---------------------------
I will give you the best way to get rid of this problem. I came across many ways, but this is the most best way to deal with..
Close the project. Right click on the vb project and open with notepad (not with vb). This Project file will only consist of all the references, libraries and information about forms and modules used in the project.
Now just remove the conflicting module or component file, you have problem, by just deleting the entire line.. Save and close it
and now open the project and add component. I swear you wont get that error.
Thank you. Enjoy
The way to troubleshoot this problem is to start a new VB6 project > Project Menu Components > tick the Components that are selected in the affected project until you get the error.
---------------------- Microsoft Visual Basic ---------------------------
Name conflicts with existing module, project, or object library
--------------------------- OK Help ---------------------------
You need to narrow it down to the two OCX's that are conflicting.
In my case I narrowed it down to Sheridan 3D Controls / THREED32.OCX and Outrider Spin Control / SPIN32.ocx
To fix the problem I used RegSvr32 to unregister the OCXs - make sure you UNregister with the /u flag.
REGSVR32 "C:\WINDOWS\system32\THREED32.OCX" /u
I then copied the OCX's to the project folder and registered them again using:
REGSVR32 "C:\Dev\Project\THREED32.OCX"
Then in the project with the problem > Project Menu Components > select the item in the listbox Sheridan 3D controls / THREED32.ocx (you cant tick without getting the error or untick the conflicting one that is selected as its in use) > click Browse and reference it from the project folder rather than C:\WINDOWS\system32\
Another trick is close the project and unregister the affected ocx - make sure you UNregister it with the /u flag, eg
RegSvr32 "c:\Windows\system32\mscomctl.ocx" /u
Then open the project > Components > and you should see the "Microsoft Windows Common Controls 6.0 (SP6)" is using a OCX file in C:...\Microsoft Vi..\VB98\mscomctl.ocx" rather than c:\Windows\system32\mscomctl.ocx.
The project should then load without these errors:
Errors during load. Refer to xyz.LOG
Try unchecking the latest object library / reference from the references and check it again and then go for your desired reference (vb6 has few bugs which can be countered by a reverse process). I solved the error mentioned using this process.

How to overcome the error "The unknown namespace tag xe:applicationLayout cannot be used as a control."

I created a sort of template DB for my Xpages applications. It is not a true template, just a design I can grab code from to start a new Xpages db.
I copied over a cc and got this error:
"The unknown namespace tag xe:applicationLayout cannot be used as a control, as the namespace http://www.ibm.com/xsp/coreex is not known."
I tried to creating a new cc in the target db and just pasting the source in, still got that error. What does that error mean and how can I overcome it?
I mean, come on, I can't copy and past design elements from one db to another???
It means that you haven't enabled the ExtLib in the application's properties. If you do to the Xsp Properties (in 9.0+) or Application Properties (in ancient releases), you can enable the com.ibm.xsp.extlib.library library, assuming you have it installed.
There is an event that can be triggered when dropping a native control onto an XPage or Custom Control. That event is used to enable the library in Xsp Properties. It's also used to enable the relevant abbreviation (xe, xc etc) on the pages. The bottom line is copy and paste isn't that sophisticated!
And it's not exclusive to the Extension Library. Try copying and pasting a Custom Control to a brand new XPage and save it. It will give you virtually the same message, but this time saying "xc" is not bound.
You need to enable the Extension Library manually if you're copying a custom control across. Alternatively, you can just drag and drop any Extension Library control onto any page in the application, then delete it!
If you're copying source code from one XPage to another, if it includes anything other than an xp tag, you need to check the relevant xml namespace is specified in the xp:view tag. So in the case of copying source code for the application layout, also adding xmlns:xe="http://www.ibm.com/xsp/coreex" to the xp:view tag.
(This was too long an elaboration to just add as a comment to Jesse's answer, which I've up-voted)

Determining which Visual Studio context menu was selected?

I'm writing a VS2012 add-in, adding a command to Build Explorer context menu (see related question). The command gets added to 2 different context menus:
Build Explorer
Team Explorer, Builds page, My Builds section
When my one callback is called, how do I know which of these it is?
I tried get the focused control (using P/Invoke as this question suggests). However, it gets me a Tabs container for (1), and null for (2). I could try to cast the control to the tabbed container, but that sounds pretty bad...
Any better alternative?
My new/other idea - it is similar to yours:
You should try to monitor which window was activated lastly.
If you create an eventhandler for your command, then you may be able to check which window is active when your command fired. A simple evenent handler for a command:
void cmdEvents_BeforeExecute( string guid, int ID, object customIn, object customOut, ref bool cancelDefault )
{
Window2 teamExplorer = _applicationObject.Windows.Item("Team Explorer") as Window2;
if (_applicationObject.ActiveWindow.Caption == teamExplorer.Caption)
{
//You are called from Team Explorer
}
else
{
//Somewhere else
}
}
And the way you can subscribe:
static _dispCommandEvents_BeforeExecuteEventHandler _myHandler;
static CommandEvents _cmdEvents;
public void OnConnection(...)
{
Command command = ...; // Init your command
int ID = command.ID;
string GUID = command.Guid;
CommandEvents _cmdEvents = _applicationObject.Events.get_CommandEvents(GUID, ID);
_myHandler = new _dispCommandEvents_BeforeExecuteEventHandler(cmdEvents_BeforeExecute);
_cmdEvents.BeforeExecute += _myHandler;
}
You may find a better way to identify the window(s) by GUID. You should keep at least _cmdEvents as static because when it will be desroyed, your event handler could vanish (least for internal commands).
In OnDisconnection you should unsubscribe.
Reworked by the comment, and founded links:
As the menu item is shown every place it seems there is no way to distinct between them from an Add-In, you should add two command and distinct them by their context.
The way instead of converting the Add-In to a VS-Package MZ-Tools HOWTO: Controlling the state of command in a Visual Studio add-in, try MZ-Tools HOWTO: Use the IVsMonitorSelection ... you can also get it from an Add-In.
But:
Neither the AddNamedCommand nor the QueryStatus methods honor the
invisible state: the button that must be invisible ...
remains disabled rather than invisible.
I think this makes it impossible to do it from an Add-In on a suitable way, but maybe you can check the contexts.
Other way you could get further, if you try to migrate your command/menu into a VSPackage and create a custom UIContext for the menu items or find a suitable predefined one. I have no access to a Studio enhanced with Build Explorer so I can't try it.
The following discussion is about custom contexts for vs-packages:
http://davedewinter.com/2008/04/05/dynamic-menu-commands-in-visual-studio-packages-part-3/
Sadly the links are broken from the post, and I can't reach Part 1. and Part 2. which is about the discussion of the problem from the beginning.
But there is no guarantee you can create a context which suits you.
Only context ID I found for Team Explorer is the guidTeamProjectCmdUIContext.
It is placed at vsshilds.h in Visual Studio 2010 SDK, vsshell*.h are also contain several others.
MSDN: Vsct files to define command, menus, ect. from packages.
Condition attribute for items:
http://msdn.microsoft.com/en-us/library/bb491718.aspx
http://msdn.microsoft.com/en-us/library/bb166515.aspx
MSDN: VisibilityItem element for commands and toolbars.
VisibilityItem element determines the static visibility of commands and toolbars.
... After the VSPackage is loaded, Visual Studio expects command visibility to be determined by the VSPackage rather than the VisibilityItem.
And finally about predefined Context Guids:
http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.interop.uicontextguids80.aspx
http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.interop.uicontextguids.aspx

Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED)): ActiveX and C# Console Application

So, I am playing around with ActiveX and C# and ways how both of them can work together. the thing is I have hit the wall right in the beginning with mentioned error. Steps I have followed:
In VS2010 I selected MFC ActiveX Control project. Then I added a method "SHORT Multiply( SHORT a, SHORT b);" by clicking the Add method option in the menu that pops when you right click _DProjectname under ProjectnameLib in solution explorer. The code for the method is as follows:
SHORT CSampleProgramActivex01Ctrl::Multiply(SHORT a, SHORT b)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// TODO: Add your dispatch handler code here
return ( a * b);
}
Now I have created a simple C# console application that references the generated COM file and when I try to use the method, the application stops with the above mentioned error. I have searched the error on the internet but no clear solution is mentioned. Any help appreciated. If you guys want clarification, let me know.
I don't know whether this is considered as solving the problem or not but I found a workaround:
First instead of C# console application, I created C# windows form application. After creating the form, I have added the whole ocx as component in the toolbox. You do this by right-clicking the Toolbox types in Toolbox menu. In the new menu, you click Choose Items. This pops up new menu and in that select the COM tab and in that check your COM component and the COM component will be added to the Toolbox menu. Now drag and drop the component on the menu and you should be good to go.
This seems to be workaround that everybody is following. Not neat but that is the norm I think.
look at here: How to use an OLE control as an automation server in Visual C++
http://support.microsoft.com/kb/146120/en-us

VC++ and MapPoint OCX control dialog issue

I am writing a VC++ MFC dialog based app which requires Microsoft MapPoint embedding in it. To do this I'm using MS VC++ .NET 2003 and MapPoint Europe 2006 to do this but am having problems as when I select "Insert ActiveX Control" no MapPoint control appears in the list of options. I have tried manually registering mappointcontrol.ocx with regsvr32 which appears to succeed but still the control doesn't appear on the list.
Can anyone suggest what I am doing wrong here, and any possible solutions.
Thanks
Ian
Have you tried using the ActiveX control test container? Is it in the list of controls? How about using the register button in the test container?
Also check the registry to see if it is registered. You should have an entry in HKEY-CLASSES-ROOT\controlName that has a CLSID element that points to a UUID. That UUID should also be in HKEY-CLASSES-ROOT\CLSID\uuid and have a LocalServer32 entry that points to the DLL and ProgID that points back to controlName.
I have now got the Mappoint control working but in a slightly different way. The control does appear on the list of controls the test container can use. I have tried reregistering it and unregistering it but still it doesn't appear on the list of controls when I try a "Insert ActiveX Control". However if I use "Add/Remove Toolbox Items" I can add it to the toolbox and then drag it into my app where it works fine. I'm not sure why this method works but it does and I can get on with my coding.
Many thanks for all your help with this.

Resources