想做一个无窗口类的定时器,特别是要求不使用任何MFC库,在参考了下面两篇文章以后,用刘辉提供的代码,在使用MFC的情况下调试通过。现在我想不使用MFC,将project->setting->general,选择“no using MFC”,就不知道该怎么调试通过了,程序代码如下,每次连接时都会提示:Test.cpp(46) : error C2664: 'SetTimer' : cannot convert parameter 4 from 'void (struct HWND__ *,unsigned int,unsigned int,unsigned long)' to 'void (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,unsigned long)'
None of the functions with this name in scope match the target type请大家帮忙调试,需要注意上面的设置,即不需要MFC。谢谢!http://expert.csdn.net/Expert/topic/1663/1663692.xml?temp=.1654932
http://www.vckbase.com/document/viewdoc.asp?id=594
1.stdafx.h:// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//#if !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)
#define AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000#include <windows.h>// TODO: reference additional headers your program requires here//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)2.stdafx.cpp:// stdafx.cpp : source file that includes just the standard includes
// Test.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information#include "stdafx.h"// TODO: reference any additional headers you need in STDAFX.H
// and not in this file3.test.h://#include <afxtempl.h>//class CMyTimer;
//用模板类中的映射表类定义一种数据类型
//typedef CMap<UINT,UINT,CMyTimer*,CMyTimer*> CTimerMap;class CMyTimer
{
public:
//设置定时器,nElapse表示时间间隔,sz表示要提示的内容
void SetMyTimer(UINT nElapse,char* sz);
//销毁该实例的定时器
void KillMyTimer();
//保存该实例的定时器标志值
UINT m_nTimerID;
//静态数据成员要提示的内容
char* szContent;
//声明静态数据成员,映射表类,用于保存所有的定时器信息
// static CTimerMap m_sTimeMap;
//静态成员函数,用于处理定时器的消息
// static void CALLBACK MyTimerProc(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime);
void CALLBACK MyTimerProc(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime);
CMyTimer();
virtual ~CMyTimer();
};4.Test.cpp:// Test.cpp : Defines the entry point for the application.
//#include "stdafx.h"
#include <stdio.h>
#include "test.h"//必须要在外部定义一下静态数据成员
//CTimerMap CMyTimer::m_sTimeMap;int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
CMyTimer m_myTimer;
m_myTimer.SetMyTimer(2000,"hello!"); MessageBox(0,"定时器开始工作(先不要按确定,要结束程序时按确定)","你好",MB_OK); m_myTimer.KillMyTimer(); return 0;
}CMyTimer::CMyTimer()
{
m_nTimerID = 0;
}CMyTimer::~CMyTimer()
{
}void CALLBACK CMyTimer::MyTimerProc(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime)
{
char sz[200];
// sprintf(sz,"%d号定时器:%s",idEvent,m_sTimeMap[idEvent]->szContent);
sprintf(sz,"%d号定时器:%s",idEvent,szContent);
MessageBox(0,sz,"你好",MB_OK);
}void CMyTimer::SetMyTimer(UINT nElapse,char* sz)
{
szContent = sz;
m_nTimerID = SetTimer(NULL,NULL,nElapse,MyTimerProc);
// m_sTimeMap[m_nTimerID] = this;
}void CMyTimer::KillMyTimer()
{
KillTimer(NULL,m_nTimerID);
// m_sTimeMap.RemoveKey(m_nTimerID);
}
None of the functions with this name in scope match the target type请大家帮忙调试,需要注意上面的设置,即不需要MFC。谢谢!http://expert.csdn.net/Expert/topic/1663/1663692.xml?temp=.1654932
http://www.vckbase.com/document/viewdoc.asp?id=594
1.stdafx.h:// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//#if !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)
#define AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000#include <windows.h>// TODO: reference additional headers your program requires here//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)2.stdafx.cpp:// stdafx.cpp : source file that includes just the standard includes
// Test.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information#include "stdafx.h"// TODO: reference any additional headers you need in STDAFX.H
// and not in this file3.test.h://#include <afxtempl.h>//class CMyTimer;
//用模板类中的映射表类定义一种数据类型
//typedef CMap<UINT,UINT,CMyTimer*,CMyTimer*> CTimerMap;class CMyTimer
{
public:
//设置定时器,nElapse表示时间间隔,sz表示要提示的内容
void SetMyTimer(UINT nElapse,char* sz);
//销毁该实例的定时器
void KillMyTimer();
//保存该实例的定时器标志值
UINT m_nTimerID;
//静态数据成员要提示的内容
char* szContent;
//声明静态数据成员,映射表类,用于保存所有的定时器信息
// static CTimerMap m_sTimeMap;
//静态成员函数,用于处理定时器的消息
// static void CALLBACK MyTimerProc(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime);
void CALLBACK MyTimerProc(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime);
CMyTimer();
virtual ~CMyTimer();
};4.Test.cpp:// Test.cpp : Defines the entry point for the application.
//#include "stdafx.h"
#include <stdio.h>
#include "test.h"//必须要在外部定义一下静态数据成员
//CTimerMap CMyTimer::m_sTimeMap;int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
CMyTimer m_myTimer;
m_myTimer.SetMyTimer(2000,"hello!"); MessageBox(0,"定时器开始工作(先不要按确定,要结束程序时按确定)","你好",MB_OK); m_myTimer.KillMyTimer(); return 0;
}CMyTimer::CMyTimer()
{
m_nTimerID = 0;
}CMyTimer::~CMyTimer()
{
}void CALLBACK CMyTimer::MyTimerProc(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime)
{
char sz[200];
// sprintf(sz,"%d号定时器:%s",idEvent,m_sTimeMap[idEvent]->szContent);
sprintf(sz,"%d号定时器:%s",idEvent,szContent);
MessageBox(0,sz,"你好",MB_OK);
}void CMyTimer::SetMyTimer(UINT nElapse,char* sz)
{
szContent = sz;
m_nTimerID = SetTimer(NULL,NULL,nElapse,MyTimerProc);
// m_sTimeMap[m_nTimerID] = this;
}void CMyTimer::KillMyTimer()
{
KillTimer(NULL,m_nTimerID);
// m_sTimeMap.RemoveKey(m_nTimerID);
}
解决方案 »
- closesocket问题
- 求解:使用阻塞模式封装CSOCKET的DLL调用异常
- 如何在界面上模拟出鼠标?
- 怎么改成Release办?如何看出来与原来的DeBug不同??
- 怎么设置多文档窗口中文档窗口中的自动折行,象notepad中一样。。。
- 我程序中碰到的socket问题?也许很菜,也许很高深,请高手们救救我吧?????问题解决了还有高分重酬!!!
- 是不是DCOM客户端都要装服务器端组件信息?
- 从Access数据库中读取一张表的数据
- 在线急聘上海程序员业余开发,要求见内——>
- Visual Studio中的Macro功能不能使用了, 请问是什么原因
- 关于程序在内存中的组织形式(非专业人士勿进)
- 请问:在线程里连接数据库的问题?
应该是保证这4个参数都全
UINT_PTR SetTimer(
HWND hWnd, // handle to window
UINT_PTR nIDEvent, // timer identifier
UINT uElapse, // time-out value
TIMERPROC lpTimerFunc // timer procedure
);
看你应该是缺了第一个,
可以这样:
SetTimer(NULL, 0, 200, MyTimerProc);
//static void CALLBACK MyTimerProc(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime);
void CALLBACK MyTimerProc(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime);
//#include "stdafx.h"
#include <windows.h>
HWND hwnd;LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
void CALLBACK MyTimerProc( UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2 );
void
CALLBACK MyTimerProc( UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2 )
{
::MessageBox( hwnd, "NULL", "NULL", MB_OK );
}int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInst, LPSTR lpszCmdLine, int nCmdShow )
{
MSG Msg;
WNDCLASS wndclass;
char lpszClassName[]="Class";
char lpszTitle[]="窗口示例"; wndclass.style=0;
wndclass.lpfnWndProc=WndProc;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground = ( HBRUSH )GetStockObject( WHITE_BRUSH );
wndclass.lpszMenuName=NULL;
wndclass.lpszClassName=lpszClassName;
if(!RegisterClass(&wndclass))
{
MessageBeep(0);
return FALSE;
}
hwnd=CreateWindow(lpszClassName,
lpszTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
::SetTimer( hwnd, 8888, 1000, ( TIMERPROC )MyTimerProc );
ShowWindow( hwnd,nCmdShow);
UpdateWindow( hwnd );
while(GetMessage(&Msg,NULL,0,0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
to Mackz: 我都是试了,静态或非静态的都不行。to JennyVenus: 当
void CALLBACK CMyTimer::MyTimerProc(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime)是一个类成员的时候,强制转换不起作用,连接的时候提示:
error C2440: 'type cast' : cannot convert from '' to 'void (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,unsigned long)'
None of the functions with this name in scope match the target type