mIRC Home    About    Download    Register    News    Help

Print Thread
#137626 16/12/05 02:26 PM
Joined: Dec 2002
Posts: 230
G
greeny Offline OP
Fjord artisan
OP Offline
Fjord artisan
G
Joined: Dec 2002
Posts: 230
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 wink):

Code:
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.

#137627 16/12/05 02:53 PM
Joined: Jan 2003
Posts: 249
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Jan 2003
Posts: 249
have you tried GetTopWindow( ) ?

#137628 16/12/05 03:00 PM
Joined: Dec 2002
Posts: 230
G
greeny Offline OP
Fjord artisan
OP Offline
Fjord artisan
G
Joined: Dec 2002
Posts: 230
No, I will try that out, thanks!

Edit: GetTopWindow() only works if the window is an MDI window, which leaves me with the problem of desktopped windows.

Last edited by greeny; 16/12/05 03:06 PM.
#137629 16/12/05 03:37 PM
Joined: Jan 2003
Posts: 249
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Jan 2003
Posts: 249
From the help file I don't read any MDI related thing.

"The GetTopWindow function examines the Z order of the child windows associated with the specified parent window and retrieves a handle to the child window at the top of the Z order."

If you give the command the mIRC HWND it should return the topmost window which is connected down to the parent mIRC from the tree of windows.

Now desktop windows do not belong to mIRC so you won't be able to get those through any active window command that uses mIRC as a parent. If you never did the experience, if you have a top desktop dialog and you return $active with a timer in mIRC, it will give you the most top window in mIRC, not the actual dialog.

I think mIRC's $active gives what GetTopWindow( ) returns using the mIRC HWND as the parameter. This should give the top most Z order window be it a @window, dialog or any other window MDI attached or not to mIRC.

GetTopWindow( ) will get you the topmost Z ordered window from any parent. If you use the desktop window as a parent which is the root parent window of the system, then you could get the HWND of any window in the whole system which is topmost at any instant.

Code:
Desktop
 |- mIRC
   |- MDI
     |- #channel
   |- @window
   |- dialog
 ...

#137630 16/12/05 03:56 PM
Joined: Dec 2002
Posts: 230
G
greeny Offline OP
Fjord artisan
OP Offline
Fjord artisan
G
Joined: Dec 2002
Posts: 230
Actually, you're right in what you say. I accidently passed the HWND of the MDI window to the function, sorry.

Either way, it still doesn't work. GetTopWindow(mwnd) now only returns one single number, no matter which window is the active one. frown

Code:
function getactivehwnd(mwnd,awnd:hwnd;data,parms:pchar;show,nopause:boolean):integer;stdcall;
begin
  strcopy(data,pchar(inttostr(GetTopWindow(mwnd))));
  result:=3;
end;

#137631 16/12/05 05:16 PM
Joined: Jan 2003
Posts: 249
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Jan 2003
Posts: 249
the HWND is a hex number, so if you want to convert that to text you can use something like wsprintf( data, "%X", HWND );

#137632 16/12/05 05:21 PM
Joined: Dec 2002
Posts: 230
G
greeny Offline OP
Fjord artisan
OP Offline
Fjord artisan
G
Joined: Dec 2002
Posts: 230
It's not a HEX number, at least not in Delphi. If it was, inttostr() would fail.

#137633 16/12/05 05:39 PM
Joined: Jan 2003
Posts: 249
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Jan 2003
Posts: 249
any number is a number, whatever representation you want to display it in. All I was saying is normally HWND params are displayed as HEX strings. Try a $window().hwnd and you should see the HEX representation the same way you do in Spy++ for example : 000C026E.

I don't quite understand why you say that the last part doesn't work. I think you didn't define the problem correctly in your first statement or I'm dumb and don't understand why GetTopWindow( MIRC HWND ) fails to give you the topmost mIRC window thus the "active" one in mIRC. You'll never be able to get from that last command the active window if it's a desktop dialog or @window since it's not attached to mIRC. And I'm pretty sure $active returns the topmost window in mIRC if the "active" one on the system is a mIRC desktop dialog. Now, I don't have mIRC here to test, I'm at work.

#137634 16/12/05 05:55 PM
Joined: Dec 2002
Posts: 230
G
greeny Offline OP
Fjord artisan
OP Offline
Fjord artisan
G
Joined: Dec 2002
Posts: 230
Well, I really don't know why it doesn't work.

All I have is this function that returns GetTopWindow(mwnd).

Then I try it in mIRC:
//echo -a $dll(test.dll,getactivehwnd,)

And it returns the same number every time I echo, no matter what window I am typing it in.

#137635 16/12/05 05:59 PM
Joined: Jan 2003
Posts: 249
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Jan 2003
Posts: 249
make sure you grabbed the correct mIRC Hwnd from LOADINFO.

I can test this thing tonight when I get home if you can't get it to work to see if it really works.

#137636 16/12/05 06:05 PM
Joined: Dec 2002
Posts: 230
G
greeny Offline OP
Fjord artisan
OP Offline
Fjord artisan
G
Joined: Dec 2002
Posts: 230
I even tried writing the mIRC hwnd manually into the source :P
Still doesn't work.

Just so you know, it's not the first DLL I code, but I'm really stuck on this one.

Thanks for your help.

#137637 17/12/05 04:27 PM
Joined: Dec 2002
Posts: 230
G
greeny Offline OP
Fjord artisan
OP Offline
Fjord artisan
G
Joined: Dec 2002
Posts: 230
No more ideas? frown

#137638 17/12/05 10:15 PM
Joined: Jan 2003
Posts: 249
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Jan 2003
Posts: 249
I'm sorry I haven't testet yet I was occupied yesterday.

I will try to see if I can get it to work tomorrow.

You can come by on IRC and we can talk about it.

#137639 19/12/05 06:17 PM
Joined: Dec 2002
Posts: 230
G
greeny Offline OP
Fjord artisan
OP Offline
Fjord artisan
G
Joined: Dec 2002
Posts: 230
Again, thank you very much ClickHeRe, I finally got it to work! smile


Link Copied to Clipboard