如何将enumwindowsproc的结果移交给结构 [英] How to hand over the results of enumwindowsproc to a struct
问题描述
你好!
枚举所有可见窗口时出现问题.
我的执行工作"的校准功能如下所示.
如您所见,我将找到的每个标题及其句柄都写到handlestruct.h中定义的结构中.
当我打电话
时,这工作得很好
EnumWindows(EnumVisiWindowTitles,NULL);
来自存储在同一文件中的主文件.
但是:我想从位于项目中不同cpp中的主调用EnumWindows(EnumVisiWindowTitles,NULL).
根据我定义MYHANDLES lumpi [10]的位置,它在回调函数的主或中是已知的.
所以我的问题是:我想调用EnumWindows(EnumVisiWindowTitles,NULL)并移交给lumpi [0]的指针.但我不知道如何解决,因为它不是LPARAM ...我尝试过打字,但没有成功.有人有什么想法吗? :doh:
谢谢您的帮助!
Hello !
I have a problem when enumerating all visible windows.
My calback function which is "doing the job" is shown below.
As you can see I am writing every caption i find together with its handle into a struct defined in handlestruct.h.
This works just fine when I call
EnumWindows(EnumVisiWindowTitles, NULL);
from a main which is stored in the same file.
BUT: I want to call EnumWindows(EnumVisiWindowTitles, NULL) from a main which is located in a different cpp in the project.
Depending on where I define MYHANDLES lumpi[10] it''s known in the main OR in the callback function.
So my question is: I would like to call EnumWindows(EnumVisiWindowTitles, NULL) and hand over a pointer to lumpi[0]. But I dont know how to it over because it is no LPARAM... I''ve tried to typecast but with no sucess. Does anyone have any ideas? :doh:
Tahnk you for any help!
#include "handlestruct.h"
MYHANDLES lumpi[10];
using namespace std;
BOOL CALLBACK EnumVisiWindowTitles(HWND hWnd, LPARAM lparam)
{
TCHAR String[200];
if (!hWnd)
return TRUE;// Not a window, return TRUE to Enumwindows in order to get the next handle
if (!::IsWindowVisible(hWnd))
return TRUE;// Not visible, return TRUE to Enumwindows in order to get the next handle
if (!SendMessageW(hWnd, WM_GETTEXT, sizeof(String), (LPARAM)String))
return TRUE;// No window title, return TRUE to Enumwindows in order to get the next handle
lumpi[lumpi[0].count].haendchen = hWnd;
for (int n=0; n<201; n++)//copy the caption to lumpi struct
{
lumpi[lumpi[0].count].title[n] = String[n];
}
lumpi[0].count++; //Increase counter
wcout<<String<<''\n'';
return true; //return true to get next handle
}
推荐答案
class CEnumWindows
{
public:
CEnumWindows(){}
~CEnumWindows(){ FreeAll(); }
int Collect(){ FreeAll(); return EnumWindows(&CEnumWindows::__fnEnum,(LPARAM)this); }
protected:
long GetWindowInfos(HWND hwnd)
{
TCHAR txt[512];
int len;
ASSERT(IsWindow(hwnd)); // this should never happens
if(len=GetWindowText(hwnd,txt,sizeof(txt)/sizeof(txt[0])))
AddCaption(txt,len);
return 1; // continue enum
}
void AddCaption(const TCHAR* txt,const int len){ /* do anything... */ }
void FreeAll(){ /* free your storage */ }
private:
static int FAR PASCAL __fnEnum(HWND hwnd,LPARAM p){ return p?((CEnumWindows*)p)->GetWindowInfos(hwnd):0; }
};
谢谢大家的帮助.
我昨天确实在
得到了答案
http://stackoverflow.com/questions/4460972/passing-a-指向as-lparam-to-enumwindowsproc-how [ ^ ]
但由于某些服务器错误而无法在此处发布...
感谢所有在我的问题上花费时间的人.
编码愉快!
:laugh:
Hi and thank you all for your help.
I did get the answer yesterday at
http://stackoverflow.com/questions/4460972/passing-a-pointer-as-lparam-to-enumwindowsproc-how[^]
but could not post it here due to some server error...
Thanks to everyone who spend time on my question.
Happy coding !
:laugh:
您如何精确转换类型? LPARAM和指针应兼容;也许您尝试直接键入强制转换MYHANDLES?
这个:
(LPARAM) lumpi[0]
可能不起作用(取决于MYHANDLES的位数),但这是:
(LPARAM) &lumpi[0]
应该很好.
简单,不太优雅的方法是添加以下内容:
extern MYHANDLES lumpi[10];
在其他" cpp文件中.
How exactly did you do your type cast? LPARAM and a pointer should be compatible; perhaps you tried to type cast MYHANDLES directly?
This:
(LPARAM) lumpi[0]
might not work (depending on how many bits MYHANDLES is), but this:
(LPARAM) &lumpi[0]
should be just fine.
The easy, less elegant, way would be to just add this:
extern MYHANDLES lumpi[10];
in the ''other'' cpp file.
这篇关于如何将enumwindowsproc的结果移交给结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!