简体   繁体   English

如何使用资源文件(* .rc)设置基于对话框的应用程序的样式

[英]How can I use a resource file (*.rc) to style a dialog-based application

How can I use a resource file (*.rc) to style a dialog-based application? 如何使用资源文件(* .rc)设置基于对话框的应用程序的样式?

I can use CreateWindow or CreateWindowEx to create the main window of an application. 我可以使用CreateWindowCreateWindowEx来创建应用程序的主窗口。 And some of the arguments of CreateWindow or CreateWindowEx define the styles of a dialogbox. CreateWindowCreateWindowEx一些参数定义了对话框的样式。 But I want to style it using resource file (*.rc) instead of the way of by pass style arguments to function. 但我想使用资源文件(* .rc)来设置它的样式,而不是通过函数的传递样式参数的方式。

Could someone give me some snippets? 有人可以给我一些片段吗?

Someobody said I can call DialogBox , and give second argument the the style template. 有人说我可以调用DialogBox ,并给第二个参数设置样式模板。 Does this create a confict between CreateWindow and the *.rc file? 这是否会在CreateWindow和* .rc文件之间产生混淆? Or can I use both of them at the same time? 或者我可以同时使用它们吗?

Use CreateDialog . 使用CreateDialog It handles wrapping the call to CreateWindowEx as well as posting the WM_INITDLG and WM_SETFONT messages if needed. 它处理包装对CreateWindowEx的调用,以及在需要时发布WM_INITDLG和WM_SETFONT消息。 There's an example linked from the docs on MSDN. 从MSDN上的文档链接了一个示例

You can get information about the content of the resource file here in the documentation for DialogEx . 您可以在DialogEx的文档中获取有关资源文件内容的信息。

Start a new Win32 Project and let it auto-generate the code. 启动一个新的Win32项目,让它自动生成代码。 Change the WinMain function to look like this: 将WinMain函数更改为如下所示:

int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{

    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);

    DialogBox(hInstance, MAKEINTRESOURCE(IDD_ABOUTBOX), NULL, About);
    return 0;
}

You may want to add a call to MoveWindow() in the WM_INITDIALOG message handler to move the window to a better spot on the screen. 您可能希望在WM_INITDIALOG消息处理程序中添加对MoveWindow()的调用,以将窗口移动到屏幕上的更好位置。

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

相关问题 在基于对话框的MFC应用程序中添加对打印和预览HTML的支持 - Add support to print & preview HTML in a dialog-based MFC app 如何使用.rc文件? - How to use a .rc file? 如何防止我的基于MFC对话框的应用程序在ESC键后关闭,但允许其他控件处理它? - How to prevent my MFC dialog-based app from closing after ESC key, but allow other controls to process it? 在基于 Windows MFC 对话框的应用程序的控制台上不显示 stdout 输出 - stdout output doesn't display on console in Windows MFC dialog-based app resource.rc文件中返回多个资源 - Multiple resources returned in resource.rc file 如何通过 CLI 在 Windows 上打开文件属性对话框? - How can I open the file properties dialog on Windows via CLI? 如何通过 CLI 打开 Windows 上的文件属性对话框? - How can I open the file properties dialog on Windows via CLI? 如何使用IFileOpenDialog打开* modal *文件对话框? - How can I open an *modal* file dialog with IFileOpenDialog? RC2247:无法打开Rc文件:资源管理器无法加载资源; 加载失败 - RC2247 : Cannot open Rc file : Resource explorer cannot load resource ; Load failed 如何使用 Powershell 在辅助应用程序中打开带有空格的文件,使用 function? - How can I use Powershell to open a file with spaces in it in an auxiliary application, using a function?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM