如何在Win32上开始使用Winforms风格的应用程序? [英] How does one gets started with Winforms style applications on Win32?

查看:84
本文介绍了如何在Win32上开始使用Winforms风格的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有点背景:我主要是一个C ++程序员,但是我所做的唯一的GUI东西是在.NET的WinForms平台的顶部。我完全不熟悉Windows GUI编程,尽管Petzold的出色的书,我非常困惑。

A bit of background: I'm a C++ programmer mostly, but the only GUI stuff I've ever done was on top of .NET's WinForms platform. I'm completely new to Windows GUI programming, and despite Petzold's excellent book, I'm extremely confused.

也就是说,看起来大多数参考的Win32入门是所有关于绘制线条和曲线和东西 - 一个话题(至少在目前我不能在乎)。

Namely, it seems that most every reference on getting started with Win32 is all about drawing lines and curves and things -- a topic about which (at least at present time) I couldn't care less.

我需要一个选中的列表框,分割器和文本框 - 在Winforms土地上需要不到10分钟的时间。已经推荐给我使用WTL库,它提供了所有这三个控件的实现 - 但我一直挂在简单的事情,如使控件使用正确的字体,以及getting高DPI正常工作。我花了两天的时间,我不禁想到,对于这些类型的事情,我必须有一个更好的参考,我找到了。 Petzold的书是好的,但它从Windows 95天没有更新,并有一个LOT改变w.r.t.应用程序应该如何正确开发自发布以来。

I need a checked list box, a splitter, and a textbox -- something that would take less than 10 minutes to do in Winforms land. It has been recommended to me to use the WTL library, which provides an implementation of all three of these controls -- but I keep getting hung up on simple things, such as getting the controls to use the right font, and getting High DPI working correctly. I've spent two days on this, and I can't help but think there has to be a better reference for these kinds of things than I've been able to find. Petzold's book is good, but it hasn't been updated since Windows 95 days, and there's been a LOT changed w.r.t. how applications should be correctly developed since it was published.

我猜我要找的是一本现代的Petzold书。在哪里可以找到这样的资源,如果有?

I guess what I'm looking for is a modern Petzold book. Where can I find such a resource, if any?

推荐答案

首先,几乎没有文档)解释如何使用WTL。

First up, there is virtually no documentation (that I could ever find) explaining how to use WTL. It seems to be a library by experts, for experts.

您的选择是:使用MFC应用程序向导创建一个应用程序,或者去Win32 API路由。 Win32 API本身是一个C API,MFC是一个围绕C Win32 API的C ++包装,并添加了一个文档视图应用程序模型。

Your choices then are: Using the MFC app wizard to create an application, or going the Win32 API route. The Win32 API itself is a C API, MFC is a C++ wrapper around the C Win32 API, with the addition of a document-view application model.

但是,从代码创建控件:本机Windows API最接近WinForm的模拟是一个对话框。对话框布局在链接到正在开发的EXE或DLL中时嵌入的资源文件中。对话框资源采用自动应用于对话框上所有控件的字体设置,对话框按照对话单元(而不是像素)布局,允许对话框自动相对于字体表面缩放,以及用户系统上的dpi设置。

However, instead of creating your controls from code: The closest analog the native Windows API has to a "WinForm" is a dialog box. Dialogs are layed out in resource files that are embedded during linking into the EXE or DLL you are developing. The dialog resource takes a font setting that is automatically applied to all controls on the dialog, and dialogs are layed out in terms of dialog units, not pixels, allowing them to automatically scale relative to the font face, and dpi setting on the users system.

如果你创建一个对话框资源,并把它添加到一个简单的应用程序,它需要看起来没有比这更复杂得到对话框到屏幕上,并关闭

If you create a dialog resource, and add it to a simple application, it need look no more complicated than this to get the dialog up onto the screen, and close in response to a click of the OK button.

#include <windows.h>
#include "resource.h"

BOOL CALLBACK MyDialogProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
  switch(uMsg){
  case WM_INITDIALOG:
    return TRUE;
  case WM_COMMAND:
    switch(LOWORD(wParam){
    case IDOK:
      EndDialog(hwnd,wParam);
    }
    return TRUE;
  }
  return FALSE;
}

int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hNull,LPCTSTR strCmdLine,int nCmdShow)
{
  return DialogBoxParam(hInstance,MAKEINTRESOURCE(IDD_DIALOG1),NULL,&DialogProc,0l);
}

这篇关于如何在Win32上开始使用Winforms风格的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆