Create a ActiveX with a MFC existing application - visual-studio

I'm trying to convert my MFC application, a simple "PaintBrush" app that draws lines and rectangles (it's only a little test from another bigger application), to a ActiveX Control that a could embed into a Windows Forms Application (with Visual C#).
I didn't found any tutorial for do this, and now, I'm not sure that this it's possible.
I know how create an ActiveX Control recently created but not how convert an existing application.
Have anybody know how I can do this?
Thanks!

Even though your part of the code often remains similar, the framework part of the code changes enough for a control vs. application that I doubt it's very reasonable to try to migrate the current project.
Rather, I'd build a new ActiveX control, and paste pieces from your current application into appropriate places in the new control -- for example, taking the code from your view's OnDraw, and pasting it into the OnDraw for the control project.

Related

How do I prevent Sharp Develop from renaming my controls?

I'm using a TabControl. I want to paste lots of controls from one tab to another but I want to only add a number at the end of the current name of each control so I don't have to name them all over again.
Is there a way to prevent auto renaming in Sharp Develop?
This method is of no use in SharpDevelop!
So I am assuming you are using the Windows Forms designer in SharpDevelop.
Currently SharpDevelop has the same behaviour as Visual Studio. If you copy and paste a control, say a button, it will create a new button with a name of button1. The Windows Forms designer needs a unique name for each control so they have to be given a new name.
One possibility would be to only add a number at the end of the control and keep the rest of the name. However this is not currently implemented. To get this feature you would have to modify SharpDevelop's source code. However I am not sure this is straightforward to do.

Visual Studio 2010 Simple Form

I've been searching, testing and trying a lot of things to create my project with Visual Studio 2010 Pro.
What I need is the same thing as Windows Form Application but ONLY in C++ (no managed stuff). So I guess I should be creating an MFC application. However, is there a way to design the main window? In the resources of the project, there are only the resources used by the main window, but it seems not possible to design (with the toolbox) the main window itself.
Am I missing something here? Anyone knows how to do this or point me to a good tutorial. I'm still searching for a solution, and I'll post it if I find it.
Thanks a lot!
You can either create a dialog-based app (as Hans wrote): The resource editor will let you add/move/size/configure controls to your dialog.
Or alternately, you can create a SDI MFC application and choose CFormView as the base class for the main view. This way, your main view (aka form) is a dialog that you can fill in using the resource editor the same way you would do with a dialog.

What could cause lag using Visual Studio 2010 with a Direct3D control?

I've got a really pesky problem. When writing a C# application using the .NET 4.0 framework and Direct3d for managed code, and creating a device inside a user control (so that I can use it as a kind of viewport), my visual studio 2010 starts "lagging" after the first compile of it. When I type something, there is a delay about 0.5s - 1s until the typed text is shown. The same delay occurs while scrolling via page down or page up or arrow keys. With other projects which are even bigger - with up to 1000 source files (C++), or other C# projects - there is no problem like this. Mouse interaction also delays for 0.5s - 1s.
So my question is what could cause this problem and how can I avoid it?
EDIT: One more hint is that I often get by compiling it:
Unable to copy file "obj\x86\Debug\Direct3DTest.exe" to "bin\Debug\Direct3DTest.exe". The process cannot access the file 'bin\Debug\Direct3DTest.exe' because it is being used by another process.
You probably have your UserControl in design view opened either in it's own document or embedded in your form. This probably causes a DirectX device to be created inside VS. Check fi that's the case and if so you should be able to find out if your control is in design mode (in VS) or in runtime mode.

Creating a Windows GUI .exe application

I have a C/C++ algorithm that I want to create a GUI application for. I would prefer a .exe application that I can pass around to people. I would preferably want to create a dll of my c/c++ algorithm and then bundle it into the Windows GUI application which is basically just a wrapper around the main c/c++ application. How can I create this GUI in VC++ all with a couple of buttons, a text box and a file chooser/browser/opener?
Can someone throw some light on this problem?
Thanks,
Abhishek
There's a number of different options. First we have the microsoft-supported libraries:
MFC - The most heavy-weight library for the windows api.
ATL - A somewhat smaller, lightweight library.
Windows API - Use the Windows API directly.
Beyond that there's a number of third party GUI toolkits, notably:
GTK+
WxWidgets
If you want to make it as small as compact as possible and avoid external DLLs, you should use the Windows API directly or possibly ATL. This also gives you additional flexibility, but it's a bit more complicated. Take a look at for example theForger's tutorial. It's a bit old, but the api has remained more or less the same for the last ten years anyway.
Here's some additional pointers for using the API directly:
What is usually known as controls is called "windows" and are created using CreateWindowEx(). This function creates different things depending on the specified "window class", such as edit, button and static (described below). You create a regular window by registering a custom class.
You can use a function called GetOpenFileName() to invoke an open dialog.
The common text box is known as the edit control in the API.
Buttons are simply called button controls.
Labels are called static controls.
If it's enough for your purposes, you can also create a dialog window using CreateDialog(). This is possibly a bit easier, since dialogs can be designed using the resource editor, while you have to create all the controls in a regular window programmatically.
In Visual Studio:
File -> New Project
In the left panel choose "Visual C++" (or C# if you prefer) and in the right panel choose Windows Forms Application. Click Ok.
When your project is created, in the Toolbox panel you can find Button, Edit Box, OpenFileDialogs and SaveFileDialogs (which you need). If you can't find Toolbox panel, you can enable it in View->Toolbox menu.
Place the controls you need on the program window as you wish by simply dragging them over.

How to create a Windows GUI with a file explorer window, allowing users to choose files?

Here's what I want to do. I want to present a file explorer, and allow the user to select files, and list the selected files below. (I then want to process those files but that's the next part)
For example, the way CD Burning softwares work. I have created a mock up here
http://dl.dropbox.com/u/113967/Mockup.png
As you can see, the left frame has a directory structure, the right frame has a file selected, and the bottom frame shows the selected file.
What framework can I go about creating this? I am familiar with command line C++ stuff, but I haven't ventured into any GUI programming, and figured this idea would be a good place to start.
Any suggestions on where to start?
Most GUI toolkits provide suitable tree and list controls, and a splitter container the user can drag to set the sizes of the three panes. If you use C# then it should take a couple of minutes to create using drag-and-drop (using windows forms you would have a Form with two Splitter controls, a TreeView and a ListView, and whatever control type the data is shown as); the other tool kits I've used tend to require more programming.
Sticking with C++, you can use MFC (CTreeCtrl, CListCtrl, CSplitterWnd), wxWindows (wxGenericDirCtrl/wxTreeCtrl,wxListCtrl,wxSplitterWindow), or QT (I don't know QT). C++ will take longer to develop for no gain (unless you're doing very intensive work, don't bother with C++ for GUIs; usually the advantages of a managed system has for multi-threaded work give a better user experience than a C++ app)
You can write your own code for that or you can use the
Windows shell which provides such facilities.
Sophisticated programming environments usually offer wrappers for ActiveX classes,
like a file browser control.

Resources