How can I use a resource file (*.rc) to style a dialog-based application?
I can use CreateWindow
or CreateWindowEx
to create the main window of an application. And some of the arguments of CreateWindow
or CreateWindowEx
define the styles of a dialogbox. But I want to style it using resource file (*.rc) instead of the way of by pass style arguments to function.
Could someone give me some snippets?
Someobody said I can call DialogBox
, and give second argument the the style template. Does this create a confict between CreateWindow
and the *.rc file? Or can I use both of them at the same time?
Use CreateDialog . It handles wrapping the call to CreateWindowEx as well as posting the WM_INITDLG and WM_SETFONT messages if needed. There's an example linked from the docs on MSDN.
You can get information about the content of the resource file here in the documentation for DialogEx .
Start a new Win32 Project and let it auto-generate the code. Change the WinMain function to look like this:
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.