Hello,
I'm currently trying to write a function that gets the HWND of the window currently active in mIRC. It is supposed to work like $active, only return the HWND instead of the window name.
I have already messed around with GetForegroundWindow(), GetFocus(), GetActiveWindow(), SendMessage(<mdi hwnd>,WM_MDIGETACTIVE,0,0) but I can't seem to find a proper solution.
Here's what I have right now (it's Delphi, but if you can tell me code in C/C++ it's no problem either

):
function getActiveHwnd(mwnd,awnd:hwnd;data,parms:pchar;show,nopause:boolean):integer;stdcall;
var tmp,res:hwnd;
begin
tmp:=strtoint(gettok(data,' ',1)); // sets tmp to the mdi hwnd (passed onto the dll via $window(-3).hwnd)
if (GetForegroundWindow()=mwnd) then res:=SendMessage(tmp,WM_MDIGETACTIVE,0,0)
else res:=GetForegroundWindow();
strcopy(data,pchar(inttostr(res)));
result:=3;
end;
It basically works, the only problem is that it sometimes returns the wrong HWND if a desktop window is active (e.g. opened with /window -d).
Can you tell me what I'm doing wrong? I've been messing with this for ages and can't figure out the problem.
Thanks in advance.
Edit: oh yes, don't tell me to use $window($active).hwnd, because this doesn't work when, for example, multiple DCC sends/gets/chats with the same nick are open, which is the point of this DLL.