Need help with the Menu controls..

Is there another way to work with Menu controls ? In my code I have a vast menu with a lots of elements(sub menu items). But the problem is, how to write less lines, when the user access an item from the sub menu, lots of static controls like buttons and static windows etc. appears in the main window as they should, but when you pass to another element of the menu I need to write a bunch of code in the VM_COMMAND for any single ID, and send tons of message to close them, way that they don't remain in the client area.

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
HWND hAmazonB, hAssassinB, hNecromancerB, hBarbarianB, hPaladinB, hSorceressB, hDruidB, hAmazonS, hAssassinS, hNecromancerS, hBarbarianS, hPaladinS, hSorceressS, hDruidS;

void CharBasics(HWND hWnd)
{
    hAmazonB        = CreateWindowW(L"button", NULL, WS_CHILD | WS_VISIBLE | BS_BITMAP,
                             0, 0, 80, 32, hWnd, (HMENU)IDBAMAB, NULL, NULL);
    SendMessage(hAmazonB, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBut1);
    hAssassinB      = CreateWindowW(L"button", NULL, WS_CHILD | WS_VISIBLE | BS_BITMAP,
                             81, 0, 80, 32, hWnd, (HMENU)IDBASAB, NULL, NULL);
    SendMessage(hAssassinB, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBut2);
    hNecromancerB   = CreateWindowW(L"button", NULL, WS_CHILD | WS_VISIBLE | BS_BITMAP,
                             162, 0, 80, 32, hWnd, (HMENU)IDBNECB, NULL, NULL);
    SendMessage(hNecromancerB, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBut3);
    hBarbarianB     = CreateWindowW(L"button", NULL, WS_CHILD | WS_VISIBLE | BS_BITMAP,
                             243, 0, 80, 32, hWnd, (HMENU)IDBBARB, NULL, NULL);
    SendMessage(hBarbarianB, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBut4);
    hPaladinB       = CreateWindowW(L"button", NULL, WS_CHILD | WS_VISIBLE | BS_BITMAP,
                             324, 0, 80, 32, hWnd, (HMENU)IDBPALB, NULL, NULL);
    SendMessage(hPaladinB, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBut5);
    hSorceressB     = CreateWindowW(L"button", NULL, WS_CHILD | WS_VISIBLE | BS_BITMAP,
                             405, 0, 80, 32, hWnd, (HMENU)IDBSORB, NULL, NULL);
    SendMessage(hSorceressB, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBut6);
    hDruidB         = CreateWindowW(L"button", NULL, WS_CHILD | WS_VISIBLE | BS_BITMAP,
                             486, 0, 80, 32, hWnd, (HMENU)IDBDRUB, NULL, NULL);
    SendMessage(hDruidB, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBut7);
    hCBdesc         = CreateWindowW(L"static", L"   Character Basics Description",
                                    WS_CHILD | WS_VISIBLE | SS_CENTER, 567, 0, 167, 32, hWnd, NULL, NULL, NULL);
    hCloseAll       = CreateWindowW(L"button", NULL, WS_CHILD | WS_VISIBLE | BS_BITMAP,
                                    735, 0, 60, 32, hWnd, (HMENU)IDBCLOSE, NULL, NULL);
    SendMessage(hCloseAll, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBut8);

}
void CharSkills(HWND hWnd)
{
    hAmazonS        = CreateWindowW(L"button", NULL, WS_CHILD | WS_VISIBLE | BS_BITMAP,
                             0, 0, 80, 32, hWnd, (HMENU)IDBAMAS, NULL, NULL);
    SendMessage(hAmazonS, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBut1);
    hAssassinS      = CreateWindowW(L"button", NULL, WS_CHILD | WS_VISIBLE | BS_BITMAP,
                             81, 0, 80, 32, hWnd, (HMENU)IDBASAS, NULL, NULL);
    SendMessage(hAssassinS, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBut2);
    hNecromancerS   = CreateWindowW(L"button", NULL, WS_CHILD | WS_VISIBLE | BS_BITMAP,
                             162, 0, 80, 32, hWnd, (HMENU)IDBNECS, NULL, NULL);
    SendMessage(hNecromancerS, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBut3);
    hBarbarianS     = CreateWindowW(L"button", NULL, WS_CHILD | WS_VISIBLE | BS_BITMAP,
                             243, 0, 80, 32, hWnd, (HMENU)IDBBARS, NULL, NULL);
    SendMessage(hBarbarianS, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBut4);
    hPaladinS       = CreateWindowW(L"button", NULL, WS_CHILD | WS_VISIBLE | BS_BITMAP,
                             324, 0, 80, 32, hWnd, (HMENU)IDBPALS, NULL, NULL);
    SendMessage(hPaladinS, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBut5);
    hSorceressS     = CreateWindowW(L"button", NULL, WS_CHILD | WS_VISIBLE | BS_BITMAP,
                             405, 0, 80, 32, hWnd, (HMENU)IDBSORS, NULL, NULL);
    SendMessage(hSorceressS, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBut6);
    hDruidS         = CreateWindowW(L"button", NULL, WS_CHILD | WS_VISIBLE | BS_BITMAP,
                             486, 0, 80, 32, hWnd, (HMENU)IDBDRUS, NULL, NULL);
    SendMessage(hDruidS, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBut7);
    hCSdesc         = CreateWindowW(L"static", L"   Character Skills Description",
                                    WS_CHILD | WS_VISIBLE | SS_CENTER, 567, 0, 167, 32, hWnd, NULL, NULL, NULL);
    hCloseAll       = CreateWindowW(L"button", NULL, WS_CHILD | WS_VISIBLE | BS_BITMAP,
                                    735, 0, 60, 32, hWnd, (HMENU)IDBCLOSE, NULL, NULL);
    SendMessage(hCloseAll, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBut8);
}
void ReadOnlyControl(HWND hWnd)
{
    hReadOnly = CreateWindowW(L"edit", NULL, WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY,
                              0, 34, 795, 445, hWnd, NULL, NULL, NULL);
}
//Main Loop
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
{
    switch(msg)
    {
    case WM_COMMAND:
        switch(wp)
        {
        case ID_BASICS:
            {
SendMessage((HWND)hAmazonB, WM_CLOSE, 0, 0);
                SendMessage((HWND)hAssassinB, WM_CLOSE, 0, 0);
                SendMessage((HWND)hNecromancerB, WM_CLOSE, 0, 0);
                SendMessage((HWND)hBarbarianB, WM_CLOSE, 0, 0);
                SendMessage((HWND)hPaladinB, WM_CLOSE, 0, 0);
                SendMessage((HWND)hSorceressB, WM_CLOSE, 0, 0);
                SendMessage((HWND)hDruidB, WM_CLOSE, 0, 0);
                SendMessage((HWND)hAmazonS, WM_CLOSE, 0, 0);
                SendMessage((HWND)hAssassinS, WM_CLOSE, 0, 0);
                SendMessage((HWND)hNecromancerS, WM_CLOSE, 0, 0);
                SendMessage((HWND)hBarbarianS, WM_CLOSE, 0, 0);
                SendMessage((HWND)hPaladinS, WM_CLOSE, 0, 0);
                SendMessage((HWND)hSorceressS, WM_CLOSE, 0, 0);
                SendMessage((HWND)hDruidS, WM_CLOSE, 0, 0);
                SendMessage((HWND)hReadOnly, WM_CLOSE, 0, 0);
                sendmessage((HWND))
                CharBasics(hWnd);
                return DefWindowProcW(hWnd, msg, wp, lp);
            }
        case ID_SKILLS:
            {
SendMessage((HWND)hAmazonB, WM_CLOSE, 0, 0);
                SendMessage((HWND)hAssassinB, WM_CLOSE, 0, 0);
                SendMessage((HWND)hNecromancerB, WM_CLOSE, 0, 0);
                SendMessage((HWND)hBarbarianB, WM_CLOSE, 0, 0);
                SendMessage((HWND)hPaladinB, WM_CLOSE, 0, 0);
                SendMessage((HWND)hSorceressB, WM_CLOSE, 0, 0);
                SendMessage((HWND)hDruidB, WM_CLOSE, 0, 0);
                SendMessage((HWND)hAmazonS, WM_CLOSE, 0, 0);
                SendMessage((HWND)hAssassinS, WM_CLOSE, 0, 0);
                SendMessage((HWND)hNecromancerS, WM_CLOSE, 0, 0);
                SendMessage((HWND)hBarbarianS, WM_CLOSE, 0, 0);
                SendMessage((HWND)hPaladinS, WM_CLOSE, 0, 0);
                SendMessage((HWND)hSorceressS, WM_CLOSE, 0, 0);
                SendMessage((HWND)hDruidS, WM_CLOSE, 0, 0);
                SendMessage((HWND)hReadOnly, WM_CLOSE, 0, 0);
                CharSkills(hWnd);
                return DefWindowProcW(hWnd, msg, wp, lp);
            }
        }
   default:
        return DefWindowProcW(hWnd, msg, wp, lp);
    }
    return 0;
}
Last edited on
You might consider to use arrays or std::vector for those values which are different (HMENU)IDB..., (LPARAM)hBut..., etc.

For the repeating stuff and the calculation of the position you may use loops.
Topic archived. No new replies allowed.