简体   繁体   English

C ++ Win32 Api资源文件

[英]C++ win32 Api resource file

i am learning win32 api . 我正在学习win32 api。 i know how to add pushbutton on the fly. 我知道如何动态添加按钮。 now i am trying to add a pushbutton using a resource file ( rse.rc ) . 现在我正在尝试使用资源文件(rse.rc)添加按钮。 below is my res.rc file defination: 以下是我的res.rc文件定义:

IDB_B1 PUSHBUTTON "TOGGLE",7 , 20, 180, 200, 30

and i have evn generated a resource.h file to be included in the source. 而且我已经evn生成了一个resource.h文件,将其包含在源代码中。 now the problem i am facing is how di add this button to my main window ? 现在我面临的问题是如何将此按钮添加到我的主窗口? i have tried adding cursor and icon using .rc file which is easy but can not get my head around this button . 我曾尝试使用.rc文件添加光标和图标,这很简单,但无法绕过此按钮。

i guess it has to be under: 我想它必须在:

WM_CREATE:

but how exactly to call it from .rc file? 但是如何从.rc文件中调用它呢?

It does not work this way. 这种方式行不通。

Resources in Win32 are used to create many things: menus, accelerators and dialogs, among others; Win32中的资​​源用于创建许多东西:菜单,加速器和对话框,等等。 but not single controls. 但不是单个控件。

What you want to do, a main window with a button can be achieved using two techniques: 您想要做的是,可以使用两种技术来实现带有按钮的主窗口:

  1. Let your main window be a dialog. 让您的主窗口成为一个对话框。 You write the resource for a full dialog, with buttons and all, and from WinMain() you call CreateDialog() . 您编写包含一个按钮和全部的完整对话框的资源,并从WinMain()调用CreateDialog() DialogBox() or similar. DialogBox()或类似的东西。
  2. Your main window is a normal window, and you create child contros manually. 您的主窗口是普通窗口,您可以手动创建子控件。 These controls are created calling CreateWindowEx() directly, with class name WC_BUTTON , as a response to WM_CREATE as you guessed. 这些控件是使用类名WC_BUTTON直接调用CreateWindowEx()创建的,作为您猜到的对WM_CREATE的响应。

Also, you can make the dialog a child of the main window, but I don't recommend that, specially if you are still learning. 另外,您可以将对话框设为主窗口的子级,但我不建议这样做,特别是如果您仍在学习中。

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

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