Currently I am trying to destroy a window (button) and redraw the main window so that I may redraw new buttons as if changing menus. I found on stackoverflow someone mention using the BeginPaint to redraw the window so it can show the button being deleted after using DeleteWindow.
Right now I do not fully understand handles (as far as I understand are identifiers) and I haven't found anything in MSDN to expand on PAINTSTRUCT outside of the window creation walkthrough. The code is something for me to mess with to learn win32 so I have not implemented functions to deal with buttons on their own.
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_CREATE:
{
HWND hwndButton = CreateWindow(
L"BUTTON", // Predefined class; Unicode assumed
L"Start", // Button text
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, // Styles
25, // x position
375, // y position
100, // Button width
50, // Button height
hwnd, // Parent window
(HMENU) 1000,
NULL, // No menu.
(HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE),
NULL); // Pointer not needed.
HWND hwndButton2 = CreateWindow(
L"BUTTON", // Predefined class; Unicode assumed
L"Second", // Button text
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, // Styles
150, // x position
375, // y position
100, // Button width
50, // Button height
hwnd, // Parent window
(HMENU) 1002,
NULL, // No menu.
(HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE),
NULL); // Pointer not needed.
}
break;
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case 1000:
MessageBox(hwnd, L"Do you wish to return?", L"Warning!", MB_YESNO | MB_ICONINFORMATION);
return 0;
case 1002:
//Bool DestroyWindow(hwnd);
//SendMessage(hwnd, WM_CLOSE,0 ,0 );
HWND hwndButton3 = CreateWindow(
L"BUTTON", // Predefined class; Unicode assumed
L"Third", // Button text
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, // Styles
250, // x position
375, // y position
100, // Button width
50, // Button height
hwnd, // Parent window
(HMENU)1003,
NULL, // No menu.
(HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE),
NULL); // Pointer not needed.
//Paint here?
return 0;
}
}
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
// All painting occurs here, between BeginPaint and EndPaint.
FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLOR_WINDOW + 1));
EndPaint(hwnd, &ps);
}
return 0;