0

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

1
Contributor
1
Reply
2
Views
7 Years
Discussion Span
Last Post by slim2hott
0

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;
}

Edited by slim2hott: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.