Нужна помощь с элементами управления меню..
Есть ли другой способ работы с элементами управления меню ? В моем коде у меня есть обширное меню с большим количеством элементов(пунктов подменю). Но проблема в том, как написать меньше строк, когда пользователь получает доступ к элементу из подменю, множество статических элементов управления, таких как кнопки и статические окна и т.д., появляется в главном окне, как и должно быть, но когда вы переходите к другому элементу меню, мне нужно написать кучу кода в VM_COMMAND для любого отдельного идентификатора и отправить тонны сообщений, чтобы закрыть их, чтобы они не оставались в клиентской области.
#include <windows.h> #include "resources.h" 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; }
Что я уже пробовал:
Я только попробовал с SendMessage..