private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {}
This code has nothing to do with MFC, it is C++/CLI.
In C++/CLI it is normal that the code for the form is in the header file. A .cpp file normally does not exist for Forms - though in theory you can create one. All non-UI code can go in a normal .cpp file.
#pragma once
namespace Test
{
usingnamespace System;
usingnamespace System::ComponentModel;
usingnamespace System::Collections;
usingnamespace System::Windows::Forms;
usingnamespace System::Data;
usingnamespace System::Drawing;
/// <summary>
/// Summary for Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->components = gcnew System::ComponentModel::Container();
this->Size = System::Drawing::Size(300,300);
this->Text = L"Form1";
this->Padding = System::Windows::Forms::Padding(0);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
}
#pragma endregion
};
}
You should have a .cpp file with the main function which looks like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// Test.cpp : main project file.
#include "stdafx.h"
#include "Form1.h"
usingnamespace Test;
[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;
}
In the beginning it is probably the best to use the IDE to do most of the work, i.e. drag the controls from the toolbox onto the form and create the event handlers in the properties tab.
If you want to learn the foundations of windows programming, I would suggest starting here:
Learn to Program for Windows in C++
https://msdn.microsoft.com/library/windows/desktop/ff381399(v=vs.85).aspx
I don't recommend C++/CLI for user interface programming. It is more for creating wrappers to interface the managed and unmanaged world. C# would be a better choice for UI. It is very capable and worth while learning (at some point).
I found MFC a lot easier to understand once I learnt a bit about WinAPI programming. I don't know if it is worth spending the time learning MFC.
Universal Windows Platform (UWP) might be something you are is will become interested in. I haven't looked into this too much yet but your choices, C++ wise, seem to be C++/CX (the CX part is a Microsoft extension) or C++ with Windows Runtime C++ Template Library (WRL).
Universal Windows Apps (C++)
https://msdn.microsoft.com/en-us/library/hh875012.aspx
Windows Runtime C++ Template Library (WRL)
https://msdn.microsoft.com/en-us/library/hh438466.aspx