Accessing LPARAM param from SendMessage acts weird.

Mark Moorhen Mark at Moorhen.com
Sun Nov 4 19:06:22 UTC 2018


Another Windows challenge:

I'm trying to get the title of the active window even if it is 
from an external application. This is what I've come up with so 
far:

<D>
import std.stdio;
import core.sys.windows.windows;

extern (Windows)

void main()
{
	HWND foreground = GetForegroundWindow();
	const(wchar) title;

	int length = SendMessage(foreground, WM_GETTEXTLENGTH, 0, 0);
	SendMessage(foreground, WM_GETTEXT, length, 
LPARAM(title));			//LPARAM is a Long Pointer

	writeln(length);
	writeln(title);

}
</D>

Outputs :

27                                                                
                                                       ´┐┐

So the lengt of the foreground windows title should be 27 chars 
long, but the title is only 3 chars (and kinda funny ones too:-(

Anyone ideas?



More information about the Digitalmars-d-learn mailing list