简体   繁体   English

如何在ANSI C中创建窗口应用程序?

[英]How to make window application in ANSI C?

Until now I've been only writing console applications but I need to write a simple window application for a school assignment. 到目前为止,我一直只编写控制台应用程序,但我需要为学校作业编写一个简单的窗口应用程序。

Could somebody point me to a good tutorial how to create windows and other ordinary windows elements such as buttons, 2d graphs etc in ANSI C? 有人可以指点我一个很好的教程如何在ANSI C中创建窗口和其他普通的窗口元素,如按钮,2d图形等? is there some good library I should use? 我应该使用一些好的库吗?

I tried googling but there are no tutorial websites devoted to C. 我尝试使用Google搜索,但没有专门针对C的教程网站。

If you can, I would also appreciate some example code. 如果可以的话,我也会感谢一些示例代码。

Thank you. 谢谢。

By the way, I use Dec C++. 顺便说一句,我使用Dec C ++。

GTK is a good library to use, but may provide non-native looks under Windows. GTK是一个很好的库,但可以在Windows下提供非本机外观。 It looks great under GNU/Linux, especially using GNOME. 它在GNU / Linux下看起来很棒,尤其是使用GNOME。

It is implemented in just C (Using the GObject Type System, part of the GLib library), so it will work great for your needs. 它仅在C(使用GObject类型系统,GLib库的一部分)中实现,因此它将非常适合您的需求。 There is also a RAD tool called Glade. 还有一个名为Glade的RAD工具。

There's nothing in the ANSI C standard about windows. 关于Windows,ANSI C标准中没有任何内容。 If you want to make a windowed application, you'll have to use platform-specific libraries (eg Win32 , Cocoa , or X11 ), or some sort of cross-platform library that encapsulates that (eg SDL , wxWidgets , or many more). 如果你想创建一个窗口化的应用程序,你将不得不使用特定于平台的库(例如Win32CocoaX11 ),或者某种封装它的跨平台库(例如SDLwxWidgets或更多) 。

http://support.microsoft.com/kb/829488 which also talks how to create http://support.microsoft.com/kb/829488也讨论了如何创建

Windows application: Creates a simple Microsoft Windows-based application. Windows应用程序:创建一个简单的基于Microsoft Windows的应用程序。 The application files include a ProjectName.cpp file that contains a _tWinMain function. 应用程序文件包含一个包含_tWinMain函数的ProjectName.cpp文件。 You can use this type of application to perform graphical user interface (GUI) based programming. 您可以使用此类应用程序来执行基于图形用户界面(GUI)的编程。

As for tutorials... use MSDN. 至于教程...使用MSDN。 Win32 API is C. You don't need "Win32 ANSI C tutorial" - you need Win32 tutorial (for example http://www.winprog.org/tutorial/start.html , http://www.functionx.com/win32/Lesson01.htm ) - unless, of course, you don't know ANSI C but then you just look for ANSI C tutorial. Win32 API C.你并不需要“的Win32 ANSI C教程” -你需要的Win32教程(例如http://www.winprog.org/tutorial/start.htmlhttp://www.functionx.com/ win32 / Lesson01.htm ) - 当然,除非您不了解ANSI C,否则您只需要查找ANSI C教程。 These subjects are independent. 这些科目是独立的。

Common places to start are Charles Petzold's Programming Windows and theForger's Win32 API Programming Tutorial . 常见的起点是Charles Petzold的Programming WindowstheForger的Win32 API编程教程

However in most cases C is no longer the preferred language for Windows development. 但是在大多数情况下,C不再是Windows开发的首选语言。 Object oriented technology is far better suited to GUI development, and with the introduction of MFC, C++ became the preferred language, and later with .Net, C# and C++/CLI. 面向对象技术更适合GUI开发,随着MFC的引入,C ++成为首选语言,后来成为.Net,C#和C ++ / CLI。

The Win32 API can be hard work, much of MFC is little better than a Win32 API wrapper, the .Net framework however was designed from the ground up, and is less encumbered by the legacy of the Win32 API monster, and working with it tends to result in far greater productivity. Win32 API可能很难工作,MFC的大部分都比Win32 API包装好一点,然而.Net框架是从头开始设计的,并且不受Win32 API怪物遗留的影响,并且使用它往往以提高生产力。

Either way, Dev-C++ is not a great tool for GUI development. 无论哪种方式,Dev-C ++都不是GUI开发的好工具。

There are lots of good libraries—too many for there to be an obvious choice without starting a religious war. 有许多好的图书馆 - 在没有开始宗教战争的情况下有太多明显的选择。 I recommend that for your first library you learn something that will work on Windows, Linux, or OSX. 我建议您在第一个库中学习一些适用于Windows,Linux或OSX的内容。 Here are two good choices, not necessarily the best, but widely used and personal favorites: 这里有两个不错的选择,不一定是最好的,但广泛使用和个人的最爱:

  • Tcl/Tk . Tcl / Tk You write most of your application in the Tcl scripting language, but you can easily integrate your own ANSI C code into Tcl, which was designed from the beginning with such integration in mind. 您可以使用Tcl脚本语言编写大部分应用程序,但是您可以轻松地将自己的ANSI C代码集成到Tcl中,Tcl从一开始就考虑到了这种集成。 The Tk toolkit is very easy to learn, and you can write many simple GUIs in pure Tcl when you are getting started. Tk工具包非常容易学习,您可以在开始时使用纯Tcl编写许多简单的GUI。 Interactive, easy, and very well supported. 互动,简单,并得到很好的支持。

  • If you want to write everything in ANSI C, I don't know of any really simple choices, but I've been fairly happy with wxwidgets . 如果你想用ANSI C编写所有内容,我不知道任何非常简单的选择,但我对wxwidgets非常满意。 All these tools have a pretty steep learning curve, however. 然而,所有这些工具都有相当陡峭的学习曲线。

There are not many plain C GUI libraries as the strengths of the language lie elsewhere. 由于该语言的优势在于其他地方,因此没有多少普通的C GUI库。 Perhaps you should think about using a language with C bindings so you can still do the number crunching in C, but use something less painful for GUI development? 也许您应该考虑使用带有C绑定的语言,这样您仍然可以在C中进行数字运算,但是使用不那么痛苦的GUI开发?

If you really want to stick to C, you can either use the OS' native API or the only current cross-platform C GUI lib I'm aware of: GTK+. 如果您真的想要坚持使用C,您可以使用操作系统的本机API或我所知道的唯一当前的跨平台C GUI库:GTK +。 If you don't really need a GUI but just graphical output, I'd go with SDL. 如果你真的不需要GUI而只需要图形输出,我会选择SDL。

我建议你下载Microsoft Visual Studio 2008 Express Edition并使用C#.Net。

As has been said, I suggest you use Winforms and switch to a .Net environment. 如前所述,我建议您使用Winforms并切换到.Net环境。 It's 2009, and I think there are more suitable solutions to GUI's :P 这是2009年,我认为有更合适的GUI解决方案:P

Edit: Nvm, didn't see it was a school assignment. 编辑:Nvm,没看到这是一个学校作业。

However, here is a C++ guide on the Win32 API: http://www.relisoft.com/win32/index.htm 但是,这是Win32 API上的C ++指南: http//www.relisoft.com/win32/index.htm

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM