选择应用程序图标(80分)

  • 主题发起人 主题发起人 吴向球
  • 开始时间 开始时间

吴向球

Unregistered / Unconfirmed
GUEST, unregistred user!
在windows中,右击应用程序快捷图标,在快捷菜单中选择“更改图标”按钮,就可以选择应用程序的图标,在delphi中怎么样实现?在应用程序中怎么样实现多个图标?请高手回答。
 
那是windows系统干的活啊,要是你自己的程序<br>可以在 Appliciation部分解决
 
在delphi的应用程序中一般情况下只能有一个图标,我怎么样在应用程序加许多图标
 
你要先做好几个图标,可以在程序中修改
 
请问怎么样修改,并使其能的应用程序的快捷方式中改变快捷图标?
 
其实也不用这么麻烦,你直接在菜单project下的resource打开的子窗口中<br>为ICon子项添加图标就可.
 
Fudei,怎么找不到你说的窗口?<br>用Image Editor建立一个资源文件,把图标放在里面,然后在工程文件里用$R编译参数把这个资源文件链接进去即可。
 
我写的一篇小东西,现在贴一下:<br><br>谈资源文件在Delphi中的应用<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 鲸鱼工作室 陈经韬<br>&nbsp; 资源文件一般为扩展名为res的文件。在VC中资源文件用得非常普遍,<br>但Delphi在其联机帮助中对资源文件没作什么介绍,其实利用其自带的<br>资源编译工具BRCC32.EXE(一般位于/Delphi/BIN目录下),我们完全可<br>以做出跟VC一样效果的文件来。//<br>&nbsp; 资源文件最大的好处是能将一些在必要时才调用的文件跟可执行文件一<br>起编译,生成一个文件.这样做最大的好处就是使外部文件免遭破坏.例如<br>在一条程序中你要临时调用一幅图片,一般作法是把图片放在某一路径下<br>(通常是主程序所在路径),但如果用户路径误删你的图片文件,则可能<br>使程序找不到相应文件而出错崩溃。另外,如果你想自己的程序界面美观,<br>想用一些自定义光标,也要用到资源文件。<br>&nbsp; 资源文件的使用步骤为:<br>&nbsp; 1.编写rc脚本文本<br>&nbsp; &nbsp;用记事本或其它文本编辑器编写一个扩展名为rc的文件。例如:<br>&nbsp; &nbsp; &nbsp; &nbsp;mycur &nbsp;cursor &nbsp;move.cur &nbsp;//加入光标<br>&nbsp; &nbsp; &nbsp; &nbsp;mypic &nbsp;Bitmap &nbsp;Water.BMP &nbsp;//加入位图<br>&nbsp; &nbsp; &nbsp; &nbsp;mywav &nbsp;WAVE &nbsp; &nbsp;happy.wav &nbsp;//加入声音<br>&nbsp; &nbsp; &nbsp; &nbsp;myAVI &nbsp;AVI &nbsp; &nbsp; EPOEN.AVI &nbsp;//加入视频<br>&nbsp; &nbsp; &nbsp; &nbsp;myIco &nbsp;ICON &nbsp; &nbsp;CJT.ICO &nbsp; &nbsp;//加入图标<br>&nbsp; &nbsp; &nbsp;格式分别为在资源文件中的名称-&gt;类型-&gt;实际文件名称,例如上面<br>第一行 &nbsp;定义一个名为mycur的光标,实际名称为加入光标move.cur.<br>&nbsp; 2.将rc文件编译成res资源文件<br>&nbsp; &nbsp; &nbsp; &nbsp; 将脚本文件和实际文件拷到Brcc32.EXE所在目录,执行DOS命令。<br>格式为:Brcc32 &nbsp;脚本文件(回车),例如有一名为myfirst.rc的脚本文件,<br>则执行 Brcc32 &nbsp;myfirst.rc(回车)即可。如果你是懒人,也可新建一批<br>处理文件,内容 只有一行:Brcc32 mufist.rc.(因为Delphi安装后一般会<br>在自动批处理文件中指明搜索路径的。)如果编译成功,则会生成一个结尾<br>为res的文件,这个 文件就是我们需要的资源文件。<br>&nbsp; &nbsp;3.在Delphi单元中加入资源文件<br>&nbsp; &nbsp; &nbsp; &nbsp; 将生成的res资源文件拷贝到你所编程序的路径下,在单元文件<br>{$R *DFM}后加上一句{$R mufirst.res},则将res文件加入去,编译后资 <br>源文件即已包含在可执行文件中了。若你有多个资源文件,也按上法依次<br>加入。<br>&nbsp; &nbsp;4.在Delphi程序中调用资源文件<br>&nbsp; &nbsp; &nbsp; &nbsp;资源文件在Delphi中的关键字为hinstance.下面给出具体用法<br>&nbsp; &nbsp; &lt;1&gt;光标的调用<br>&nbsp; &nbsp; &nbsp; &nbsp; 首先在程序中定义一个值大于0的常量,因为Delphi本身用0-负<br>16来索引 默认的光标,所以我们制定的光标应从表面上1开始索引。然后<br>在窗口的Oncreat事件中添加以下代码:<br>&nbsp; &nbsp; &nbsp; &nbsp;screen.cursor[35]:Load cursor (hinstance,'mycur');<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;其中35为大于1的常量,mycur为光标在资源文件中的名字。如<br>果希望在 其他控件上使用定制光标,例如Panel控件,只需在程序的适当<br>处加入以下代码:<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Panel1.cursor:=35;<br>&nbsp; &nbsp; &lt;2&gt;位图的调用<br>&nbsp; &nbsp; &nbsp; &nbsp;新建一项工程,添加一Timage控件,在需要显示的地方写以下代码:<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Var mymap:Hbitmap;<br>&nbsp; &nbsp; &nbsp; &nbsp;begin <br>&nbsp; &nbsp; &nbsp; &nbsp; hmymap:=LoadBitmap(hinstance,'mypic');<br>&nbsp; &nbsp; &nbsp; &nbsp;Image1.picture.Bitmap.Handle:=mymap;<br>&nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp; 其中"mypic"为位图资源文件中的名称。<br>&nbsp; &nbsp;〈3〉AVI文件的调用<br>&nbsp; &nbsp; &nbsp; &nbsp; 新建一工程,添加一Animate控件,在需要的地方加入:<br>&nbsp; &nbsp; &nbsp; &nbsp; animater1.resname:='myAVI';<br>&nbsp; &nbsp; &nbsp; &nbsp; animater1.Active:=true;<br>&nbsp; &nbsp; &nbsp; &nbsp;其中myAVI为视频文件在资源文件中的名称。<br>&nbsp; &nbsp;〈4〉调用WAV文件<br>&nbsp; &nbsp; &nbsp; &nbsp;在uses中加入mmsystm单元,以便在程序中播放WAV文件。播放时Playsound<br>&nbsp; &nbsp; &nbsp; &nbsp;(pchar('mywav'),hinstance,sndsync or snd_resource);其中mywav为声音<br>&nbsp; &nbsp; &nbsp; &nbsp;文件在资源中的名称。<br>&nbsp; &nbsp;〈5〉加入光标<br>&nbsp; &nbsp; &nbsp; &nbsp;加入光标比较容易,只要将res文件加入单元文件中即可。但需注意,名称<br>&nbsp; &nbsp; &nbsp; &nbsp;最好取"W"."WW"等,使第一个字母尽量靠后,以免与主程序的图标顺序颠倒。<br>&nbsp; &nbsp; &nbsp; 补充:1.资源类型除上述类型外,还可以字体文件,字符串文件等。<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2.资源文件不但可以在标准图形界面下使用还可在控制台下使用。<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 下面我们来试验一下:<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 新建一工程,将唯一的一个Form删除,然后修改工程文件。增加一句<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {$Apptype console},在uses子句中加入mmsystem,并将其它引用单元<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 删掉。将Begin和end之间语句删掉。至此,我们就可和Turbo PASCAL<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 下编程序一样,且还可以调用windows的API和资源。将资源文件----<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {$R myfist.res}加入。在Begin和end之间写下:<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; writeln('演示程序,按任意键开始!');<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; readln;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; playsound(pchar('mywav'),hinstance,snd_sync or snd_resource);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; writeln('演示结束!');<br>&nbsp; &nbsp; &nbsp; 运行程序,将弹出一个标准DOS窗口,按任意键播放声音文件。是不是很COOL呢!<br>&nbsp; &nbsp; &nbsp; 我曾下载过一个播放器,在其安装目录下我发现有一"DOS程序",用鼠标双击它<br>&nbsp; &nbsp; &nbsp; 便弹出一个DOS窗口,显示DOS时代特有的画图,并有背景音乐!可能就是用这个<br>&nbsp; &nbsp; &nbsp; 方法做的。<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;3.Delphi本身自带了一个叫Image Editor的工具,同样可以编辑资源文<br>&nbsp; &nbsp; &nbsp; 本,但和本文的方法比较,可得出下表:<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;**************************************<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Image Editor &nbsp; &nbsp; &nbsp; &nbsp; Brcc32<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BMP &nbsp; 只支持16位色 &nbsp; &nbsp; &nbsp; &nbsp;任意色<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 光标 &nbsp; 黑白两色 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;任意色<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ICO &nbsp; &nbsp;只支持16位色 &nbsp; &nbsp; &nbsp; &nbsp;任意色<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AVI &nbsp; &nbsp;不支持 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;支持<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WAV &nbsp; &nbsp;不支持 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;支持<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;字体 <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;字符串 &nbsp; &nbsp;不支持 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;支持<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;其他 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; ****************************************<br>★软件作者:<br><br>&nbsp; &nbsp; 陈经韬<br>&nbsp; &nbsp;<br>&nbsp; &nbsp; 430074湖北省武汉市武昌民院路湖北经济管理大学计算机系(本)9803班 &nbsp;<br>&nbsp; &nbsp; E-Mail: lovejingtao@21.cn.com<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jingtao@990.net<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
 
如果运行的时候想改本程序的什么信息,可以用<br>SetClassLong。<br>如果想改变连接的图标、名称等信息,可以用IShellLink接口搞定,如:<br><br>const<br>&nbsp; IID_IPersistFile: TGUID = (<br>&nbsp; &nbsp; D1:$0000010B;D2:$0000;D3:$0000;D4:($C0,$00,$00,$00,$00,$00,$00,$46));<br>&nbsp; ObjectLinked = 'D:/TEMP/TEST.OBJ';<br>&nbsp; ObjectLink = 'D:/TEMP/TEST.OBJ.LNK';<br>&nbsp; IconLibrary = 'C:/WINNT/SYSTEM32/SHELL32.DLL';<br>&nbsp; IconIndex = 1;<br><br>implementation<br><br>uses ShlObj, ActiveX;<br><br>{$R *.DFM}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; ShellLink: IShellLink;<br>&nbsp; PersistFile: IPersistFile;<br>begin<br>&nbsp; CoInitialize (nil);<br>&nbsp; CoCreateInstance (CLSID_ShellLink,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nil,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CLSCTX_INPROC_SERVER,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IID_IShellLinkA,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ShellLink);<br>&nbsp; ShellLink.SetPath (ObjectLinked);<br>&nbsp; ShellLink.SetIconLocation (IconLibrary, IconIndex);<br>&nbsp; ShellLink.QueryInterface (IID_IPersistFile, PersistFile);<br>&nbsp; PersistFile.Save (ObjectLink, TRUE);<br>&nbsp; CoFreeUnusedLibraries;<br>&nbsp; CoUninitialize;<br>
 
多人接受答案了。
 
后退
顶部