3

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?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
fr33m4n
  • 542
  • 2
  • 13
  • 31

2 Answers2

2

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.

Ken White
  • 123,280
  • 14
  • 225
  • 444
2

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.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536