I want to do Graphics programming in C. I had searched a lot about the compiler that provides a rich set of functions for doing GUI programming in C, but I couldn't find anything.
我想在C语言中进行图形编程,我搜索了很多关于编译器的信息,这些编译器为在C语言中进行GUI编程提供了丰富的函数集,但是我什么都没找到。
Basically I want to draw buttons and then accept the choice from the user and take an appropriate action. It would be helpful if you can suggest a C compiler, or a library that I can add to my compiler. I am working on the Windows operating system.
基本上,我想要绘制按钮,然后接受用户的选择并采取适当的操作。如果您能推荐一个C编译器,或者一个我可以添加到我的编译器的库,那将会很有帮助。我正在开发Windows操作系统。
Presently, I am using TURBO C compiler that does not support direct methods for creating buttons. Any help would be appreciated.
目前,我使用的是TURBO C编译器,它不支持创建按钮的直接方法。如有任何帮助,我们将不胜感激。
6 个解决方案
#1
96
This is guaranteed to have nothing to do with the compiler. All compilers do is compile the code that they are given. What you're looking for is a GUI library, which you can write code against using any compiler that you want.
这保证与编译器无关。所有编译器所做的就是编译它们所给出的代码。您正在寻找的是一个GUI库,您可以使用任何您想要的编译器来编写代码。
Of course, that being said, your first order of business should be to ditch Turbo C. That compiler is about 20 years old and continuing to use it isn't doing you any favors. You can't write modern GUI applications, as it will only produce 16-bit code. All modern operating systems are 32-bit, and many are now 64-bit. It's also worth noting that 64-bit editions of Windows will not run 16-bit applications natively. You'll need an emulator for that; it's not really going to engender much feeling of accomplishment if you can only write apps that work in a DOS emulator. :-)
当然,也就是说,你的第一笔生意应该是抛弃Turbo C.那个编译器大约有20年的历史,而且它还在继续使用,这对你没有任何好处。您不能编写现代GUI应用程序,因为它只生成16位代码。所有现代操作系统都是32位的,而且很多现在都是64位的。同样值得注意的是,64位Windows版本本身不会运行16位的应用程序。你需要一个模拟器;如果你只能编写在DOS模拟器中工作的应用程序,那就不会有什么成就感。:-)
Microsoft's Visual Studio Express C++ is available as a free download. It includes the same compiler available in the full version of the suite. The C++ package also compiles pure C code.
微软的Visual Studio Express c++可以免费下载。它包括完整版本的套件中可用的相同编译器。c++包也编译纯C代码。
And since you're working in Windows, the Windows API is a natural choice. It allows you to write native Windows applications that have access to the full set of GUI controls. You'll find a nice tutorial here on writing WinAPI applications in C. If you choose to go with Visual Studio, it also includes boilerplate code for a blank WinAPI application that will get you up and running quickly.
由于您在Windows中工作,所以Windows API是一个自然的选择。它允许您编写具有访问完整GUI控件集的本地Windows应用程序。如果您选择使用Visual Studio,您将在这里找到一个关于在c中编写WinAPI应用程序的很好的教程,它还包含一个空白WinAPI应用程序的样板代码,它将使您能够快速启动并运行。
If you really care about learning to do this, Charles Petzold's Programming Windows is the canonical resource of the subject, and definitely worth a read. The entire Windows API was written in C, and it's entirely possible to write full-featured Windows applications in C. You don't need no stinkin' C++.
如果你真的很关心如何学习,Charles Petzold的编程窗口是这个主题的权威资源,绝对值得一读。整个Windows API都是用C编写的,用C编写功能齐全的Windows应用程序是完全可能的。
That's the way I'd do it, at least. As the other answers suggest, GTK is also an option. But the applications it generates are just downright horrible-looking on Windows.
至少我是这么做的。正如其他答案所表明的,GTK也是一个选项。但它所产生的应用程序只是在Windows上看起来非常可怕。
EDIT: Oh dear... It looks like you're not alone in wanting to write "GUI" applications using an antiquated compiler. A Google search turns up the following library: TurboGUI: A GUI Framework for Turbo C/C++:
编辑:哦亲爱的……您似乎并不是唯一希望使用过时的编译器编写“GUI”应用程序的人。谷歌搜索出现了以下库:TurboGUI: Turbo C/ c++的GUI框架:
If you're another one of those poor people stuck in the hopelessly out-of-date Indian school system and forced to use Turbo C to complete your education, this might be an option. I'm loathe to recommend it, as learning to work around its limitations will be completely useless to you once you graduate, but apparently it's out there for you if you're interested.
如果你是另一个被困在落后的印度学校系统里,*使用涡轮C来完成你的教育的穷人,这可能是一个选择。我不愿意推荐它,因为一旦你毕业了,学习它的局限性对你来说是完全没用的,但如果你感兴趣的话,很显然它就在你的身边。
#2
13
The most famous library to create some GUI in C language is certainly GTK.
用C语言创建GUI的最有名的库当然是GTK。
With this library you can easily create some buttons (for your example). When a user clicks on the button, a signal is emitted and you can write a handler to do some actions.
使用这个库,您可以轻松地创建一些按钮(例如您的示例)。当用户单击按钮时,会发出一个信号,您可以编写一个处理程序来执行一些操作。
#3
8
Use win APIs in your main function:
在你的主要功能中使用win api:
- RegisterClassEx() note: you have to provide a pointer to a function (usually called WndProc) which handles windows messages such as WM_CREATE, WM_COMMAND etc
- 请注意:您必须提供一个指向函数(通常称为WndProc)的指针,该函数处理windows消息,如WM_CREATE、WM_COMMAND等
- CreateWindowEx()
- CreateWindowEx()
- ShowWindow()
- 显示窗口()
- UpdateWindow()
- UpdateWindow()
Then write another function which handles win's messages (mentioned in #1). When you receive the message WM_CREATE you have to call CreateWindow(). The class is what control is that window, for example "edit" is a text box and "button" is a.. button :). You have to specify an ID for each control (of your choice but unique among all). CreateWindow() returns a handle to that control, which needs to be memorized. When the user clicks on a control you receive the WM_COMMAND message with the ID of that control. Here you can handle that event. You might find useful SetWindowText() and GetWindowText() which allows you to set/get the text of any control.
You will need only the win32 SDK. You can get it here.
然后编写另一个函数来处理win的消息(在#1中提到)。当您收到消息WM_CREATE时,您必须调用CreateWindow()。类是那个窗口的控件,例如“编辑”是一个文本框,“按钮”是一个。按钮:)。您必须为每个控件指定一个ID(在所有选项中都是惟一的)。CreateWindow()返回需要记住的控件的句柄。当用户单击控件时,您将收到带有该控件ID的WM_COMMAND消息。这里你可以处理那个事件。您可能会发现有用的SetWindowText()和GetWindowText(),它允许您设置/获取任何控件的文本。您只需要win32 SDK。你可以在这里。
#4
5
C is more of a hardware programming language, there are easy GUI builders for C, GTK, Glade, etc. The problem is making a program in C that is the easy part, making a GUI that is a easy part, the hard part is to combine both, to interface between your program and the GUI is a headache, and different GUI use different ways, some threw global variables, some use slots. It would be nice to have a GUI builder that would bind easily your C program variables, and outputs. CLI programming is easy when you overcome memory allocation and pointers, GUI you can use a IDE that uses drag and drop. But all around I think it could be simpler.
C是更多的硬件编程语言,C,有简单的GUI建筑商GTK,空地,等等。问题是在C程序是比较容易的部分,使GUI是容易的部分,难的是将两者结合起来,之间的接口程序GUI是头痛,和不同的GUI使用不同的方法,一些全局变量,使用槽。如果有一个能很容易绑定C程序变量和输出的GUI构建器,那就太好了。当您克服内存分配和指针时,CLI编程很容易,您可以使用使用拖放的IDE GUI。但我认为它可以更简单。
#5
2
Windows API and Windows SDK if you want to build everything yourself (or) Windows API and Visual C Express. Get the 2008 edition. This is a full blown IDE and a remarkable piece of software by Microsoft for Windows development.
Windows API和Windows SDK如果你想自己构建所有东西(或)Windows API和Visual C Express。2008年版。这是微软为Windows开发设计的一个完整的IDE和一个出色的软件。
All operating systems are written in C. So, any application, console/GUI you write in C is the standard way of writing for the operating system.
所有操作系统都是用C编写的,因此,任何用C编写的应用程序、控制台/GUI都是操作系统的标准编写方式。
#6
1
A C compiler itself won't provide you with GUI functionality, but there are plenty of libraries for that sort of thing. The most popular is probably GTK+, but it may be a little too complicated if you are just starting out and want to quickly get a GUI up and running.
C编译器本身不会为您提供GUI功能,但是有很多库可以实现这类功能。最流行的可能是GTK+,但是如果您刚刚开始,并且希望快速地启动并运行GUI,那么它可能有点太复杂了。
For something a little simpler, I would recommend IUP. With it, you can use a simple GUI definition language called LED to layout controls (but you can do it with pure C, if you want to).
对于简单一点的东西,我推荐IUP。有了它,您可以使用一种简单的GUI定义语言,名为LED to layout控件(但是如果您愿意,可以使用纯C)。
#1
96
This is guaranteed to have nothing to do with the compiler. All compilers do is compile the code that they are given. What you're looking for is a GUI library, which you can write code against using any compiler that you want.
这保证与编译器无关。所有编译器所做的就是编译它们所给出的代码。您正在寻找的是一个GUI库,您可以使用任何您想要的编译器来编写代码。
Of course, that being said, your first order of business should be to ditch Turbo C. That compiler is about 20 years old and continuing to use it isn't doing you any favors. You can't write modern GUI applications, as it will only produce 16-bit code. All modern operating systems are 32-bit, and many are now 64-bit. It's also worth noting that 64-bit editions of Windows will not run 16-bit applications natively. You'll need an emulator for that; it's not really going to engender much feeling of accomplishment if you can only write apps that work in a DOS emulator. :-)
当然,也就是说,你的第一笔生意应该是抛弃Turbo C.那个编译器大约有20年的历史,而且它还在继续使用,这对你没有任何好处。您不能编写现代GUI应用程序,因为它只生成16位代码。所有现代操作系统都是32位的,而且很多现在都是64位的。同样值得注意的是,64位Windows版本本身不会运行16位的应用程序。你需要一个模拟器;如果你只能编写在DOS模拟器中工作的应用程序,那就不会有什么成就感。:-)
Microsoft's Visual Studio Express C++ is available as a free download. It includes the same compiler available in the full version of the suite. The C++ package also compiles pure C code.
微软的Visual Studio Express c++可以免费下载。它包括完整版本的套件中可用的相同编译器。c++包也编译纯C代码。
And since you're working in Windows, the Windows API is a natural choice. It allows you to write native Windows applications that have access to the full set of GUI controls. You'll find a nice tutorial here on writing WinAPI applications in C. If you choose to go with Visual Studio, it also includes boilerplate code for a blank WinAPI application that will get you up and running quickly.
由于您在Windows中工作,所以Windows API是一个自然的选择。它允许您编写具有访问完整GUI控件集的本地Windows应用程序。如果您选择使用Visual Studio,您将在这里找到一个关于在c中编写WinAPI应用程序的很好的教程,它还包含一个空白WinAPI应用程序的样板代码,它将使您能够快速启动并运行。
If you really care about learning to do this, Charles Petzold's Programming Windows is the canonical resource of the subject, and definitely worth a read. The entire Windows API was written in C, and it's entirely possible to write full-featured Windows applications in C. You don't need no stinkin' C++.
如果你真的很关心如何学习,Charles Petzold的编程窗口是这个主题的权威资源,绝对值得一读。整个Windows API都是用C编写的,用C编写功能齐全的Windows应用程序是完全可能的。
That's the way I'd do it, at least. As the other answers suggest, GTK is also an option. But the applications it generates are just downright horrible-looking on Windows.
至少我是这么做的。正如其他答案所表明的,GTK也是一个选项。但它所产生的应用程序只是在Windows上看起来非常可怕。
EDIT: Oh dear... It looks like you're not alone in wanting to write "GUI" applications using an antiquated compiler. A Google search turns up the following library: TurboGUI: A GUI Framework for Turbo C/C++:
编辑:哦亲爱的……您似乎并不是唯一希望使用过时的编译器编写“GUI”应用程序的人。谷歌搜索出现了以下库:TurboGUI: Turbo C/ c++的GUI框架:
If you're another one of those poor people stuck in the hopelessly out-of-date Indian school system and forced to use Turbo C to complete your education, this might be an option. I'm loathe to recommend it, as learning to work around its limitations will be completely useless to you once you graduate, but apparently it's out there for you if you're interested.
如果你是另一个被困在落后的印度学校系统里,*使用涡轮C来完成你的教育的穷人,这可能是一个选择。我不愿意推荐它,因为一旦你毕业了,学习它的局限性对你来说是完全没用的,但如果你感兴趣的话,很显然它就在你的身边。
#2
13
The most famous library to create some GUI in C language is certainly GTK.
用C语言创建GUI的最有名的库当然是GTK。
With this library you can easily create some buttons (for your example). When a user clicks on the button, a signal is emitted and you can write a handler to do some actions.
使用这个库,您可以轻松地创建一些按钮(例如您的示例)。当用户单击按钮时,会发出一个信号,您可以编写一个处理程序来执行一些操作。
#3
8
Use win APIs in your main function:
在你的主要功能中使用win api:
- RegisterClassEx() note: you have to provide a pointer to a function (usually called WndProc) which handles windows messages such as WM_CREATE, WM_COMMAND etc
- 请注意:您必须提供一个指向函数(通常称为WndProc)的指针,该函数处理windows消息,如WM_CREATE、WM_COMMAND等
- CreateWindowEx()
- CreateWindowEx()
- ShowWindow()
- 显示窗口()
- UpdateWindow()
- UpdateWindow()
Then write another function which handles win's messages (mentioned in #1). When you receive the message WM_CREATE you have to call CreateWindow(). The class is what control is that window, for example "edit" is a text box and "button" is a.. button :). You have to specify an ID for each control (of your choice but unique among all). CreateWindow() returns a handle to that control, which needs to be memorized. When the user clicks on a control you receive the WM_COMMAND message with the ID of that control. Here you can handle that event. You might find useful SetWindowText() and GetWindowText() which allows you to set/get the text of any control.
You will need only the win32 SDK. You can get it here.
然后编写另一个函数来处理win的消息(在#1中提到)。当您收到消息WM_CREATE时,您必须调用CreateWindow()。类是那个窗口的控件,例如“编辑”是一个文本框,“按钮”是一个。按钮:)。您必须为每个控件指定一个ID(在所有选项中都是惟一的)。CreateWindow()返回需要记住的控件的句柄。当用户单击控件时,您将收到带有该控件ID的WM_COMMAND消息。这里你可以处理那个事件。您可能会发现有用的SetWindowText()和GetWindowText(),它允许您设置/获取任何控件的文本。您只需要win32 SDK。你可以在这里。
#4
5
C is more of a hardware programming language, there are easy GUI builders for C, GTK, Glade, etc. The problem is making a program in C that is the easy part, making a GUI that is a easy part, the hard part is to combine both, to interface between your program and the GUI is a headache, and different GUI use different ways, some threw global variables, some use slots. It would be nice to have a GUI builder that would bind easily your C program variables, and outputs. CLI programming is easy when you overcome memory allocation and pointers, GUI you can use a IDE that uses drag and drop. But all around I think it could be simpler.
C是更多的硬件编程语言,C,有简单的GUI建筑商GTK,空地,等等。问题是在C程序是比较容易的部分,使GUI是容易的部分,难的是将两者结合起来,之间的接口程序GUI是头痛,和不同的GUI使用不同的方法,一些全局变量,使用槽。如果有一个能很容易绑定C程序变量和输出的GUI构建器,那就太好了。当您克服内存分配和指针时,CLI编程很容易,您可以使用使用拖放的IDE GUI。但我认为它可以更简单。
#5
2
Windows API and Windows SDK if you want to build everything yourself (or) Windows API and Visual C Express. Get the 2008 edition. This is a full blown IDE and a remarkable piece of software by Microsoft for Windows development.
Windows API和Windows SDK如果你想自己构建所有东西(或)Windows API和Visual C Express。2008年版。这是微软为Windows开发设计的一个完整的IDE和一个出色的软件。
All operating systems are written in C. So, any application, console/GUI you write in C is the standard way of writing for the operating system.
所有操作系统都是用C编写的,因此,任何用C编写的应用程序、控制台/GUI都是操作系统的标准编写方式。
#6
1
A C compiler itself won't provide you with GUI functionality, but there are plenty of libraries for that sort of thing. The most popular is probably GTK+, but it may be a little too complicated if you are just starting out and want to quickly get a GUI up and running.
C编译器本身不会为您提供GUI功能,但是有很多库可以实现这类功能。最流行的可能是GTK+,但是如果您刚刚开始,并且希望快速地启动并运行GUI,那么它可能有点太复杂了。
For something a little simpler, I would recommend IUP. With it, you can use a simple GUI definition language called LED to layout controls (but you can do it with pure C, if you want to).
对于简单一点的东西,我推荐IUP。有了它,您可以使用一种简单的GUI定义语言,名为LED to layout控件(但是如果您愿意,可以使用纯C)。