QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2663|回复: 0
打印 上一主题 下一主题

Load bitmaps and icons from the programs's resources

[复制链接]
字体大小: 正常 放大
韩冰        

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2005-1-26 19:27 |只看该作者 |倒序浏览
|招呼Ta 关注Ta

$ [* x! Y+ G0 _5 G& F$ X1 F Answer:( \% g) n6 t( K This FAQ assumes that you have already bound your bitmaps or icons to your executable. If you need help adding bitmaps or icons to a project, see the FAQ on adding icons, cursors, and bitmaps to a BCB project.

7 r& T) _9 P$ ]. K

Bitmaps ; A ^$ x% Z% }' B+ Q, ETBitmap contains two functions called LoadFromResourceID and LoadFromResourceName that allow you to load bitmaps from the program's resources. Use LoadFromResourceID when the ID of your bitmap resource is an integer (the RC file example used numeric ID's). Use LoadFromResourceName when the bitmap's ID is a string. If you used the Image Editor to create a .RES file, you will need LoadFromResourceName because the Image Editor saves the resources using string IDs. Here are some code examples.

7 Z1 e0 Z4 e% i* e3 a+ G

// Loading a bitmap that uses numeric IDs. , N% ]! }, `/ g1 ] Graphics::TBitmap *bmp = new Graphics::TBitmap; 5 `7 q# ^3 E. y1 }% Z6 v1 r bmp->LoadFromResourceID((int)HInstance,IDB_SPLASH);

# Z+ \- i, f8 \: R6 z

// Loading a bitmap that uses string IDs, like the! p% h. }; Y3 D: I. x // ones that the Image Editor creates.4 ^6 A# e5 H- n0 j Graphics::TBitmap *bmp = new Graphics::TBitmap;6 J; f, ~3 o. Q* D. R5 z" Q bmp->LoadFromResourceName((int)HInstance,"Bitmap1");

7 c+ [) j! h6 l8 r9 S2 K

// Loading a bitmap into a TImage control/ h9 M0 N: P [: F c& D2 y // using numeric IDs. 0 z. r6 T! B' }" p+ ]! m Image1->icture->Bitmap->LoadFromResourceID((int)HInstance,IDB_SPLASH);

9 @3 j: Q* r. Y9 c) I+ d( p

Note: You can also use API functions to load the bitmaps. Use the API LoadBitmap function and assign the result to the Handle property of TBitmap.

6 ?5 P0 i3 t0 H+ k$ t V9 @( d+ Q

Icons

# j2 _$ i+ A _5 p8 h8 W, W, U

TIcon is the VCL class for working with icons. Unlike TBitmap, TIcon does not contain member functions to help you load the icon. You must use the API functions LoadIcon or LoadImage to load the icon into a TIcon object. LoadIcon is simpler to use, but it can only load 32 x 32 icons. If you use LoadIcon to load an icon of any other size, the API will enlarge or shrink the icon image to 32 x 32. LoadImage allows you to load icons of any size, but it takes more arguments. Here are some icon examples.

0 ~% D* y: e$ _0 g

// Load a 32 x 32 icon that uses an integer ID ( J) d' r, |, ]& u1 Y, `8 |7 s+ n TIcon *icon = new Graphics::TIcon;2 ] c8 T8 h! Y, m1 s: @ ]0 T' w# l icon->Handle=LoadIcon(HInstance,MAKEINTRESOURCE(ID_FOLDER_ICON));

* l$ E2 S2 O: S `2 i

// Load a 32 x 32 icon that uses a string ID6 N) p- [' Q$ N3 @0 i g' K' _ TIcon *icon = new Graphics::TIcon; * h6 d, m9 X3 f3 j1 O& `# W- E icon->Handle=LoadIcon(HInstance,"IconFolder");

1 V' f" q" ~$ {! ]0 K. ~

// load a system icon " Q; r: `+ _; _7 g6 p# S TIcon *icon = new Graphics::TIcon;: p( a" o' ]* R9 F icon->Handle=LoadIcon(HInstance,IDI_EXCLAMATION);

i. ~" G7 u$ o& K4 @3 y4 @

// Load a 16 x 16 icon that uses an integer ID * g/ f! p- |1 h. I P3 K TIcon *icon = new Graphics::TIcon; & X. z" ~2 e2 O! L, D5 Y$ U& ? icon->Handle=LoadImage(HInstance,4 ~0 X K+ e% h! c MAKEINTRESOURCE(ID_SMALL_FOLDER), ! [/ K( z0 t4 Q- O( y( S1 H IMAGE_ICON,4 G! U% o" l, N- r2 \# e0 } 16,16,* Z8 |9 t' Z* A5 T LR_LOADREALSIZE);

( s/ ^% k& R. [

// Load a 16 x 16 icon that uses a string ID 0 Y0 B1 C% a y9 \! o TIcon *icon = new Graphics::TIcon; % R4 i8 d( v: _6 P4 M icon->Handle=LoadImage(HInstance, b/ D( N7 D) C1 ]& B3 m "SmallFolder"), * s( E, d- h: `- _2 g- `- W0 f IMAGE_ICON, ' K3 y4 D0 o* r$ H4 ` 16,16, 8 N) U$ j. ~ y LR_LOADREALSIZE);

$ [2 \, r% L- K7 ~4 G

//Load an icon directly into a TImage control; f. [& X! u4 }- e o+ \ Image1->icture->Icon->Handle = LoadIcon(HInstance,IDI_EXCLAMATION);

zan
转播转播0 分享淘帖0 分享分享0 收藏收藏0 支持支持0 反对反对0 微信微信
您需要登录后才可以回帖 登录 | 注册地址

qq
收缩
  • 电话咨询

  • 04714969085
fastpost

关于我们| 联系我们| 诚征英才| 对外合作| 产品服务| QQ

手机版|Archiver| |繁體中文 手机客户端  

蒙公网安备 15010502000194号

Powered by Discuz! X2.5   © 2001-2013 数学建模网-数学中国 ( 蒙ICP备14002410号-3 蒙BBS备-0002号 )     论坛法律顾问:王兆丰

GMT+8, 2026-4-18 12:06 , Processed in 0.434635 second(s), 52 queries .

回顶部