Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C++ GUI] Help me convert C# into C++

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
NINTENDO
Grandmaster Cheater Supreme
Reputation: 0

Joined: 02 Nov 2007
Posts: 1371

PostPosted: Tue Apr 20, 2010 2:34 am    Post subject: [C++ GUI] Help me convert C# into C++ Reply with quote

Ok so can someone tell me how to create a gui with a button.

This is kind of what I want to achieve:

Code:
using System;
using System.Windows.Forms;

namespace HelloWorldGui
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Hello world");
        }
    }
}

_________________
Intel over amd yes.
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Tue Apr 20, 2010 4:46 am    Post subject: Reply with quote

This is C++ with Qt.. Should be ~okay.

helloworld.h
Code:
#ifndef HELLOWORLD_H
#define HELLOWORLD_H

#include <QMainWindow>
#include <QPushButton>
#include <QMessageBox>
#include <QHBoxLayout>
#include <QWidget>

class HelloWorld : public QMainWindow
{
   Q_OBJECT

public:
   HelloWorld(QWidget *parent = 0, Qt::WFlags flags = 0);
   ~HelloWorld();

private slots:
   void buttonClicked();

};

#endif // HELLOWORLD_H


helloworld.cpp:
Code:
#include "helloworld.h"

HelloWorld::HelloWorld(QWidget *parent, Qt::WFlags flags)
   : QMainWindow(parent, flags)
{
   QWidget *widget = new QWidget( this );
   QHBoxLayout *layout = new QHBoxLayout( widget );
   QPushButton *button = new QPushButton( tr("Click me!"), widget );
   layout->addStretch();
   layout->addWidget( button );
   layout->addStretch();
   widget->setLayout( layout );
   this->setCentralWidget( widget );
   this->connect( button, SIGNAL(clicked()), SLOT(buttonClicked()) );
}

HelloWorld::~HelloWorld()
{

}

void HelloWorld::buttonClicked()
{
   QMessageBox mb;
   mb.setText( tr("Hello world!") );
   mb.exec();
}


main.cpp:
Code:
#include <QApplication>

#include "helloworld.h"

int main(int argc, char *argv[])
{
   QApplication a(argc, argv);
   HelloWorld w;
   w.show();
   return a.exec();
}


Sure I could make it shorter, but this one looks at least a bit better. Well, C++ doesn't provide any GUI components itself. You might want to take a look at WinAPI if you're coding for Windows.
Back to top
View user's profile Send private message
NINTENDO
Grandmaster Cheater Supreme
Reputation: 0

Joined: 02 Nov 2007
Posts: 1371

PostPosted: Tue Apr 20, 2010 4:49 am    Post subject: Reply with quote

Thx for the fast reply.
_________________
Intel over amd yes.
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites