6/24/10

Digital clock using timer(MFC)

Buzz It
#include_afxwin.h_//replace "_"with"<>"
#include_afxext.h_
class myframe:public CFrameWnd
{
public:
int hh,mm,ss;
CStatic st;
CFont f;
myframe()
{
Create(0,"Status");
}
void OnCreate()
{
CClientDC d(this);
SetTimer (1,100,NULL);
st.Create("",WS_CHILDWS_VISIBLESS_CENTERIMAGE,CRect(20,33,684,775),this,2);
f.CreateFont(75,50,0,0,1,0,0,0,8,0,0,0,0,"arial");
d.SelectObject(&f);
st.SetFont(&f,true);
return;
}
void OnTimer(UINT id)
{
st.SetWindowText("");
CTime t;
t=CTime ::GetCurrentTime ();
hh=t.GetHour ();
if(hh==0)
hh=12;
mm=t.GetMinute ();
ss=t.GetSecond ();
CHAR s[33];
wsprintf(s,"%d:%d:%d",hh,mm,ss);
st.SetWindowText(s);
}
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(myframe, CFrameWnd)
ON_WM_CREATE()
ON_WM_TIMER()
END_MESSAGE_MAP()
class myapp:public CWinApp
{
public:
int InitInstance()
{
myframe *p;
p=new myframe;
p->ShowWindow(3);
m_pMainWnd=p;
return 1;
}
};
myapp a;


Output

0 comments:

Post a Comment