|
#include "stdafx.h"
#using <mscorlib.dll>
#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
#include <tchar.h>
#include <windows.h>
using namespace System;
using namespace System::ComponentModel;
using namespace System::Drawing;
using namespace System::Windows::Forms;
__gc class CEnumWindows
{
private:
__nogc class _CEnumWindows
{
private:
static BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM)
{
CEnumWindows* pew = CEnumWindows::GetClass();
pew->m_EnumProc->Invoke(hwnd, NULL);
return TRUE;
}
public:
void StartFinding()
{
EnumWindows((WNDENUMPROC)_CEnumWindows::EnumWindowsProc,NULL);
}
};
private:
_CEnumWindows* m_ew;
public:
__delegate bool EnumProc(IntPtr hwnd, IntPtr lParam);
static CEnumWindows* GetClass()
{
return m_pclass;
}
static CEnumWindows* m_pclass=NULL;
CEnumWindows()
{
m_pclass = this;
m_ew = new _CEnumWindows();
}
~CEnumWindows()
{
delete m_ew;
}
void StartFinding()
{
m_ew->StartFinding();
}
EnumProc* m_EnumProc;
};
public __gc class NForm : public Form
{
public:
bool EWHandler(IntPtr hwnd, IntPtr lParam)
{
char buff[512];
if(GetWindowText((HWND)hwnd.ToInt32(),buff,511))
{
String* s = String::Format("{0}{1}",
__box(hwnd.ToInt32())->ToString("X8")->PadRight(30),
Convert::ToString(buff));
lbox->Items->Add(s);
}
return false;
}
NForm()
{
StartPosition = FormStartPosition::CenterScreen;
Text = "Callbacks with IJW - Nish for CodeProject - Avoid DllImport";
Size = Drawing::Size(750,550);
FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedDialog;
MaximizeBox = false;
lbox = new ListBox();
lbox->Location=Point(5,5);
lbox->Size=Drawing::Size(730,500);
lbox->Sorted = true;
Controls->Add(lbox);
CEnumWindows* p = new CEnumWindows();
p->m_EnumProc = new CEnumWindows::EnumProc(this,&NForm::EWHandler);
p->StartFinding();
}
ListBox* lbox;
};
int __stdcall WinMain(HINSTANCE,HINSTANCE,LPSTR,int)
{
Application::Run(new NForm());
return 0;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Nish Nishant is a technology enthusiast from Columbus, Ohio. He has over 20 years of software industry experience in various roles including Chief Technology Officer, Senior Solution Architect, Lead Software Architect, Principal Software Engineer, and Engineering/Architecture Team Leader. Nish is a 14-time recipient of the Microsoft Visual C++ MVP Award.
Nish authored C++/CLI in Action for Manning Publications in 2005, and co-authored Extending MFC Applications with the .NET Framework for Addison Wesley in 2003. In addition, he has over 140 published technology articles on CodeProject.com and another 250+ blog articles on his WordPress blog. Nish is experienced in technology leadership, solution architecture, software architecture, cloud development (AWS and Azure), REST services, software engineering best practices, CI/CD, mentoring, and directing all stages of software development.
Nish's Technology Blog :
voidnish.wordpress.com