CheckBox Dialog
A Win32 dialog demo showing how to detect a checkbox click and read its state with IsDlgButtonChecked.
The complete message flow for a checkbox in a Win32 dialog: the control fires WM_COMMAND with its own ID when clicked, and IsDlgButtonChecked tells you whether it landed checked or unchecked. The surrounding template also shows the standard system-menu extras (a separator plus custom items handled in WM_SYSCOMMAND) and an About sub-dialog. Use it as the reference whenever you need reliable check-state detection without owner-draw tricks.
/////////////////////////////////////////////////////////////////////
#include <Windows.H>
#include <WindowsX.H>
#include <ShellAPI.H>
#include <Stdio.H>
#include <Stdlib.H>
#include "Headers/Definitions.H"
#include "Headers/Functions.H"
#include "Dialogs/MainDialog.H"
#include "Dialogs/AboutDialog.H"
/////////////////////////////////////////////////////////////////////
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevious, LPSTR CmdLine, int CmdShow)
{
HANDLE xMutex;
if( (xMutex = OpenMutex(SYNCHRONIZE, FALSE, TitleCaption)) )
{
MessageBox (NULL, "Only One Instance Can Run At A Time!" , TitleCaption, 0 + MB_ICONASTERISK + MB_SYSTEMMODAL);
ReleaseMutex(xMutex);
CloseHandle(xMutex);
return 1;
}
xMutex = CreateMutex(0, 0, TitleCaption);
MainInstance = hInstance;
DialogBox(MainInstance,MAKEINTRESOURCE(100),0,MainDialog);
ReleaseMutex(xMutex);
CloseHandle(xMutex);
return 0;
}
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
BOOL CALLBACK MainDialog(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
static HMENU SystemMenu;
while(1) // Loop Forever
{
if(Msg==WM_INITDIALOG)
{
MainDialog_hWnd=hDlg;
SystemMenu = GetSystemMenu(MainDialog_hWnd,FALSE);
AppendMenu(SystemMenu,MF_SEPARATOR,0,0);
AppendMenu(SystemMenu,MF_STRING,1000,"www.NetWorkDLS.Com");
AppendMenu(SystemMenu,MF_STRING,1001,"Version");
SendMessage(MainDialog_hWnd,(UINT)WM_SETTEXT,(WPARAM)0,(LPARAM)TitleCaption);
SendMessage(MainDialog_hWnd,WM_SETICON,TRUE,(LPARAM)LoadIcon(GetWindowInstance(MainDialog_hWnd),MAKEINTRESOURCE(300)));
CenterWindow(MainDialog_hWnd);
break;
}
if(Msg==WM_COMMAND)
{
if(wParam==100) //- Okay (Dialog Command)
{
EndDialog(MainDialog_hWnd,0);
}
if(wParam==1000) //- Check Bix (Dialog Command)
{
if(IsDlgButtonChecked(MainDialog_hWnd,1000))
MessageBox(MainDialog_hWnd, "Box Checked", TitleCaption, 0 + MB_ICONASTERISK + MB_TASKMODAL);
}
if(wParam==1500) //- About (Dialog Command)
{
ShowWindow(MainDialog_hWnd, SW_HIDE);
DialogBox(MainInstance,MAKEINTRESOURCE(1000),MainDialog_hWnd,AboutDialog);
ShowWindow(MainDialog_hWnd, SW_SHOW);
}
if(wParam==2000) //- Exit (Dialog Command)
{
EndDialog(MainDialog_hWnd,0);
}
break;
}
if(Msg==WM_SYSCOMMAND)
{
if(LOWORD(wParam)==1000) //- NetWorkDLS.Com (SysMenu Command)
{
ShellExecute(0,"Open","Http://www.NetWorkDLS.com",NULL,NULL,SW_SHOWNORMAL);
}
if(LOWORD(wParam) == 1001) //- Version (SysMenu Command)
{
MessageBox(MainDialog_hWnd, FileVersion, TitleCaption, 0 + MB_ICONASTERISK + MB_TASKMODAL);
}
}
if(Msg==WM_CLOSE) //Exit (Windows Message)
{
KillTimer(MainDialog_hWnd,0);
EndDialog(MainDialog_hWnd,0);
}
break;
}
return 0;
}
/////////////////////////////////////////////////////////////////////