wxWidgets for C++リソースファイルから画像を静的にマウント

14200 ワード

wxWidgetsに画像をロードするのは簡単ですが、画像ファイルと実行可能ファイルを一緒に配置すると、パブリッシュ時に実行可能ファイルをパブリッシュするだけで済みます.この機能を実現するには、一般的にリソースファイルを使用して解決することができます.Windowsの下のリソースファイルのソースファイルは*.rc,コンパイル後は*.res.linuxの下で類似して、ソースファイルは*.xrc、コンパイル後は*.xres.ただし、xml形式であり、このリソースファイルをマウントするにも動的にマウントする必要があります.プロファイルに相当します.実行可能ファイルに直接コンパイルしたい場合.ツールwxrcが必要です.この作業はwxWidgetsのuntilsディレクトリで、自分でコンパイルできます.このツールを使用すると*.xrcはc++コードを生成し,画像であれば文字配列に変換する.その後、他のプログラムと一緒にコンパイルします.wxrc-c mainを使用できます.xrc -v -o main.hmain.xrcのフォーマットは次のとおりです.
xml version="1.0"
?>
 
<
resource 
version
="2.3.0.1"
>
       
<
object 
class
="wxBitmap"
 name
="background"
>
background.jpg
object
>
 
resource
>
   main.h     :

//
//
 This file was automatically generated by wxrc, do not edit by hand.
//
#include 
<
wx
/
wxprec.h
>
#ifdef __BORLANDC__    
#pragma
 hdrstop
#endif
#include 
<
wx
/
filesys.h
>
#include 
<
wx
/
fs_mem.h
>
#include 
<
wx
/
xrc
/
xmlres.h
>
#include 
<
wx
/
xrc
/
xh_all.h
>
static
 size_t xml_res_size_0 
=
 
55966
;
static
 unsigned 
char
 xml_res_file_0[] 
=
 {
255
,
216
,
255
,
224
,
0
,
16
,
74
,
70
,
73
,
70
,
0
,
1
,
2
,
0
,
0
,
100
,
0
,
100
,
0
,
0
,
255
,
236
,
0
,
17
,
68
,
117
,
99
,
107
,
121
,
0
,
1
,
0
,
4
,
0
,
0
,
0
,
60
,
0
,
0
,
255
,
238
,
0
,
14
,
65
,
100
,
111
,
98
,
101
,
0
,
100
,
192
,
0
,
0
,
0
,
1
,
255
,
219
,
0
,
132
,
0
,
6
,
4
,
4
,
4
,
5
,
4
,
6
,
5
,
5
,
6
,
9
,
6
,
5
,
6
,
9
,
11
,
8
,
6
,
6
,
8
,
11
,
12
,
10
,
10
,
11
,
10
,
10
,
12
,
16
,
12
,
12
,
12
,
12
,
12
,
12
,
16
,
12
,
14
,
15
,
16
,
15
,
14
,
12
,
19
,
19
,
20
,
20
,
19
,
19
,
28
,
27
,
27
,
27
,
28
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
1
,
7
,
7
,
7
,
13
,
12
,
13
,
24
,
16
,
16
,
24
,
26
,
21
,
17
,
21
,
26
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
31
,
255
,
192
,
0
,
17
,
8
,
2
,
201
,
3
,
248
,
3
,
1
,
17
,
0
,
2
,..
102
,
222
,
191
,
202
,
130
,
94
,
195
,
45
,
21
,
39
,
169
,
149
,
113
,
241
,
11
,
45
,
173
,
84
,
25
,
120
,
94
,
18
,
190
,
190
,
196
,
107
,
2
,
216
,
129
,
52
,
90
,
4
,
128
,
1
,
130
,
160
,
201
,
16
,
36
,
0
,
147
,
0
,
84
,
68
,
164
,
164
,
47
,
80
,
44
,
0
,
96
,
168
,
202
,
0
,
201
,
145
,
130
,
178
,
49
,
229
,
32
,
127
,
255
,
217
};
static
 size_t xml_res_size_1 
=
 
161
;
static
 unsigned 
char
 xml_res_file_1[] 
=
 {
60
,
63
,
120
,
109
,
108
,
32
,
118
,
101
,
114
,
115
,
105
,
111
,
110
,
61
,
34
,
49
,
46
,
48
,
34
,
32
,
101
,
110
,
99
,
111
,
100
,
105
,
110
,
103
,
61
,
34
,
85
,
84
,
70
,
45
,
56
,
34
,
63
,
62
,
10
,
60
,
114
,
101
,
115
,
111
,
117
,
114
,
99
,
101
,
32
,
118
,
101
,
114
,
115
,
105
,
111
,
110
,
61
,
34
,
50
,
46
,
51
,
46
,
48
,
46
,
49
,
34
,
62
,
10
,
32
,
32
,
60
,
111
,
98
,
106
,
101
,
99
,
116
,
32
,
99
,
108
,
97
,
115
,
115
,
61
,
34
,
119
,
120
,
66
,
105
,
116
,
109
,
97
,
112
,
34
,
32
,
110
,
97
,
109
,
101
,
61
,
34
,
98
,
97
,
99
,
107
,
103
,
114
,
111
,
117
,
110
,
100
,
34
,
62
,
114
,
101
,
115
,
111
,
117
,
114
,
99
,
101
,
115
,
46
,
104
,
36
,
98
,
97
,
99
,
107
,
103
,
114
,
111
,
117
,
110
,
100
,
46
,
106
,
112
,
103
,
60
,
47
,
111
,
98
,
106
,
101
,
99
,
116
,
62
,
10
,
60
,
47
,
114
,
101
,
115
,
111
,
117
,
114
,
99
,
101
,
62
,
10
};
void
 InitXmlResource(){    
//
 Check for memory FS. If not present, load the handler:
    {        wxMemoryFSHandler::AddFile(wxT(
"
XRC_resource/dummy_file
"
), wxT(
"
dummy one
"
));        wxFileSystem fsys;        wxFSFile 
*

=
 fsys.OpenFile(wxT(
"
memory:XRC_resource/dummy_file
"
));        wxMemoryFSHandler::RemoveFile(wxT(
"
XRC_resource/dummy_file
"
));        
if
 (f) delete f;        
else
 wxFileSystem::AddHandler(
new
 wxMemoryFSHandler);    }    wxMemoryFSHandler::AddFile(wxT(
"
XRC_resource/resources.h$background.jpg
"
), xml_res_file_0, xml_res_size_0);    wxMemoryFSHandler::AddFile(wxT(
"
XRC_resource/resources.h$main.xrc
"
), xml_res_file_1, xml_res_size_1);    wxXmlResource::Get()
->
Load(wxT(
"
memory:XRC_resource/resources.h$main.xrc
"
));}
その後、メインプログラムでInitXmlResource関数を呼び出します.これをマウントするにはjpg図は、
    wxXmlResource::Get()->InitAllHandlers();     
wxBitmap background = wxXmlResource::Get()->LoadBitmap(_T("background"));
m_pStaticBitmap = new wxStaticBitmap(this, wxID_ANY, background, wxPoint(0, 0), wxSize(1024, 768));
を使用しますが、wxStaticBitmapを使用する場合は、wxFrameのOnSizeに
    m_pStaticBitmap->Refresh();
windows , 。 linux 。
を追加する必要があります.