Click here to Skip to main content
15,886,088 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey, guys. I'm VERY new to programming windows manually and I'm stuck on this problem. I'm trying to follow this tutorial: http://www.winprog.org/tutorial/dialogs.html[^]

The program window came up fine until I tried to add the dialog box. The dialog box uses "menures.rc and menures.h". I included the menures header in the main file, and that stopped the "undeclared" errors. I guess now I need to declare the "IDD_ABOUT" and "ID_HELP_ABOUT" in my main function, or something. But, I have no idea how. Thanks in advance for the help.

The error is: expected primary-expression before '[symbol here]'
I put notes next to where the error occurs.

MAIN.CPP (Not the full code, so let me know if more is required)
// Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
        case WM_CREATE:
        {
        HMENU hMenu, hSubMenu;
        HICON hIcon, hIconSm;

        hMenu = CreateMenu();

        hSubMenu = CreatePopupMenu();
        AppendMenu(hSubMenu, MF_STRING, ID_FILE_EXIT, "E&xit");  //ERROR HERE: expected primary-expression before ','
        AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&File");

        hSubMenu = CreatePopupMenu();
        AppendMenu(hSubMenu, MF_STRING, ID_STUFF_GO, "&Go");  //SAME ERROR AS ABOVE HERE
        AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Stuff");

        SetMenu(hwnd, hMenu);


        hIcon = (HICON)LoadImage(NULL, "Ufo.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE);
        if(hIcon)
            SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
        else
            MessageBox(hwnd, "Could not load large icon!", "Error", MB_OK | MB_ICONERROR);

        hIconSm = (HICON)LoadImage(NULL, "Ufo.ico", IMAGE_ICON, 16, 16, LR_LOADFROMFILE);
        if(hIconSm)
            SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)hIconSm);
        else
            MessageBox(hwnd, "Could not load small icon!", "Error", MB_OK | MB_ICONERROR);
            }
        break;
        
        case WM_COMMAND:
            switch(LOWORD(wParam))
        {
              case ID_HELP_ABOUT:   //ERROR HERE: expected primary-expression before ':'
            {
           int ret = DialogBox(GetModuleHandle(NULL),  //ERROR HERE: expected primary-expression before ')'  
              MAKEINTRESOURCE(IDD_ABOUT), hwnd, AboutDlgProc);
           if(ret == IDOK){
              MessageBox(hwnd, "Dialog exited with IDOK.", "Notice",
                    MB_OK | MB_ICONINFORMATION);
            }
            if(ret == IDCANCEL){
                MessageBox(hwnd, "Dialog exited with IDCANCEL.", "Notice",
                    MB_OK | MB_ICONINFORMATION);
            }
            else if(ret == -1){
                MessageBox(hwnd, "Dialog failed!", "Error",
                    MB_OK | MB_ICONINFORMATION);
            }
        }
        break;    
                case ID_FILE_EXIT:  //SAME ERROR AS ABOVE HERE

                break;
                case ID_STUFF_GO:  //ERROR HERE: expected primary-expression before ':'
               DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_ABOUT), hwnd, AboutDlgProc);  //ERROR HERE: expected primary-expression before ')'
                break;
            }
        
        case WM_LBUTTONDOWN:
        {
             char szFileName[MAX_PATH];
             HINSTANCE hInstance = GetModuleHandle(NULL);
             
             GetModuleFileName(hInstance, szFileName, MAX_PATH);
             MessageBox(hwnd, szFileName, "This program is:", MB_OK | MB_ICONINFORMATION);
        }
        case WM_CLOSE:
            DestroyWindow(hwnd);
        break;
        
        case WM_DESTROY:
            PostQuitMessage(0);
        break;
        
        default:
            return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;
}


RESOURCES.H

C#
#define IDR_MYMENU
#define IDI_MYICON
#define ID_FILE_EXIT
#define ID_STUFF_GO


RESOURCES.RC

SQL
#include "resources.h"
IDR_MYMENU MENU
BEGIN
    POPUP "&File"
    BEGIN
        MENUITEM "E&xit", ID_FILE_EXIT
    END
    POPUP "&Stuff"
    BEGIN
        MENUITEM "&Go", ID_STUFF_GO
        MENUITEM "G&o somewhere else", 0, GRAYED
    END
END
IDI_MYICON ICON "menu_one.ico"



MENURES.H

C#
#define IDD_ABOUT
#define ID_HELP_ABOUT



MENURES.RC
#include "menures.h"

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
Posted
Updated 17-Jul-11 13:37pm
v2

1 solution

You probably need to #include "resources.h" at the top of the file.

Download Thinking in C++ 2nd Edition by Bruce Eckel[^], it will explain some things you'll probably need to know.

Good luck :)

Best regards
Espen Harlinn
 
Share this answer
 
Comments
thomas struss 17-Jul-11 20:20pm    
Thanks for the response! I do have "resources.h" included at the top of my main file and in my .rc file. Any other ideas are welcome.
Espen Harlinn 18-Jul-11 5:55am    
#include "MENURES.H" too
thomas struss 18-Jul-11 11:24am    
Thanks for the reply. I have menures.h included too, though. Anybody know of any books or websites with more info? The best I've found is the website I mentioned and a web-book with MFC apps. Frustrating...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900