csdn中我查到有人问这个问题,可是都没解决。
我是想用SetTimer(1,1000,TimeProc).
int CCh802View::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
SetTimer(1,1000,TimeProc);
return 0;
}void CCh802View::TimeProc(HWND hWnd,UINT message,UINT iTimerID,DWORD dwTime)
{
bool fFlipFlop=false;
RECT rc;
CDC* pDC=GetDC();
MessageBeep(-1);
fFlipFlop=!fFlipFlop;
CWnd::GetClientRect(&rc);
CBrush newBrush;
newBrush.CreateSolidBrush(fFlipFlop?RGB(255,0,0):RGB(0,255,255));
pDC->FillRect(&rc,&newBrush);
ReleaseDC(pDC);
newBrush.DeleteObject();}
头文件中我已声明为static void CALLBACK TimeProc(HWND hWnd,UINT message,UINT iTimerID,DWORD dwTime);
只有声明为static,因为是回调函数,不需要this指针,否则出错。
可是声明后又出现问题:
H:\project\vc6\ch802\ch802View.cpp(120) : error C2352: 'CWnd::GetDC' : illegal call of non-static member function
d:\program files\vc6\vc98\mfc\include\afxwin.h(2067) : see declaration of 'GetDC'
H:\project\vc6\ch802\ch802View.cpp(123) : error C2352: 'CWnd::GetClientRect' : illegal call of non-static member function
d:\program files\vc6\vc98\mfc\include\afxwin.h(2051) : see declaration of 'GetClientRect'
H:\project\vc6\ch802\ch802View.cpp(128) : error C2352: 'CWnd::ReleaseDC' : illegal call of non-static member function
d:\program files\vc6\vc98\mfc\include\afxwin.h(2069) : see declaration of 'ReleaseDC'
Error executing cl.exe.ch802.exe - 3 error(s), 0 warning(s),
我理解是static函数,不能调用其他成员函数?
我该怎么解决?
我是想用SetTimer(1,1000,TimeProc).
int CCh802View::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
SetTimer(1,1000,TimeProc);
return 0;
}void CCh802View::TimeProc(HWND hWnd,UINT message,UINT iTimerID,DWORD dwTime)
{
bool fFlipFlop=false;
RECT rc;
CDC* pDC=GetDC();
MessageBeep(-1);
fFlipFlop=!fFlipFlop;
CWnd::GetClientRect(&rc);
CBrush newBrush;
newBrush.CreateSolidBrush(fFlipFlop?RGB(255,0,0):RGB(0,255,255));
pDC->FillRect(&rc,&newBrush);
ReleaseDC(pDC);
newBrush.DeleteObject();}
头文件中我已声明为static void CALLBACK TimeProc(HWND hWnd,UINT message,UINT iTimerID,DWORD dwTime);
只有声明为static,因为是回调函数,不需要this指针,否则出错。
可是声明后又出现问题:
H:\project\vc6\ch802\ch802View.cpp(120) : error C2352: 'CWnd::GetDC' : illegal call of non-static member function
d:\program files\vc6\vc98\mfc\include\afxwin.h(2067) : see declaration of 'GetDC'
H:\project\vc6\ch802\ch802View.cpp(123) : error C2352: 'CWnd::GetClientRect' : illegal call of non-static member function
d:\program files\vc6\vc98\mfc\include\afxwin.h(2051) : see declaration of 'GetClientRect'
H:\project\vc6\ch802\ch802View.cpp(128) : error C2352: 'CWnd::ReleaseDC' : illegal call of non-static member function
d:\program files\vc6\vc98\mfc\include\afxwin.h(2069) : see declaration of 'ReleaseDC'
Error executing cl.exe.ch802.exe - 3 error(s), 0 warning(s),
我理解是static函数,不能调用其他成员函数?
我该怎么解决?
然后在TimerProc()函数中使用api函数。
{
bool fFlipFlop=false;
RECT rc;
CCh802View* pThis = (CCh802View*)CWnd::FromHandle(hWnd);
CDC* pDC = pThis->GetDC();
MessageBeep(-1);
fFlipFlop=!fFlipFlop;
pThis->GetClientRect(&rc);
CBrush newBrush;
newBrush.CreateSolidBrush(fFlipFlop?RGB(255,0,0):RGB(0,255,255));
pDC->FillRect(&rc,&newBrush);
pThis->ReleaseDC(pDC);
newBrush.DeleteObject();
}
我还有个问题想问一下:
WM_SETTINGCHANGE,WM_SIZING;这些消息msdn上有,为什么mfc上查不到,我要用到这些消息,该怎么办?
我的分少,就不再另给分了。