Faild to SetTimer!

tinymouse 2000-02-12 09:57:00
In which condition this could happen?
How to avoid this?

My source code are here:
CMainFrameWnd::NewObject()
{
...
UINT uTimeSetted=0;
do
timesetted=SetTimer(1,timer,NULL);
while (uTimeSetted);//死循环
...
}//CMainFrameWnd is derived from CMainWnd.
...全文
287 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Sniper 2000-02-15
  • 打赏
  • 举报
回复
正如darkwing所说,tinymouse的逻辑搞反了。
SimonDW 2000-02-14
  • 打赏
  • 举报
回复
while (! uTimeSetted)才对
WHQ 2000-02-14
  • 打赏
  • 举报
回复
窗口未创建时,SetTimer肯定会失败的,应该如Sniper所说,在OnCreate时调用SetTimer
fbq 2000-02-14
  • 打赏
  • 举报
回复
由于一些原因,如系统很繁忙,SetTimer可能失败!我见过美国的一个大程序,100万行规模,运行时100多个线程,它对于SetTimer要写三次,即当SetTimer失败后再SetTimer,再失败后再SetTimer,如果还失败,就返回错误.开始我们并不理解这种做法,但实际运行时,当系统很繁忙时,SetTimer出现了不定期错误,我们才明白老美的这种解决方法!
zhangjun 2000-02-14
  • 打赏
  • 举报
回复
不能用while(...)
nTimeSetted 是 timer ID
当然死循环
应该响因WM_ONTIMER 事件
Sniper 2000-02-13
  • 打赏
  • 举报
回复
不需要这样调用,可能你调用的时机不对,当窗口对象创建前调用会导致失败。你可以OnCreate()方法中调用试一下。
tinymouse 2000-02-13
  • 打赏
  • 举报
回复
I want it could set timer success here.
At first I use code as this:

UINT uTimeSetted=SetTimer(Condition,100,NULL);
ASSERT(uTimeSetted==0);//Message wrong when run it.
Sniper 2000-02-13
  • 打赏
  • 举报
回复
为什么要这样调用SetTimer,一次不行吗?
GoldenLion 2000-02-13
  • 打赏
  • 举报
回复
do
utimesetted=SetTimer(1,timer,NULL);
while (!uTimeSetted);//if non-zero, success
// MainFrm.cpp : implementation of the CMainFrame class // #include "stdafx.h" #include "Snake.h" #include "MainFrm.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CMainFrame IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd) BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) //{{AFX_MSG_MAP(CMainFrame) ON_WM_CREATE() //}}AFX_MSG_MAP END_MESSAGE_MAP() static UINT indicators[] = { ID_SEPARATOR, // status line indicator ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL, }; ///////////////////////////////////////////////////////////////////////////// // CMainFrame construction/destruction CMainFrame::CMainFrame() { // TODO: add member initialization code here } CMainFrame::~CMainFrame() { } int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || !m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) { TRACE0("Failed to create toolbar\n"); return -1; // fail to create } if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT))) { TRACE0("Failed to create status bar\n"); return -1; // fail to create } // TODO: Delete these three lines if you don't want the toolbar to // be dockable m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndToolBar); return 0; } BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { if( !CFrameWnd::PreCreateWindow(cs) ) return FALSE; // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return TRUE; } ///////////////////////////////////////////////////////////////////////////// // CMainFrame diagnostics #ifdef _DEBUG void CMainFrame::AssertValid() const { CFrameWnd::AssertValid(); } void CMainFrame::Dump(CDumpContext& dc) const { CFrameWnd::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CMainFrame message handlers //DEL void CMainFrame::OnGameStart() //DEL { //DEL // TODO: Add your command handler code here //DEL IniGame(); //DEL m_nGameStatus = 1; //DEL SetTimer(1,100,NULL); //DEL Invalidate(); //DEL }

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧