views:

75

answers:

2

Hello,

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

+3  A: 

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.
Emil H
I would add cpp cli
rerun
@rerun, But you can't create a GUI using cpp cli, right?
Emil H
Sure you can you just use the windows forms and .net
rerun
Ah. C++/CLI. I thought you were talking about something else. I omitted that because it isn't standard C++ but a super set that runs in the CLR, and also because I'm only vaguely aware of it. It's of course easier than the other options though, since you have access to windows forms.
Emil H
Hi guys, I did understand the part where I create a Windows Form Application in Visual Studio and layout the UI components on the form. My question is, how do I bundle a dll (of my existing C/C++ algorithm) into this Form application? On the click of a button, I only need to pass to a function in the dll, the file path that I choose from the File Browser. The function then does the rest once it gets the file path. So in short, I want to create a GUI around my code which is working fine from the command prompt console. Thanks, Abhishek
Abhishek
A: 

In Visual Studio:

  1. File -> New Project

  2. In the left panel choose "Visual C++" (or C# if you prefer) and in the right panel choose Windows Forms Application. Click Ok.

  3. 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.

  4. Place the controls you need on the program window as you wish by simply dragging them over.

virious