void CALLBACK MyTimerProc (HWND hwnd, UINT message, UINT iTimerID, DWORD dwTime)
{
SYSTEMTIME stLocal;
GetLocalTime(&stLocal);
TCHAR strTime[256];
wsprintf(strTime,"%i年 %i月 %i日 %i:%i:%i",stLocal.wYear, stLocal.wMonth,
stLocal.wDay, stLocal.wHour, stLocal.wMinute, stLocal.wSecond);
SetDlgItemText(hwnd, IDC_EDITTIME, strTime);
}
BOOL Main_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
{
SetTimer(hwnd, 0, 1000, MyTimerProc);
return TRUE;
}
其他控件:
复选框控件、check总共有三种状态。
取得复选按钮的是否选中:
LRESULT Button_GetCheck(HWND hwndCtl);
BST_CHECKED BST_UNCHECKED
switch(id)
{
case IDC_OK:
{
HWND hwndcheck = GetDlgItem(hwnd, IDC_CHECK1);
int checkstate = Button_GetCheck(hwndcheck);
if(checkstate == BST_CHECKED){
MessageBox(hwnd, TEXT("被选中了"), TEXT(""), MB_OK);
}
if (BST_UNCHECKED == checkstate){
MessageBox(hwnd, TEXT("未被选中"), TEXT(""), MB_OK);
}
}
break;
default:
break;
}
设置复选按钮是否选中:
LRESULT Button_SetCheck(HWND hwndCtl, int check);
BST_CHECKED BST_UNCHECKED
switch(id)
{
case IDC_OK:
{
HWND hwndcheck = GetDlgItem(hwnd, IDC_CHECK1);
int checkstate = Button_GetCheck(hwndcheck);
if(checkstate == BST_CHECKED){
Button_SetCheck(hwndcheck, BST_UNCHECKED);
}
if (BST_UNCHECKED == checkstate){
Button_SetCheck(hwndcheck, BST_CHECKED);
}
}
break;
default:
break;
}
ListBox(和 Combo 类似)
(1)添加项:
如果采用 LBS_SORT 样式,那么填入清单方块最简单的方法是借助
ListBox_AddString:
int ListBox_AddString(HWND hwndCtl, LPCSTR lpsz);
如果没有采用 LBS_SORT, 那么可以使用 ListBox_InsertString 指定一个索引值,
将字符串插入到清单方块中:
int ListBox_InsertString(HWND hwndCtl, int index, LPCSTR lpsz);
(2)删除项:
int ListBox_DeleteString(HWND hwndCtl, int index);
(3)取得有多少项:
int ListBox_GetCount(HWND hwndCtl);
(4)选定某一项
int ListBox_SetCurSel(HWND hwndCtl, int index);将 iParam 设定为-1 则取消所有选择
(5) 确定目前选项的索引:
int ListBox_GetCurSel(HWND hwndCtl); 如果没有项目被选中,那么从呼叫中传回的
iIndex 值为
LB_ERR。
(6)将某项目复制到文字缓冲区中:
int ListBox_GetText(HWND hwndCtl, int index, LPCTSTR lpszBuffer);