Im developing a program on window using only Win32 Api (so no .Net or win form here) and when testing the radio button on my program, i noticed that the radio button is one time used. i set each of the radio button to change the title to diffrent name if you press it back and forward multiple times but when i tried to do that it only change the title once. heres the minimal reproducible sample:
#include <Windows.h>
#define RDCC1 1001
#define RDCC2 1002
#define DEFRADIOBUTTONSIZEX 200
#define BUTTONSTYLE WS_VISIBLE | WS_CHILD
#define DEFRADIOBUTTONSIZEY 20
#define MAINWINDOWX 800
#define MAINWINDOWY 600
#define MAINWINDOWSTYLE WS_OVERLAPPED| WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{
HWND clckinerval = nullptr;
HINSTANCE hinst = GetModuleHandle(0);
int tempsw = 0;
auto add = [&](const wchar_t* name, int id, int x, int y, int w, int h, bool first = false)
{
DWORD style = WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON;
if (first) style |= WS_GROUP | WS_TABSTOP;
return CreateWindowEx(0, L"Button", name, style,
x, y, w, h, hwnd, (HMENU)id, hinst, NULL);
};
switch (msg)
{
case WM_CREATE:
{
HWND radio1 = add(L"RD1", RDCC1, 17, 30, 200, 20, true);
HWND radio2 = add(L"RD2", RDCC2, 17, 51, 200, 20);
SendMessage(radio1, BM_SETCHECK, BST_CHECKED, TRUE);
break;
}
case WM_COMMAND:
{
switch (wp)
{
case RDCC1:
{
SetWindowText(hwnd, L"Hello");
}
case RDCC2:
{
if (tempsw == NULL) {
SetWindowText(hwnd, L"Hello");
tempsw = 1;
}
else
{
SetWindowText(hwnd, L"Bye");
}
}
UpdateWindow(hwnd);
break;
}
}
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLOR_WINDOW));
EndPaint(hwnd, &ps);
break;
}
case WM_DESTROY:
{
PostQuitMessage(0);
break;
}
}
return DefWindowProc(hwnd, msg, wp, lp);
}
int WINAPI wWinMain(HINSTANCE hinst, HINSTANCE hiprevinst, PWSTR nCmdLine, int ncmdshow)
{
const wchar_t CLASS_NAME[] = L"Send help i spend too much on this";
WNDCLASS wc = { };
wc.lpfnWndProc = WndProc;
wc.hInstance = hinst;
wc.lpszClassName = CLASS_NAME;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
RegisterClass(&wc);
HWND hwnd = CreateWindowEx(0, CLASS_NAME, L"Sample", MAINWINDOWSTYLE, CW_USEDEFAULT, CW_USEDEFAULT, MAINWINDOWX, MAINWINDOWY, NULL, NULL, hinst, NULL);
ShowWindow(hwnd, ncmdshow);
MSG msg;
while (GetMessage(&msg, NULL, NULL, NULL))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}