SolvedVisual C++ "Windows Forms Application"

Posts 1–8 of 8 · Page 1 of 1
Visual C++ "Windows Forms Application"
So I designed a friendly gui in hope to add to it the real code which is running while a clicking event occurs.
The problem is I don't seem to be able to put my code there cause the compiler is giving me error when I try to include the "Windows.h" file.
From my understanding, it causes conflict with other setting or files.

This is my code without errors, just the gui and no touching of the main file:

Code:
#pragma once

namespace My123321
{
    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace 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: System::Windows::Forms::Button^  button1;
    protected: 
    private: System::Windows::Forms::Label^  label1;
    private: System::Windows::Forms::TextBox^  textBox1;

    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)
        {
            System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
            this->button1 = (gcnew System::Windows::Forms::Button());
            this->label1 = (gcnew System::Windows::Forms::Label());
            this->textBox1 = (gcnew System::Windows::Forms::TextBox());
            this->SuspendLayout();
            // 
            // button1
            // 
            this->button1->Cursor = System::Windows::Forms::Cursors::Hand;
            this->button1->Location = System::Drawing::Point(260, 69);
            this->button1->Name = L"button1";
            this->button1->Size = System::Drawing::Size(75, 23);
            this->button1->TabIndex = 0;
            this->button1->Text = L"&Change";
            this->button1->UseVisualStyleBackColor = true;
            this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
            // 
            // label1
            // 
            this->label1->AutoSize = true;
            this->label1->Font = (gcnew System::Drawing::Font(L"Arial", 9.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
                static_cast<System::Byte>(0)));
            this->label1->Location = System::Drawing::Point(12, 18);
            this->label1->Name = L"label1";
            this->label1->Size = System::Drawing::Size(317, 32);
            this->label1->TabIndex = 1;
            this->label1->Text = L"This application will change your nickname in game.\r\nThe nickname must not be hig" 
                L"her than 12 characters.";
            // 
            // textBox1
            // 
            this->textBox1->Location = System::Drawing::Point(15, 71);
            this->textBox1->MaxLength = 12;
            this->textBox1->Name = L"textBox1";
            this->textBox1->Size = System::Drawing::Size(239, 20);
            this->textBox1->TabIndex = 2;
            // 
            // Form1
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(345, 104);
            this->Controls->Add(this->textBox1);
            this->Controls->Add(this->label1);
            this->Controls->Add(this->button1);
            this->Cursor = System::Windows::Forms::Cursors::Arrow;
            this->Icon = (cli::safe_cast<System::Drawing::Icon^  >(resources->GetObject(L"$this.Icon")));
            this->MaximizeBox = false;
            this->MaximumSize = System::Drawing::Size(361, 142);
            this->MinimizeBox = false;
            this->MinimumSize = System::Drawing::Size(361, 142);
            this->Name = L"Form1";
            this->ShowIcon = false;
            this->SizeGripStyle = System::Windows::Forms::SizeGripStyle::Hide;
            this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
            this->Text = L"Nickname Changer";
            this->ResumeLayout(false);
            this->PerformLayout();

        }
    #pragma endregion
    public: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
                 
             }
    };
}
But when I'm trying to add this code in the "button1_Click" function, the errors start:

Code:
#include <Windows.h>
MessageBox(NULL, "message", "msg", MB_OK);
I searched and found that instead of the MessageBox function I can use MessageBox::Show() which is identically the same. But that doesn't fix my entirely problem. Since I need to use more functions that relly on the Windows.h file.
Any suggestion, or I'm doing it completely wrong?
If I'll start a WIN32 Project in Visual Studio I'll probably be able to implement my old code but for that I'll need to learn a bunch of whole new things. So it's not simple.
You need to download Visual basic because C++ don't support some commands from Visual basic which it will be hard to make it on Visual C++
I already have Visual Basic, but how I will be able to migrate a code that is written in C++ into the gui?
Quote Originally Posted by Jabberwock View Post
I already have Visual Basic, but how I will be able to migrate a code that is written in C++ into the gui?
Re-Design it to fit with Visual basic
Quote Originally Posted by Hexicidal View Post


Re-Design it to fit with Visual basic
Please die ;_;

@OP: The problem is that you've created a Windows Form Application, which relies on the .net framework which probably conflicts with windows.h which does not use the .net framework. I've never used WFA projects so I wouldn't know how to fix it either.
Thank you.

Moderators can close the thread now.
The best way, in my experience, to use managed and unmanaged code in the same application is by building an unmanaged dll and exporting the functions you need to your managed application. Next you build a wrapper that can cleanly handle the exceptions in the dll and you're set.
What's the exact compiler error that you're having?

If you're actually putting this exact code
Code:
#include <Windows.h>
MessageBox(NULL, "message", "msg", MB_OK);
In the event, you're definitely going to get a compiler error :3
Posts 1–8 of 8 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us