简体   繁体   English

如何在Visual Studio Visual C ++ Win32项目中查看主窗体,以便编辑它?

[英]How can I view the main form in a Visual Studio Visual C++ Win32 Project so I can edit it?

I am migrating a C++ Builder program to a Visual Studio 2013 C++/Win32/Win32 Project. 我正在将C ++ Builder程序迁移到Visual Studio 2013 C ++ / Win32 / Win32项目。

Try as I may, however, after I create a new project (C++/Win32/Win32 Project), I can't see how to view/edit the main form which is created automatically when Visual Studio creates the project. 但是,在创建新项目(C ++ / Win32 / Win32项目)之后,我可能会尝试查看/编辑Visual Studio创建项目时自动创建的主窗体。 I know how to view/edit forms in C#, C++ Builder, and Delphi, but I'm not seeing how to view the form so that I can add to it in VS 2013 for a C++ Windows application. 我知道如何在C#,C ++ Builder和Delphi中查看/编辑表单,但我没有看到如何查看表单,以便我可以在VS 2013中为C ++ Windows应用程序添加它。

What is it that I do not understand? 什么是我不明白? What rock is the main form hidden under in the IDE? 什么摇滚是IDE中隐藏的主要形式?

I know the form is there, with a simple menu and an about box, because it is displayed when the newly created project/program is run. 我知道表单在那里,有一个简单的菜单和一个关于框,因为它是在运行新创建的项目/程序时显示的。

By form I mean the main window for the newly created application. 表单我指的是新创建的应用程序的主窗口。

Sounds to me like you created a straight Win32 project (non-MFC). 听起来像你创建了一个直接的Win32项目(非MFC)。 In that case, there isn't a form designer like you are accustomed to. 在这种情况下,没有像您习惯的表单设计师。 Much is created by code. 很多是由代码创建的。

You'll find something like: 你会发现类似的东西:

case IDM_ABOUT:
    DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
    break;

Open the Resource Files, Win32Project1.rc, and open the Dialog subfolder, you'll see a dialog designer. 打开资源文件,Win32Project1.rc,打开Dialog子文件夹,您将看到一个对话框设计器。 Besides that, you won't find a Form that is editable the way C++ Builder allows. 除此之外,您将找不到可以像C ++ Builder允许的方式编辑的表单。 At first glance you'll think you have a form designer, but shortly you'll find it is pretty lacking. 乍一看,你会认为你有一个表单设计师,但不久你会发现它很缺乏。 To design complex UIs requires more. 设计复杂的UI需要更多。

The bad news, if you are coming from a C++ Builder background, you will find Visual C++ not so RAD / WYSIWIG. 坏消息,如果你来自C ++ Builder背景,你会发现Visual C ++不是RAD / WYSIWIG。 There are several ways to do it, not all of which involve design time form wizards. 有几种方法可以做到这一点,并非所有方法都涉及向导的设计时间。 Much of traditional Visual C++ programming creates the UI dynamically. 许多传统的Visual C ++编程动态地创建UI。

If you want true RAD with Visual Studio, you'll need to move to C# / .NET and Winforms or WPF. 如果你想在Visual Studio中使用真正的RAD,你需要转到C#/ .NET和Winforms或WPF。

If you are sticking with C++, I recommend you recreate your project and choose the MFC option, or look at Qt or another 3rd party UI framework. 如果您坚持使用C ++,我建议您重新创建项目并选择MFC选项,或者查看Qt或其他第三方UI框架。 MFC (Microsoft Foundation Classes) and the MFC Project Wizard will give you more controls to choose from, and more of a jump start by helping you create an app skeleton with Single/Multiple Document Interface, etc. MFC(Microsoft基础类)和MFC项目向导将为您提供更多可供选择的控件,以及通过帮助您创建具有单/多文档界面等的应用程序框架的更多启动。

There is a big paradigm change between a "Winforms" application and a standard Visual C++ Windows application: “Winforms”应用程序和标准的Visual C ++ Windows应用程序之间存在着巨大的范例变化:

  • Winforms applications use managed code, which can be C#, VB or C++/CLI. Winforms应用程序使用托管代码,可以是C#,VB或C ++ / CLI。

  • In Winforms, the programmer doesn't have to know about the Windows message pump to write code for forms, controls and events. 在Winforms中,程序员不必知道用于编写表单,控件和事件代码的Windows消息泵。

  • Visual C++ applications do not typically use managed code, and these programs run without the .Net framework. Visual C ++应用程序通常不使用托管代码,并且这些程序在没有.Net框架的情况下运行。

  • If you want, you can use Winforms in your Visual C++ project, but that action will convert the project to a managed code project (C++/CLI). 如果需要,可以在Visual C ++项目中使用Winforms,但该操作会将项目转换为托管代码项目(C ++ / CLI)。

  • Visual C++ uses resource files to store the layout of the forms, whereas winforms application uses designer classes (For example, myForm.designer.cs) Visual C ++使用资源文件来存储表单的布局,而winforms应用程序使用设计器类(例如,myForm.designer.cs)

Unfortunately there is no editor available in Visual studio to edit the main window. 遗憾的是,Visual Studio中没有可用于编辑主窗口的编辑器。 You have to do that using code. 你必须使用代码来做到这一点。 Debug this method in your project to see how the Windows message system works. 在项目中调试此方法以查看Windows消息系统的工作方式。

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    int wmId, wmEvent;
    PAINTSTRUCT ps;
    HDC hdc;

    switch (message)
    {
    case WM_COMMAND:
        wmId    = LOWORD(wParam);
        wmEvent = HIWORD(wParam);
        // Parse the menu selections:
        switch (wmId)
        {
        case IDM_ABOUT:
            DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
            break;
        case IDM_EXIT:
            DestroyWindow(hWnd);
            break;
        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
        }
        break;
    case WM_PAINT:
        hdc = BeginPaint(hWnd, &ps);


    // TODO: *****************Add any drawing code here...*****************



        EndPaint(hWnd, &ps);
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}

Open the resource files where you can edit the "about box" & menu items. 打开资源文件,您可以在其中编辑“关于框”和菜单项。 The window is created using the API CreateWindow & the parameters passed to the functions defines the view of the window. 该窗口是使用API​​ CreateWindow创建的,传递给函数的参数定义了窗口的视图。 In win32, only dialog boxes can be edited in the resource file while the view of your window requires writing code in the win32 message ie WM_PAINT to draw the window according to your requirement. 在win32中,只能在资源文件中编辑对话框,而窗口视图需要在win32消息中编写代码,即WM_PAINT根据您的要求绘制窗口。 If your looking for a form window like interface than you can call the dialogbox api in the winmain & remove all code to window creation. 如果您正在寻找类似于界面的表单窗口,则可以在winmain中调用dialogbox api并删除所有代码以创建窗口。 That would be much easier to add buttons, list & other controls. 添加按钮,列表和其他控件会更容易。

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

相关问题 我可以稍后将我的 Visual C++ win32 项目转换为跨平台项目吗? - Can I convert my Visual C++ win32 project into a crossplatform later? 如何使用Direct8 dll编译/调试Visual Studio 2012 Win32项目 - How can I compile/debug Visual Studio 2012 Win32 project with Direct8 dlls 如何在Win32 C ++中复制窗口的可视内容并将其放在新窗口中? - How can i copy the visual content of a window and put it on a new window in win32 c++? 如何将项目win32控制台应用程序转换为C ++ Windows窗体? - How can I convert project win32 console application into C++ Windows Form? 如何让 Visual Studio 2017 自动签署 Win32 应用程序? - How can I get Visual Studio 2017 to sign a Win32 application automatically? 如何在Win32 C ++项目Visual Studio 2010中使用ActiveX dll - How to use ActiveX dll in win32 C++ project visual studio 2010 如何在Visual Studio C ++ Win32项目中填充组合框 - How to fill combobox in a Visual Studio C++ Win32 project 如何在Win32 Project C ++中将几个项目添加到列表框中? - How Can I add several Items to a Listbox in Win32 Project C++? 我可以从Visual Studio立即窗口调用Win32 API吗? - Can I call a Win32 API from the Visual Studio Immediate Window? 如何从另一个C ++ win32控制台应用程序调用C ++ Win32 DLL - How Can I call a C++ Win32 DLL from another C++ win32 Console Application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM