I am trying to create radio buttons in Dev-C++ using C. I am new to Win32 API programming also. What I have done so far is create the main app window, added textboxes, check boxes and a few radio buttons. The only issue I have now is that You cannot select the radio buttons during runtime. I am just wonder what I am missing to make the radio buttons work.
main.cpp
#include <windows.h>
#include <stdio.h>
#include "resource.h"
char ConvertTime[8], ETime[8], UKTime[8], HKTime[8], Hour[8], Min[8], AMPM[8];
int intHour;
HWND hWndConvertTime, hWndETTime, hWndUKTime, hWndHKTime, hWndBetween1,
hWndBetween2, hWndETSelect, hWndUKSelect, hWndHKSelect;
HWND hWnd;
HINSTANCE hInst;
LRESULT CALLBACK DlgProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
DialogBox(hInstance, MAKEINTRESOURCE(IDD_CONTROLS_DLG), hWnd,
reinterpret_cast<DLGPROC>(DlgProc));
hInst = hInstance;
return 0;
}
LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
hWndConvertTime = GetDlgItem(hWndDlg, IDC_CONVERT_TIME);
hWndETTime = GetDlgItem(hWndDlg, IDC_EASTERN_TIME);
hWndUKTime = GetDlgItem(hWndDlg, IDC_UK_TIME);
hWndHKTime = GetDlgItem(hWndDlg, IDC_HK_TIME);
hWndBetween1 = GetDlgItem(hWndDlg, IDC_BETWEEN1);
hWndBetween2 = GetDlgItem(hWndDlg, IDC_BETWEEN2);
hWndETSelect = GetDlgItem(hWndDlg, IDC_EASTERN_SELECT);
hWndUKSelect = GetDlgItem(hWndDlg, IDC_UK_SELECT);
hWndHKSelect = GetDlgItem(hWndDlg, IDC_HK_SELECT);
switch(Msg)
{
case WM_INITDIALOG:
SetWindowText(hWndConvertTime, "");
SetWindowText(hWndETTime, "");
SetWindowText(hWndHKTime, "");
SetWindowText(hWndUKTime, "");
return TRUE;
case WM_COMMAND:
switch(wParam)
{
case IDC_CONVERT:
// Gets the user entered time and converts it to usable format
GetWindowText(hWndConvertTime, ConvertTime, 9);
strncpy(Hour, ConvertTime, 2);
strncpy(Min, ConvertTime + 3, 2);
strncpy(AMPM, ConvertTime + 6, 2);
intHour = atoi(Hour);
if (strchr(ConvertTime, 'A') == NULL || strchr(ConvertTime, 'P') == NULL ||
strchr(ConvertTime, 'a') == NULL || strchr(ConvertTime, 'p') == NULL)
{
// converting to 24hr format
if (strchr(AMPM, 'P') != NULL && strchr(AMPM, 'p') != NULL)
{
if (intHour != 12)
{
intHour = intHour + 12;
}
}
else if (strchr(AMPM, 'A') != NULL && strchr(AMPM, 'a') != NULL)
{
if (intHour == 12)
{
intHour = 0;
}
}
}
// Compares and Calculations
if (IsDlgButtonChecked(hWnd, IDC_EASTERN_SELECT) == BST_CHECKED)
{
}
// ET Hour formating then printing to label
sprintf(Hour, "%i", intHour);
// UK Hour formating then printing to label
sprintf(Hour, "%i", intHour);
// HK Hour formating then printing to label
sprintf(Hour, "%i", intHour);
return TRUE;
case IDCANCEL:
EndDialog(hWndDlg, 0);
return TRUE;
}
break;
}
return FALSE;
}
resource.h
#define IDD_CONTROLS_DLG 101
#define IDC_CONVERT_TIME 1002
#define IDC_EASTERN_TIME 1003
#define IDC_UK_TIME 1004
#define IDC_HK_TIME 1005
#define IDC_CONVERT 1006
#define IDC_BETWEEN1 1007
#define IDC_BETWEEN2 1008
#define IDC_EASTERN_SELECT 1009
#define IDC_UK_SELECT 1010
#define IDC_HK_SELECT 1011
#include "resource.h"
#include <afxres.h>
IDD_CONTROLS_DLG DIALOG DISCARDABLE 0, 0, 160, 230
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "HSBC Conversion Clock"
FONT 8, "MS Sans Serif"
BEGIN
LTEXT "Conversion Time: ",IDC_STATIC,20,20,80,8
EDITTEXT IDC_CONVERT_TIME,100,20,40,12,ES_RIGHT | ES_AUTOHSCROLL
CHECKBOX "Between 3/8 - 3/29?", IDC_BETWEEN1, 40, 40, 100, 8, BS_AUTOCHECKBOX
CHECKBOX "Between 10/25 - 11/1?" IDC_BETWEEN2, 40, 60, 100, 8, BS_AUTOCHECKBOX
RADIOBUTTON "Eastern Time", IDC_EASTERN_SELECT, 40, 80, 100, 8, BS_RADIOBUTTON | WS_GROUP
RADIOBUTTON "UK Time", IDC_UK_SELECT, 40, 100, 100, 8, BS_RADIOBUTTON
RADIOBUTTON "HK Time", IDC_HK_SELECT, 40, 120, 100, 8, BS_RADIOBUTTON
LTEXT "Eastern Time: ",IDC_STATIC,20,140,80,8
EDITTEXT IDC_EASTERN_TIME,100,140,40,12,ES_RIGHT | ES_AUTOHSCROLL
LTEXT "UK Time: ",IDC_STATIC,20,160,80,8
EDITTEXT IDC_UK_TIME,100,160,40,12,ES_RIGHT | ES_AUTOHSCROLL
LTEXT "HK Time: ",IDC_STATIC,20,180,80,8
EDITTEXT IDC_HK_TIME,100,180,40,12,ES_RIGHT | ES_AUTOHSCROLL
PUSHBUTTON "Convert",IDC_CONVERT,25,200,30,15
PUSHBUTTON "Quit",IDCANCEL,100,200,30,15
END