找回密码
 注册
Simdroid-非首页
查看: 772|回复: 6

〔新年礼物〕在用mcc编译exe时,指定icon

[复制链接]
发表于 2006-2-12 17:06:23 | 显示全部楼层 |阅读模式 来自 新加坡
论坛上不时有人问起如何修改mcc产生的exe文件的光标。缺省情况下,mcc产生的exe并不包含任何资源信息(Resource),在Windows Explorer里看起来,该exe的光标就像是个普通的命令行程序。

首先想到的一个方法就是利用工具软件比如ResourceHacker来修改光标,但是在缺省情况下,mcc产生的exe文件并不包含任何资源信息。所以这条路行不通。

后来有想到那么就给该exe加一个任意一个资源文件,然后再使用ResourceHacker修改,实践证明这样是可行的。具体作起来需要:1. 修改相应的compopts.bat文件,在连接器linker的命令行后面加上我们将要使用的res文件名。你可以从任何VC工程获得一个res用到这里。2.然后照样用mcc命令编译。结果,产生的exe已经有资源了,虽然这时光标不是我们想要的,但我们已经可以用ResourceHacker等来修改光标了。这个方法虽然看起来解决了问题,可惜不完美,而且第一次由mcc产生的exe的光标无法定制。我最开始的时候想到的是这个方法,但迟迟没有贴出来,主要是因为我想找到更好的方法后再和大家分享。

过年期间抽空重新思考了一下,找到了更为简单和完善的方法。不用修改compopts.bat,而且可以在执行mcc命令时指定所用的光标文件。具体方法如下:
第一步:首先创建一个简单资源源文件(rc文件),这是一个文本文件,在其中加上如下一行:
  1. appicon ICON "myicon.ico"
复制代码
其中myicon.ico则是需要使用的光标文件。

第二步:在mcc的命令行加上刚刚创建的rc文件。比如刚才产生的rc文件取名为myapp.rc,我们需要编译的matlab应用程序是myapp01.m,那么可以用如下命令编译:
  1. mcc -m myapp01.m myapp.rc
复制代码
哇!结果你将会发现,产生的myapp01.exe在Windows Explorer中的光标就是我们指定的。

好了,利用这个方法,以及令外一些在matlab程序中改变Figure窗口图标的方法,我们完全可以实现对编译后的exe文件光标的完全定制。(关于修改Figure窗口的光标的方法,在论坛上和拙作《深入浅出matlab7.x混合编程》中都有提到)

顺祝大家新年好!

评分

1

查看全部评分

发表于 2006-2-21 17:38:25 | 显示全部楼层 来自 陕西西安

Re:〔新年礼物〕在用mcc编译exe时,指定icon

Simdroid开发平台
强烈支持!
发表于 2007-6-26 09:49:58 | 显示全部楼层 来自 北京
写的真好,谢谢!
回复 不支持

使用道具 举报

发表于 2009-1-6 10:30:20 | 显示全部楼层 来自 北京
谢谢!!学习了:handshake

评分

1

查看全部评分

回复 不支持

使用道具 举报

发表于 2009-1-6 22:33:10 | 显示全部楼层 来自 上海
这个方法不错,很简单。
以前都是采用一个有图标的exe文件,来引导这个黑窗口文件。
多谢多谢!
回复 不支持

使用道具 举报

发表于 2009-1-8 15:20:24 | 显示全部楼层 来自 河南新乡

可以借助nsis

http://www.chinavib.com/forum/thread-5382-1-1.html
1. Compile your GUI into an exe. We'll call it "foo.exe".
2. Download and install NSIS - the installation program created and
used by the fine folks at Nullsoft (think Winamp):

http://www.nullsoft.com/free/nsis/

3. Make an NSIS script text file in the same directory as your exe,
let's call it "file.nsi". Put the following text in there:

SilentInstall silent

; The name of the NSIS install program you're creating
Name "NotSeen"

; The file that NSIS writes
OutFile "nocmdwindow.exe"

Section "Ignore"
; Change this exe file to the name of the exe you created
nsExec::Exec "cmd /C foo.exe"
SectionEnd

4. Save the file and compile it into the new exe ("nocmdwindow.exe")
by right clicking on it and selecting Compile. Or you can open the
"Make NSIS GUI" window and select "Load Script..." from the File menu.

5. Now run "nocmdwindow.exe". As promised, no command window. And
so simple to implement. Plus, if you ever want to see the command
window for diagnostic purposes, you can always run the original exe
file ("foo.exe"), and it will run normally with its glorious DOS
window.

You also have a really easy to use and powerful Windows installer
program that's free. The no command window trick works with NSIS by
calling a dll (nsExec.dll) and running the program through it,
suppressing all text output, but leaving popup windows alone.

评分

1

查看全部评分

回复 不支持

使用道具 举报

发表于 2011-12-28 21:27:44 | 显示全部楼层 来自 北京
注册论坛来就是为了来读taohe老师的帖子,谢谢分享。

评分

1

查看全部评分

回复 不支持

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|小黑屋|联系我们|仿真互动网 ( 京ICP备15048925号-7 )

GMT+8, 2024-5-8 17:32 , Processed in 0.066679 second(s), 21 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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