‘试图引用不存在的令牌’什么意思?(100分)

  • 主题发起人 主题发起人 shangshang
  • 开始时间 开始时间
S

shangshang

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.Button2Click(Sender: TObject);<br>var<br>&nbsp; IconIndex : word;<br>&nbsp; h : hIcon;<br>begin<br>&nbsp; IconIndex := 1;<br>&nbsp; h :=ExtractAssociatedIcon(application.handle,pchar('c:/test.bmp'),IconINdex);<br>&nbsp; if h=0 then &nbsp;RaiseLastWin32Error;<br>&nbsp; DrawIcon(image1.Canvas.Handle,10,10,h);<br>end;<br><br>我想这样获取文档的关联图标,但老是h=0,提示试图引用不存在的令牌。<br>大家一运行就能看到了。<br>ExtractAssociatedIcon到底该怎么用啊?<br>我的环境win2000,d5.
 
很显然,你的ExtractAssociatedIcon函数出了错,没有打开你要打开的文件。我也遇到过这种提示<br>一般都是没有打开想要打开的文件或者打开的文件和需要的数据不匹配。具体用法等我看看。
 
var<br>&nbsp; IconIndex : word;<br>&nbsp; h : hIcon;<br>begin<br>&nbsp; IconIndex := 1;<br>&nbsp; if opendialog1.Execute then<br>&nbsp; begin<br>&nbsp; h :=ExtractAssociatedIcon(application.handle,pchar(opendialog1.FileName),IconINdex);<br>&nbsp; if h=0 then &nbsp;RaiseLastWin32Error;<br>&nbsp; DrawIcon(image1.Canvas.Handle,10,10,h);<br>&nbsp; end;<br>end;<br>如果用来打开icon的话,程序没有问题,bmp就会出错。你再看看是不是。我加了个opendialog
 
我是想让它取得任意文档关联的系统中的图标啊。<br>我以为这个函数可以,可就是试不出来。<br>我可以用别的方法达到目的,但我想知道这样为什么不行。<br>
 
兄弟,我劝你看看help上面是怎么写的,好像只能打开icon啊
 
eflyer老兄,我非常讶异的告诉你一个好消息,这段代码我刚刚试了。<br>发现可以正常运行了,什么都没有改,就把你的代码拷下来。然后就不抱错了。<br>正确的把我所选的文件的关联图标给画了出来。真是莫名奇妙。<br>以前我千方百计的试验,总是报这个错误,现在却一点不错了。奇怪!<br>我把帖子结了吧。免的占地方。<br>见到的高手,如果谁能告诉我一些相关的东西,我可以另给分的。<br>谢谢eflyer老兄的热心。
 
我查了一下msdn ,有好多的函数可以用比如你可以用ExtractIcon函数阿<br>Icon Functions<br>The following functions are used with icons. <br><br>Function Description <br>CopyIcon Copies an icon from another module. <br>CreateIcon Creates an icon with a specified size, color, and bit pattern. <br>CreateIconFromResource Creates an icon or cursor from resource bits. <br>CreateIconFromResourceEx Creates an icon or cursor from resource bits. <br>CreateIconIndirect Creates an icon or cursor from an ICONINFO structure. <br>DestroyIcon Destroys an icon. &nbsp;<br>DrawIcon Draws an icon. <br>DrawIconEx Draws an icon or cursor, performing raster operations, and stretching or compressing the icon or cursor. <br>DuplicateIcon Creates a duplicate of a specified icon. <br>ExtractAssociatedIcon Gets a handle to an indexed icon in a file or an icon found in an executable file. <br>ExtractIcon Gets a handle to an icon from an executable file, dynamic-link library (DLL), or icon file. <br>ExtractIconEx Gets an array of handles to large or small icons extracted from an executable file, dynamic-link library (DLL), or icon file. <br>GetIconInfo Gets information about an icon or cursor. <br>LoadIcon Loads an icon from the executable file associated with an application. <br>LookupIconIdFromDirectory Searches for an icon or cursor that best fits the current display device. <br>LookupIconIdFromDirectoryEx Searches for an icon or cursor that best fits the current display device. <br>
 
后退
顶部