4

I'm experimenting with the Win32 API in C++, specifically with writing resource files. Now, my entire project was working just fine, menus and titles and everything. However, when I add this code for a modal dialog box to the .rc file:

IDD_ABOUT DIALOG DISCARDABLE  0, 0, 239, 66
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "My About Box"
FONT 8, "MS Sans Serif"
BEGIN
    DEFPUSHBUTTON   "&OK",IDOK,174,18,50,14
    PUSHBUTTON      "&Cancel",IDCANCEL,174,35,50,14
    GROUPBOX        "About this program...",IDC_STATIC,7,7,225,52
    CTEXT           "An example program showing how to use Dialog Boxes\r\n\r\nby theForger", IDC_STATIC,16,18,144,33
END

Windres exits with the following error:

windres: resource.rc:40: syntax error

Line 40 refers to:

GROUPBOX "About this program...",IDC_STATIC,7,7,225,52

According to MSDN,

The GROUPBOX statement, which you can use only in a DIALOGEX statement, defines the text, identifier, dimensions, and attributes of a control window.

GROUPBOX text, id, x, y, width, height [, style [, extended-style]]

Their example:

GROUPBOX "Options", 101, 10, 10, 100, 100

What am I doing wrong?

Community
  • 1
  • 1
Ken Bellows
  • 6,711
  • 13
  • 50
  • 78

2 Answers2

4

I think it is pretty much self-explanatory from

can use only in a DIALOGEX statement

YeenFei
  • 3,180
  • 18
  • 26
4

If you still have the same syntax error on the same line after switching to a DIALOGEX statement (as @YeenFei pointed out), the only thing I can think of is that IDC_STATIC is not defined.

Try changing it to

GROUPBOX "About this program...",-1,7,7,225,52

If that fixes the problem, it's because the identifier isn't defined.

I did a search through the Platform SDK headers (6.1 and 7.1) and didn't find it. I think that might be an MFC-specific identifier -- some quick Googling suggests MFC defines it in "afxres.h" if it isn't already defined.

IDOK and IDCANCEL work even though you didn't explicitly define them because they are defined in the Platform SDK (in "winuser.h").

Tadmas
  • 6,238
  • 3
  • 39
  • 31
  • IDC_STATIC is also defined in winuser.h – Ken Bellows Jan 24 '11 at 21:09
  • @KenB: Not it's not. It's a control value that would normally be taken from a project-specific `resource.h`. See any of the numerous sample programs in the Windows Platform SDK. – Adam Rosenfield Jan 24 '11 at 21:43
  • I just used grep and found it defined not only in winuser.h but also in afxres.h. – Ken Bellows Jan 24 '11 at 21:58
  • I don't know why, but defining IDC_STATIC fixes it for some reason. – Ken Bellows Jan 24 '11 at 22:11
  • @KenB If you see it in winuser.h, what version of the Platform SDK do you have? It might have been in an older version. (I also used grep, and I got no hits at all for the versions I have.) Maybe the definition in your header file is surrounded by a version check? – Tadmas Jan 24 '11 at 22:50
  • 1
    I am using MinGW 4.5.2. Here is what I have concluded upon further examination of the header files. Winuser.h does indeed have IDC_STATIC documented; however, it is not actually defined because it is surrounded by an #if 0 statement, with a comment noting, "This is supposed to be defined by the program using it not defined in the w32api headers. I've left it here for documentation purposes." – Ken Bellows Jan 27 '11 at 18:11