| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 5438 人关注过本帖
标题:如何用vc++6.0编个闹钟
只看楼主 加入收藏
wfpb
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:2188
专家分:0
注 册:2006-4-2
收藏
得分:0 

程序代码:

摘自MSDN:
CTime::GetCurrentTime
static CTime PASCAL GetCurrentTime( );

Remarks

Returns a CTime object that represents the current time.

Example

// example for CTime::GetCurrentTime
CTime t = CTime::GetCurrentTime();



程序代码:

CString Format( LPCTSTR pFormat ) const;

CString Format( UINT nFormatID ) const;

Return Value

A CString that contains the formatted time.

Parameters

pFormat

A formatting string similar to the printf formatting string. Formatting codes, preceded by a percent (%) sign, are replaced by the corresponding CTime component. Other characters in the formatting string are copied unchanged to the returned string. See the run-time functionstrftime for details. The value and meaning of the formatting codes for Format are listed below:

%D Total days in this CTime


%H Hours in the current day


%M Minutes in the current hour


%S Seconds in the current minute


%% Percent sign
nFormatID

The ID of the string that identifies this format.

Remarks

Call this member function to create a formatted representation of the date/time value. If the status of this CTime object is null, the return value is an empty string. If the status of CTime is invalid, the return value is an empty string.

Example

// example for CTime::Format and CTime::FormatGmt
CTime t( 1999, 3, 19, 22, 15, 0 );
// 10:15PM March 19, 1999
CString s = t.Format( \"%A, %B %d, %Y\" );
ASSERT( s == \"Friday, March 19, 1999\" );


[此贴子已经被作者于2006-9-4 17:47:41编辑过]


[glow=255,red,2]wfpb的部落格[/glow] 学习成为生活的重要组成部分!
2006-09-04 17:46
xigong
Rank: 1
等 级:新手上路
威 望:1
帖 子:19
专家分:0
注 册:2006-9-2
收藏
得分:0 
好长的一段代码,后一段没看懂。我用了DateTimepicker控件,请问如何实现时间显示的不断刷新?我看了该控件变量所有的消息机制,但好象还是没有找到解决问题的方法。是我控件用错了吗?望给予指导,谢谢。
2006-09-06 23:28
yeshirow
Rank: 4
等 级:贵宾
威 望:10
帖 子:854
专家分:0
注 册:2006-6-8
收藏
得分:0 

好像問題被複雜化了,
只是編寫一個鬧鍾...
------------------------------
先初始一個報時的 CTime,
例如希望在 2 小時後報時,
CTime beginTime = CTime::GetCurrentTime() + CTimeSpan(0, 2, 0, 0);
然後在一個 Timer 計時中判斷當前的時間與 beginTime 的 "大小"
先啓動一個計時器:
this->SetTimer(myTimerID, 10, NULL); // 10 秒檢查一次, 自己定義

... OnTimer(UINT nIdEvent)
{
.......
CTime endTime = CTime::GetCurrentTime();
if(endTime >= beginTime)
{
KillTimer(myTimerID);
this->MessageBox("報時啦....");
}
.......
}


原來朋友仔感情再天真, 亦是我永遠也會愛惜的人, 明日愛他人, 也記住學會不要緊; 原來朋友比戀人更高分, 亦讓我開始懂得不記恨, 若大家都敏感, 我更要永遠記得拒絕再因小事怪人, 爲何沒有這條校訓...Twins-朋友仔 MCSD Training
2006-09-07 02:36
xigong
Rank: 1
等 级:新手上路
威 望:1
帖 子:19
专家分:0
注 册:2006-9-2
收藏
得分:0 

不好意思,确实看不懂啊。
... OnTimer(UINT nIdEvent)
{
.......
CTime endTime = CTime::GetCurrentTime();
if(endTime >= beginTime)
{
KillTimer(myTimerID);
this->MessageBox("報時啦....");
}
.......
}
这段代码放在哪,还有this指针具体指的是哪
个对象?
这段代码是基于对话框的吗?如果是,这些函数应该是在哪个控件所对应的函数呢?我实际上做的是一个记事簿,本以为可以用一个闹钟再加上记事的对象就性了,现在看来远没那么简单。我的记事簿是基于模态对话框的,想有一个时钟,并且在预定的时间到的时候有对话框弹出,但不知道系统时间与预定时间该如何进行校对,这个校对的函数应该放在哪里?

2006-09-08 22:18
xigong
Rank: 1
等 级:新手上路
威 望:1
帖 子:19
专家分:0
注 册:2006-9-2
收藏
得分:0 
特别是在哪放这个校对的函数最令人头痛。
2006-09-08 22:21
yeshirow
Rank: 4
等 级:贵宾
威 望:10
帖 子:854
专家分:0
注 册:2006-6-8
收藏
得分:0 
以下是引用xigong在2006-9-8 22:18:08的发言:

...我的记事簿是基于模态对话框的,想有一个时钟,并且在预定的时间到的时候有对话框弹出,.....

就是一個對話框程式.
this 就是 你建立的 Dialog 對話框類.
OnTimer 是 Dialog 的成員函式, (由 WM_TIMER 産生).
--------------------------------------------------------------------


原來朋友仔感情再天真, 亦是我永遠也會愛惜的人, 明日愛他人, 也記住學會不要緊; 原來朋友比戀人更高分, 亦讓我開始懂得不記恨, 若大家都敏感, 我更要永遠記得拒絕再因小事怪人, 爲何沒有這條校訓...Twins-朋友仔 MCSD Training
2006-09-08 22:45
xigong
Rank: 1
等 级:新手上路
威 望:1
帖 子:19
专家分:0
注 册:2006-9-2
收藏
得分:0 
我在对话框类里定义了beginTime,并在其构造函数中对其进行初始化。把this->SetTimer(myTimerID, 10, NULL);    放到了类的初始化函数里。又添加了OnTimer(UINT nIdEvent)函数。但是编译时系统提示说myTimerID未定义。我不知道我放代码的地方有没有错。还有myTimerID是一个什么样类型的数据?我去查了MSDN,但是还是没看懂。不知道我的问题提得是不是有些傻,但我确实不懂,还请指教,谢谢。
2006-09-10 12:34
wfpb
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:2188
专家分:0
注 册:2006-4-2
收藏
得分:0 
SetTimer的第一个参数只是你要设置的记时器的编号,你直接写1都没关系。他这个参数就是和OnTimer的第一个参数对应的。

[glow=255,red,2]wfpb的部落格[/glow] 学习成为生活的重要组成部分!
2006-09-10 15:03
xigong
Rank: 1
等 级:新手上路
威 望:1
帖 子:19
专家分:0
注 册:2006-9-2
收藏
得分:0 
也就是说myTimerID应该是一个常量吧?那我代码放的位置有错吗?
2006-09-10 22:03
wfpb
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:2188
专家分:0
注 册:2006-4-2
收藏
得分:0 

差不多吧


[glow=255,red,2]wfpb的部落格[/glow] 学习成为生活的重要组成部分!
2006-09-10 22:35
快速回复:如何用vc++6.0编个闹钟
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017277 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved