Guidance
指路人
g.yi.org
Guidance Forums / wxWidgets (wxWindows) in C++ / trying to load bitmaps into a wxobjarray

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. trying to load bitmaps into a wxobjarray
#4822
Posted by: 2004-07-15 06:37:33
I'm trying to load bitmaps into a wxobjarray. Basically i am using a for statement and am looping thru an array of file names trying to load them into a bitmap Object array.

Here is some code i'm using:


This is my declare

WX_DECLARE_OBJARRAY(MyBitmapArray, ArrayOfBitmaps);



class MyBitmapArray
{

ArrayOfBitmaps       m_BitmapArray;
};

use of my objarray:

            #if wxUSE_LIBJPEG
                   
            if ( !image.LoadFile( _T("arrayoffiles")) )
                wxLogError(wxT("Can't load JPG image"));
            else
                my_jpeg = new wxBitmap( image );
                m_BitmapArray.Add(my_jpeg);
            #endif // wxUSE_LIBJPEG

My problem is i get a compile error that I'm trying to convert wxBitmap to
const MyBitmapArray

How do i make my objarray of type wxBitmap?

Am I going about this all wrong?

Thanks in advance
Message2. Re: trying to load bitmaps into a wxobjarray
#4823
Posted by: bec 2004-07-15 08:36:39
Hi there..
pretty sure you should use

WX_DECLARE_OBJARRAY(wxBitmap, wxArrayBitmap);

If that doesn't work i recommend going to
http://www.lehigh.edu/~jrl1/
and downloading wxthings.
This contains some lovely code by John Labenski. The wxBitmapComboBox code creates an array of bitmaps.
You might find it very useful..

Bec.
Message3. Re: trying to load bitmaps into a wxobjarray
#4825
Posted by: 2004-07-15 11:26:44
Thanks bec,

I looked at Johns wxthings code and lovely code indeed. A little to advanced for me though. Know of a simpler version?

When i try to use:

WX_DECLARE_OBJARRAY(wxBitmap, wxArrayBitmap);

I get a compile error that i'm trying to redefine wxBitmap.

I suppose my problem is lacking in the use of classes.

thanks again

b_man
Message4. Re: trying to load bitmaps into a wxobjarray
#4833
Posted by: bec 2004-07-16 08:26:42
right...have a simple example for you..

This def complies using VC++..

cheers bec.

-------------------------------------------------------------------------------
// for compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

// for all others, include the necessary headers
#ifndef WX_PRECOMP
    #include "wx/app.h"
    #include "wx/log.h"
    #include "wx/frame.h"
    #include "wx/button.h"
    #include "wx/checkbox.h"
    #include "wx/listbox.h"
    #include "wx/statbox.h"
    #include "wx/stattext.h"
    #include "wx/textctrl.h"
#endif

#include "wx/sizer.h"
#include "wx/arrimpl.cpp"

// ----------------------------------------------------------------------------
// our classes
// ----------------------------------------------------------------------------

WX_DECLARE_OBJARRAY(wxBitmap, wxArrayBitmap);
WX_DEFINE_OBJARRAY( wxArrayBitmap );


// Define a new application type, each program should derive a class from wxApp
class WidgetsApp : public wxApp
{
public:
    // override base class virtuals
    // ----------------------------

    // this one is called on application startup and is a good place for the app
    // initialization (doing it here and not in the ctor allows to have an error
    // return: if OnInit() returns false, the application terminates)
    virtual bool OnInit();
};

// Define a new frame type: this is going to be our main frame
class WidgetsFrame : public wxFrame
{
public:
    // ctor(s) and dtor
    WidgetsFrame(void);
    WidgetsFrame(const wxString& title);
    ~WidgetsFrame(){};

    wxArrayBitmap m_bitmapArray;    // the individual bitmaps
};

// ----------------------------------------------------------------------------
// misc macros
// ----------------------------------------------------------------------------
IMPLEMENT_APP(WidgetsApp)

// ============================================================================
// implementation
// ============================================================================

// ----------------------------------------------------------------------------
// app class
// ----------------------------------------------------------------------------

bool WidgetsApp::OnInit()
{
    if ( !wxApp::OnInit() )
        return FALSE;

    wxFrame *frame = new WidgetsFrame(_T(" widgets demo"));
    frame->Show();

    return TRUE;
}

// ----------------------------------------------------------------------------
// WidgetsFrame construction
// ----------------------------------------------------------------------------

WidgetsFrame::WidgetsFrame(const wxString& title)
            : wxFrame(NULL, -1, title, wxPoint(0, 50), wxSize(400, 400))
{
     // Set up toolbar
    wxBitmap toolBarBitmaps[8];

    toolBarBitmaps[0] = wxBitmap("res/new_file.bmp", wxBITMAP_TYPE_BMP);
    toolBarBitmaps[1] = wxBitmap("res/file_open.bmp", wxBITMAP_TYPE_BMP);
    toolBarBitmaps[2] = wxBitmap("res/file_save.bmp", wxBITMAP_TYPE_BMP);
    toolBarBitmaps[3] = wxBitmap("res/file_save_as.bmp", wxBITMAP_TYPE_BMP);

    m_bitmapArray.Add(toolBarBitmaps[0]);
    m_bitmapArray.Add(toolBarBitmaps[1]);
    m_bitmapArray.Add(toolBarBitmaps[2]);
    m_bitmapArray.Add(toolBarBitmaps[3]);
}

Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Sat 2024-4-20  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0