Creating a Windows GUI .exe application - windows

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.

Related

How do I add a window from the resources as a child window?

I am creating a windows using win32:
HWND mainWnd = CreateWindow(...);
Now I can add gui elements as children of mainWnd. However this soon becomes a bit tedious and I want to use the designer built into Visual Studio to help me.
I noticed that under Add Resource there is a Dialog entry. Among the dialogs IDD_FORMVIEW seems the most general so I added one of these. Next I added gui elements to it using the designer.
Now I want to use this as a child of my mainWnd. How do I do this?
I found some examples using DialogBox, but I do not want a separate dialog, I want this window as a child of my mainWnd.
The designer in Visual Studio is appropriate for creating dialog boxes, not arbitrary windows.
That being said, there are a couple of approaches (in increasing order of difficulty):
Make your main window a dialog. Petzold's book has an example of using a dialog as the main window of the program. (If I recall correctly, it's the calculator example.)
Create the dialog and, before you show it, change its style to WS_CHILD, change its extended style to WS_EX_CONTROLPARENT, and parent it to your main window. For all the navigation stuff to work, you'll have to add IsDialogMessage calls in your message pump. This is do-able, but it's likely hard to get everything working well.
A mixture of 1 and 2 where you create one dialog for your main window, then create a second dialog for the content (with DS_CONTROL), and put the second dialog in the first. I've never tried this approach myself, but it seems like it should work.
Write your own code to parse the dialog resource and create the child windows, which is basically re-doing a lot of the work that CreateDialog does for you.
Given your desire to use the GUI to design the UI, I suspect only the first solution is simple enough that you would be interested.
Use the CreateDialog API to create the window from the resource. If you do not want it to look like a dialog then remove the titlebar style from the resource properties.
To use a dialog created from a dialog resource template you have to specify the DS_CONTROL window style in the template.
Read more about dialog boxes here.
Dialog resources are explained here

VS2010: How to see GUI

I need to know how to open the form of a program I am debugging.
I loaded an existing solution into VS2010, I can see the code, but I want to see the GUI part of the project, click on buttons and see what part of the code they take me to, set breakpoints where I feel like.
I don't know how to see the GUI in VS2010, where can I do that?
Also, where would be a good resource to learn the ins and outs of VS2010?
Depending on how the UI was created, there may or may not be a way to see the UI at design time. Particularly if this is an older Windows UI application, it's likely that the windows are created entirely in code, and there is no design-time UI for you to see.
There is a dialog editor, for dialog windows that are defined in resource (*.rc) files. CTRL-SHIFT-E brings up the Resource Viewer and you can look for things under the Dialog node. It is possible that your main window is a dialog-style window, as that's one of the options you get when you create a new MFC-based application.
Otherwise, your only option to see what your UI looks like is to run the program and see. Tracking down which UI elements do which actions in your program will require finding the appropriate event handlers or message handler methods (again, depending on what UI framework, if any, is in use) and setting breakpoints.
The generic answer is:
Hit F5 to starting Debugging mode. (Or under the Debug menu choose Start Debugging)
But it depends on how your project is setup and what type of project it is if F5 will work that easily for you.
What kind of program/language are you using?
With a form, I believe you have to File-->Open-->Project/Solution
Now if its a website, you would open Website. If you tried to open a windows form under a website then you wont see the design.
Typically you would just double click your form name (form1.cs) because then your design view will pop up or hit Shift+F7 or rightclick --> view designer. Then just double click whatever tools you have on your form (like a button) and it will automatically go to the button code.
If its a website, then it would be under website1.aspx while the code sits in website1.aspx.cs
But if none of that helps, here is a good place to learn this stuff
VisualStudioWalkthroughs

How to add controls from a control library to VS studio toolbox automatically (WP7)?

I want to achieve that when the user installs the WP7 control library he will find it in the Visual Studio toolbox automatically without manually adding it. In addition I would like to organize toolbox tabs in a logical manner.
I know it can be done for other platforms. For example I tried writing *.design.dll as described here - it does not work for WP7.
Any pointers how to work with toolbox for VS 2010 / WP7?
Nobody answered, so here is my brief summary:
The control library cannot be added to the Toolbox automatically unless you program VS plugin (package). Too much work for me...
*.design.dll (see the link above) basically works.
2a) You can hide controls from the Toolbox (BrowsableAttribute) and you can define control icons. That's probably everything you can do for Toolbox. The user has to add Toolbox tabs and "choose items" manually.
Well, I am not quite sure here, because when you drop the control dll file onto the Toolbox, then at least ToolboxTabNameAttribute works, i.e. corresponding Toolbox tabs are created automatically. Unfortunately, the tab is empty.
Also, when the control library is properly installed, then some of the controls are added to Choose items Toolbox dialog. Unfortunately, in my case most of the controls are missing and have to be added by manual browsing.
2b) Designer support (Properties window for the control) is better. You can hide properties (BrowsableAttribute), define categories (CategoryAttribute) and define descriptions (DescriptionAttribute).
Descriptions can be extracted from you documentation xml file, so that you don't need to write them again. To get the code google for MetadataBase.cs. Just be carefull, the files you'll find contain fatal bugs (ParseDescription method) and ignore some properties (getters that return a collection).
After all, the result is not that bad.

Create a ActiveX with a MFC existing application

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.

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