【Windows API】Button Control Functions

①CheckDlgButton

Changes the check state of a button control
②CheckRadioButton

Adds a check mark to (checks) a specified radio button in a group and removes a check mark from (clears) all other radio buttons in the group

③IsDlgButtonChecked

The IsDlgButtonChecked function determines whether a button control is checked or whether a three-state button control is checked, unchecked, or indeterminate 

#define _CRT_SECURE_NO_WARNINGS
#include <windows.h>
#include <tchar.h>
#include "resource.h"

int CDECL MessageBoxPrintf(TCHAR *szCaption, TCHAR *szFormat, ...)
{
    TCHAR szBuffer[1024];
    va_list pArgList;
    va_start(pArgList, szFormat);
    _vsntprintf(szBuffer, sizeof(szBuffer) / sizeof(TCHAR), szFormat, pArgList);
    va_end(pArgList);
    return MessageBox(NULL, szBuffer, szCaption, 0);
}

int CALLBACK DialogProc(HWND hwndDlg,
    UINT uMsg,
    WPARAM wParam,
    LPARAM lParam)
{
    switch (uMsg)
    {
    case WM_COMMAND:
        switch (LOWORD(wParam))
        {
        case WM_INITDIALOG:
            return TRUE;
        case IDOK :
            CheckDlgButton(hwndDlg, IDC_CHECK1, BST_CHECKED);
            CheckRadioButton(hwndDlg, IDC_RADIO1, IDC_RADIO3, IDC_RADIO2);
            if (IsDlgButtonChecked(hwndDlg, IDC_RADIO2) == BST_CHECKED)
                MessageBox(NULL, TEXT(""), TEXT("确定"), 0);
            return TRUE;
        case IDNO :
            CheckDlgButton(hwndDlg, IDC_CHECK1, BST_UNCHECKED);
            CheckRadioButton(hwndDlg, IDC_RADIO1, IDC_RADIO3, IDC_RADIO1);
            if (IsDlgButtonChecked(hwndDlg, IDC_RADIO2) == BST_CHECKED)
                MessageBox(NULL, TEXT(""), TEXT("取消"), 0);
            return TRUE;
        case IDCANCEL :
            EndDialog(hwndDlg, 0);
            PostQuitMessage(0);
            return TRUE;
        }
    }
    return FALSE;
}

int CALLBACK WinMain(HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow)
{
    HWND hwnd;
    MSG message;

    hwnd = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, DialogProc);
    if (hwnd == NULL)
        MessageBoxPrintf(TEXT(""), TEXT("%d"), GetLastError());

    ShowWindow(hwnd, nCmdShow);

    UpdateWindow(hwnd);

    while (GetMessage(&message, NULL, 0, 0))
    {
        TranslateMessage(&message);
        DispatchMessage(&message);
    }
    return message.wParam;
}

 

posted on 2014-03-28 14:07  至死丶不渝  阅读(273)  评论(0编辑  收藏  举报

导航