I have made a window that has message boxes, menus and dialogs, but can someone tell me what is wrong with this .rc code? It looks ok for me it gives me this error:

[Resource error] syntax error

on the line 3, the one that starts with style.

#include "resource.h"

IDD_ABOUT DIALOG DISCARDABLE  0, 0, 239, 66
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU

CAPTION "What do you think of my program?"
FONT 9, "MS Sans Serif"

BEGIN

    DEFPUSHBUTTON   "&Good",IDOK,174,18,50,14
    PUSHBUTTON      "&Bad",IDCANCEL,174,35,50,14
    GROUPBOX        "About this program...",IDC_STATIC,7,7,225,52
    CTEXT           "When you press good, \nthe program will create a text file \nand write in the name of the button \nthat you clicked",
  
IDC_STATIC,16,18,144,33

END

I have the #defines for this in the resource.h below

#define IDC_STATIC                      -1
#define IDR_MYMENU                      101
#define IDI_MYICON                      102
#define IDD_ABOUT                       103
#define ID_FILE_EXIT                    40001
#define ID_STUFF_GO                     40002
#define ID_ABOUT_US                     40004
#define ID_HELP_ABOUT                   40005

Thanks

Dani AI

Generated

A few concrete things stand out from 's posts that commonly cause a dialog not to appear even though the project builds.

First, keep resource headers pure: resource.h should contain only ID #defines (and optional extern declarations). Defining globals (the HWND hwnd; in the posted resource.h) or putting the entire AboutDlgProc implementation into resource.h can confuse the resource compiler and makes maintenance fragile. Move the dialog procedure implementation into the .cpp file and leave only the IDD/IDC defines in resource.h.

Second, verify the menu command ID actually sent by the menu matches the case handled in WndProc. A mismatched ID (for example the menu uses ID_ABOUT_US but WndProc listens for ID_HELP_ABOUT) means WM_COMMAND never takes the dialog path. Temporarily show a small debug MessageBox or use a breakpoint and inspect LOWORD(wParam) inside WM_COMMAND to confirm which ID arrives.

Third, validate the resource itself and the dialog proc signature. Make sure the dialog resource compiles into the binary (use Visual Studio Resource View or Resource Hacker) and that the proc uses the documented signature (INT_PTR/CALLBACK) as described in the DialogBox and DialogProc docs. If DialogBox returns –1, call GetLastError to get a system error code. Microsoft documentation: DialogBox function () and DialogProc callback ().

Also check the .rc formatting: multiline CTEXT/control lines must be a single control entry (the stray newline in the original RC is a classic syntax error). Finally, avoid linking runtimes manually—use your C++ linker driver (g++/cl) to pull in libstdc++/MSVCRT automatically, and prefer cleaner separation of resource definitions and code for easier debugging.

terribly sorry for double post, but it has to be done.

I fixed my .rc code by adding

#include "afxres.h"

and then i got linker errors, so then i linked libstdc++.a into my work. My program now compiles without any errors, but I have an even bigger problem, when I click one of the tabs at the top of my window, a dialog box is supposed to appear, but nothing happens, here is my source code, I have changed my resource.h and I will post it, but my .rc code is the same except the changes that I was talking about.

Source code:

#include <windows.h>
#include <iostream>
#include <fstream> 
#include "resource.h"

using namespace std;

/* This program is just for practice, nothing interesting here, just basic window making practice and
yes this program is very useless. */

/* This program is ment to bring up a dialog box after you press the About Us menu item,
then, if you press IDOK, or IDCANCEL, it "tries" to write to a text file, but it doesn't, 
I don#t think I am supposed to use fstream here, but correct me if I am wrong. */


char szClassName[ ] = "WindowsApp";



LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
	switch(Message)
	{
		case WM_COMMAND:
			switch(LOWORD(wParam))
			{
				case ID_FILE_EXIT:
					PostMessage(hwnd, WM_CLOSE, 0, 0);
				break;
				
				case ID_STUFF_GO:
					MessageBox(hwnd, "Under construction", "Sorry!",  MB_OK | MB_ICONEXCLAMATION );
				break;
				
				case ID_HELP_ABOUT:
				{
					int result = DialogBox(GetModuleHandle(NULL), 
						MAKEINTRESOURCE(IDD_ABOUT), hwnd, AboutDlgProc);
			      if(result == IDOK){	
                              ofstream file;
                              file.open ("result.txt");
                              file << "Good\n";
                              file.close();                              	
                                                                                        		                          
                       MessageBox(hwnd, "Thank you for your contribution", "Result added to text file...", MB_OK | MB_ICONINFORMATION);

				}

			      else if(result == IDCANCEL){
                              ofstream file;
                              file.open ("result.txt");
                              file << "Bad\n";
                              file.close();
                              	                        
                       MessageBox(hwnd, "Thank you for your contribution", "Result added to text file...",  MB_OK | MB_ICONINFORMATION);   
                    
					}

					else if(result == -1){
						MessageBox(hwnd, "Dialog failed!", "Error",
							MB_OK | MB_ICONERROR);
					}
				}
				break;
			}
		break;

		case WM_CLOSE:               
            DestroyWindow(hwnd);                        
		break;

		case WM_DESTROY:
			PostQuitMessage(0);
		break;

		default:
			return DefWindowProc(hwnd, Message, wParam, lParam);
	}
	return 0;
}


int WINAPI WinMain (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nFunsterStil)
                    

{
    
    HWND hwnd;               
    MSG messages;            
    WNDCLASSEX wincl;        

    
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WndProc;      
    wincl.style = CS_DBLCLKS;                 
    wincl.cbSize = sizeof (WNDCLASSEX);

    
    wincl.hIcon   = LoadIcon(GetModuleHandle(NULL),   MAKEINTRESOURCE(IDI_MYICON));
    wincl.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON), IMAGE_ICON, 16, 16, 0);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = MAKEINTRESOURCE(IDR_MYMENU);                
    wincl.cbClsExtra = 0;                      
    wincl.cbWndExtra = 0;                      
    
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    
    if(!RegisterClassEx(&wincl))
	{
		MessageBox(NULL, "Window Registration Failed!", "Error!",
			MB_ICONEXCLAMATION | MB_OK);
		return 0;
	}

    
    hwnd = CreateWindowEx (
           0,                   
           szClassName,         
           "Window with dialog",       
           WS_OVERLAPPEDWINDOW, 
           CW_USEDEFAULT,       
           CW_USEDEFAULT,       
           544,                 
           375,                 
           HWND_DESKTOP,        
           NULL,                
           hThisInstance,       
           NULL                 
           );

  
    ShowWindow (hwnd, nFunsterStil);

    
    while (GetMessage (&messages, NULL, 0, 0))
    {
      
        TranslateMessage(&messages);
       
        DispatchMessage(&messages);
    }

    
    return messages.wParam;
}

Resource.h

#define IDC_STATIC               -1
#define IDR_MYMENU                      101
#define IDI_MYICON                      102
#define IDD_ABOUT                       103
#define ID_FILE_EXIT                    40001
#define ID_STUFF_GO                     40002
#define ID_ABOUT_US                     40004
#define ID_HELP_ABOUT                   40005

HWND hwnd;

BOOL CALLBACK AboutDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
	switch(Message)
	{
		case WM_INITDIALOG:

		return TRUE;
		case WM_COMMAND:
			switch(LOWORD(wParam))
			{
				case IDOK:
					EndDialog(hwnd, IDOK);
				break;
				case IDCANCEL:
					EndDialog(hwnd, IDCANCEL);
				break;
			}
		break;
		default:
			return FALSE;
	}
	return TRUE;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.