Whats wrong with my Menu?

I have a menu i am trying to do, i got it from
MSDN but i cant figure out whats wrong, it just keeps saying syntax error, i wish it would tell me so i can figure it out but it wont.

Main.cpp:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "resource.h"
#include <fstream>
#include <string>

using namespace std;

HINSTANCE hInst;

BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{


    switch(uMsg)
    {
        case WM_INITDIALOG:
            /*
             * TODO: Add code to initialize the dialog.
             */
            return TRUE;

        case WM_CLOSE:

            EndDialog(hwndDlg, 0);
            return TRUE;

        case WM_COMMAND:

            switch(LOWORD(wParam))
            {
                case Save:
                    ofstream file("save.txt");

                    char tmp[MAX_PATH+1] = {0};
                    GetDlgItemText(hwndDlg, 3, tmp, MAX_PATH);

                    file << tmp;
                    {
                        HWND Disable = GetDlgItem(hwndDlg, Save);
                        EnableWindow(Disable, FALSE);
                    }
                    {
                        Sleep(1000);
                        HWND Enable = GetDlgItem(hwndDlg, Save);
                        EnableWindow(Enable, TRUE);
                    }
                    file.close();
            }

    }

    return FALSE;
}


int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
    hInst = hInstance;

    // The user interface is a modal dialog box
    return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DialogProc);
}



Resource.rc:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "resource.h"

DLG_MAIN DIALOGEX 280, 170, 310, 165

CAPTION "TexEd V. 1.0.0 Alpha"

FONT 8, "Tahoma"

STYLE WS_VSCROLL
STYLE DS_SETFONT | DS_FIXEDSYS | WS_MINIMIZEBOX | WS_CAPTION | WS_SYSMENU


BEGIN
    EDITTEXT 3, 0, 0, 300, 150, ES_MULTILINE | ES_WANTRETURN | ES_AUTOHSCROLL | ES_AUTOVSCROLL
    CONTROL "Save", Save, "Button", 0x10010000, 0, 150, 300, 15
    
    Menuone MENU
{
     MENUITEM "&Soup", 100
     MENUITEM "S&alad", 101
     POPUP "&Entree"
     {
          MENUITEM "&Fish", 200
          MENUITEM "&Chicken", 201
          POPUP "&Beef"
          {
               MENUITEM "&Steak", 301
               MENUITEM "&Prime Rib", 302
          }
     }
     MENUITEM "&Dessert", 103
}

END

Icon ICON "Resources/Npad.ico"




Resource.h:

1
2
3
4
5
6
7
8
9
#include <windows.h>

// ID of Main Dialog
#define DLG_MAIN 101

#define Save 1
#define text 2
#define Icon 3
#define Menuone 4 
First of all, you can't define MENU inside DIALOG
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "resource.h"

DLG_MAIN DIALOGEX 280, 170, 310, 165

CAPTION "TexEd V. 1.0.0 Alpha"

FONT 8, "Tahoma"

STYLE WS_VSCROLL
STYLE DS_SETFONT | DS_FIXEDSYS | WS_MINIMIZEBOX | WS_CAPTION | WS_SYSMENU

// Dialog
BEGIN
    EDITTEXT 3, 0, 0, 300, 150, ES_MULTILINE | ES_WANTRETURN | ES_AUTOHSCROLL | ES_AUTOVSCROLL
    CONTROL "Save", Save, "Button", 0x10010000, 0, 150, 300, 15
END

// Menu
Menuone MENU
{
     MENUITEM "&Soup", 100
     MENUITEM "S&alad", 101
     POPUP "&Entree"
     {
          MENUITEM "&Fish", 200
          MENUITEM "&Chicken", 201
          POPUP "&Beef"
          {
               MENUITEM "&Steak", 301
               MENUITEM "&Prime Rib", 302
          }
     }
     MENUITEM "&Dessert", 103
}


Icon ICON "Resources/Npad.ico"


And you have to assign the menu to the dialog using LoadMenu() and SetMenu() functions:
1
2
3
4
5
6
        case WM_INITDIALOG:
        {
           HMENU hMenu=LoadMenu(GetModuleHandle(0),MAKEINTRESOURCE(Menuone));
           SetMenu(hwndDlg,hMenu);
            return TRUE;           
        }

Ok i got it to work, now how do i make it so when i click a menu item it does something? i have this:

Main.cpp:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "resource.h"
#include <fstream>
#include <string>

using namespace std;

HINSTANCE hInst;

BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{


    switch(uMsg)
    {
        case WM_INITDIALOG: //Initiates the window
            {
                HWND Grey = GetDlgItem(hwndDlg, Load);
                EnableWindow(Grey, FALSE);
            }
            //Menu Initialization
            {
                HMENU hMenu = LoadMenu(GetModuleHandle(0), MAKEINTRESOURCE(Menuone));
                SetMenu(hwndDlg, hMenu);
            }
            return TRUE;

        case WM_CLOSE:

            EndDialog(hwndDlg, 0);
            return TRUE;

        case WM_COMMAND:

            switch(LOWORD(wParam))
            {
                case Save:
                    {
                        ofstream file("save.txt");

                        char tmp[MAX_PATH+1] = {0};
                        GetDlgItemText(hwndDlg, 3, tmp, MAX_PATH);

                        file << tmp;
                        file.close();
                    }
                    {
                        HWND Disable = GetDlgItem(hwndDlg, Save);
                        EnableWindow(Disable, FALSE);
                    }
                    Sleep(500);
                    {
                        HWND Enable = GetDlgItem(hwndDlg, Save);
                        EnableWindow(Enable, TRUE);
                    }
                    return TRUE;
                    break;

                case Menuone:
                    MessageBox(hwndDlg, "You clicked Save", "Save", MB_ICONMASK);
            }

    }

    return FALSE;
}


int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
    hInst = hInstance;

    // The user interface is a modal dialog box
    return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DialogProc);
}



Resource.rc:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "resource.h"

DLG_MAIN DIALOGEX 280, 170, 300, 192

CAPTION "TexEd V. 1.0.1 Alpha"

FONT 8, "Tahoma"

STYLE DS_SETFONT | DS_FIXEDSYS | WS_MINIMIZEBOX | WS_CAPTION | WS_SYSMENU


BEGIN
    EDITTEXT 3, 0, 0, 300, 150, ES_MULTILINE | ES_WANTRETURN | ES_AUTOHSCROLL | ES_AUTOVSCROLL
    PUSHBUTTON "Save", Save, 0, 150, 300, 15
    PUSHBUTTON "Load", Load, 0, 165, 300, 15
END

    Menuone MENU
    {
      POPUP "File"
      {
          MENUITEM "Save", 2
          MENUITEM "Load", 3
      }

    }

//Reference
 /*
{
     MENUITEM "&Soup", 100
     MENUITEM "&Salad", 101
     POPUP "&Entree"
     {
          MENUITEM "&Fish", 200
          MENUITEM "&Chicken", 201
          POPUP "&Beef"
          {
               MENUITEM "&Steak", 301
               MENUITEM "&Prime Rib", 302
          }
     }
     MENUITEM "&Dessert", 103
}
*/

Icon ICON "Resources/Txt.ico"


Again, you don't assign meaningful identifiers to your resources
1
2
3
4
5
// resource.h
// ..
#define ID_LOAD  5
#define ID_SAVE  6
// ... 


1
2
3
4
5
6
7
8
9
// resource.rc
Menuone MENU
    {
      POPUP "File"
      {
          MENUITEM "Save", ID_SAVE
          MENUITEM "Load", ID_LOAD
      }
    }


Now you can use the menu id in your message loop:
1
2
3
4
5
6
7
8
9
10
11
case WM_COMMAND:

            switch(LOWORD(wParam))
            {
               // ...
                case ID_SAVE:
                    MessageBox(hwndDlg, "You clicked Save", "Save", MB_ICONMASK);
                    break;
            }

    }





--
You might find this helpful: http://www.resedit.net/
I got it thanks. I did try Res edit once but didnt know how to set it all up, i tried looking up help for it but didnt find much. I tried doing it myself and it sort of worked, i did make something but when i ran the program none of the buttons or anything showed up.
Topic archived. No new replies allowed.