如何使用rad studio显示窗口总数
How to show total number of windows using rad studio?
我正在尝试下面的代码在我的cpp文件,它给我的错误:
[bcc32错误]Unit1.cpp(15): E2031不能从'int (stdcall * (_closure)(HWND *,long))(HWND__ *,long)'转换为'int (stdcall *)(HWND *,long)'
我做错了什么?
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
BOOL WINAPI EnumWindows((WNDENUMPROC) EnumWinProc, NULL);
}
BOOL CALLBACK EnumWinProc(HWND hwnd, LPARAM lParam)
{
char title[80];
GetWindowText(hwnd,title,sizeof(title));
Listbox1->Items->Add(title);
return TRUE;
}
您所展示的不可能是您的实际代码。首先,您对EnumWindows()
使用的语法是错误的,不能按原样编译。其次,错误是抱怨转换__closure
,这意味着您试图使用非静态类方法作为回调(这是您不能做的),但在您所展示的代码中没有这样的方法。
class TForm1 : public TForm
{
__published:
TListBox *ListBox1;
...
private:
static BOOL CALLBACK EnumWinProc(HWND hwnd, LPARAM lParam);
...
public:
__fastcall TForm1(TComponent* Owner);
...
};
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
EnumWindows(&EnumWinProc, reinterpret_cast<LPARAM>(this));
}
BOOL CALLBACK TForm1::EnumWinProc(HWND hwnd, LPARAM lParam)
{
TCHAR title[80];
if (GetWindowText(hwnd, title, 80))
reinterpret_cast<TForm1*>(lParam)->ListBox1->Items->Add(title);
return TRUE;
}
另外:
// Note: NOT a member of the TForm1 class...
BOOL CALLBACK EnumWinProc(HWND hwnd, LPARAM lParam)
{
TCHAR title[80];
if (GetWindowText(hwnd, title, 80))
reinterpret_cast<TStrings*>(lParam)->Add(title);
return TRUE;
}
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
EnumWindows(&EnumWinProc, reinterpret_cast<LPARAM>(ListBox1->Items));
}
丢失BOOL WINAPI
。你正在尝试调用一个函数,而不是声明一个。
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
EnumWindows((WNDENUMPROC) EnumWinProc, NULL);
}
同时,丢掉不必要的(WNDENUMPROC)
转换。你的回调函数应该有正确的签名,如果没有,你想知道。
相关文章:
- 如果不在窗口 10 中声明名为 openCV 的 openCV namedWindow,QT 图像显示将无法正常工作
- Visual Studio 2017 停止工作,并在打开后显示许多控制台窗口
- 在 GLFW 窗口中显示 FFMPEG 解码帧
- Gtkmm 窗口为空白,不显示任何小部件或标题
- 为什么输出窗口上没有显示输出?
- C++ 窗口显示无框图像
- 如何使用Qt在新窗口中显示视频帧
- 如何以编程方式使窗口全屏显示?
- 强制将以SW_HIDE启动的进程中的窗口显示为STARTUPINFO
- 制作垫子类型对象的数组.输出窗口显示同一帧
- Gtk::在将我的gtkmm2移植到gtkmm3应用程序时,窗口显示并退出
- OpenGL:新窗口显示当前打开的窗口的内容
- WINAPI 创建窗口显示奇怪的结果
- 为什么通过CreateProcess调用的程序的窗口显示为SW_HIDE和CREATE_NO_INDOW
- 输出窗口显示三个图像,而不是一个
- 分窗口显示一个软件,总是在最上面
- WINAPI -窗口显示在调试版本中,而不是在发布版本中
- 在Visual Studio中使用本地Windows调试器运行第一个程序。输出窗口显示大量"Cannot find or open the PDB file"
- 我们如何防止控制台窗口显示在Visual Studio下
- 更新窗口显示OpenGL/GLUT c++