win32资源文件帮助
在此网站上,在“编辑控件”标题下,有有几行这样的代码..
case WM_CREATE:
hwndEdit = CreateWindow(TEXT("Edit"), NULL, WS_CHILD | WS_VISIBLE | WS_BORDER,
50, 50, 150, 20, hwnd, (HMENU) ID_EDIT,
NULL, NULL);
hwndButton = CreateWindow(
TEXT("button"), TEXT("Set Title"),
WS_VISIBLE | WS_CHILD,
50, 100, 80, 25,
hwnd, (HMENU) ID_BUTTON, NULL, NULL);
break;
我知道这种创建按钮等的方法是即时完成的,但我想知道如果不这样做,而不是使用资源文件,你会如何做到这一点? 在 Forgers Win32 教程 中,它展示了如何使用资源文件制作菜单,以及如何来描述对话框等,但我似乎无法使用资源文件在主(父)窗口上放置任何控件??
例如,我有以下 .rc 文件
#include "resource.h"
ID_MENU MENU
BEGIN
POPUP "&File"
BEGIN
MENUITEM "E&xit", ID_FILE_EXIT
END
POPUP "&About"
BEGIN
MENUITEM "&Information", ID_ABOUT_INFO
END
END
ID_ABOUT_INFO DIALOG DISCARDABLE 0,0,250,250
CAPTION "Information"
BEGIN
CTEXT "some text",ID_BLA,15,15,144,33
END
//this is all fine but how do I decribe the main window?, instead of the menu and dialog boxes?.
如何描述主窗口而不是即时创建内容?有某种关键字吗?
on this website, under the "Edit Control" title, there are a couple of lines of code like this..
case WM_CREATE:
hwndEdit = CreateWindow(TEXT("Edit"), NULL, WS_CHILD | WS_VISIBLE | WS_BORDER,
50, 50, 150, 20, hwnd, (HMENU) ID_EDIT,
NULL, NULL);
hwndButton = CreateWindow(
TEXT("button"), TEXT("Set Title"),
WS_VISIBLE | WS_CHILD,
50, 100, 80, 25,
hwnd, (HMENU) ID_BUTTON, NULL, NULL);
break;
I know that this method of creating buttons and such are done on the fly, But I was wondering how you would do it without doing it like this, instead using a resource file?.
In the Forgers Win32 tutorial it shows how to make a menu using a resource file, and how to describe a dialog box etc, But I cant seem to put any controls on the main(parent) window using a resource file??.
for example I have the following .rc file
#include "resource.h"
ID_MENU MENU
BEGIN
POPUP "&File"
BEGIN
MENUITEM "E&xit", ID_FILE_EXIT
END
POPUP "&About"
BEGIN
MENUITEM "&Information", ID_ABOUT_INFO
END
END
ID_ABOUT_INFO DIALOG DISCARDABLE 0,0,250,250
CAPTION "Information"
BEGIN
CTEXT "some text",ID_BLA,15,15,144,33
END
//this is all fine but how do I decribe the main window?, instead of the menu and dialog boxes?.
How do I describe the main window instead of creating things on the fly?. Is there some kind of keyword?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以创建一个对话框作为主窗口。
如果您在 Visual Studio 中使用 MFC,请使用项目向导创建基于对话框的应用程序。
(文件 -> 新项目 -> Visual C++ / MFC -> MFC 应用程序 -> 确定 -> 应用程序类型 -> 基于对话框。)
生成的应用程序将为您创建主对话框,并在关闭时退出。
此类野兽的简单示例(包括源代码)如下:
http://www.pretentiousname.com/ICFRanger/index.html< /p>
如果您使用的是直接 Win32,则可以使用 CreateDialogParam (或类似),然后像任何其他窗口一样显示它,并运行消息循环。 (或者您可以使用 DoModal,它运行自己的消息循环,但请注意模式对话框的行为需要略有不同,尤其是在关闭时。)
一个简单的例子,包括源代码,在这里:
http://www.pretentiousname.com/setpoint_aon/index.html< /p>
(这些都是我写的程序,但是非常简单,因此没有太多妨碍理解它们的作用。)
You can create a dialog as your main window.
If you are using MFC in Visual Studio, use the project wizard to create a Dialog-Based app.
(File -> New Project -> Visual C++ / MFC -> MFC Application -> OK -> Application Type -> Dialog based.)
The generated application will then create your main dialog for you, and exit when it closes.
A simple example of such a beast, including source, is here:
http://www.pretentiousname.com/ICFRanger/index.html
If you are using straight Win32, you'd create the dialog using CreateDialogParam (or similar) and then show it like any other window, and run a message loop. (Or you could use DoModal, which runs its own message loop, but beware that modal dialogs need to behave slightly differently, especially when it comes to closing.)
A simple example of that, including source, is here:
http://www.pretentiousname.com/setpoint_aon/index.html
(Those are both programs I wrote, but very simple ones, so there's not much to get in the way of understanding what they do.)
TheForger 已将其所有示例代码添加到 zip 文件中,您可以下载它们并一探究竟。
您仍然需要创建窗口,TheForger 也会执行此操作,但随后他将图标和菜单包含在
WNDCLASSEX
结构中,该结构将传递给要创建的窗口创建的。然后通过 resouce.h 文件从资源文件(.rc 文件)中收集该信息。MSDN 也有关于资源文件的部分,正如你所看到的
未提及主窗口。
TheForger has added all his example code in a zip file, you can download them and check it out.
You still need to create the window, TheForger does this as well, but then he includes the icons and menus in the
WNDCLASSEX
struct which is passed to the window that is to be created. This is then collected from the resource file (.rc file) via the resouce.h file.MSDN has a section about resource files as well, and as you can see
The main window(s) are not mentioned.
在 API 级别,考虑诸如
CreateDialog 之类的函数
。没有比这更复杂的了。
尽管对话框作为主窗口存在一些问题,特别是在MFC中(它对其进行了特殊处理)。
干杯&呵呵,,
At the API-level, consider functions like
CreateDialog
.It's not more complicated than that.
Although a dialog as main window has some problems, especially in MFC (which treats it specially).
Cheers & hth.,
您可以设计一个像对话框一样的窗口并将其放入资源文件中。然后使用 FindResource 和 LoadResource 函数获取指向 DLGTEMPLATE 的指针,其中包含所有对话框布局,您可以使用它们来调整自己的窗口大小并放置控件在您在对话框中定义的位置(尽管解释 DLGTEMPLATE 并不容易)。不要忘记释放指向 DLGTEMPLATE 的指针。
You can design a window like it was a dialog and put it in your resourcefile .Then use the FindResource and LoadResource functions to get a pointer to a DLGTEMPLATE ,which contains all the dialogs layout which you can use to size you own window and place controls at the positions you defined in the dialog (It's not easy though to interpret the DLGTEMPLATE). Don't forget to free the pointer to the DLGTEMPLATE.
使用 CreateWindow 和各种预定义的类。如果您要创建一个按钮,您将使用“BUTTON”类,设置样式 WS_CHILD|WS_VISIBLE 并将窗口过程设置为 NULL。
Use CreateWindow and the various predefined classes. If you were to create a button you would use the class "BUTTON" set the style WS_CHILD|WS_VISIBLE and set the window procedure to NULL.