Tentu saja library ini bisa dikompilasi dengan banyak C++ kompiler mulai dari Microsoft C++ sampai GCC. Ini contoh coding sederhana yang saya buat dan berhasil dengan baik di kompilasi dengan MingGW.
//////////////////////////////////////////////////////////////// // Name: simple.cpp // Purpose: Simple wxWidgets sample // Author: Hermanto // Created: 2012-06-06 // Copyright: (c) 2012, Hermanto // Licence: wxWindows licence //////////////////////////////////////////////////////////////// #includeKeterangan kode program: Setiap aplikasi yang dibuat dengan wxWidgets selalu diturunkan dari kelas wxApp. Dan setidaknya mempunyai satu definisi fungi OnInit yang akan dijalankan pertama kali ketika wxWidgets mulai menjalankan kode (sama seperti main atau WinMain ketika kita menulis kode C atau aplikasi Win32) .// Declare the application class class MyApp : public wxApp { public: // Called on application startup virtual bool OnInit(); }; // Declare our main frame class class MyFrame : public wxFrame { public: // Constructor MyFrame (const wxString title); }; // Give wxWidgets the means to create MyApp object IMPLEMENT_APP(MyApp) // Initialize the application bool MyApp::OnInit() { // Create the main application window MyFrame *frame = new MyFrame(wxT("wxWidgets pertamaku")); // Show it frame->Show(true); // Start the event loop return true; } MyFrame::MyFrame(const wxString title) : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(400,300)) { // Show window on centre screen Centre(); }
// Declare the application class
class MyApp : public wxApp
{
public:
// Called on application startup
virtual bool OnInit();
};
Selanjutnya lihatlah kelas MyFrame.Kelas ini diturunkan dari kelas wxFrame yang merupakan top-level window yang terdapat window lain misalnya title atau menu (khusus menu insya Allah nanti akan dibuat tutorial tersendiri). Kelas yang baru kita buat ini terdiri satu konstruktor.
// Declare our main frame class
class MyFrame : public wxFrame
{
public:
// Constructor
MyFrame (const wxString title);
};
Pada baris kode berikutnya kita cantumkan sebuah macro pada kode impelementasi kita yang bertujuan untuk memberikan informasi kepada wxWidgets jenis object yang harus dibuat.
// Give wxWidgets the means to create MyApp object IMPLEMENT_APP(MyApp)Kemudian implementasi dari OnInit biasanya minimal membuat satu window. Jika kembalian fungsi bernilai true , maka wxWidgets mulai dengan looping event melalui proses input user dan menjalankan event handlers jika diperlukan. Jika kembalian fungsi bernilai false, aplikasi akan diakhiri.
// Initialize the application
bool MyApp::OnInit()
{
// Create the main application window
MyFrame *frame = new MyFrame(wxT("wxWidgets pertamaku"));
// Show it
frame->Show(true);
// Start the event loop
return true;
}
Terakhir, kita implementasikan konstruktor yang frame window yang kita buat dengan fungsi Center() untuk menampilkan ditengah layar.
MyFrame::MyFrame(const wxString title)
: wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(400,300))
{
// Show window on centre screen
Centre();
}
Untuk mempermudah kamu bisa download kode keseluruhan di simple.cpp
Dapat juga menjalankan hasil kompilasi yang langsung dijalankan di OS Windows file simple.zipSemoga postingan ini bisa membantu.
Tag : C/C++, Pemrograman, wxWidgets

0 Response to "wxWidgets Pertamaku"
Posting Komentar