﻿id	summary	reporter	owner	description	type	status	milestone	component	version	severity	resolution	keywords	cc
529	Identifying .NET controls using WM_GETCONTROLNAME	zfisherdrums	Jon	"Having read previous request and response for DataGrid on ticket #23, I do not wish to beleaguer the point. Nor is it my place to specifiy what is/is not trivial to accommodate into AutoIT. However, with all the requests for persistent .NET control identification, I wonder what is the possibility of utilizing the ""WM_GETCONTROLNAME"" message either natively or in a standard UDF.

I enclose the following MSDN code only to provide some fruits of my ""research"" on this, and my failed attempt to port it into a UDF:

{{{
/*
given an hWnd, this code attempts to send a message to the window to get the
instance name of the control bound to the window
Steps:
1. Get the Value of the WM_GETCONTROLNAME message (RegisterWindowMessage)
2. Get the Process Info for this window (GetWindowThreadProcessId)
3. Open the process and get a process handle (OpenProcess)
4. Allocate memory within the target process (VirtualAllocEx)
5. Send the target window a WM_GETCONTROLNAME message and a pointer to the
memory (SendMessageTimeout)
6. Read the response from the allocated memory (ReadProcessMemory)
7. Close process handle, release memory
*/
//we enter this code with hwnd set to a specific window handle
//error checking omitted for brevity

const int bufsize = 1024;
wchar_t CtlName[bufsize];
DWORD ProcessId;
SIZE_T NumRead;

unsigned int GetName = RegisterWindowMessage(L""WM_GETCONTROLNAME"");
DWORD dwResult = GetWindowThreadProcessId(hwnd, &ProcessId);
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS,false,ProcessId);
LPVOID OtherMem = VirtualAllocEx(hProcess, 0, bufsize, MEM_COMMIT,PAGE_READWRITE);
LPARAM lpOtherMem = reinterpret_cast<LPARAM>(OtherMem);
unsigned int SendFlags = SMTO_ABORTIFHUNG|SMTO_BLOCK;
LRESULT lResult = SendMessageTimeout(hwnd, GetName, bufsize, lpOtherMem, SendFlags, 5000, &NumRead);

//if lResult == 0 then failure or timeout, if GetLastError reports 0, then it is a timeout
//if successful NumRead contains the number of characters, if NumRead == 0 then the name is empty

BOOL bResult = ReadProcessMemory(hProcess, OtherMem, CtlName, bufsize,
&NumRead);

//CtlName now contains the instance name of the control, or is empty if there is no name

//clean up
bResult = CloseHandle(hProcess);
bResult = VirtualFreeEx(hProcess,OtherMem,1024,MEM_RELEASE);
}}}

[http://www.autoitscript.com/forum/index.php?showtopic=78561&view=findpost&p=567202]"	Feature Request	closed	3.3.1.1	AutoIt		None	Completed	NET controls	
