CWnd::SetTimer This method installs a system timer. A time-out value is specified, and every time a time-out occurs, the system posts a WM_TIMER message to the message queue of the installing application or passes the message to an application-defined TimerProc callback function. UINT SetTimer( UINT nIDEvent, UINT nElapse, void (CALLBACK EXPORT* lpfnTimer)( HWND, UINT, UINT, DWORD) ); Parameters nIDEvent Specifies a nonzero timer identifier. nElapse Specifies the time-out value, in milliseconds. lpfnTimer Specifies the address of the application-supplied TimerProc callback function that processes the WM_TIMER messages. If this parameter is NULL, the WM_TIMER messages are placed in the application message queue and handled by the CWnd object. Return Value The timer identifier of the new timer if the function is successful. An application passes this value to the CWnd::KillTimer method to kill the timer. Nonzero if it is successful; otherwise, it is zero.Res The lpfnTimer callback function need not be named TimerProc, but it must be defined as follows:void CALLBACK EXPORT TimerProc( HWND hWnd, // handle of CWnd that called SetTimer UINT nMsg, // WM_TIMER UINT nIDEvent // timer identification DWORD dwTime // system time );Timers are a limited global resource; therefore it is important that an application check the value returned by the SetTimer method to verify that a timer is actually available.Example This example uses CWnd::SetTimer, CWnd::OnTimer, and CWnd::KillTimer to handle WM_TIMER messages. A timer is set up to send a WM_TIMER message to the main frame window every 2 seconds in OnStartTimer. OnStopTimer will stop the timer by calling CWnd::KillTimer. OnTimer was set up through ClassWizard to handle WM_TIMER messages for the main frame window. In this example, the PC speaker will beep every 2 seconds.void CMainFrame::OnStartTimer() { m_nTimer = SetTimer(1, 2000, 0); }void CMainFrame::OnStopTimer() { KillTimer(m_nTimer); }void CMainFrame::OnTimer(UINT nIDEvent) { MessageBeep(0xFFFFFFFF); // Beep // Call base class handler. CMDIFrameWnd::OnTimer(nIDEvent); }Requirements Windows CE versions: 1.0 and later Header file: Declared in Afxwin.h Platform: H/PC Pro, Palm-size PC, Pocket PCSee Also CWnd::KillTimer Built on Friday, January 12, 2001 -------------------------------------------------------------------------------- Send feedback to MSDN.Look here for MSDN Online resources.
GW_LOG_SC代表十六进制数0x00000001
这些define定义的只是一个助记符
让你在程序中遇见的时候可以读得懂
#define E_SUCCESS 0X00000000 // 成功//command status
为什么要用十六进制来表示呢?他代表什么呢?
代表命令吗?地址?到底什么呢?
if ( XXXXXXX()==E_SUCCESS )
{
//成功代码
}
else
{
//错误处理
}
其实就是宏定义吗.一般c和c++书上讲的都比较详细呀 自己看吧ok?? good luck!
1、当定义超过类型长度是容易看出来,比如:
#define GW_LOG_SC 0x00000001 //command id
#define E_SUCCESS 0X00000000 // 成功//command status
int CanDo()
{
...
return E_SUCCESS;
}
2、某些特定的的操作可通过位运算来加快速度,看看CWnd类的窗口风格定义就知道了。
3、容易给初学者留下“高手”的印象:)
if ( 你是不是什么都没学过)
{
开始学习?;
}
else
{
是不是你没有表达出你的意思?;
}
{if (我很会vc的话)
then
{我会赚好多分
}
else
{我会失去好多分}
}
我是高手了!
then
{我会赚好多分
}一等一的 VC ?
俺好象没有用过 if.... then ??小妹妹总是很可爱
有了她们,写程式再也不枯燥了 :)
MAX_MSG_LEN =16
GW_LOG_SC=0x00000001
if (我是高手)
{我就会有钱;
有美眉;
}
else
{我没有钱;
没有美眉;
}
本小妹本是刚毕业之人,手头没钱又没分,工作苦无边,可惜那公司偏让我用vc,害得我是没日没夜,苦熬煎,幸亏那csdn,大哥大姐们,给我生活的力量,让我有了分又有钱,这恩情,小妹我,永记在心。
CCmppwgDlg::OnTimer(UINT nIDEvent)中的nIDEvent 中指的是什么东西,例如if (nIDEvent==1) //侦听消息包
{}
if(nIDEvent==6){}
if(nIDEvent==2) // 查看连接状态,我不太明白,告诉我好吗?谢谢了!
GW_LOG_SC代表十六进制数0x00000001
{
他不是人;
}
else
{
他是人;
}
return ;
具体的是什么样也不清楚。可以去查一下msdn嘛。
{}
if(nIDEvent==6){}
if(nIDEvent==2) // 查看连接状态
*********************************************************
设了两个定时器(timer)一个用数字1表示,一个用数字2表示(1,2是他们的ID号).定时器,每到设定的时间就会发出WM_TIMER事件.OnTimer(UINT nIDEvent)就是这个事件的处理函数.这段程序的意思是:定时侦听消息包和查看连接状态
如果是1发来的WM_TIMER就侦听消息包,如果是2发来的WM_TIMER就查看连接状态.
/me 递上擦过鼻涕的餐巾纸两张...
英文畅销书 + “金山快译” = 畅销书中文译本
可见金山的翻译还不错,够你用啦,哈哈
在resource.h文件中,定义了 #define IDP_SOCKETS_INIT_FAILED 103
在cmppwg.cpp文件中 AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
告诉我什么意思好吗?
还有,
#ifdef _AFXDLL
Enable3dControls();
#else
Enable3dControlsStatic();
#endif
是什么意思?特别是Enable3dControls();我不懂,告诉我啊,谢谢!
Enable3dControls();怎么是说调用.dll文件的,不明白,这个.dll从哪来,告诉我好吗?谢谢了!
Windows的界面元素是三D的,这一句加载3D界面库DLL
# define MAX(x,y) (x)>(y)?(x);(y)
main()
{int a=5,b=2,c=3,d=3,t;
t=MAX(a+b,c+d)*10;
cout<<t<<endl;
}
在cmppwg.cpp文件中 AfxMessageBox(IDP_SOCKETS_INIT_FAILED);AfxMessageBox 是消息对话框的啦,AfxWin.h中定义的原型如下
int AFXAPI AfxMessageBox(LPCTSTR lpszText, UINT nType = MB_OK,
UINT nIDHelp = 0);
int AFXAPI AfxMessageBox(UINT nIDPrompt, UINT nType = MB_OK,
UINT nIDHelp = (UINT)-1);AFX - Advanced Framework X,呵呵,据说这个 X 是为了好听押韵,也有说是Extention的,如果对MFC底层不是很了解,建议先看看《深入浅出MFC》,还不错了。
有时候没有MSDN也未必就做不了事情,Visual Assist和WinTab这类的IDE插件能帮你快速找到引用的函数原型和定义的.h文件,快速找到函数原型,一般看看就知道怎么用了。你真厉害,是不是在改别人写的代码吧?
还是socket的,不会是代别人发问吧?如果我们老总也向你们老总这样,招聘一堆这样的小妹,俺就没饭吃了 x~`(
================================================================CSDN 论坛助手 Ver 1.0 B0402提供下载。 改进了很多,功能完备!★ 浏览帖子速度极快![建议系统使用ie5.5以上]。 ★ 多种帖子实现界面。
★ 保存帖子到本地[html格式]★ 监视您关注帖子的回复更新。
★ 可以直接发贴、回复帖子★ 采用XML接口,可以一次性显示4页帖子,同时支持自定义每次显示帖子数量。可以浏览历史记录!
★ 支持在线检测程序升级情况,可及时获得程序更新的信息。★★ 签名 ●
可以在您的每个帖子的后面自动加上一个自己设计的签名哟。Http://www.ChinaOK.net/csdn/csdn.zip
Http://www.ChinaOK.net/csdn/csdn.rar
Http://www.ChinaOK.net/csdn/csdn.exe [自解压]
.....
if (bHasAGirlFriend)
{
CString strGFName = GetMyFriendName();
if (strGFName == "youcailing(采苓) ")
{
SetTimer(1, 500, NULL);
}
else
SetTimer(6, 500, NULL);
}
else
{
SetTimer(2, 500, NULL);
}
......CCmppwgDlg::OnTimer(UINT nIDEvent)
{
if (nIDEvent==1) //侦听消息包
{
我会不让你写程序;
}
if(nIDEvent==6)
{
DoNothing();
}
if(nIDEvent==2) // 查看连接状态
{
CString strStatus = Get_youcailing_Status();
CString strStatusMine = GetMyStatus();
if (IsSimulate(strStatus, strStatusMine) == TRUE)
兴许我还有希望;
else
没戏啦;
}
}
SetTimer(6, 500, NULL); SetTimer(2, 500, NULL);中的1,6,2和nIDEvent==1,nIDEvent==6,nIDEvent==2中的1,6,2有联系吗,怎么个练习法,告诉我好吗?
500表示每隔500ms发一次TIMER消息。。
NULL表示采用标准消息处理函数OnTimer(UINT nIDEvent)也不知道我的程序走到那个if语句中去了。。
我满意了再答复你了
#define GW_LOG_SC 0x00000001
161 和 0x00000001分别是什么意思?谢谢!
我猜第1个是maximum message length--最大消息长度
第2个就不晓得了...应该是缩写,你查查源程序把 :)函数的定义查MSDN就可以了。至于学习vc吗,要有耐性。多练习,多实践。
CWnd::SetTimer
This method installs a system timer. A time-out value is specified, and every time a time-out occurs, the system posts a WM_TIMER message to the message queue of the installing application or passes the message to an application-defined TimerProc callback function. UINT SetTimer(
UINT nIDEvent,
UINT nElapse,
void (CALLBACK EXPORT* lpfnTimer)(
HWND, UINT, UINT, DWORD) );
Parameters
nIDEvent
Specifies a nonzero timer identifier.
nElapse
Specifies the time-out value, in milliseconds.
lpfnTimer
Specifies the address of the application-supplied TimerProc callback function that processes the WM_TIMER messages. If this parameter is NULL, the WM_TIMER messages are placed in the application message queue and handled by the CWnd object.
Return Value
The timer identifier of the new timer if the function is successful. An application passes this value to the CWnd::KillTimer method to kill the timer. Nonzero if it is successful; otherwise, it is zero.Res
The lpfnTimer callback function need not be named TimerProc, but it must be defined as follows:void CALLBACK EXPORT TimerProc(
HWND hWnd, // handle of CWnd that called SetTimer
UINT nMsg, // WM_TIMER
UINT nIDEvent // timer identification
DWORD dwTime // system time
);Timers are a limited global resource; therefore it is important that an application check the value returned by the SetTimer method to verify that a timer is actually available.Example
This example uses CWnd::SetTimer, CWnd::OnTimer, and CWnd::KillTimer to handle WM_TIMER messages. A timer is set up to send a WM_TIMER message to the main frame window every 2 seconds in OnStartTimer. OnStopTimer will stop the timer by calling CWnd::KillTimer. OnTimer was set up through ClassWizard to handle WM_TIMER messages for the main frame window. In this example, the PC speaker will beep every 2 seconds.void CMainFrame::OnStartTimer()
{
m_nTimer = SetTimer(1, 2000, 0);
}void CMainFrame::OnStopTimer()
{
KillTimer(m_nTimer);
}void CMainFrame::OnTimer(UINT nIDEvent)
{
MessageBeep(0xFFFFFFFF); // Beep // Call base class handler.
CMDIFrameWnd::OnTimer(nIDEvent);
}Requirements
Windows CE versions: 1.0 and later
Header file: Declared in Afxwin.h
Platform: H/PC Pro, Palm-size PC, Pocket PCSee Also
CWnd::KillTimer Built on Friday, January 12, 2001
--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.
{
m_nTimer = SetTimer(1, 2000, 0);
}void CMainFrame::OnStopTimer()
{
KillTimer(m_nTimer);
}void CMainFrame::OnTimer(UINT nIDEvent)
{
MessageBeep(0xFFFFFFFF); // Beep // Call base class handler.
CMDIFrameWnd::OnTimer(nIDEvent);
}
我想问一下CMDIFrameWnd::OnTimer(nIDEvent);中的nIDEvent为什么不指定为1,难道在这里默认是1吗?
你只有一个SetTimer(1, 2000, 0);干吗非要写上个if (nIDEvent == 1)才舒服啊。。看来有MM喜欢
.....
if (bHasAFriend)
{
CString strGFName = GetMyName();
if (strGFName == "Me")
{
SetTimer(1,1000, NULL);
}
else
SetTimer(6, 60000, NULL);
}
else
{
SetTimer(2, 500, NULL);
}
......CCmppwgDlg::OnTimer(UINT nIDEvent)
{
if (nIDEvent==1) //帮我回答问题
{
我会很高兴!
}
if(nIDEvent==6)//时间有点长奥
{
我会有点高兴!
}
if(nIDEvent==2) //时间还可以,并且我满意
{
兴许我会考虑!
else
继续加油啊!
}
}
youcailing(采苓) 改了以后就没意思了,不知道它能做什么有意义的事。采苓在编程之前要想好自己要达到什么目的,写完程序之后要检查能否达到目的。
if(nIDEvent==2) //时间还可以,并且我满意
{
兴许我会考虑!
else
继续加油啊!
}
这句话错了,自己改错!
如果你对VC觉得难以入门的话,就试着把你自己以前写的一些“重量级”Basic程序改成VC的。
经过这个过程之后你可能就真正掌握了VC.
是语法错误吗?
if(nIDEvent==2) //时间还可以,并且我满意
兴许我会考虑!
else
继续加油啊!
yes?
告诉我啊?
to zaozi(枣子):
你伤害了我,还一笑而过,你说的过分,我伤的难过,眼泪流过,伤心是多余的,只怪自己不懂得太多...~~~~5555~~
我要重整旗鼓,将编程进行到底。
以后大家提问就再前面加3个字"小妹我"保证有大批sl高手帮你,然后你在让他们吐。对与采苓:看了你说的写的, 觉你不是学VC的料赶快换行吧。不是我打击你,你以后会后悔学VC的。2个字"天赋", 一看你就没有.:(
if...
goto Study; //风格不好,不要见怪
else..
goto Study;
Study:
{
还是先学习吧,这样问问题也不是办法;
}
难得有MM进来坐坐。。
大多数女人做程序员,先天就有缺陷,这是公认的道理。youcailing(采苓)“同学“的好学是非常值得鼓励的,
但鉴于youcailing(采苓)“同学“的个人发展,
本人赞同alphapiao(叶飘飞)的看法。或许youcailing(采苓)有一天成了极少数的那一派(个人希望不是:)),
那就是CSDN又毒害了了一个根正苗红的好MM了。以上发言仅限于 class femal.