Error: Duplicate Case Value

I'm not sure what I'm doing wrong here but if somebody can offer some advice I'd appreciate it.

First the error message I receive is:

...\main.cpp: In function 'LRESULT DialogWndProc(HWND, UINT, WPARAM, LPARAM)':
...\main.cpp:105:13: error: duplicate case value
...\main.cpp:104:2: error: previously used here


I'm also not sure what a good way to organize multiple callback's would be. Is it customary to move callbacks prototypes into their own .cpp then #include them in the main.cpp. I guess I could move the callbacks to the end of the main.cpp and then have the declarations in the header file, I'm just not sure what people usually prefer.

I don't normally like to clutter up the top of my main.cpp with a bunch of declarations and prototypes at the top.

I've mixed a few other parts of the winforgers tutorial together, and everything was working until I tried to mix a modeless dialog with a modal dialog.

I haven't added in menu options for ID_DIALOG_SHOW or ID_DIALOG_HIDE yet, but I don't think that has anything to do with my compilation issues right now.

Anyways, here is my broken code.


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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include <iostream>
#include "win_skel.h"

//Global Variable For Modeless Dialog Box handle
HWND g_hToolbar = NULL;

BOOL CALLBACK ToolDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
    switch(Message)
    {
        case WM_COMMAND:
            switch(LOWORD(wParam))
            {
                case IDC_PRESS:
                    MessageBox(hwnd, "Hi!", "This is a message",
                        MB_OK | MB_ICONEXCLAMATION);
                break;
                case IDC_OTHER:
                    MessageBox(hwnd, "Bye!", "This is also a message",
                        MB_OK | MB_ICONEXCLAMATION);
                break;
            }
        break;
        default:
            return FALSE;
    }
    return TRUE;
}

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

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine, int iCmdShow)
{
     //For Main Window
     MSG msg;
     HWND hWinMainWnd;
     TCHAR szNoRegister[]=_T("Unable To Register Window Class! Operation Canceled.");

    if(!DialogRegisterClass(hInstance)) {
         MessageBox(GetDesktopWindow(),szNoRegister,szAppName,MB_ICONERROR);
         return FALSE;
         }

     hWinMainWnd=CreateDialog(hInstance, szClassName, 0, NULL);

     ShowWindow(hWinMainWnd, iCmdShow);
     UpdateWindow(hWinMainWnd);

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

     return (int)msg.wParam;
}

ATOM DialogRegisterClass(HINSTANCE hInst)
{
     WNDCLASSEX wcex;

     wcex.cbSize = sizeof(WNDCLASSEX);
     wcex.style = CS_HREDRAW | CS_VREDRAW;
     wcex.lpfnWndProc = DialogWndProc;
     wcex.cbClsExtra	 = 0;
     wcex.cbWndExtra = DLGWINDOWEXTRA; // this required if dialog box is main window
     wcex.hInstance	= hInst;
     wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
     wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
     wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
     wcex.lpszMenuName = MAKEINTRESOURCE(IDM_DIALOG_MENU);
     wcex.lpszClassName = szClassName;
     wcex.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON), IMAGE_ICON, 16, 16, 0);

     return RegisterClassEx(&wcex);

}

LRESULT CALLBACK DialogWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch(message)
	{
	case WM_CREATE:
            case WM_CREATE:
            g_hToolbar = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_TOOLBAR),
            hwnd, ToolDlgProc);
            if(g_hToolbar != NULL)
            {
                ShowWindow(g_hToolbar, SW_SHOW);
            }
            else
            {
                MessageBox(hwnd, "CreateDialog returned NULL", "Warning!",
                    MB_OK | MB_ICONINFORMATION);
            }
    break;

	case WM_COMMAND:
	case WM_SYSCOMMAND:
	switch(LOWORD(wParam))
	{
		case IDOK: //Pre-defined Windows Message
		    std::cout << "\nUse File >> Exit Application to quit";
        break;
        case ID_CUSTOM1: //Custom Windows Message I defined
            std::cout << "\nHello World";
        break;
		case IDCANCEL: //Another pre-defined windows message
		     PostQuitMessage(0);
		     return 0;
        //Dialog Box controls
        case ID_HELP_ABOUT:
        {
            int ret = DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_ABOUT), hwnd, AboutDlgProc);
            if(ret == IDOK){
                MessageBox(hwnd, "Dialog exited with IDOK.", "Notice",
                    MB_OK | MB_ICONINFORMATION);
            }
            else 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;
        //Modeless Dialog Controls
        case ID_DIALOG_SHOW:
            ShowWindow(g_hToolbar, SW_SHOW);
        break;
        case ID_DIALOG_HIDE:
            ShowWindow(g_hToolbar, SW_HIDE);
        break;
        default:
            break;
	}
	break;

	case WM_CLOSE:
	case WM_DESTROY:
	    DestroyWindow(g_hToolbar);
		PostQuitMessage(0);
	}
	return DefWindowProc(hwnd, message, wParam, lParam);
}


win_skel.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <Windows.h>
#include <tchar.h>

#define szClassName _T("IDD_VANILLA_DIALOG")
#define szAppName _T("Simple Dialog Window")

#define IDC_STATIC -1
#define IDM_DIALOG_MENU 101
#define ID_CUSTOM1 9001 //I Think using the 9000 range is ok for custom messages.
#define IDI_MYICON 9002//for Icons
#define IDD_ABOUT 9003 //for dialog box
#define ID_HELP_ABOUT 9004 //for dialog box message
#define IDD_TOOLBAR 9005 //for a modeless dialog box
#define IDC_PRESS 9006 //Modeless dialogbox message 1
#define IDC_OTHER 9007 //modeless dialogbox message 2
#define ID_DIALOG_SHOW 9008 //show modeless dialog box
#define ID_DIALOG_HIDE 9009 //hide modeless dialog box

int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int);
ATOM DialogRegisterClass(HINSTANCE);
LRESULT CALLBACK DialogWndProc(HWND,UINT,WPARAM,LPARAM);


win_skel.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
51
52
53
54
55
56
57
#include "win_skel.h"

//The buttons OK and Cancel
IDD_VANILLA_DIALOG DIALOGEX 0, 0, 186, 105
STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_VISIBLE |
		WS_BORDER | WS_CAPTION | WS_DLGFRAME | WS_GROUP | WS_SYSMENU
EXSTYLE WS_EX_OVERLAPPEDWINDOW | WS_EX_APPWINDOW
CLASS szClassName
CAPTION "Vanilla Dialog"
FONT 8, "Ms Shell Dlg 2", 400, 0, 1
BEGIN
    DEFPUSHBUTTON   "OK", IDOK, 78, 73, 50, 14
    PUSHBUTTON      "Cancel", ID_HELP_ABOUT, 132, 73, 50, 14
END

//The Menu options
IDM_DIALOG_MENU MENU DISCARDABLE
BEGIN
    POPUP "&File"
    BEGIN
	MENUITEM "Exit Application" ,    IDCANCEL
	MENUITEM "Custom Message" , ID_CUSTOM1
    END
    POPUP "&Edit"
    BEGIN
	MENUITEM "Click On Cancel" ,     IDOK
    END
END

//Popup Dialog Box

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

//Modeless Dialog Box

IDD_TOOLBAR DIALOGEX 0, 0, 98, 52
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION
EXSTYLE WS_EX_TOOLWINDOW
CAPTION "My Dialog Toolbar"
FONT 8, "MS Sans Serif"
BEGIN
    PUSHBUTTON      "&Press This Button",IDC_PRESS,7,7,84,14
    PUSHBUTTON      "&Or This One",IDC_OTHER,7,31,84,14
END

//The Icons
IDI_MYICON ICON "menu_one.ico"
The error message says it all:
102
103
104
105
switch(message)
{
case WM_CREATE:
    case WM_CREATE: // Whoops! Duplicate case value 
*Slaps forehead*

Thanks >_<
Topic archived. No new replies allowed.