在 Windows 上编写轻量级 GUI 程序的最快路径是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/272764/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the quickest path to writing a lightweight GUI program on Windows?
提问by Adrian Dunston
I want a small (< 30MB) standalone Windows executable (a single file) that creates a window which asks the user for the location of a directory and then launches a different program in that directory.
我想要一个小的(< 30MB)独立的 Windows 可执行文件(单个文件),它创建一个窗口,询问用户目录的位置,然后在该目录中启动不同的程序。
This executable has to run on XP, Vista, Server 2003, and Server 2008 versions of Windows in 32-bits and 64 bits on x86-64 architecture as well as Itanium chips.
此可执行文件必须在 x86-64 架构以及安腾芯片上的 XP、Vista、Server 2003 和 Server 2008 版本的 Windows 上以 32 位和 64 位运行。
It would be spectacular if we only had to build it once in order to run it on all these platforms, but that is not a requirement. This is for a proprietary system, so GPL code is off-limits.
如果我们只需要构建一次就可以在所有这些平台上运行它,那就太棒了,但这不是必需的。这是针对专有系统的,因此 GPL 代码是禁止的。
What is the fastest way to put this together?
将它们放在一起的最快方法是什么?
These are some things I'm looking into, so if you have info about their viability, I'm all about it:
这些是我正在研究的一些事情,所以如果你有关于它们可行性的信息,我就是这样:
- Perl/Tk using perl2exe to get the binary.
- Ruby with wxruby
- Learn MFC programming and do it the right way like everybody else.
- Perl/Tk 使用 perl2exe 来获取二进制文件。
- 红宝石与 wxruby
- 学习 MFC 编程并像其他人一样以正确的方式进行编程。
回答by Vinko Vrsalovic
What about a WSH script? It won't be an exe, right, but to ask for a folder I don't see the need for an exe file, much less a 30Mb one...
WSH 脚本怎么样?它不会是 exe,对,但是要请求一个文件夹,我认为不需要 exe 文件,更不用说 30Mb 的了...
A 1Kb script, save it as whatever name you like with vbs extension and run it. This, in case it's not clear, asks you for a folder name and then runs calc.exe from the system32 subdirectory. You can of course do a lot better than this in 2 or 4 Kb.
一个 1Kb 的脚本,使用 vbs 扩展名将其保存为您喜欢的任何名称并运行它。如果不清楚,它会询问您的文件夹名称,然后从 system32 子目录运行 calc.exe。您当然可以在 2 或 4 Kb 中做得比这更好。
Set WshShell = WScript.CreateObject("WScript.Shell")
win = InputBox("Please type your Windows folder location.")
If Right(win,1) <> "\" Then
win = win & "\"
End If
WshShell.Run win & "system32\calc.exe"
To add a Folder Browser dialog instead of an InputBox, check thisout.
要添加文件夹浏览器对话框而不是输入框,请查看此内容。
Clear benefits are:
明显的好处是:
- Simplicity (well, VB is ugly, but you can use JScript if you prefer), no need to compile it!
- Compatibility, works on every windows machine I have available (from 98 onwards)
- 简单(好吧,VB 很丑,但如果您愿意,可以使用 JScript),无需编译!
- 兼容性,适用于我可用的每台 Windows 机器(从 98 开始)
回答by utku_karatas
Quickest way on Windows for a lightweight and fast GUI? One word.. Delphi!It lacks the 64 bit support for now but then FreePascalwould come to the rescue.
在 Windows 上获得轻量级和快速 GUI 的最快方法?一个字..德尔福!它目前缺乏 64 位支持,但随后FreePascal会来救援。
回答by user3891
I'd use .NET and WinForms. The idea of scripted solution is appealing, but in practice I often find you end up jumping through hoops to do anything beyond the basic case and still don't have the flexibility to do everything you want.
我会使用 .NET 和 WinForms。脚本化解决方案的想法很吸引人,但在实践中,我经常发现您最终会在基本案例之外做任何事情,但仍然无法灵活地做您想做的所有事情。
回答by DavidK
Having a small stand-alone application and developing it quickly are, I'm sorry to say, usually conflicting requirements.
很抱歉,拥有一个小的独立应用程序并快速开发它通常是相互冲突的需求。
To be honest, given how incredibly simple the application is, I would write it in C with direct Win32 calls: one call to SHBrowseForFolder() to get the directory, and one to ShellExecuteEx() to run the program. Even MFC is far too heavy-weight for such a modest application. Set the C runtime to be statically linked and you should be able to keep the size of the stand-alone executable to less than 100k. A decent Windows C coder should be able to knock that up in less than an hour, assuming you have one to hand.
老实说,考虑到应用程序非常简单,我会用 C 语言编写它并直接调用 Win32:一次调用 SHBrowseForFolder() 以获取目录,一次调用 ShellExecuteEx() 以运行程序。对于这样一个普通的应用程序,即使是 MFC 也太重了。将 C 运行时设置为静态链接,您应该能够将独立可执行文件的大小保持在 100k 以下。一个体面的 Windows C 编码器应该能够在不到一个小时的时间内完成,假设你有一个。
回答by Electrons_Ahoy
回答by Bryan Oakley
Tcl/tk is one solution. You can have a single file executable (including custom images, dlls, etc) using something called a "starpack" -- a virtual filesystem that is both tcl interpreter and application code. I think it would weigh in at maybe a couple megabytes.
Tcl/tk 是一种解决方案。您可以使用称为“starpack”的东西(一种既是 tcl 解释器又是应用程序代码的虚拟文件系统)拥有单个文件可执行文件(包括自定义图像、dll 等)。我认为它的重量可能只有几兆字节。
From your specifications it would take me personally maybe 15 minutes to get a first working version.
根据您的规格,我个人可能需要 15 分钟才能获得第一个工作版本。
Tcl/Tk has a BSD license.
Tcl/Tk 拥有 BSD 许可证。
回答by Dexygen
I agree with the Tcl/Tk answer above. For more information about the starpack that he refers to, see: http://www.equi4.com/tclkit/it's a Tcl/Tk interpreter available for various OS's all in about 1MB. In the past there apparently has been concerned about the look and feel of Tcl/Tk UI's, but this has been addressed by a new framework named "Tile" that supports the native look and feel of the user's OS.
我同意上面的 Tcl/Tk 答案。有关他所指的 starpack 的更多信息,请参见:http: //www.equi4.com/tclkit/它是一个 Tcl/Tk 解释器,可用于各种操作系统,大小约为 1MB。过去,人们显然一直在关注 Tcl/Tk UI 的外观和感觉,但这一问题已通过名为“Tile”的新框架解决,该框架支持用户操作系统的本机外观和感觉。
回答by Matt Dillard
For all of its flaws, Visual Basic has historically been great for super-simple apps like this.
尽管存在所有缺陷,Visual Basic 历来非常适合此类超级简单的应用程序。
回答by PabloG
For a quick and dirty GUI program like you said, you can use an AutoItscript. You can even compile to an exe.
对于像您说的那样快速而肮脏的 GUI 程序,您可以使用 AutoIt脚本。您甚至可以编译为 exe。
For an GUI example of AutoIt, you can check my stdout redirect script in a previous answer here
对于 AutoIt 的 GUI 示例,您可以在此处的先前答案中查看我的 stdout 重定向脚本
回答by Douglas Mayle
You could do this in MFC and have an executable in under 100k. In general, if you want to keep the size of your executables down, you can use UPX to perform exe compression. If you want an example, take a look at uTorrent. It's a full featured BitTorrent app in less than 300k of executable.
您可以在 MFC 中执行此操作,并在 100k 以下拥有一个可执行文件。一般来说,如果您想减小可执行文件的大小,可以使用 UPX 来执行 exe 压缩。如果你想要一个例子,看看uTorrent。这是一个功能齐全的 BitTorrent 应用程序,可执行文件少于 300k。