Dialog window reinitialisation issue - c++

I have the following issue. In my c++ project I wanted to create a dialog window to input settings for the application to be used.
The window is created when you click in the menu: application -> robot settings.
I created the window in the following way:
void Robot_Settings::CreateSettingsWindow(HWND hWnd, RECT& windowSize)
{
GetWindowRect(hWnd, &windowSize);
HWND hSDlg = CreateWindowW(
L"SettingsDialogClass",
NULL,
WS_OVERLAPPED | WS_MINIMIZEBOX | WS_SYSMENU | WS_VISIBLE | WS_CLIPSIBLINGS,
(windowSize.right - SETTINGS_WINDOW_SIZE) / 2,
(windowSize.bottom - SETTINGS_WINDOW_SIZE) / 2,
SETTINGS_WINDOW_SIZE,
SETTINGS_WINDOW_SIZE,
hWnd,
NULL,
NULL,
NULL
);
}
then I have the window procedure:
LRESULT CALLBACK Robot_Settings::SettingsDialogProcedure(HWND hSDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_COMMAND:
switch (wParam)
{
case SETTINGS_BUTTON_SAVE:
collectInputs(hSDlg);
break;
case SETTINGS_BUTTON_CANCEL:
DestroyWindow(hSDlg);
break;
}
case WM_CREATE:
AddControlsToSettingsDialog(hSDlg);
break;
case WM_DESTROY:
DestroyWindow(hSDlg);
break;
default:
return DefWindowProcW(hSDlg, msg, wParam, lParam);
}
}
And I add the inner controls on WM_CREATE:
void Robot_Settings::AddControlsToSettingsDialog(HWND hSDlg)
{
// Create Text info about amount input
CreateWindowW(
L"Static",
L"Input the amount of robots you want to get simulated:",
WS_VISIBLE | WS_CHILD,
(int)(SETTINGS_WINDOW_SIZE * 0.15),
(int)(SETTINGS_WINDOW_SIZE * 0.2),
(int)(SETTINGS_WINDOW_SIZE / 2),
(int)(SETTINGS_WINDOW_SIZE / 2),
hSDlg,
NULL,
NULL,
NULL
);
// Create Text info about formation input
CreateWindowW(
L"Static",
L"Input the formation of th robots in this format -> \"x-x-x-x\" where x is the amount of robots you want to have in each row:",
WS_VISIBLE | WS_CHILD,
(int)(SETTINGS_WINDOW_SIZE * 0.15),
(int)(SETTINGS_WINDOW_SIZE * 0.4),
(int)(SETTINGS_WINDOW_SIZE / 2),
(int)(SETTINGS_WINDOW_SIZE / 2),
hSDlg,
NULL,
NULL,
NULL
);
// Create Text info about speed input
CreateWindowW(
L"Static",
L"Input the speed calculated in squares per second at which you want the robots to move:",
WS_VISIBLE | WS_CHILD,
(int)(SETTINGS_WINDOW_SIZE * 0.15),
(int)(SETTINGS_WINDOW_SIZE * 0.6),
(int)(SETTINGS_WINDOW_SIZE / 2),
(int)(SETTINGS_WINDOW_SIZE / 2),
hSDlg,
NULL,
NULL,
NULL
);
// Create TextField for amount input
hAmount = CreateWindowW(
L"Edit",
L"",
WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP,
(int)(SETTINGS_WINDOW_SIZE * 0.7),
(int)(SETTINGS_WINDOW_SIZE * 0.2),
100,
20,
hSDlg,
NULL,
NULL,
NULL
);
//formation radio buttons
CreateWindowW(
L"BUTTON",
L"Formation",
WS_VISIBLE | WS_CHILD | BS_GROUPBOX,
(int)(SETTINGS_WINDOW_SIZE * 0.7),
(int)(SETTINGS_WINDOW_SIZE * 0.35),
120,
120,
hSDlg,
NULL,
NULL,
NULL);
hTriangle = CreateWindowW(
L"BUTTON",
L"Triangle",
WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP,
(int)(SETTINGS_WINDOW_SIZE * 0.72),
(int)(SETTINGS_WINDOW_SIZE * 0.4),
100,
20,
hSDlg,
(HMENU) ID_RADIO_TRIANGLE,
NULL,
NULL);
hRectangle = CreateWindowW(
L"BUTTON",
L"Rectangle",
WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP,
(int)(SETTINGS_WINDOW_SIZE * 0.72),
(int)(SETTINGS_WINDOW_SIZE * 0.45),
100,
20,
hSDlg,
(HMENU) ID_RADIO_RECTANGLE,
NULL,
NULL);
hRhombus = CreateWindowW(
L"BUTTON",
L"Rhombus",
WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP,
(int)(SETTINGS_WINDOW_SIZE * 0.72),
(int)(SETTINGS_WINDOW_SIZE * 0.5),
100,
20,
hSDlg,
(HMENU) ID_RADIO_RHOMBUS,
NULL,
NULL);
// Create TextField for speed input
hSpeed = CreateWindowW(
L"Edit",
L"",
WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP,
(int)(SETTINGS_WINDOW_SIZE * 0.7),
(int)(SETTINGS_WINDOW_SIZE * 0.6),
100,
20,
hSDlg,
NULL,
NULL,
NULL
);
// Create button Cancel
CreateWindowW(
L"Button",
L"Cancel",
WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP,
(int)(SETTINGS_WINDOW_SIZE * 0.7),
(int)(SETTINGS_WINDOW_SIZE * 0.8),
100,
40,
hSDlg,
(HMENU)SETTINGS_BUTTON_CANCEL,
NULL,
NULL
);
// Create button Save
CreateWindowW(
L"Button",
L"Save",
WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP,
(int)(SETTINGS_WINDOW_SIZE * 0.7 - 110),
(int)(SETTINGS_WINDOW_SIZE * 0.8),
100,
40,
hSDlg,
(HMENU)SETTINGS_BUTTON_SAVE,
NULL,
NULL
);
}
So, my issue is, that every time I try to input any text or click on the radio buttons the window seems to be reinitialized or repainted (can't figure out which is happening but it's not a normal behaviour anyway). And if you check the rectangle radiobutton the window closes.
You can find the entire project at:
https://github.com/JamesHawkJ/cpp/tree/master/WycieczkaRobotow
Can you please help me solve this problem?

Every time you receive a WM_COMMAND message from any control other than SETTINGS_BUTTON_SAVE or SETTINGS_BUTTON_CANCEL, your window procedure falls through to WM_CREATE case and calls AddControlsToSettingsDialog. You are creating more and more child windows, stacked on top of each other.
Also, SettingsDialogProcedure is declared to return LRESULT, but it may reach the closing brace without encountering a return statement. This exhibits undefined behavior.

Related

Newline on win32 gui textbox when using SetWindowText

I create a textbox on a win32 gui app. Later on I'm trying to set a text to it but newline "\n" isn't working when using SetWindowText
g_ButtonManager.hWndThirtyText = CreateWindowExW(WS_EX_CLIENTEDGE, TEXT("Edit"), TEXT(""),
WS_CHILD | WS_VISIBLE | WS_BORDER | ES_MULTILINE,
10, 95, //x,y
200, 60, //width, height
hWnd, (HMENU)IDM_THIRTYTEXT, NULL, NULL);
Even though I:
SetWindowTextA(g_ButtonManager.hWndThirtyText, "Hello\nThere");
It displays HelloThere in the same line.
---Edit
Even with | ES_WANTRETURN
g_ButtonManager.hWndThirtyText = CreateWindowExW(WS_EX_CLIENTEDGE, TEXT("Edit"), TEXT("Hello\nMy\nFriend"),
WS_CHILD | WS_VISIBLE | WS_BORDER | ES_MULTILINE | ES_WANTRETURN,,
10, 95, //x,y
200, 60, //width, height
hWnd, (HMENU)IDM_THIRTYTEXT, NULL, NULL);
Will not work.
Oh, I figured it.
\r\n is required for a newline.

c++ windows application Static text over edit window

Hello i am making my first windows application code.
I want to know how can i make a CreateWindow(TEXT("STATIC") child window, inside my main window, in which when the user clicks to add text on it,i want the
CreateWindow(TEXT("STATIC"), TEXT("REPORT") "REPORT" text to dissapear.
(Some of the text is in greek)
Example: like this "Email or username" and "password" texts, that dont interrupt the user
https://www.codecademy.com/login?redirect=about%3A%2F%2Fblank
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
switch(Message) {
case WM_COMMAND:{
break;
}
case WM_CREATE:{
HMENU hMenubar= CreateMenu();
HMENU hFile= CreateMenu();
HMENU hOptions= CreateMenu();
AppendMenu(hMenubar, MF_POPUP, (UINT_PTR)hFile, "File");
AppendMenu(hMenubar, MF_POPUP, NULL, "Edit");
AppendMenu(hMenubar, MF_POPUP, (UINT_PTR)hOptions, "Options");
AppendMenu(hFile, MF_STRING, NULL, "Open");
AppendMenu(hOptions, MF_STRING, NULL, "Correction");
AppendMenu(hOptions, MF_STRING, NULL, "Search");
SetMenu(hwnd,hMenubar);
CreateWindow(TEXT("edit"), TEXT(""),
WS_VISIBLE | WS_CHILD | WS_BORDER | ES_AUTOHSCROLL,
10, 10, 200, 30,
hwnd, (HMENU) ID_NAMEBOX, NULL, NULL
);
CreateWindow(TEXT("STATIC"), TEXT("NAME"),
WS_VISIBLE | WS_CHILD,
10, 10, 200, 30,
hwnd, (HMENU) ID_VNAMEBOX, NULL, NULL
);
CreateWindow(TEXT("edit"), TEXT("CALL1"),
WS_VISIBLE | WS_CHILD | WS_BORDER | ES_AUTOHSCROLL,
220, 10, 200, 30,
hwnd, (HMENU) ID_CALLBOX, NULL, NULL
);
CreateWindow(TEXT("edit"), TEXT("CALL2"),
WS_VISIBLE | WS_CHILD | WS_BORDER | ES_AUTOHSCROLL,
220, 50, 200, 30,
hwnd, (HMENU) ID_CALLBOX, NULL, NULL
);
CreateWindow(TEXT("edit"), TEXT("REPORT"),
WS_VISIBLE | WS_CHILD | WS_BORDER | ES_AUTOHSCROLL,
10, 90, 410, 100,
hwnd, (HMENU) ID_REPORTBOX, NULL, NULL
);
hwnd= CreateWindow(TEXT("button"), TEXT("SUBMIT"),
WS_VISIBLE | WS_CHILD,
55, 50, 100, 30,
hwnd, (HMENU) ID_SUBMITBOX, NULL, NULL
);
break;
}
/* Upon destruction, tell the main thread to stop */
case WM_DESTROY: {
PostQuitMessage(0);
break;
}
/* All other messages (a lot of them) are processed using default procedures */
default:
return DefWindowProc(hwnd, Message, wParam, lParam);
}
return 0;
}

Moving a child control to top

How can i move a control to top of the other when they have overlap together in windows API.
For example i create 2 buttons b1 and b2
HWND b1 = CreateWindow(L"BUTTON", L"button1", WS_CHILD | WS_VISIBLE | WS_TABSTOP,
100, 100, 200, 50, my_Window_handle, (HMENU)100, NULL, NULL);
HWND b2 = CreateWindow(L"BUTTON", L"button2", WS_CHILD | WS_VISIBLE | WS_TABSTOP,
50, 100, 250, 50, my_Window_handle, (HMENU)101, NULL, NULL);
I want to move b1 to top of the b2 or any control.
I used the function SetWindowPos as
SetWindowPos(b1, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
but id does not work correctly.
You don't want the child window to be top most, you want it to be at the top of the z-order. Like this:
SetWindowPos(b1, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
The documentation says for HWND_TOP:
Places the window at the top of the Z order.
Topmost will not work here because the child window must stay at the same z-order as its parent and SetWindowPos with HWND_TOPMOST as Hwnd_InsertAfter will try to change it. Only thing you need here is WS_CLIPSIBLINGS and then b1 will remain on top of b2.
b1 = CreateWindow(L"BUTTON", L"button1", WS_CHILD | WS_VISIBLE | WS_TABSTOP,
100, 100, 200, 50, hWnd, (HMENU)100, NULL, NULL);
b2 = CreateWindow(L"BUTTON", L"button2", WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_CLIPSIBLINGS, 50, 100, 250, 50, hWnd, (HMENU)101, NULL, NULL);
As well as setting the z-order, you need to set the WS_CLIPSIBLINGS style on the controls if they overlap, to stop them drawing over the top of each other.

The Tab-key doesn't works in the child controls

The following is my winapi program that window contains 3 sets of controls:
The controls that created directly in the window
The controls in Group1
The controls in Group2
When I press Tab-key , it only traverse in set1.
Why I can't switch to the child control of the group1 and group2 by Tab-key?
#include <Windows.h>
LRESULT __stdcall WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
switch (message)
{
case WM_CTLCOLORSTATIC:
{
HDC hdcStatic = (HDC)wParam;
SetTextColor(hdcStatic, RGB(0, 0, 255));
SetBkMode(hdcStatic, TRANSPARENT);
return (LRESULT)GetStockObject(NULL_BRUSH);
}
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
////////////////////////////////////////////////////////////////////////////
void CreateEdit(const HWND &parent, const int &x, const int &y, const int &id) {
CreateWindow(L"EDIT", L"", WS_BORDER | WS_CHILD | WS_VISIBLE | WS_TABSTOP, x, y, 200, 20, parent, (HMENU)id, NULL, NULL);
}
////////////////////////////////////////////////////////////////////////////
int __stdcall wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow)
{
WNDCLASSEX wndclass{};
wndclass.cbSize = sizeof(wndclass);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.hInstance = hInstance;
wndclass.hbrBackground = CreateSolidBrush(RGB(255, 128, 255));
wndclass.lpszClassName = L"test";
RegisterClassEx(&wndclass);
HWND hWndMainWindow = CreateWindow(
wndclass.lpszClassName,
L"test",
WS_EX_OVERLAPPEDWINDOW | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_VISIBLE,
100, 100, 500, 500,
NULL, NULL, hInstance, NULL);
::ShowWindow(hWndMainWindow, SW_SHOW);
::UpdateWindow(hWndMainWindow);
//Creating Controls~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int x = 10, y = 20, id = 100;
HWND g1 = CreateWindow(L"button", L"Group1", WS_CHILD | WS_VISIBLE | BS_GROUPBOX | WS_TABSTOP | WS_GROUP, 0, 50, 220, 200, hWndMainWindow, (HMENU)++id, NULL, NULL);
//Controls in Group1
CreateEdit(g1, x, (y += 30), ++id);
CreateEdit(g1, x, (y += 30), ++id);
CreateEdit(g1, x, (y += 30), ++id);
CreateEdit(g1, x, (y += 30), ++id);
HWND g2 = CreateWindow(L"button", L"Group2", WS_CHILD | WS_VISIBLE | BS_GROUPBOX | WS_TABSTOP | WS_GROUP, 260, 50, 220, 200, hWndMainWindow, (HMENU)++id, NULL, NULL);
y = 20;
//Controls in Group2
CreateEdit(g2, x, (y += 30), ++id);
CreateEdit(g2, x, (y += 30), ++id);
CreateEdit(g2, x, (y += 30), ++id);
CreateEdit(g2, x, (y += 30), ++id);
//The controls that create directly in the main window
y = 270;
CreateWindow(L"static", L"Main Window Controls", WS_CHILD | WS_VISIBLE, x, y, 200, 30, hWndMainWindow, (HMENU)++id, NULL, NULL);
CreateEdit(hWndMainWindow, x, (y += 30), ++id);
CreateEdit(hWndMainWindow, x, (y += 30), ++id);
CreateEdit(hWndMainWindow, x, (y += 30), ++id);
CreateEdit(hWndMainWindow, x, (y += 30), ++id);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
MSG msg;
while (GetMessage(&msg, NULL, 0, 0) > 0) {
if (!IsDialogMessage(hWndMainWindow, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int)msg.wParam;
}
The two child windows that host "Group1" and "Group2" both need to be marked as "control parents" with the WS_EX_CONTROLPARENT style. This style means:
The window itself contains child windows that should take part in
dialog box navigation. If this style is specified, the dialog manager
recurses into children of this window when performing navigation
operations such as handling the TAB key, an arrow key, or a keyboard
mnemonic
Change your code to create those windows as follows:
HWND g1 = CreateWindowEx(WS_EX_CONTROLPARENT, L"button", L"Group1", WS_CHILD | WS_VISIBLE | BS_GROUPBOX | WS_TABSTOP | WS_GROUP, 0, 50, 220, 200, hWndMainWindow, (HMENU)++id, NULL, NULL);
HWND g2 = CreateWindowEx(WS_EX_CONTROLPARENT, L"button", L"Group2", WS_CHILD | WS_VISIBLE | BS_GROUPBOX | WS_TABSTOP | WS_GROUP, 260, 50, 220, 200, hWndMainWindow, (HMENU)++id, NULL, NULL);
(As an aside, it seems wrong to make your windows children of the groupbox. They don't need to be - you can just position them inside it but make them siblings of it instead of children. The groupbox is specifically designed to work this way - I don't know how well it will work with the controls as children.)
Since you're not creating a dialog box, your main window should be created with the WS_EX_CONTROLPARENT style.
Make sure that you only place this style on your main window. The child windows should not be using this style.

Use radio buttons for switching different views in the main window

I have an application in Win32/C++ that has three buttons located in the left side of the main window. When clicking on one of them, a group of radiobuttons has to be displayed to allow the user to switch views among different submenus.
The code looks like this:
case WM_CREATE:
{
HWND hWndButton=CreateWindowEx(NULL,
"BUTTON",
"Inserting",
WS_TABSTOP|WS_VISIBLE|
WS_CHILD|BS_DEFPUSHBUTTON,
10,
10,
100,
24,
hWnd,
(HMENU)INSERT_BUTTON,
GetModuleHandle(NULL),
NULL);
HWND hWndButton2=CreateWindowEx(NULL,
"BUTTON",
"Listing",
WS_TABSTOP|WS_VISIBLE|
WS_CHILD|BS_DEFPUSHBUTTON,
10,
60,
100,
24,
hWnd,
(HMENU)LIST_BUTTON,
GetModuleHandle(NULL),
NULL);
HWND hWndButton3=CreateWindowEx(NULL,
"BUTTON",
"Consulting",
WS_TABSTOP|WS_VISIBLE|
WS_CHILD|BS_DEFPUSHBUTTON,
10,
110,
100,
24,
hWnd,
(HMENU)SELECT_BUTTON,
GetModuleHandle(NULL),
NULL);
}
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case INSERT_BUTTON:
{
HWND hGrpButtons=CreateWindowEx(WS_EX_WINDOWEDGE,
"BUTTON",
"Select a table:",
WS_VISIBLE | WS_CHILD| BS_GROUPBOX, // Styles
150,30,470,70,
hWnd,
NULL,
GetModuleHandle(NULL), NULL);
HWND hwndCB1 = CreateWindowEx(WS_EX_WINDOWEDGE, "BUTTON", "TSector", WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON | WS_GROUP,
160, 60, 80, 20, hWnd,(HMENU)CB1, GetModuleHandle(NULL), NULL);
HWND hwndCB2 = CreateWindowEx(WS_EX_WINDOWEDGE, "BUTTON", "TSeccio", WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON ,
250, 60, 80, 20, hWnd,(HMENU)CB2, GetModuleHandle(NULL), NULL);
HWND hwndCB3 = CreateWindowEx(WS_EX_WINDOWEDGE, "BUTTON", "TActivitat", WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON,
340, 60, 80, 20, hWnd,(HMENU)CB3, GetModuleHandle(NULL), NULL);
HWND hwndCB4 = CreateWindowEx(WS_EX_WINDOWEDGE, "BUTTON", "TClasse", WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON,
430, 60, 80, 20, hWnd,(HMENU)CB4, GetModuleHandle(NULL), NULL);
HWND hwndCB5 = CreateWindowEx(WS_EX_WINDOWEDGE, "BUTTON", "TQuantitat", WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON,
520, 60, 85, 20, hWnd,(HMENU)CB5, GetModuleHandle(NULL), NULL);
switch(HIWORD(wParam))
{
case CB1:
//Do something
break;
}
}
break;
}
break;
Maybe the switch after creating the radiobuttons is not well implemented but anyway, when compiling, any of the menus that I want to display when clicking on each radiobuttons are not recognised: the compile error I'm retrieving says that I need to declare each menu.
It sounds weird to me because it works in other cases.
Any help would be much appreciated.
CB1 is the identifier of your control, if it is undeclared then just declare using the #define, like this:
#define CB1 1000
the identifier cannot be repeated with id of others controls.
a good way to create menus is to create all the submenus hidden, and when someone click in an option, you just show the submenu using the ShowWindow function.
to create a hidden submenu, just remove the WS_VISIBLE in the CreateWindowEx.
see this example:
// Opts
#define Fruits 1
#define Colors 2
// Fruits
#define Apple 5
#define Pineapple 6
// Colors
#define Red 10
#define Blue 11
void HideAll(HWND hwnd)
{
// Fruits
ShowWindow(GetDlgItem(hwnd, Apple), SW_HIDE);
ShowWindow(GetDlgItem(hwnd, Pineapple), SW_HIDE);
// Colors
ShowWindow(GetDlgItem(hwnd, Red), SW_HIDE);
ShowWindow(GetDlgItem(hwnd, Blue), SW_HIDE);
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_CREATE:
// Menus - All created visible
CreateWindowEx(WS_EX_WINDOWEDGE, "BUTTON", "Fruits", WS_VISIBLE | WS_CHILD,
10, 10, 80, 20, hwnd,(HMENU)Fruits, GetModuleHandle(NULL), NULL);
CreateWindowEx(WS_EX_WINDOWEDGE, "BUTTON", "Colors", WS_VISIBLE | WS_CHILD,
10, 40, 80, 20, hwnd,(HMENU)Colors, GetModuleHandle(NULL), NULL);
// Fruits - All created Invisible
CreateWindowEx(WS_EX_WINDOWEDGE, "BUTTON", "Apple", WS_CHILD,
100, 10, 80, 20, hwnd,(HMENU)Apple, GetModuleHandle(NULL), NULL);
CreateWindowEx(WS_EX_WINDOWEDGE, "BUTTON", "Pineapple", WS_CHILD,
100, 40, 80, 20, hwnd,(HMENU)Pineapple, GetModuleHandle(NULL), NULL);
// Colors - All created Invisible
CreateWindowEx(WS_EX_WINDOWEDGE, "BUTTON", "Red", WS_CHILD,
100, 10, 80, 20, hwnd,(HMENU)Red, GetModuleHandle(NULL), NULL);
CreateWindowEx(WS_EX_WINDOWEDGE, "BUTTON", "Blue", WS_CHILD,
100, 40, 80, 20, hwnd,(HMENU)Blue, GetModuleHandle(NULL), NULL);
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case Fruits:
// Hide old
HideAll(hwnd);
// Show new
ShowWindow(GetDlgItem(hwnd, Apple), SW_SHOW);
ShowWindow(GetDlgItem(hwnd, Pineapple), SW_SHOW);
break;
case Colors:
// Hide old
HideAll(hwnd);
// Show new
ShowWindow(GetDlgItem(hwnd, Red), SW_SHOW);
ShowWindow(GetDlgItem(hwnd, Blue), SW_SHOW);
break;
}
break;
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
This is the result of the program:
and when someone click in fruits, it show the fruits suboptions:
and when someone click in colors, the ShowWindow hide the old suboptions and show new suboptions: