游戏开发论坛

 找回密码
 立即注册
搜索
查看: 17729|回复: 18

请问关于loadimage函数使用资源文件时的使用方法

[复制链接]

1

主题

6

帖子

6

积分

新手上路

Rank: 1

积分
6
发表于 2005-9-15 13:06:00 | 显示全部楼层 |阅读模式
小弟在VB使用loadimage函数使用资源文件(.res)中的位图时,该函数的前两个参数和最后一个参数始终不会设,不知哪位大哥能告诉小弟这三个参数该如何写,最好能写一行具体的代码,小弟不胜感激!

22

主题

209

帖子

229

积分

中级会员

Rank: 3Rank: 3

积分
229
发表于 2005-9-15 15:11:00 | 显示全部楼层

Re:请问关于loadimage函数使用资源文件时的使用方法

'//* 从资源文件中取ini
Sub from_Res_To_ini(num As Integer, Optional icmd As String = "INI", Optional sini As String = "temp1.ini") '//* 从资源文件中取图
   On Error Resume Next
    Dim pict() As Byte
    If icmd = "INI" Then
       pict = LoadResData(num, icmd)
      
    ElseIf icmd = "图标" Or icmd = 3 Then
       'pict = LoadResPicture(num, 1)
    End If
    Open App.Path & "\bin\" & sini For Binary Access Write As #43 '//* 输出的文件
        Put #43, , pict '//*  向文件写入 MIDI 文件
    Close #43
End Sub



'//* 从资源文件中取图
Sub from_Res_To_icon(num As Integer, Optional icmd As String = "CUSTOM", Optional icon As String = "temp1.ico") '//* 从资源文件中取图
   On Error Resume Next
    Dim pict() As Byte
    If icmd = "CUSTOM" Then
       pict = LoadResData(num, icmd)
    ElseIf icmd = "图标" Or icmd = 3 Then
       'pict = LoadResPicture(num, 1)
    End If
    Open App.Path & "\icon\" & icon For Binary Access Write As #3 '//* 输出的文件
        Put #3, , pict '//*  向文件写入 MIDI 文件
    Close #3
End Sub

1

主题

6

帖子

6

积分

新手上路

Rank: 1

积分
6
 楼主| 发表于 2005-9-15 17:09:00 | 显示全部楼层

Re:请问关于loadimage函数使用资源文件时的使用方法

谢谢啊谢谢!!!回去赶紧试验一下!

1

主题

6

帖子

6

积分

新手上路

Rank: 1

积分
6
 楼主| 发表于 2005-9-15 17:12:00 | 显示全部楼层

Re:请问关于loadimage函数使用资源文件时的使用方法

不过小生愚昧,还是不大懂如何在loadimage函数中使用该位图文件阿!

22

主题

209

帖子

229

积分

中级会员

Rank: 3Rank: 3

积分
229
发表于 2005-9-16 14:36:00 | 显示全部楼层

Re:请问关于loadimage函数使用资源文件时的使用方法

loadimage函数 是从那里来的,要做什么 ??
是 RES 的文件吗?
位图 是 bmp 吗?
是要从 RES 是读 bmp 吗 ??
说下用的语言 ?? VB 中没有看到 loadimage

1

主题

6

帖子

6

积分

新手上路

Rank: 1

积分
6
 楼主| 发表于 2005-9-17 00:55:00 | 显示全部楼层

Re:请问关于loadimage函数使用资源文件时的使用方法

loadimage是个API函数,我使用VB环境编程时遇到该问题,从资源文件也就是.res文件中读取位图bmp,是要从资源文件中加载图片显示到窗口时用到该函数的。

22

主题

209

帖子

229

积分

中级会员

Rank: 3Rank: 3

积分
229
发表于 2005-9-19 12:19:00 | 显示全部楼层

Re:请问关于loadimage函数使用资源文件时的使用方法

没有办法,这个问题不会有多少人回答的,原因就不用说了,,,,
要想从RES中LOADING 图可以用  LoadResPicture

用以从资源 (.res) 文件装载位图、图标或光标。

语法

LoadResPicture(index, format)

LoadResPicture 函数的语法包含下列部分:

部分 描述
index 必需的。一个整数或字符串,它用来指定资源文件中数据的标识符 (ID) 。ID标识符为 1 的资源保留给应用程序的图标。
format 必需的。一个数值或常数,如下列“设置值”中所描述的,指定返回数据的格式。


设置值

用于 format 的设置值有:

常数 值 描述
vbResBitmap 位图 0 位图资源
vbResIcon 图标 1 图标资源
vbResCursor 2 光标资源


说明

可以使用 LoadResPicture 函数代替对存储在 Form 或控件的 Picture 属性中的图形的引用。

将位图、图标或光标存储在资源文件中并从该资源文件对它们进行访问能改进装载时间,这是因为可以根据需要从资源文件单独装载,而不是在装载 Form 时一并全部装载。

LoadResPicture 的使用对于 Visual Basic 应用程序的本地化有好处,这是因为需要翻译的资源在一个资源文件中被隔离,并且无须访问源代码或重新编译该应用程序。


LoadResData 函数
      

用以从资源 (.res) 文件装载若干可能类型的数据,并返回一个 Byte 数组。

语法

LoadResData(index, format)

LoadResData 函数的语法包含下列部分:

部分 描述
index 必需的。一个整数或字符串,它用来指定资源文件中数据的标识符 (ID)。ID 标识符为 1 的资源保留给应用程序的图标。
Format 必需的。一个数值,它用来按照下列“设置值”中的描述,指定返回数据的原始格式。该数值也可以是用户定义资源的字符串名。


设置值

用于 format 的设置值有:

设置 描述
1 光标资源
2 位图资源
3 图标资源
4 菜单资源
5 对话框
6 字符串资源
7 字体目录资源
8 字体资源
9 加速键表
10 用户定义资源
12 群组光标
14 群组图标


说明

LoadResData 从资源文件装载的数据可以达到 64K。

对位图、图标、光标资源类型使用 LoadResData 将返回包含该资源中的实际二进制位的字符串。如果想使用实际的位图、图标或资源,请使用 LoadResPicture oˉêy.

LoadResData 的使用对于 Visual Basic 应用程序本地化有好处,这是因为需要翻译的资源在一个资源文件中被隔离,并且无须访问源代码或重新编译该应用

89

主题

822

帖子

847

积分

高级会员

Rank: 4

积分
847
发表于 2005-9-19 12:27:00 | 显示全部楼层

Re:请问关于loadimage函数使用资源文件时的使用方法

?
API函数不会用最简单的办法就是查MSDN,上面说的很清楚



LoadImage Function

--------------------------------------------------------------------------------

The LoadImage function loads an icon, cursor, animated cursor, or bitmap.

Syntax

HANDLE LoadImage(          HINSTANCE hinst,
    LPCTSTR lpszName,
    UINT uType,
    int cxDesired,
    int cyDesired,
    UINT fuLoad
);
Parameters

hinst
[in] Handle to an instance of the module that contains the image to be loaded. To load an OEM image, set this parameter to zero.
lpszName
[in]
Specifies the image to load. If the hinst parameter is non-NULL and the fuLoad parameter omits LR_LOADFROMFILE, lpszName specifies the image resource in the hinst module. If the image resource is to be loaded by name, the lpszName parameter is a pointer to a null-terminated string that contains the name of the image resource. If the image resource is to be loaded by ordinal, use the MAKEINTRESOURCE macro to convert the image ordinal into a form that can be passed to the LoadImage function.

If the hinst parameter is NULL and the fuLoad parameter omits the LR_LOADFROMFILE value, the lpszName specifies the OEM image to load. The OEM image identifiers are defined in Winuser.h and have the following prefixes.

OBM_ OEM bitmaps
OIC_ OEM icons
OCR_ OEM cursors

To pass these constants to the LoadImage function, use the MAKEINTRESOURCE macro. For example, to load the OCR_NORMAL cursor, pass MAKEINTRESOURCE(OCR_NORMAL) as the lpszName parameter and NULL as the hinst parameter.

If the fuLoad parameter includes the LR_LOADFROMFILE value, lpszName is the name of the file that contains the image.

uType
[in] Specifies the type of image to be loaded. This parameter can be one of the following values.
IMAGE_BITMAP
Loads a bitmap.
IMAGE_CURSOR
Loads a cursor.
IMAGE_ICON
Loads an icon.
cxDesired
[in] Specifies the width, in pixels, of the icon or cursor. If this parameter is zero and the fuLoad parameter is LR_DEFAULTSIZE, the function uses the SM_CXICON or SM_CXCURSOR system metric value to set the width. If this parameter is zero and LR_DEFAULTSIZE is not used, the function uses the actual resource width.
cyDesired
[in] Specifies the height, in pixels, of the icon or cursor. If this parameter is zero and the fuLoad parameter is LR_DEFAULTSIZE, the function uses the SM_CYICON or SM_CYCURSOR system metric value to set the height. If this parameter is zero and LR_DEFAULTSIZE is not used, the function uses the actual resource height.
fuLoad
[in] This parameter can be one or more of the following values.
LR_DEFAULTCOLOR
The default flag; it does nothing. All it means is "not LR_MONOCHROME".
LR_CREATEDIBSECTION
When the uType parameter specifies IMAGE_BITMAP, causes the function to return a DIB section bitmap rather than a compatible bitmap. This flag is useful for loading a bitmap without mapping it to the colors of the display device.
LR_DEFAULTSIZE
Uses the width or height specified by the system metric values for cursors or icons, if the cxDesired or cyDesired values are set to zero. If this flag is not specified and cxDesired and cyDesired are set to zero, the function uses the actual resource size. If the resource contains multiple images, the function uses the size of the first image.
LR_LOADFROMFILE
Loads the image from the file specified by the lpszName parameter. If this flag is not specified, lpszName is the name of the resource.
LR_LOADMAP3DCOLORS
Searches the color table for the image and replaces the following shades of gray with the corresponding 3-D color: Color Replaced with
Dk Gray, RGB(128,128,128) COLOR_3DSHADOW
Gray, RGB(192,192,192) COLOR_3DFACE
Lt Gray, RGB(223,223,223) COLOR_3DLIGHT
Do not use this option if you are loading a bitmap with a color depth greater than 8bpp.
LR_LOADTRANSPARENT
Retrieves the color value of the first pixel in the image and replaces the corresponding entry in the color table with the default window color (COLOR_WINDOW). All pixels in the image that use that entry become the default window color. This value applies only to images that have corresponding color tables.
Do not use this option if you are loading a bitmap with a color depth greater than 8bpp.

If fuLoad includes both the LR_LOADTRANSPARENT and LR_LOADMAP3DCOLORS values, LRLOADTRANSPARENT takes precedence. However, the color table entry is replaced with COLOR_3DFACE rather than COLOR_WINDOW.

LR_MONOCHROME
Loads the image in black and white.
LR_SHARED
Shares the image handle if the image is loaded multiple times. If LR_SHARED is not set, a second call to LoadImage for the same resource will load the image again and return a different handle.
When you use this flag, the system will destroy the resource when it is no longer needed.

Do not use LR_SHARED for images that have non-standard sizes, that may change after loading, or that are loaded from a file.

When loading a system icon or cursor, you must use LR_SHARED or the function will fail to load the resource.

Windows 95/98/Me: The function finds the first image with the requested resource name in the cache, regardless of the size requested.

LR_VGACOLOR
Uses true VGA colors.
Return Value

If the function succeeds, the return value is the handle of the newly loaded image.

If the function fails, the return value is NULL. To get extended error information, call .




Remarks

When you are finished using a bitmap, cursor, or icon you loaded without specifying the LR_SHARED flag, you can release its associated memory by calling one of the functions in the following table.

Resource Release function
Bitmap DeleteObject
Cursor DestroyCursor
Icon DestroyIcon


The system automatically deletes these resources when the process that created them terminates, however, calling the appropriate function saves memory and decreases the size of the process's working set.

Windows 95/98/Me: LoadImageW is supported by the Microsoft® Layer for Unicode (MSLU). To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.

Example

For an example, see Using Window Classes.

Function Information

Header Declared in Winuser.h, include Windows.h
Import library User32.lib
Minimum operating systems Windows 95, Windows NT 4.0
Unicode Implemented as Unicode and ANSI versions on Windows NT, Windows 2000, Windows XP

1

主题

6

帖子

6

积分

新手上路

Rank: 1

积分
6
 楼主| 发表于 2005-9-20 00:00:00 | 显示全部楼层

Re:请问关于loadimage函数使用资源文件时的使用方法

拜托各位大哥,其实我的疑问是:不用loadrespicture函数而是用loadimage函数可否直接加载资源文件中的位图。小弟英文不大好,看不懂上面的英文说明啊! 拜托各位大哥不要再讲解loadrespicture函数的用法了!可否直接给一个用loadimage加载资源中的位图的例子?

22

主题

209

帖子

229

积分

中级会员

Rank: 3Rank: 3

积分
229
发表于 2005-9-20 10:27:00 | 显示全部楼层

Re:请问关于loadimage函数使用资源文件时的使用方法

PS:VB很少人使用它。。

应该是此 函数 不在 VB 的使用范围内,,,,
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2026-1-23 06:51

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表