[英]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. 我可以使用
CreateWindow
或CreateWindowEx
来创建应用程序的主窗口。 And some of the arguments of CreateWindow
or CreateWindowEx
define the styles of a dialogbox. CreateWindow
或CreateWindowEx
一些参数定义了对话框的样式。 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.