ich versuche derzeit mit wxWidgets eine Grafik (genauer gesagt eine ".bmp"-Datei) anzuzeigen. Dies mache ich indem ich indem ich ein Image erzeuge, dieses in ein Bitmap konvertiere und dann über den Device Content auf den Frame zeichne:
Code: Alles auswählen
bool mainFrame::loadImage(const wxChar *filename)
{
wxImage image(filename);
wxBitmap bitmap(image);
wxClientDC dc(this);
dc.DrawBitmap(bitmap, 1, 1, false);
}
Hier mal der Code:
gui.cpp
Code: Alles auswählen
#include "gui.h"
#include <wx/wx.h>
#include <wx/dc.h>
#include <wx/image.h>
#include <wx/bitmap.h>
#include <wx/defs.h>
BEGIN_EVENT_TABLE(mainFrame, wxFrame)
EVT_MOTION(mainFrame::onMotion)
END_EVENT_TABLE()
bool mainApp::OnInit()
{
mainFrame *frame = new mainFrame(wxT("GUI"), wxPoint(-1, -1), wxSize(800, 700));
frame->Show(true);
this->SetTopWindow(frame);
return true;
::wxInitAllImageHandlers();
}
mainFrame::mainFrame(const wxChar *title, wxPoint pos, wxSize size) : wxFrame((wxFrame *)NULL, -1, title, pos, size)
{
mainPanel = new wxPanel(this, wxID_ANY, wxDefaultPosition, size);
this->loadImage(wxT("karte.bmp"));
}
bool mainFrame::loadImage(const wxChar *filename)
{
wxImage image(filename);
wxBitmap bitmap(image);
wxClientDC dc(this->mainPanel);
dc.DrawBitmap(bitmap, 1, 1, false);
}
void mainFrame::onMotion(wxMouseEvent &event)
{
this->loadImage(wxT("karte.bmp"));
}
mainFrame::~mainFrame()
{
}
Code: Alles auswählen
#include <wx/wx.h>
#ifndef GUI_H
#define GUI_H
class mainApp : public wxApp
{
public:
virtual bool OnInit();
};
class mainFrame : public wxFrame
{
private:
wxPanel *mainPanel;
DECLARE_EVENT_TABLE()
public:
mainFrame(const wxChar *title, wxPoint pos, wxSize size);
bool loadImage(const wxChar *filename);
~mainFrame();
void onMotion(wxMouseEvent &event);
};
#endif
Code: Alles auswählen
#include "gui.h"
#include <wx/wx.h>
IMPLEMENT_APP(mainApp)
Mfg.
hackmack