×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Creating a C++ Windows application

Creating a C++ Windows application

Creating a C++ Windows application

(OP)
I am wanting to create application that has alot of forms but works mostly with c++ on the backend. I am using VS 2010/ VS C++ 2010, I can make a form, I can code in c++, but how to i make it a regular application instead of a console application. I can provide more details on my idea if needed

RE: Creating a C++ Windows application

Step by step:

1. Start VC++ 2010
2. New Project...
3. Left panel (Installed Templates): CLR
4. Right panel: Windows Forms Application, set project name etc

That's all, now make Windows Forms GUI application.
Welcome to the "MS Forever Pseudo-C++ World;)...

Are you sure that it's a "regular" application?
 

RE: Creating a C++ Windows application

(OP)
ok, well what I want to know is can I use the regular c++ code that I was taught, for example

CODE

#include <iostream>

using namespace std;

int main()
{
  cout << "hi" << endl;
  return 0;
}

and stuff like that instead of things like this:

CODE

#include "stdafx.h"
#include "Form1.h"

using namespace Test1;

[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
    // Enabling Windows XP visual effects before any controls are created
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false);

    // Create the main window and run it
    Application::Run(gcnew Form1());
    return 0;
}

which is what I current have the the main.cpp file when I created the project

like if I wanted to create a button, but make a function that does exactly what I want it to do, can I just drop the button in the form and call my function from the the button function?
 

RE: Creating a C++ Windows application

You created a Form Project.

You need a win32 console program.  Create an empty project.  Add a new file to the project and type your code in.

RE: Creating a C++ Windows application

No any "forms" if you want code

CODE

#include <iostream>

using namespace std;

int main()
{
  cout << "hi" << endl;
  return 0;
}
On the one hand it's true "regular" console application code, on the other hand, no std::cout object in C++ GUI application with forms...

In other words, you want stratosphere submarine...
 

RE: Creating a C++ Windows application

(OP)
xwb - So the console will control what the form does or I am missing the pint?

ArkM - so there is no way to combine the 2 samples of code to work together?

The idea for me here is to create a program that stores, updates, teams in a league. i know a database will be required, but I want the interface to be Windows GUI, but the data processesing and etc to be C++. If doing that through the forms in the only I understand but If I can combined the 2(forms, and c++ code) then I can make it more stable and powerful

RE: Creating a C++ Windows application

Well, I think that Windows Forms programming in MS C++/CLI is a kind of outrage upon the C++ language ;)

You may program in clear C++ with Ultimate++ (or Qt - but it's not "clear" C++;) environments. For example, download and install Ultimate++ TheIDE (there are lots of example projects in the installation).

No any standard GUI model (therefore no any "forms") in C++ language. However there are many class libraries with GUI classes (see examples above). Remember: std::cout is an implementation of abstract character stream. If you want, you may implement your own C++ class to "print" data in cout << ... style and send this output to your own console-like window (one of all others).
 

RE: Creating a C++ Windows application

(OP)
So in order to do this I would have to conform to the way that it is done in visual c++ or pick something else?

RE: Creating a C++ Windows application

Ultimate++ and Qt environments are compiler-independent. They work with Visual C++ and some other C++ compilers for Windows, Linux and MacOS. So you may write portable C++ codes with (or without) GUI. Use proper GUI C++ libraries - that's all.

All GUI applications in typical OSes are event-driven. Must be external GUI events generator (OS). The program must catch and process (in a good time) GUI events (repaint window, for example). No any external (asynchronous) events in console applications - there is a single control flow which runs through main() function. That's why you need some library to incapsulate these drastic differences between console and GUI undeground program logics.
 

RE: Creating a C++ Windows application

I'm not sure why you think you can't use standard C++ in a Windows application.  If you choose a Win32 project all the pieces you speak of are there.  They just have a slightly different look in Windows than say, Linux.  But the template takes care of setting up the main function for you.

You'll get a _tWinMain function which is your application entry point, and sets up some other miscellaneous variables.  Once it does that, it then the begins the message pump

CODE

// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
    if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
}

This basically pulls the messages off the message queue, and "pumps" the message into your application.  And all your messages are handled by the callback function WndProc.

You simply handle the BN_CLICK, WM_COMMAND, WM_PAINT, etc. messages in WndProc.

Also, this sample code was taken from Visual studio 2010, and is unmanaged c++ code.  The sample you are showing appears to be managed code.

The real issue with a Win32 application, which you'll soon find out, is that the WndProc procedure turns in to a HUGE switch statement as you handle more and more messages/notifications...

RE: Creating a C++ Windows application

(OP)
ok Vachaun22 but say when the button click happens i want it to run a cpp file that has this:

CODE

cout << "hi" << endl;

everytime I try to compile that it fails and gives that line as an error.

RE: Creating a C++ Windows application

(OP)
ok one last question for this thread, When i make a form, the form design is in the header file(.h), is there a way that I can get the form to do the action from a cpp file instead?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close