对话框:
代码:
#include "stdafx.h"
#include <windows.h>
#include <windowsx.h>
#include "resource.h"
#include "MainDlg.h"
BOOL WINAPI Main_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
HANDLE_MSG(hWnd, WM_INITDIALOG, Main_OnInitDialog);
HANDLE_MSG(hWnd, WM_COMMAND, Main_OnCommand);
HANDLE_MSG(hWnd,WM_CLOSE, Main_OnClose);
}
return FALSE;
}
BOOL Main_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
{
return TRUE;
}
void Main_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
switch(id)
{
case IDC_SET:
{
HWND hwnd_check = GetDlgItem(hwnd,IDC_CHECK1);
int check_state = Button_GetCheck(hwnd_check);
if(BST_UNCHECKED==check_state)
{
Button_SetCheck(hwnd_check,BST_CHECKED);
}
if(BST_CHECKED==check_state)
{
Button_SetCheck(hwnd_check,BST_UNCHECKED);
}
}
break;
case IDC_OK:
{
HWND hwnd_check = GetDlgItem(hwnd,IDC_CHECK1);
int check_state = Button_GetCheck(hwnd_check);
if(BST_UNCHECKED==check_state)
{
MessageBox(hwnd,TEXT("未选中"),TEXT(""),MB_OK);
}
if(BST_CHECKED==check_state)
{
MessageBox(hwnd,TEXT("已选中"),TEXT(""),MB_OK);
}
break;
default:
break;
}
}
void Main_OnClose(HWND hwnd)
{
EndDialog(hwnd, 0);
}
//这个我认为不会错啊,可是.....
//我写完第一个case是调试了一下没错,
//可是再写第二个case是就错了,
//怎么了?变量名不能相同?好像不是这个问题!