Use radio buttons for switching different views in the main window - c++

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:

Related

c++ winapi - best practice for switching between 2 different sets of buttons/control layouts in the same window on button press

I'm a hobbyist programmer coming back to C++ after many years away from programming and new to winapi so sorry for the "basic" GUI question. I'm trying to find the best practice for implementing the following, very common, behaviour.
From a users perspective this is the behaviour I want to create. I have 1 window with some buttons in it. The user clicks on 1 of the buttons and the window contents appears to change to show different buttons/text fields etc. The user interacts with these controls then finally clicks a "back" button and they are returned to the first screen.
This behaviour is so common I thought it would be easy to find examples and best practices for implementing it but clearly I'm not asking the right questions in google. Not sure if the right way forward is a new window, a child window and how to set up winproc to capture the events in these 2 options, i.e. a winproc for each window or child or 1 massive winproc for everything. Hence the best practice question.
Can anyone help, either be explaining the best way to set this up with the WINAPI or by pointing me to some material online. I've spent days looking, plenty on creating 1 windows with controls. Very happy to follow tutorials and experiment to learn more.
Thanks jwezorek I got very close to your updated code last night but still couldn't get the child events to work. Finally cracked it using your updated code and putting the page switch buttons in the same pane as the other buttons so all clicks were handled on a pane basis in the child winproc. Thank you all for your help. Code below in case it's of interest/use to anyone else.
#include <windows.h>
#define PANE1_ID 101
#define BUTTON11_ID 102
#define BUTTON12_ID 103
#define BUTTON_TO_PAGE_1 104
#define PANE2_ID 201
#define BUTTON21_ID 202
#define BUTTON22_ID 203
#define BUTTON_TO_PAGE_2 204
LRESULT CALLBACK parentWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK childWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
HINSTANCE g_hinst;
static HWND g_pane1;
static HWND g_pane2;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
g_hinst = hInstance;
MSG msg = { 0 };
// Parent window definition
WNDCLASS parentWindow = { 0 };
parentWindow.lpfnWndProc = parentWndProc;
parentWindow.hInstance = hInstance;
parentWindow.hbrBackground = (HBRUSH)(COLOR_BACKGROUND);
parentWindow.lpszClassName = L"MainWindow";
if (!RegisterClass(&parentWindow))
return 1;
// Child window definition
WNDCLASS childWindow = { 0 };
childWindow.lpfnWndProc = childWndProc;
childWindow.hInstance = hInstance;
childWindow.hbrBackground = (HBRUSH)(COLOR_BACKGROUND);
childWindow.lpszClassName = L"Pane";
if (!RegisterClass(&childWindow))
return 1;
// Create main window
if (!CreateWindow(parentWindow.lpszClassName, L"grouped buttons", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, 640, 480, 0, 0, hInstance, NULL))
return 2;
while (GetMessage(&msg, NULL, 0, 0) > 0) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK parentWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
// create pane 2 with button then hide the pane and the button to switch to pane 1
g_pane2 = CreateWindow(L"Pane", L"", WS_CHILD | WS_VISIBLE, 20, 20, 250, 200, hWnd, (HMENU)PANE2_ID, g_hinst, 0);
CreateWindow(L"BUTTON", L"Button 2.1", WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON, 50, 10, 180, 35, g_pane2, (HMENU)BUTTON21_ID, g_hinst, 0);
CreateWindow(L"BUTTON", L"Button 2.2", WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON, 50, 40, 180, 35, g_pane2, (HMENU)BUTTON22_ID, g_hinst, 0);
CreateWindow(L"BUTTON", L"Back to Page 1", WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON, 50, 130, 180, 35, g_pane2, (HMENU)BUTTON_TO_PAGE_1, g_hinst, 0);
ShowWindow(g_pane2, SW_HIDE);
UpdateWindow(g_pane2);
// create pane 1 with buttons and show it and the button to switch to pane 2
g_pane1 = CreateWindow(L"Pane", L"", WS_CHILD | WS_VISIBLE, 20, 20, 250, 200, hWnd, (HMENU)PANE1_ID, g_hinst, 0);
CreateWindow(L"BUTTON", L"Button 1.1", WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON, 10, 10, 180, 35, g_pane1, (HMENU)BUTTON11_ID, g_hinst, 0);
CreateWindow(L"BUTTON", L"Button 1.2", WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON, 10, 40, 180, 35, g_pane1, (HMENU)BUTTON12_ID, g_hinst, 0);
CreateWindow(L"BUTTON", L"Go to page 2", WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON, 10, 130, 180, 35, g_pane1, (HMENU)BUTTON_TO_PAGE_2, g_hinst, 0);
ShowWindow(g_pane1, SW_SHOW);
UpdateWindow(g_pane1);
break;
case WM_CLOSE:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
LRESULT CALLBACK childWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if (message == WM_COMMAND) {
switch (wParam) {
case BUTTON_TO_PAGE_2:
{
// MessageBox(hWnd, L"You pressed go to page 2", L"Button Pressed", MB_OK);
ShowWindow(g_pane1, SW_HIDE);
ShowWindow(g_pane2, SW_SHOW);
}
break;
case BUTTON11_ID:
MessageBox(NULL, L"Button 1.1", L"Page 1 Button", 0);
break;
case BUTTON12_ID:
MessageBox(NULL, L"Button 1.2", L"Page 1 Button", 0);
break;
case BUTTON_TO_PAGE_1:
{
// MessageBox(hWnd, L"You pressed go to page 1", L"Button Pressed", MB_OK);
ShowWindow(g_pane2, SW_HIDE);
ShowWindow(g_pane1, SW_SHOW);
}
break;
case BUTTON21_ID:
MessageBox(NULL, L"Button 2.1", L"Page 2 Button", 0);
break;
case BUTTON22_ID:
MessageBox(NULL, L"Button 2.2", L"Page 2 Button", 0);
break;
}
return 0;
}
else {
return DefWindowProc(hWnd, message, wParam, lParam);
}
}

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

How can I make my Windows API GUI code more object-oriented?

For a class project I am creating a tic tac toe game with a GUI. The assignment requires the use of classes.
The assignment didn't originally require a GUI, so I created a working tic tac toe game with a command line interface. However, to earn some extra points I'd now like to implement a GUI. The problem is we haven't covered GUI design.
So far, I am able to display a window with 9 buttons on it. As you can see from the code below this is all done without classes. How could I separate my code into a single class or classes? Then, how would I display the GUI after creating an object in main?
I'm not trying to bring on any framework dependencies beyond the already-included windows.h system header.
In the end I'd like to have a class to handle the interface and a class to handle the logic.
Thanks for any suggestions
main.cpp
#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow )
{
MSG msg ;
WNDCLASS wc = {0};
wc.lpszClassName = TEXT( "Buttons" );
wc.hInstance = hInstance ;
wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
wc.lpfnWndProc = WndProc ;
wc.hCursor = LoadCursor(0, IDC_ARROW);
RegisterClass(&wc);
CreateWindow( wc.lpszClassName, TEXT("Buttons"),
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
150, 150, 340, 360, 0, 0, hInstance, 0);
while( GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int) msg.wParam;
}
LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch(msg)
{
case WM_CREATE:
{
CreateWindow(TEXT("button"), TEXT(""),
WS_VISIBLE | WS_CHILD ,
20, 20, 80, 80,
hwnd, (HMENU) 1, NULL, NULL);
CreateWindow(TEXT("button"), TEXT(""),
WS_VISIBLE | WS_CHILD ,
120, 20, 80, 80,
hwnd, (HMENU) 2, NULL, NULL);
CreateWindow(TEXT("button"), TEXT(""),
WS_VISIBLE | WS_CHILD ,
220, 20, 80, 80,
hwnd, (HMENU) 3, NULL, NULL);
CreateWindow(TEXT("button"), TEXT(""),
WS_VISIBLE | WS_CHILD ,
20, 120, 80, 80,
hwnd, (HMENU) 4, NULL, NULL);
CreateWindow(TEXT("button"), TEXT(""),
WS_VISIBLE | WS_CHILD ,
120, 120, 80, 80,
hwnd, (HMENU) 5, NULL, NULL);
CreateWindow(TEXT("button"), TEXT(""),
WS_VISIBLE | WS_CHILD ,
220, 120, 80, 80,
hwnd, (HMENU) 5, NULL, NULL);
CreateWindow(TEXT("button"), TEXT(""),
WS_VISIBLE | WS_CHILD ,
20, 220, 80, 80,
hwnd, (HMENU) 1, NULL, NULL);
CreateWindow(TEXT("button"), TEXT(""),
WS_VISIBLE | WS_CHILD ,
120, 220, 80, 80,
hwnd, (HMENU) 1, NULL, NULL);
CreateWindow(TEXT("button"), TEXT(""),
WS_VISIBLE | WS_CHILD ,
220, 220, 80, 80,
hwnd, (HMENU) 1, NULL, NULL);
break;
}
// incomplete
case WM_COMMAND:
{
if (LOWORD(wParam) == 1) {
Beep(40, 50);
}
if (LOWORD(wParam) == 2) {
PostQuitMessage(0);
}
break;
}
case WM_DESTROY:
{
PostQuitMessage(0);
break;
}
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
You're probably looking for Raymond Chen's C++ version of his scratch program
It shows you how to use C++ classes (and member functions) together with the C-style callback approach used by the Windows API. Pretty much all his blog posts are worth reading, if you're interested in how to do things well in Windows, and why the APIs work the way they do.
But, there's still a lot that can be improved in Raymond's program, especially with the new std::unique_ptr (it didn't exist in 2005 when his post appeared, and he has a reputation for actually writing those over two years before they become public, so he may have not even had C++03 to work with).
Nonetheless, it shows you how to store a this pointer in a Win32 GUI object and how to dispatch messages to member functions for handling.

c++ textbox doesn't let you type

I am creating a simple chat program where clients can send messages to a server, which shows the received messages. For some reason, I can't type in the textbox even though its not set to read only. Can anyone see the simple error without me posting the entire code? This is where i create the textbox:
static HWND text;
switch(msg)
{
case WM_CREATE:
{
text = CreateWindow(TEXT("Edit"), TEXT("Enter text here..."),
WS_VISIBLE | WS_CHILD | WS_BORDER,
0, 0, 300, 25,
hwnd, (HMENU) ID_EDIT, NULL, NULL);
CreateWindow(TEXT("Button"), TEXT("Post"),
WS_VISIBLE | WS_CHILD,
310, 0, 70, 25,
hwnd, (HMENU) ID_POST, NULL, NULL);
CreateWindow(TEXT("Button"), TEXT("Connect"),
WS_VISIBLE | WS_CHILD,
0, 35, 70, 25,
hwnd, (HMENU) ID_CONNECT, NULL, NULL);
break;
}
Applying my mental powers, I'd say that you wrote your own message loop in the main function and that you are not calling TranslateMessage().
Function TranslateMessage() is responsible for converting key messages into char messages (no, that's not done automatically :-). The end result is that your EDIT windows (all your windows) do not receive WM_CHAR messages.
So your message loop should at least have something like this:
MSG msg;
while (GetMessage(&msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

Parent Window creation

I know it is a very simple question but i currently cant create a parent window...
My code:
LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
static HWND paste;
static HWND update_list;
/*HWND changeuser = CreateWindow(0, 0,
0,
0, 0, x, y,
0, (HMENU)changeuser2, 0, NULL); */
switch(msg)
{
case WM_CREATE:
meniu(hwnd);
CreateWindow(TEXT("static"), TEXT("\nSuckers online:"),
WS_VISIBLE | WS_CHILD | SS_CENTER,
0, 0, x, 55,
hwnd, (HMENU)delete, NULL, NULL);
connected = CreateWindow(TEXT("edit"), TEXT(""),
WS_VISIBLE | WS_CHILD | WS_VSCROLL| ES_MULTILINE ,
0, 60, x, 340,
hwnd, (HMENU)delete2, NULL, NULL);
CreateWindow(TEXT("static"), TEXT(""),
WS_VISIBLE | WS_CHILD | SS_CENTER|BS_PUSHBUTTON,
0, 405, x, 358,
hwnd, (HMENU) delete3, NULL, NULL);
paste = CreateWindow(TEXT("Edit"), TEXT("Paste the ip here"),
WS_VISIBLE | WS_CHILD | SS_CENTER,
x/2 - 60, 410, 120, 40,
hwnd, (HMENU) ip, NULL, NULL);
CreateWindow(TEXT("Button"), TEXT("Connect!"),
WS_VISIBLE | WS_CHILD | SS_CENTER | BS_PUSHBUTTON,
x/2 - 120, 450, 120, 40,
hwnd, (HMENU) connect2, NULL, NULL);
update_list = CreateWindow(TEXT("Button"), TEXT("Update the list!"),
WS_VISIBLE | WS_CHILD | SS_CENTER | BS_PUSHBUTTON,
x/2, 450, 120, 40,
hwnd, (HMENU) update, NULL, NULL);
_beginthread( lista, 0, (void*)(0) );//begin thread lista
break;
case WM_CTLCOLORSTATIC : {
HBRUSH br = CreateSolidBrush(RGB(80,67,77)); // change background color
SetTextColor((HDC)wParam,RGB(0,102,51)); //the controls text color
return (LRESULT) br;
}
case WM_COMMAND:
switch LOWORD(wParam)
{
case exit:
PostQuitMessage(0);
break;
case ip:
int nr;
nr = GetWindowTextLength(paste);
if (nr >= 17)
SetWindowText(paste, "");
break;//omor textul, ca sa pot sa fac paste
case connect2:
GetWindowText(paste,adresa,16);
_beginthread( start, 0, (void*)(0) ); //as\ici se face conexiunea principala
//DestroyWindow(hwnd);
MessageBox(0,"Connected with the user","Ok",0);
break;
case update:
exit2 = true;
Sleep(100);
SetWindowText(connected,"");
_beginthread( lista, 0, (void*)(0) );//begin thread lista
break;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
I want the other windows created to be the child of the changeuser window...
I just cant make it happen...
Any help will be appreciated!
To change the window of a parent, use SetParent().
But i would think about the structure - if you need to change the parent of one or more windows in a normal dialog setting, it is likely these windows should have a different parent.
In your case there is a problem in your handling of window messages though:
If your message handler receives WM_DESTROY you call PostQuitMessage(), which probably results in your application closing.
There are two ways you can handle that:
use different window processes for your main dialog and child dialogs (preferably)
or use the hwnd parameter to decide wether you call PostQuitMessage()
You can't 'replace' a window. If you need to tear down and replace your main window, delete it and make a new one. Windows only get the parent flag when they have children, not because you tell them to.