在程序中我使用這一個語句,為什么會出錯?
#include "winuser.h"
....
bool KeyLib::GetAllTopWindow()
{
FreeWindow(WindowRoot);
if(EnumWindows((WNDENUMPROC)EnumWindowsProc, 0 ))
{
FreeSnapshot();
GetSnapshot();
pWindow=WindowRoot;
while(pWindow)
{
pThread=ThreadRoot;
while ( pThread )
{
if ( pThread->ThreadId == pWindow->ThreadId )
{
pWindow->Thread = pThread;
pProcess = ProcessRoot;
while ( pProcess )
{
if ( pProcess->ProcessId == pThread->OwnerProcessId )
{
pWindow->ProcessId = pProcess->ProcessId;
pWindow->Process = pProcess;
strcpy ( pWindow->FileName, pProcess->FileName );
break;
}
pProcess = pProcess->Next;
}
break;
}
pThread = pThread->Next;
}
pWindow = pWindow->Next;
}
return true;
}
else return false;
}
出錯提示如下:
E:\myprogramm\KeyMessage\KeyLib.cpp(378) : error C2440: 'type cast' : cannot convert from '' to 'int (__stdcall *)(struct HWND__ *,long)'
None of the functions with this name in scope match the target type
E:\myprogramm\KeyMessage\KeyLib.cpp(439) : error C2440: 'type cast' : cannot convert from '' to 'int (__stdcall *)(struct HWND__ *,long)'
None of the functions with this name in scope match the target type
Error executing cl.exe.KeyMessage.exe - 2 error(s), 0 warning(s)
#include "winuser.h"
....
bool KeyLib::GetAllTopWindow()
{
FreeWindow(WindowRoot);
if(EnumWindows((WNDENUMPROC)EnumWindowsProc, 0 ))
{
FreeSnapshot();
GetSnapshot();
pWindow=WindowRoot;
while(pWindow)
{
pThread=ThreadRoot;
while ( pThread )
{
if ( pThread->ThreadId == pWindow->ThreadId )
{
pWindow->Thread = pThread;
pProcess = ProcessRoot;
while ( pProcess )
{
if ( pProcess->ProcessId == pThread->OwnerProcessId )
{
pWindow->ProcessId = pProcess->ProcessId;
pWindow->Process = pProcess;
strcpy ( pWindow->FileName, pProcess->FileName );
break;
}
pProcess = pProcess->Next;
}
break;
}
pThread = pThread->Next;
}
pWindow = pWindow->Next;
}
return true;
}
else return false;
}
出錯提示如下:
E:\myprogramm\KeyMessage\KeyLib.cpp(378) : error C2440: 'type cast' : cannot convert from '' to 'int (__stdcall *)(struct HWND__ *,long)'
None of the functions with this name in scope match the target type
E:\myprogramm\KeyMessage\KeyLib.cpp(439) : error C2440: 'type cast' : cannot convert from '' to 'int (__stdcall *)(struct HWND__ *,long)'
None of the functions with this name in scope match the target type
Error executing cl.exe.KeyMessage.exe - 2 error(s), 0 warning(s)
解决方案 »
- 潘爱民的编程水平怎么样?
- 这些运算符什么意思呀
- 简单问题,有经验高手帮忙!
- 请问:new TCHAR[123]和new TCHAR(123)有什莫区别?
- 为什么我用BitBlt到客户区中的图形,在打印预览中不能正确显示,分不多,大家帮帮我
- 请问改变window 窗体的caption中的字体需要用到那些api ?
- 请问,如何能让我的程序的图表在WINDOWS的右下角,就是放在QQ图标和输入法图标的那个位置
- 急!急!急!关于FTP的问题. 在线等候!!!
- 做关于数据库的程序,怎样才能把界面做得比较好看呢?
- 看书还是提问?探讨“Windows编程“的学习方法!
- 下面是一个做好的 alt 针对 vfp 数据库的一个控件,谁能来帮我看看做个详细说明?
- 请问:如何求两数余数的算法(这两个数大到不能用基本数据类型来存储,只能用字符串)
把她定义成静态成员函数或者全局函数。
(不是静态成员函数,就出现这样的问题,因为静态成员函数没有this指针!)
#include <iostream>
#include <windows.h>
using namespace std;class CA {
private:
static BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam) {
const int BUFF_SIZE = 256;
static TCHAR szWndTxt[BUFF_SIZE]; GetWindowText(hWnd, szWndTxt, BUFF_SIZE);
cout << szWndTxt << endl; return TRUE;
};
public:
void Func() const {
if(EnumWindows((WNDENUMPROC)EnumWindowsProc, 0 )) {
cout << "Y" << endl;
}
}
};void main(void) {
CA objA;
objA.Func();
}
能否講詳細一點?基礎太差了!
謝謝!
BOOL CALLBACK KeyLib::EnumWindowsProc(HWND hwnd, LPARAM lparam)
{
int i=sizeof(TWINDOW);
if(ChildRoot==NULL)
{
pWindow2=new TWINDOW;
ChildCount=1;
memset(pWindow2,0,i);
ChildRoot=pWindow2;
}
else
{
ChildCount++;
pWindow2->Next=new TWINDOW;
pWindow2=pWindow2->Next;
memset(pWindow2,0,i);
}
pWindow2->Visible=IsWindowVisible(hwnd);
pWindow2->Handle = hwnd;
pWindow2->ThreadId = GetWindowThreadProcessId(hwnd,&(pWindow2->ProcessId));
GetClassName( hwnd, pWindow2->ClassName, MAX_PATH);
int j = GetWindowTextLength(hwnd);
pWindow2->Name = new char[j+4];
GetWindowText( hwnd, pWindow2->Name, j+4);
return true;}BOOL CALLBACK KeyLib::EnumChildProc(HWND hwnd, LPARAM lParam)
{
int i=sizeof(TWINDOW);
if(ChildRoot==NULL)
{
pWindow2=new TWINDOW;
ChildCount=1;
memset(pWindow2,0,i);
ChildRoot=pWindow2;
}
else
{
ChildCount++;
pWindow2->Next=new TWINDOW;
pWindow2=pWindow2->Next;
memset(pWindow2,0,i);
}
pWindow2->Visible=IsWindowVisible(hwnd);
pWindow2->Handle=hwnd;
pWindow2->ThreadId=GetWindowThreadProcessId(hwnd,&(pWindow2->ProcessId));
GetClassName(hwnd,pWindow2->ClassName,MAX_PATH);
int j=GetWindowTextLength(hwnd);
pWindow2->Name=new char[j+4];
GetWindowText(hwnd,pWindow2->Name,j+4);
return true;
}
class KeyLib
{
public:
static BOOL CALLBACK EnumChildProc(HWND hwnd,LPARAM lParam);
static BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lparam);
...
我加在那里,還是不行啊?