本文介绍了如何将enumwindowsproc的结果移交给结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!

枚举所有可见窗口时出现问题.
我的执行工作"的校准功能如下所示.
如您所见,我将找到的每个标题及其句柄都写到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; }
};




这篇关于如何将enumwindowsproc的结果移交给结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 10:02