小弟我新建了一个基于对话框的MFC程序,在OnInitialDlg()中设置了多媒体定时器(之前在工程设置中有加入Winmm.lib.库和windows.h 头文件和TimeProc的声明等等)使用了timeSetEvent():hTimer=timeSetEvent(1,1,TimeProc,word,TIME_PERIODIC);
但是总是有错误如下:
error C2065: 'timeSetEvent' : undeclared identifier
error C2065: 'TIME_PERIODIC' : undeclared identifier
,请指点迷津!!!

解决方案 »

  1.   

    没包含Winmm.lib对应的头文件吧
      

  2.   

    MSDN上有说要包含的 
    就是不知道怎么系统不识别TIMESETEVENT函数呢
      

  3.   

    Requirements 
      Windows NT/2000/XP: Included in Windows NT 3.1 and later.
      Windows 95/98/Me: Included in Windows 95 and later.
      Header: Declared in Mmsystem.h; include Windows.h.
      Library: Use Winmm.lib.
      

  4.   

    难道你没包含\Program Files\Microsoft Visual Studio\VC98\INCLUDE??我想也不应该吧,这是VC自己包含的呀,除非你不小心删了
      

  5.   

    我又试过了,上面两个问题解决了,可是又出现新的问题,好像试调用约定的问题,请帮忙看一下!下面试对话框的程序:
    // ceshiDlg.cpp : implementation file
    //#include "stdafx.h"
    #include "ceshi.h"
    #include "ceshiDlg.h"
    #include   "mmsystem.h" 
    #include <windows.h>
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif/////////////////////////////////////////////////////////////////////////////
    // CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialog
    {
    public:
    CAboutDlg();// Dialog Data
    //{{AFX_DATA(CAboutDlg)
    enum { IDD = IDD_ABOUTBOX };
    //}}AFX_DATA // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CAboutDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL// Implementation
    protected:
    //{{AFX_MSG(CAboutDlg)
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
    {
    //{{AFX_DATA_INIT(CAboutDlg)
    //}}AFX_DATA_INIT
    }void CAboutDlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CAboutDlg)
    //}}AFX_DATA_MAP
    }BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
    //{{AFX_MSG_MAP(CAboutDlg)
    // No message handlers
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CCeshiDlg dialog
    CCeshiDlg::CCeshiDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CCeshiDlg::IDD, pParent)
    {
    //{{AFX_DATA_INIT(CCeshiDlg)
    // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT
    // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    }void CCeshiDlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CCeshiDlg)
    // NOTE: the ClassWizard will add DDX and DDV calls here
    //}}AFX_DATA_MAP
    }BEGIN_MESSAGE_MAP(CCeshiDlg, CDialog)
    //{{AFX_MSG_MAP(CCeshiDlg)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CCeshiDlg message handlersBOOL CCeshiDlg::OnInitDialog()
    {
    CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range.
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
    CString strAboutMenu;
    strAboutMenu.LoadString(IDS_ABOUTBOX);
    if (!strAboutMenu.IsEmpty())
    {
    pSysMenu->AppendMenu(MF_SEPARATOR);
    pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
    }
    } // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE); // Set big icon
    SetIcon(m_hIcon, FALSE); // Set small icon
    // hInstance=LoadLibrary("Winmm.lib");
    // GetProcAddress(hInstance,"timeSetEvent);

    // TODO: Add extra initialization here
    hTime=::timeSetEvent(1,1,(LPTIMECALLBACK )TimeProc,word,TIME_PERIODIC);
    return TRUE; // return TRUE  unless you set the focus to a control
     
    }void CCeshiDlg::OnSysCommand(UINT nID, LPARAM lParam)
    {
    if ((nID & 0xFFF0) == IDM_ABOUTBOX)
    {
    CAboutDlg dlgAbout;
    dlgAbout.DoModal();
    }
    else
    {
    CDialog::OnSysCommand(nID, lParam);
    }
    }// If you add a minimize button to your dialog, you will need the code below
    //  to draw the icon.  For MFC applications using the document/view model,
    //  this is automatically done for you by the framework.void CCeshiDlg::OnPaint() 
    {
    if (IsIconic())
    {
    CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle
    int cxIcon = GetSystemMetrics(SM_CXICON);
    int cyIcon = GetSystemMetrics(SM_CYICON);
    CRect rect;
    GetClientRect(&rect);
    int x = (rect.Width() - cxIcon + 1) / 2;
    int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon
    dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
    CDialog::OnPaint();
    }
    }// The system calls this to obtain the cursor to display while the user drags
    //  the minimized window.
    HCURSOR CCeshiDlg::OnQueryDragIcon()
    {
    return (HCURSOR) m_hIcon;
    }void CALLBACK CCeshiDlg::TimeProc(
      UINT uID,      
      UINT uMsg,     
      DWORD dwUser,  
      DWORD dw1,     
      DWORD dw2      
    )
    {
    //do something;
    }下面是出现的问题:
    --------------------Configuration: ceshi - Win32 Debug--------------------
    Compiling...
    ceshiDlg.cpp
    C:\Program Files\Microsoft Visual Studio\MyProjects\ceshi\ceshiDlg.cpp(125) : error C2440: 'type cast' : cannot convert from '' to 'void (__stdcall *)(unsigned int,unsigned int,unsigned long,unsigned long,unsigned long)'
            None of the functions with this name in scope match the target type
    Error executing cl.exe.
    Creating browse info file...ceshi.exe - 1 error(s), 0 warning(s)
      

  6.   

    上面绝大部分都是系统自带的程序,只有三两句是自己的程序
    其中hTime和word的定义是: DWORD word;UINT hTime;
      

  7.   

    TimeProc声明成静态成员函数
    static ...