简体   繁体   English

Windows GUI C ++编程

[英]Windows GUI C++ Programming

I want to learn C++ GUI programming using Visual Studio 2008. I'm not sure where to start though. 我想学习使用Visual Studio 2008的C ++ GUI编程。我不知道从哪里开始。 I learned C++ in high school, but not GUI. 我在高中时学过C ++,但不是GUI。 I've been doing C# for about 3 years now and thats how I "learned" GUI programming. 我已经做了大约3年的C#,这就是我如何“学习”GUI编程。 Now I want to learn how to write GUI's without the use of the .NET framework, so where do I start? 现在我想学习如何在不使用.NET框架的情况下编写GUI,那么我从哪里开始呢?

Charles Petzold's "Programming Windows 5th Edition" is the Bible for Windows programming. Charles Petzold的“Programming Windows 5th Edition”是用于Windows编程的圣经。

http://www.charlespetzold.com/pw5/ http://www.charlespetzold.com/pw5/

Since you say you've been doing C# GUI programming for about 3 years, I'll assume that means Windows Forms. 既然你说你已经做了大约3年的C#GUI编程,我会认为这意味着Windows Forms。 One way to dip your toe in the water is to remember that WinForms is really just an object-oriented wrapper around user32 . 将脚趾浸入水中的一种方法是记住WinForms实际上只是围绕user32的面向对象的包装器。 So load up Reflector and take a look at the way some of the controls are implemented. 因此,加载Reflector并查看一些控件的实现方式。 You'll see that these strange messages like WM_PAINT and WM_KEYDOWN are pumped to the WndProc of the various controls by Windows. 你会看到像WM_PAINTWM_KEYDOWN这些奇怪的消息被Windows引入各种控件的WndProc In plain old Win32 or MFC programming, the same thing is still going on. 在普通的旧Win32或MFC编程中,同样的事情仍在继续。 Doing this will let you slowly peel back the layers of the onion; 这样做可以让你慢慢剥离洋葱的层; you'll get a better feel for how Windows Forms works, too. 您也可以更好地了解Windows窗体的工作原理。 From there, I'd recommend picking up Programming Windows by Petzold; 从那里,我建议选择Petzold 编程Windows ; it's old, but the native APIs in Windows don't move around that much. 它已经过时了,但Windows中的原生API并没有那么多。 Have fun! 玩得开心!

MFC is almost outdated now. MFC现在几乎已经过时了。 I would recommend to use WTL instead . 我建议改用WTL。

Well it is also not a good idea just to start programming for GUI in C++ when there are so many good frameworks available like QT cross platform framework. 当有很多像QT跨平台框架这样的好框架时,开始用C ++编程GUI也不是一个好主意。

Some heretical opinions... 一些异端的观点......

I wouldn't recommend C++ for writing complex Windows GUIs - language/library combos like C# or Delphi are so much more productive. 我不建议使用C ++来编写复杂的Windows GUI - 像C#或Delphi这样的语言/库组合可以提高效率。 If you want to get into C++ programming I'd suggest using it to write a multi-threaded server of some sort - a simple Web server would do for starters. 如果你想进入C ++编程,我建议用它来编写某种类型的多线程服务器 - 一个简单的Web服务器可以为初学者做。

And if you really want to understand the underlying Windows APIs, I think there is something to be said for writing a simple application (like, say, a simplified version of notebook) in C (not C++). 如果你真的想了解底层的Windows API,我认为在C(而不是C ++)中编写一个简单的应用程序(比如说,简化版本的笔记本)有一些东西可以说。 You'll only want to do it once, but you will learn a lot in the process. 你只想做一次,但你会在这个过程中学到很多东西。

And before anyone starts madly down-voting, let me say that I am a C++ programmer of over 20 years standing, and really love the language. 在任何人开始疯狂地投票之前,让我说我是一位拥有20多年历史的C ++程序员,并且非常喜欢这种语言。

Would it be OK with you to write GUIs in VC++ using Microsoft Foundation Classes or MFC? 你可以使用Microsoft基础类或MFC在VC ++中编写GUI吗? That is how I would and have written VC++ GUIs in the past. 这就是我过去编写VC ++ GUI的方式。

There have been many books written on MFC over the years. 多年来,MFC上写了很多书。 I'm sure any one of them will do nicely. 我相信他们中的任何一个都会做得很好。 You may find in the literature the reference ATL which is a Microsoft iteration on STL. 您可以在文献中找到参考ATL,它是STL上的Microsoft迭代。 MFC and ATL kind of merged over the years so anything ATL is also applicable to an MFC app these days. 多年来MFC和ATL类型合并,所以任何ATL现在也适用于MFC应用程序。

Good luck and have fun! 祝好运并玩得开心点!

Ah I know how you feel, old interpreted languages programmer that want to know the magic behind compiled programing. 啊我知道你的感受,老解释语言程序员想知道编译程序背后的魔力。 Well I can't find the tutorial that I used to learn windows programing, but just know that there is good win32 tutorials around, so you don't waste your time buying a book just yet. 好吧,我找不到我以前学习windows编程的教程,但只知道有很好的win32教程,所以你不要浪费时间买书。 I found it: http://www.relisoft.com/win32/index.htm Neatest tutorial around, trust me. 我找到了它: http//www.relisoft.com/win32/index.htm最新的教程,相信我。

As of now (Windows 8), WinRT, a completely new API has been brought to the audience by Microsoft and I'm quite excited about it. 截至目前(Windows 8),WinRT是一个全新的API,已被微软带给观众,我对它非常兴奋。 Never done MFC programming, but saw some code samples and they look weirdly 90's C-style (modern C-style is often better!). 从来没有做过MFC编程,但看到了一些代码示例,它们看起来奇怪的是90年代的C风格(现代C风格通常更好!)。 So, without going to start directly with MFC, I think I will start with WinRT 因此,如果不直接使用MFC,我想我将从WinRT开始

:) :)

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

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