重载wxArtProvider改写wxWidgets图标

 

快乐虾

http://blog.csdn.net/lights_joy/

lights@hb165.com

 

本文适用于

wxWidgets- 2.8.8

vs2008

Windows XP

 

欢迎转载,但请保留作者信息

 

wxWidgets在显示图标的时候将调用wxArtProvider::CreateBitmap函数,通过重载此函数可以有机会替换这些图标,包括菜单,工具栏,窗口等的图标。

首先从wxArtProvider继承一个子类并重载其CreateBitmap函数:

class MyArtProvider : public wxArtProvider

{

protected:

    virtual wxBitmap CreateBitmap(const wxArtID& id, const wxArtClient& client,

                                  const wxSize& size);

};

然后需要通知wxWidgets使用这个新的ArtProvider

        wxArtProvider::Push(new MyArtProvider);

这个动态创建的MyArtProvider将由wxWidgets负责释放。

最后看看CreateBitmap的实现:

wxBitmap MyArtProvider::CreateBitmap(const wxArtID& id,

                                     const wxArtClient& client,

                                     const wxSize& WXUNUSED(size))

{

    if ( client == wxART_MESSAGE_BOX )

    {

        if ( id == wxART_INFORMATION )

            return wxBitmap(info_xpm);

        if ( id == wxART_ERROR )

            return wxBitmap(error_xpm);

        if ( id == wxART_WARNING )

            return wxBitmap(warning_xpm);

        if ( id == wxART_QUESTION )

            return wxBitmap(question_xpm);

    }

    return wxNullBitmap;

}

idclient两个参数指明了当前要绘制的图标类型的它们的ID

client可能取以下值:

// ----------------------------------------------------------------------------

// Art clients

// ----------------------------------------------------------------------------

 

#define wxART_TOOLBAR              wxART_MAKE_CLIENT_ID(wxART_TOOLBAR)

#define wxART_MENU                 wxART_MAKE_CLIENT_ID(wxART_MENU)

#define wxART_FRAME_ICON           wxART_MAKE_CLIENT_ID(wxART_FRAME_ICON)

 

#define wxART_CMN_DIALOG           wxART_MAKE_CLIENT_ID(wxART_CMN_DIALOG)

#define wxART_HELP_BROWSER         wxART_MAKE_CLIENT_ID(wxART_HELP_BROWSER)

#define wxART_MESSAGE_BOX          wxART_MAKE_CLIENT_ID(wxART_MESSAGE_BOX)

#define wxART_BUTTON               wxART_MAKE_CLIENT_ID(wxART_BUTTON)

 

#define wxART_OTHER                wxART_MAKE_CLIENT_ID(wxART_OTHER)

从这些定义可以看出ArtProvider可以替换所有显示的图标。

id则是wxWidgets内部定义的一些图标:

// ----------------------------------------------------------------------------

// Art IDs

// ----------------------------------------------------------------------------

 

#define wxART_ADD_BOOKMARK         wxART_MAKE_ART_ID(wxART_ADD_BOOKMARK)

#define wxART_DEL_BOOKMARK         wxART_MAKE_ART_ID(wxART_DEL_BOOKMARK)

#define wxART_HELP_SIDE_PANEL      wxART_MAKE_ART_ID(wxART_HELP_SIDE_PANEL)

#define wxART_HELP_SETTINGS        wxART_MAKE_ART_ID(wxART_HELP_SETTINGS)

#define wxART_HELP_BOOK            wxART_MAKE_ART_ID(wxART_HELP_BOOK)

#define wxART_HELP_FOLDER          wxART_MAKE_ART_ID(wxART_HELP_FOLDER)

#define wxART_HELP_PAGE            wxART_MAKE_ART_ID(wxART_HELP_PAGE)

#define wxART_GO_BACK              wxART_MAKE_ART_ID(wxART_GO_BACK)

#define wxART_GO_FORWARD           wxART_MAKE_ART_ID(wxART_GO_FORWARD)

#define wxART_GO_UP                wxART_MAKE_ART_ID(wxART_GO_UP)

#define wxART_GO_DOWN              wxART_MAKE_ART_ID(wxART_GO_DOWN)

#define wxART_GO_TO_PARENT         wxART_MAKE_ART_ID(wxART_GO_TO_PARENT)

#define wxART_GO_HOME              wxART_MAKE_ART_ID(wxART_GO_HOME)

#define wxART_FILE_OPEN            wxART_MAKE_ART_ID(wxART_FILE_OPEN)

#define wxART_FILE_SAVE            wxART_MAKE_ART_ID(wxART_FILE_SAVE)

#define wxART_FILE_SAVE_AS         wxART_MAKE_ART_ID(wxART_FILE_SAVE_AS)

#define wxART_PRINT                wxART_MAKE_ART_ID(wxART_PRINT)

#define wxART_HELP                 wxART_MAKE_ART_ID(wxART_HELP)

#define wxART_TIP                  wxART_MAKE_ART_ID(wxART_TIP)

#define wxART_REPORT_VIEW          wxART_MAKE_ART_ID(wxART_REPORT_VIEW)

#define wxART_LIST_VIEW            wxART_MAKE_ART_ID(wxART_LIST_VIEW)

#define wxART_NEW_DIR              wxART_MAKE_ART_ID(wxART_NEW_DIR)

#define wxART_HARDDISK             wxART_MAKE_ART_ID(wxART_HARDDISK)

#define wxART_FLOPPY               wxART_MAKE_ART_ID(wxART_FLOPPY)

#define wxART_CDROM                wxART_MAKE_ART_ID(wxART_CDROM)

#define wxART_REMOVABLE            wxART_MAKE_ART_ID(wxART_REMOVABLE)

#define wxART_FOLDER               wxART_MAKE_ART_ID(wxART_FOLDER)

#define wxART_FOLDER_OPEN          wxART_MAKE_ART_ID(wxART_FOLDER_OPEN)

#define wxART_GO_DIR_UP            wxART_MAKE_ART_ID(wxART_GO_DIR_UP)

#define wxART_EXECUTABLE_FILE      wxART_MAKE_ART_ID(wxART_EXECUTABLE_FILE)

#define wxART_NORMAL_FILE          wxART_MAKE_ART_ID(wxART_NORMAL_FILE)

#define wxART_TICK_MARK            wxART_MAKE_ART_ID(wxART_TICK_MARK)

#define wxART_CROSS_MARK           wxART_MAKE_ART_ID(wxART_CROSS_MARK)

#define wxART_ERROR                wxART_MAKE_ART_ID(wxART_ERROR)

#define wxART_QUESTION             wxART_MAKE_ART_ID(wxART_QUESTION)

#define wxART_WARNING              wxART_MAKE_ART_ID(wxART_WARNING)

#define wxART_INFORMATION          wxART_MAKE_ART_ID(wxART_INFORMATION)

#define wxART_MISSING_IMAGE        wxART_MAKE_ART_ID(wxART_MISSING_IMAGE)

 

#define wxART_COPY                 wxART_MAKE_ART_ID(wxART_COPY)

#define wxART_CUT                  wxART_MAKE_ART_ID(wxART_CUT)

#define wxART_PASTE                wxART_MAKE_ART_ID(wxART_PASTE)

#define wxART_DELETE               wxART_MAKE_ART_ID(wxART_DELETE)

#define wxART_NEW                  wxART_MAKE_ART_ID(wxART_NEW)

 

#define wxART_UNDO                 wxART_MAKE_ART_ID(wxART_UNDO)

#define wxART_REDO                 wxART_MAKE_ART_ID(wxART_REDO)

 

#define wxART_QUIT                 wxART_MAKE_ART_ID(wxART_QUIT)

 

#define wxART_FIND                 wxART_MAKE_ART_ID(wxART_FIND)

#define wxART_FIND_AND_REPLACE     wxART_MAKE_ART_ID(wxART_FIND_AND_REPLACE)

 

 

参考资料

dll方式编译wxWidgets-2.8.8( 2008-9-6 )

wxWidgetsMFC动态类型信息比较 2008-9-7

wxWidgets程序链接错误解决( 2008-10-24 )

animate示例看wxWidgets的程序结构( 2008-10-25 )

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

嵌云阁主

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值