Help with wxImagePanel.

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
papayrus
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 204
Joined: Tue Jan 25, 2011 4:55 pm
Location: USA

Help with wxImagePanel.

Post by papayrus »

Hello I need some help with this. I am still using code blocks for now. I have a control I drag out on a panel called wxImagePanel but I can not find any way to get it to compile or function. I just want to load an image in to it for now so I can learn how to use it.
When I double click the wxImagePanel control I go in to code and it auto creates this code in my Main.cpp

Code: Select all

void testFrame::OnImagePanel1Paint(wxPaintEvent& event)
{
}
and it generates this code at the top

Code: Select all

ImagePanel1 = new wxImagePanel(this, ID_IMAGEPANEL1, wxPoint(160,80), wxDefaultSize, wxRAISED_BORDER|wxTAB_TRAVERSAL, _T("ID_IMAGEPANEL1"));
    ImagePanel1->SetStretch(false);
Then in Main.h it makes

Code: Select all

/***************************************************************
 * Name:      testMain.h
 * Purpose:   Defines Application Frame
 * Author:     ()
 * Created:   2012-09-01
 * Copyright:  ()
 * License:
 **************************************************************/

#ifndef TESTMAIN_H
#define TESTMAIN_H

//(*Headers(testFrame)
#include <wx/menu.h>
#include "wx/wxImagePanel.h"
#include <wx/frame.h>
#include <wx/statusbr.h>
//*)

class testFrame: public wxFrame
{
    public:

        testFrame(wxWindow* parent,wxWindowID id = -1);
        virtual ~testFrame();

    private:

        //(*Handlers(testFrame)
        void OnQuit(wxCommandEvent& event);
        void OnAbout(wxCommandEvent& event);
        void OnImagePanel1Paint(wxPaintEvent& event);
        //*)

        //(*Identifiers(testFrame)
        static const long ID_IMAGEPANEL1;
        static const long idMenuQuit;
        static const long idMenuAbout;
        static const long ID_STATUSBAR1;
        //*)

        //(*Declarations(testFrame)
        wxImagePanel* ImagePanel1;
        wxStatusBar* StatusBar1;
        //*)

        DECLARE_EVENT_TABLE()
};

#endif // TESTMAIN_H
I notice there is #include "wx/wxImagePanel.h" at the top of this but I do not have that file in my project and am not sure how to create it.
The errors I am getting are
testMain.h|15|wx/wxImagePanel.h: No such file or directory|
testMain.h|42|error: expected `;' before '*' token|
testMain.cpp|67|error: `ImagePanel1' was not declared in this scope|
testMain.cpp|67|error: `wxImagePanel' has not been declared|

So do I need to make a new .h file and mane it wxImagePanel.h? Also if that is the case then can someone tell me please what I need to put in that file. When I do that and in the project I make a new file and then choose header file and name it wxImagePanel it makes the file in the project and in the file is this code already

Code: Select all

#ifndef WXIMAGEPANEL_H_INCLUDED
#define WXIMAGEPANEL_H_INCLUDED



#endif // WXIMAGEPANEL_H_INCLUDED


Is this the right way to begin this? OR do I need to make a class which when I do that makes 2 files one wxImagePanel.cpp and the other wxImagePanel.h and inside the generated codes are
wxImagePanel.cpp

Code: Select all

#include "wxImagePanel.h"

wxImagePanel::wxImagePanel()
{
    //ctor
}

wxImagePanel::~wxImagePanel()
{
    //dtor
}
and in wxImagePanel.h is

Code: Select all

#ifndef WXIMAGEPANEL_H_INCLUDED
#define WXIMAGEPANEL_H_INCLUDED



#endif // WXIMAGEPANEL_H_INCLUDED
Sorry I put so much but getting this solved is important to me thanks in advance.
User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2409
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania

Re: Help with wxImagePanel.

Post by evstevemd »

Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
papayrus
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 204
Joined: Tue Jan 25, 2011 4:55 pm
Location: USA

Re: Help with wxImagePanel.

Post by papayrus »

Yep I am looking at that now and trying to figure out what I need to do with is. Do I need to make a new header file named wxImagePanel and add some part of that code to it?
User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2409
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania

Re: Help with wxImagePanel.

Post by evstevemd »

papayrus wrote:
Yep I am looking at that now and trying to figure out what I need to do with is. Do I need to make a new header file named wxImagePanel and add some part of that code to it?
image_panel.h

Code: Select all

#include <wx/wx.h>
#include <wx/sizer.h>
 
class wxImagePanel : public wxPanel
    {
        wxBitmap image;
        
    public:
        wxImagePanel(wxFrame* parent, wxString file, wxBitmapType format);
        
        void paintEvent(wxPaintEvent & evt);
        void paintNow();
        
        void render(wxDC& dc);
        
        // some useful events
        /*
         void mouseMoved(wxMouseEvent& event);
         void mouseDown(wxMouseEvent& event);
         void mouseWheelMoved(wxMouseEvent& event);
         void mouseReleased(wxMouseEvent& event);
         void rightClick(wxMouseEvent& event);
         void mouseLeftWindow(wxMouseEvent& event);
         void keyPressed(wxKeyEvent& event);
         void keyReleased(wxKeyEvent& event);
         */
        
        DECLARE_EVENT_TABLE()
    };
 
 
BEGIN_EVENT_TABLE(wxImagePanel, wxPanel)
// some useful events
/*
 EVT_MOTION(wxImagePanel::mouseMoved)
 EVT_LEFT_DOWN(wxImagePanel::mouseDown)
 EVT_LEFT_UP(wxImagePanel::mouseReleased)
 EVT_RIGHT_DOWN(wxImagePanel::rightClick)
 EVT_LEAVE_WINDOW(wxImagePanel::mouseLeftWindow)
 EVT_KEY_DOWN(wxImagePanel::keyPressed)
 EVT_KEY_UP(wxImagePanel::keyReleased)
 EVT_MOUSEWHEEL(wxImagePanel::mouseWheelMoved)
 */
 
// catch paint events
EVT_PAINT(wxImagePanel::paintEvent)
 
END_EVENT_TABLE()
image_panel.cpp

Code: Select all

// some useful events
/*
 void wxImagePanel::mouseMoved(wxMouseEvent& event) {}
 void wxImagePanel::mouseDown(wxMouseEvent& event) {}
 void wxImagePanel::mouseWheelMoved(wxMouseEvent& event) {}
 void wxImagePanel::mouseReleased(wxMouseEvent& event) {}
 void wxImagePanel::rightClick(wxMouseEvent& event) {}
 void wxImagePanel::mouseLeftWindow(wxMouseEvent& event) {}
 void wxImagePanel::keyPressed(wxKeyEvent& event) {}
 void wxImagePanel::keyReleased(wxKeyEvent& event) {}
 */
 
wxImagePanel::wxImagePanel(wxFrame* parent, wxString file, wxBitmapType format) :
wxPanel(parent)
{
    // load the file... ideally add a check to see if loading was successful
    image.LoadFile(file, format);
}
 
/*
 * Called by the system of by wxWidgets when the panel needs
 * to be redrawn. You can also trigger this call by
 * calling Refresh()/Update().
 */
 
void wxImagePanel::paintEvent(wxPaintEvent & evt)
{
    // depending on your system you may need to look at double-buffered dcs
    wxPaintDC dc(this);
    render(dc);
}
 
/*
 * Alternatively, you can use a clientDC to paint on the panel
 * at any time. Using this generally does not free you from
 * catching paint events, since it is possible that e.g. the window
 * manager throws away your drawing when the window comes to the
 * background, and expects you will redraw it when the window comes
 * back (by sending a paint event).
 */
void wxImagePanel::paintNow()
{
    // depending on your system you may need to look at double-buffered dcs
    wxClientDC dc(this);
    render(dc);
}
 
/*
 * Here we do the actual rendering. I put it in a separate
 * method so that it can work no matter what type of DC
 * (e.g. wxPaintDC or wxClientDC) is used.
 */
void wxImagePanel::render(wxDC&  dc)
{
    dc.DrawBitmap( image, 0, 0, false );
}
 

app.cpp

Code: Select all

class MyApp: public wxApp
    {
        
        wxFrame *frame;
        wxImagePanel * drawPane;
    public:
        bool OnInit()
        {
            // make sure to call this first
            wxInitAllImageHandlers();
            
            wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
            frame = new wxFrame(NULL, wxID_ANY, wxT("Hello wxDC"), wxPoint(50,50), wxSize(800,600));
            
            // then simply create like this
            drawPane = new wxImagePanel( frame, wxT("image.jpg"), wxBITMAP_TYPE_JPEG);
            sizer->Add(drawPane, 1, wxEXPAND);
            
            frame->SetSizer(sizer);
            
            frame->Show();
            return true;
        } 
        
    };
 
IMPLEMENT_APP(MyApp)
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
papayrus
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 204
Joined: Tue Jan 25, 2011 4:55 pm
Location: USA

Re: Help with wxImagePanel.

Post by papayrus »

evstevemd wrote:
papayrus wrote:
Yep I am looking at that now and trying to figure out what I need to do with is. Do I need to make a new header file named wxImagePanel and add some part of that code to it?
image_panel.h

Code: Select all

#include <wx/wx.h>
#include <wx/sizer.h>
 
class wxImagePanel : public wxPanel
    {
        wxBitmap image;
        
    public:
        wxImagePanel(wxFrame* parent, wxString file, wxBitmapType format);
        
        void paintEvent(wxPaintEvent & evt);
        void paintNow();
        
        void render(wxDC& dc);
        
        // some useful events
        /*
         void mouseMoved(wxMouseEvent& event);
         void mouseDown(wxMouseEvent& event);
         void mouseWheelMoved(wxMouseEvent& event);
         void mouseReleased(wxMouseEvent& event);
         void rightClick(wxMouseEvent& event);
         void mouseLeftWindow(wxMouseEvent& event);
         void keyPressed(wxKeyEvent& event);
         void keyReleased(wxKeyEvent& event);
         */
        
        DECLARE_EVENT_TABLE()
    };
 
 
BEGIN_EVENT_TABLE(wxImagePanel, wxPanel)
// some useful events
/*
 EVT_MOTION(wxImagePanel::mouseMoved)
 EVT_LEFT_DOWN(wxImagePanel::mouseDown)
 EVT_LEFT_UP(wxImagePanel::mouseReleased)
 EVT_RIGHT_DOWN(wxImagePanel::rightClick)
 EVT_LEAVE_WINDOW(wxImagePanel::mouseLeftWindow)
 EVT_KEY_DOWN(wxImagePanel::keyPressed)
 EVT_KEY_UP(wxImagePanel::keyReleased)
 EVT_MOUSEWHEEL(wxImagePanel::mouseWheelMoved)
 */
 
// catch paint events
EVT_PAINT(wxImagePanel::paintEvent)
 
END_EVENT_TABLE()
image_panel.cpp

Code: Select all

// some useful events
/*
 void wxImagePanel::mouseMoved(wxMouseEvent& event) {}
 void wxImagePanel::mouseDown(wxMouseEvent& event) {}
 void wxImagePanel::mouseWheelMoved(wxMouseEvent& event) {}
 void wxImagePanel::mouseReleased(wxMouseEvent& event) {}
 void wxImagePanel::rightClick(wxMouseEvent& event) {}
 void wxImagePanel::mouseLeftWindow(wxMouseEvent& event) {}
 void wxImagePanel::keyPressed(wxKeyEvent& event) {}
 void wxImagePanel::keyReleased(wxKeyEvent& event) {}
 */
 
wxImagePanel::wxImagePanel(wxFrame* parent, wxString file, wxBitmapType format) :
wxPanel(parent)
{
    // load the file... ideally add a check to see if loading was successful
    image.LoadFile(file, format);
}
 
/*
 * Called by the system of by wxWidgets when the panel needs
 * to be redrawn. You can also trigger this call by
 * calling Refresh()/Update().
 */
 
void wxImagePanel::paintEvent(wxPaintEvent & evt)
{
    // depending on your system you may need to look at double-buffered dcs
    wxPaintDC dc(this);
    render(dc);
}
 
/*
 * Alternatively, you can use a clientDC to paint on the panel
 * at any time. Using this generally does not free you from
 * catching paint events, since it is possible that e.g. the window
 * manager throws away your drawing when the window comes to the
 * background, and expects you will redraw it when the window comes
 * back (by sending a paint event).
 */
void wxImagePanel::paintNow()
{
    // depending on your system you may need to look at double-buffered dcs
    wxClientDC dc(this);
    render(dc);
}
 
/*
 * Here we do the actual rendering. I put it in a separate
 * method so that it can work no matter what type of DC
 * (e.g. wxPaintDC or wxClientDC) is used.
 */
void wxImagePanel::render(wxDC&  dc)
{
    dc.DrawBitmap( image, 0, 0, false );
}
 

app.cpp

Code: Select all

class MyApp: public wxApp
    {
        
        wxFrame *frame;
        wxImagePanel * drawPane;
    public:
        bool OnInit()
        {
            // make sure to call this first
            wxInitAllImageHandlers();
            
            wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
            frame = new wxFrame(NULL, wxID_ANY, wxT("Hello wxDC"), wxPoint(50,50), wxSize(800,600));
            
            // then simply create like this
            drawPane = new wxImagePanel( frame, wxT("image.jpg"), wxBITMAP_TYPE_JPEG);
            sizer->Add(drawPane, 1, wxEXPAND);
            
            frame->SetSizer(sizer);
            
            frame->Show();
            return true;
        } 
        
    };
 
IMPLEMENT_APP(MyApp)
I can't get this to compile I have a few errors.

ImagePanel\ImagePanelMain.h|15|wx/wxImagePanel.h: No such file or directory|
ImagePanel\ImagePanelMain.h|44|error: ISO C++ forbids declaration of `wxImagePanel' with no type|
ImagePanel\ImagePanelMain.h|44|error: expected `;' before '*' token|
ImagePanel\ImagePanelMain.cpp|69|error: `ImagePanel1' was not declared in this scope|
ImagePanelMain.cpp|69|error: `wxImagePanel' has not been declared|
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Re: Help with wxImagePanel.

Post by Auria »

imagepanel.h is not part of wxWidgets, it is a file in your own project, so you need #include "image_panel.h" instead of #include <wx/wximagepanel.h>
"Keyboard not detected. Press F1 to continue"
-- Windows
papayrus
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 204
Joined: Tue Jan 25, 2011 4:55 pm
Location: USA

Re: Help with wxImagePanel.

Post by papayrus »

Auria wrote:imagepanel.h is not part of wxWidgets, it is a file in your own project, so you need #include "image_panel.h" instead of #include <wx/wximagepanel.h>
Yes I realise the file is missing. I am using wxSmith here and I have created the test application which has a visual editor so in order to simplify I will explain what I have now.
I made the project and named it ImagePanel when the project is created it gives you an already made blank GUI and the files created in the project are actually I will just attach a screenshot of the project files so it's easier.
My Project
My Project
Hope I did that right first attachment I have made in here.

These files are auto created when you start a project so I have done no editing at all yet and that's what is there now. So I was wondering if I need to make a seaparate class or just make a separate .h file or can I just put it all in what I already have?
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Re: Help with wxImagePanel.

Post by Auria »

I have no idea how wxSmith can deal with custom controls, sorry, so I can't help with the wxSmith part.
"Keyboard not detected. Press F1 to continue"
-- Windows
papayrus
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 204
Joined: Tue Jan 25, 2011 4:55 pm
Location: USA

Re: Help with wxImagePanel.

Post by papayrus »

Sorry I mean it is code blocks but I am using wxSmith for the visual designer. I hope this is not too much but I broke it all down here. In the first image of the project I dragged the control out on the panel already.
My Initial Files.
My Initial Files.

in ImagePanelApp.cpp the code after adding wxImagePanel control is.

Code: Select all

/***************************************************************
 * Name:      ImagePanelApp.cpp
 * Purpose:   Code for Application Class
 * Author:     ()
 * Created:   2012-09-04
 * Copyright:  ()
 * License:
 **************************************************************/

#include "wx_pch.h"
#include "ImagePanelApp.h"

//(*AppHeaders
#include "ImagePanelMain.h"
#include <wx/image.h>
//*)

IMPLEMENT_APP(ImagePanelApp);

bool ImagePanelApp::OnInit()
{
    //(*AppInitialize
    bool wxsOK = true;
    wxInitAllImageHandlers();
    if ( wxsOK )
    {
    	ImagePanelFrame* Frame = new ImagePanelFrame(0);
    	Frame->Show();
    	SetTopWindow(Frame);
    }
    //*)
    return wxsOK;

}
In ImagePanelMain.cpp the code after adding wxImagePanel control is.

Code: Select all

/***************************************************************
 * Name:      ImagePanelMain.cpp
 * Purpose:   Code for Application Frame
 * Author:     ()
 * Created:   2012-09-04
 * Copyright:  ()
 * License:
 **************************************************************/

#include "wx_pch.h"
#include "ImagePanelMain.h"
#include <wx/msgdlg.h>

//(*InternalHeaders(ImagePanelFrame)
#include <wx/intl.h>
#include <wx/string.h>
//*)

//helper functions
enum wxbuildinfoformat {
    short_f, long_f };

wxString wxbuildinfo(wxbuildinfoformat format)
{
    wxString wxbuild(wxVERSION_STRING);

    if (format == long_f )
    {
#if defined(__WXMSW__)
        wxbuild << _T("-Windows");
#elif defined(__UNIX__)
        wxbuild << _T("-Linux");
#endif

#if wxUSE_UNICODE
        wxbuild << _T("-Unicode build");
#else
        wxbuild << _T("-ANSI build");
#endif // wxUSE_UNICODE
    }

    return wxbuild;
}

//(*IdInit(ImagePanelFrame)
const long ImagePanelFrame::ID_IMAGEPANEL1 = wxNewId();
const long ImagePanelFrame::ID_PANEL1 = wxNewId();
const long ImagePanelFrame::idMenuQuit = wxNewId();
const long ImagePanelFrame::idMenuAbout = wxNewId();
const long ImagePanelFrame::ID_STATUSBAR1 = wxNewId();
//*)

BEGIN_EVENT_TABLE(ImagePanelFrame,wxFrame)
    //(*EventTable(ImagePanelFrame)
    //*)
END_EVENT_TABLE()

ImagePanelFrame::ImagePanelFrame(wxWindow* parent,wxWindowID id)
{
    //(*Initialize(ImagePanelFrame)
    wxMenuItem* MenuItem2;
    wxMenuItem* MenuItem1;
    wxMenu* Menu1;
    wxMenuBar* MenuBar1;
    wxMenu* Menu2;

    Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("id"));
    Panel1 = new wxPanel(this, ID_PANEL1, wxPoint(176,88), wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL1"));
    ImagePanel1 = new wxImagePanel(Panel1, ID_IMAGEPANEL1, wxPoint(112,32), wxSize(168,128), wxRAISED_BORDER|wxTAB_TRAVERSAL, _T("ID_IMAGEPANEL1"));
    ImagePanel1->SetStretch(false);
    MenuBar1 = new wxMenuBar();
    Menu1 = new wxMenu();
    MenuItem1 = new wxMenuItem(Menu1, idMenuQuit, _("Quit\tAlt-F4"), _("Quit the application"), wxITEM_NORMAL);
    Menu1->Append(MenuItem1);
    MenuBar1->Append(Menu1, _("&File"));
    Menu2 = new wxMenu();
    MenuItem2 = new wxMenuItem(Menu2, idMenuAbout, _("About\tF1"), _("Show info about this application"), wxITEM_NORMAL);
    Menu2->Append(MenuItem2);
    MenuBar1->Append(Menu2, _("Help"));
    SetMenuBar(MenuBar1);
    StatusBar1 = new wxStatusBar(this, ID_STATUSBAR1, 0, _T("ID_STATUSBAR1"));
    int __wxStatusBarWidths_1[1] = { -1 };
    int __wxStatusBarStyles_1[1] = { wxSB_NORMAL };
    StatusBar1->SetFieldsCount(1,__wxStatusBarWidths_1);
    StatusBar1->SetStatusStyles(1,__wxStatusBarStyles_1);
    SetStatusBar(StatusBar1);

    ImagePanel1->Connect(wxEVT_PAINT,(wxObjectEventFunction)&ImagePanelFrame::OnImagePanel1Paint,0,this);
    Connect(idMenuQuit,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&ImagePanelFrame::OnQuit);
    Connect(idMenuAbout,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&ImagePanelFrame::OnAbout);
    //*)
}

ImagePanelFrame::~ImagePanelFrame()
{
    //(*Destroy(ImagePanelFrame)
    //*)
}

void ImagePanelFrame::OnQuit(wxCommandEvent& event)
{
    Close();
}

void ImagePanelFrame::OnAbout(wxCommandEvent& event)
{
    wxString msg = wxbuildinfo(long_f);
    wxMessageBox(msg, _("Welcome to..."));
}

void ImagePanelFrame::OnImagePanel1Paint(wxPaintEvent& event)
{
}
In Headers the file ImagePanelApp.h after adding the control the code is

Code: Select all

/***************************************************************
 * Name:      ImagePanelApp.h
 * Purpose:   Defines Application Class
 * Author:     ()
 * Created:   2012-09-04
 * Copyright:  ()
 * License:
 **************************************************************/

#ifndef IMAGEPANELAPP_H
#define IMAGEPANELAPP_H

#include <wx/app.h>

class ImagePanelApp : public wxApp
{
    public:
        virtual bool OnInit();
};

#endif // IMAGEPANELAPP_H
In Headers the file ImagePanelMain.h after adding the control is

Code: Select all

/***************************************************************
 * Name:      ImagePanelMain.h
 * Purpose:   Defines Application Frame
 * Author:     ()
 * Created:   2012-09-04
 * Copyright:  ()
 * License:
 **************************************************************/

#ifndef IMAGEPANELMAIN_H
#define IMAGEPANELMAIN_H

//(*Headers(ImagePanelFrame)
#include <wx/menu.h>
#include "wx/wxImagePanel.h"
#include <wx/panel.h>
#include <wx/frame.h>
#include <wx/statusbr.h>
//*)

class ImagePanelFrame: public wxFrame
{
    public:

        ImagePanelFrame(wxWindow* parent,wxWindowID id = -1);
        virtual ~ImagePanelFrame();

    private:

        //(*Handlers(ImagePanelFrame)
        void OnQuit(wxCommandEvent& event);
        void OnAbout(wxCommandEvent& event);
        void OnImagePanel1Paint(wxPaintEvent& event);
        //*)

        //(*Identifiers(ImagePanelFrame)
        static const long ID_IMAGEPANEL1;
        static const long ID_PANEL1;
        static const long idMenuQuit;
        static const long idMenuAbout;
        static const long ID_STATUSBAR1;
        //*)

        //(*Declarations(ImagePanelFrame)
        wxImagePanel* ImagePanel1;
        wxPanel* Panel1;
        wxStatusBar* StatusBar1;
        //*)

        DECLARE_EVENT_TABLE()
};

#endif // IMAGEPANELMAIN_H
I will show what is in the file that is made if I make an extra header file and name it wxImagePanel like in the image below.
File Added if choose header.
File Added if choose header.
If I add the header file not a class and I name the file wxImagePanel.h and in that file the code generated is.

Code: Select all

#ifndef WXIMAGEPANEL_H_INCLUDED
#define WXIMAGEPANEL_H_INCLUDED



#endif // WXIMAGEPANEL_H_INCLUDED
If I do not make a header but make a class instead I get the 2 files in the image below and the code for each file
2 Files Added if I choose to make a class instead of a header.
2 Files Added if I choose to make a class instead of a header.
one is in sources in directory src named wxImagePanel.cpp and the code in it is

Code: Select all

#include "wxImagePanel.h"

wxImagePanel::wxImagePanel()
{
    //ctor
}

wxImagePanel::~wxImagePanel()
{
    //dtor
}
The other file generated if I make a class is in the directory Headers include and it is called wxImagePanel.h and the code is

Code: Select all

#ifndef WXIMAGEPANEL_H
#define WXIMAGEPANEL_H


class wxImagePanel
{
    public:
        wxImagePanel();
        virtual ~wxImagePanel();
    protected:
    private:
};

#endif // WXIMAGEPANEL_H
So thats it should I be just making a header file or a class that makes the 2 files? Or can I just make it work without adding a header file or a class at all?
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Re: Help with wxImagePanel.

Post by Auria »

You are losing me here. What you need is very simple, you need one .cpp file and one .h file for the custom control. The problem about using wxSmith is that wxSmith will only know wxWidgets built-in controls by default (it looks like you somehow told it you want to use 'wxImagePanel' but it thinks it's a wxWidgets built-in control and includes "wx/wxImagePanel.h"), it won't know your custom control. The part I cannot help with is how to make wxSmith play with your custom control. Usually in GUI builders you would add an empty panel, and then in your code manually add your custom control to that panel. But I don't know specifically about wxSmith.
"Keyboard not detected. Press F1 to continue"
-- Windows
papayrus
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 204
Joined: Tue Jan 25, 2011 4:55 pm
Location: USA

Re: Help with wxImagePanel.

Post by papayrus »

Auria wrote:You are losing me here. What you need is very simple, you need one .cpp file and one .h file for the custom control. The problem about using wxSmith is that wxSmith will only know wxWidgets built-in controls by default (it looks like you somehow told it you want to use 'wxImagePanel' but it thinks it's a wxWidgets built-in control and includes "wx/wxImagePanel.h"), it won't know your custom control. The part I cannot help with is how to make wxSmith play with your custom control. Usually in GUI builders you would add an empty panel, and then in your code manually add your custom control to that panel. But I don't know specifically about wxSmith.
Yes that is true for all the controls but they have the wxImagePanel control in there as well as like an extra thing.I think I am supposed to create the wxImagePanel.h file and then add the proper code in the main apps file. So if I were to go ahead and add a new file just a header file to the project and name it wxImagePanel.h what would I need to put in it? looking above you can see that when I do that it in the header file this code is already produced.

Code: Select all

#ifndef WXIMAGEPANEL_H_INCLUDED
#define WXIMAGEPANEL_H_INCLUDED



#endif // WXIMAGEPANEL_H_INCLUDED
In the part where I said if I just add new header file to the project and not a class. Then you can see in the ImagePanelMain.cpp thelast line of code gets generated when I double click that imagePanel I dragged out. So yes it is missing the wxImagePanel.h file I just am, not sure what I would put in it if I created it.
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Re: Help with wxImagePanel.

Post by Auria »

I have no idea what 'wxImagePanel' wxSmith is referring to (why don't you ask this on the CodeBlocks forum, maybe people over there would know more). But it looks like it wants to include <wx/wximagepanel.h>, so placing the include with the right name under a folder named 'wx' sounds like a good first step

whether you add an empty file or a class to the project is almost certainly irrelevant, that will only dictate the default contents of the file and you're going to override that anyway
"Keyboard not detected. Press F1 to continue"
-- Windows
Post Reply