16,473
社区成员
发帖
与我相关
我的任务
分享
void CNewButton::OnTimer(UINT nIDEvent) // WM_TIMER
{
// TODO: Add your message handler code here and/or call default
if(1 == nIDEvent)
{
if(GetState() & 0x0004)
{
int ID_EDIT = 0;
int ID_BUTTON = 0;
if(IDC_BUTTON1 == GetDlgCtrlID())
{
ID_EDIT = IDC_EDIT1;
ID_BUTTON = IDC_BUTTON1;
}
else
{
ID_EDIT = IDC_EDIT2;
ID_BUTTON = IDC_BUTTON2;
}
int num = GetParent()->GetDlgItemInt(ID_EDIT);
num++;
GetParent()->SetDlgItemInt(ID_EDIT, num);
}
}
CButton::OnTimer(nIDEvent);
}
void CNewButton::PreSubclassWindow()
{
// TODO: Add your specialized code here and/or call the base class
SetTimer(1, 100, NULL);
CButton::PreSubclassWindow();
}
void CNewButton::OnDestroy() // WM_DESTROY
{
CButton::OnDestroy();
// TODO: Add your message handler code here
KillTimer(1);
}
TCHAR buff[256];
int i=0,j=0;
回调函数中
case WM_TIMER:
{
ZeroMemory(buff,sizeof(buff)/sizeof(TCHAR));
wsprintf(buff,TEXT("第%d次"),i);
i++;
SetWindowText(GetDlgItem(hWnd,IDC_EDT1),buff);
}break;
在WM_COMMAND中
case IDC_BTN1:
{
if(j%2==0)
{
SetTimer(hwnd,1,100,NULL);
}
else
{
ZeroMemory(buff,sizeof(buff)/sizeof(TCHAR));
wsprintf(buff,TEXT("按钮弹起"));
SetWindowText(GetDlgItem(hwnd,IDC_EDT1),buff);
KillTimer(hwnd,1);
}
j++;
}break;