mIRC Homepage
Posted By: orcberg VB.NET and mIRC - 20/05/05 03:40 PM
Okay, I am trying to something _extremely_ basic -- I'm trying to use the FindWindow() API to get the window handle for mIRC. Just seeing if I got the code right, I set up code that looks like this:

Code:
Public Class Form1
    Inherits System.Windows.Forms.Form

    'API Functions
    Public Declare Auto Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Public Declare Auto Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim lhWnd As Long

        lhWnd = FindWindow("mIRC", vbNullString)
        MsgBox(lhWnd)


    End Sub
End Class


I have also tried
Code:
lhWnd = FindWindow(vbNullString, "mIRC")
to find the window handle by the exact caption. Regardless of what I do, I am constantly getting what seems to be a random 17-digit number. Every time I click the button, it's a different number. From what I understand, a window handle is not that long. Out of curiousity I entered a window caption that doesn't exist and got the same result.

I have referenced so many API writeups and _none_ of them seem to work right. I'm not sure what I'm omitting or doing wrong, but it has become extremely frustrating and I'm hoping someone can give me a hand smile

Ultimately, I want to write a program that will send text to a specific channel on mIRC. I'm nowhere near that though, because I'm still getting my ass kicked on the first step. :P Thanks.
Posted By: silent Re: VB.NET and mIRC - 21/05/05 08:07 AM
Hm,

i tried the same with:

Code:
procedure TForm1.Button1Click(Sender: TObject);
var
  Handle: THandle;
begin
  Handle := FindWindow('mIRC', nil);
  ShowMessage(IntToStr(Handle));
end;


and i always get the right handle, and if i switch 'mIRC' and "nil" then it doesnt show me random values, i just get 0, like i has to be. Mayb ur bug is on another place.

(Sorry for bad english wink)
Posted By: tidy_trax Re: VB.NET and mIRC - 21/05/05 01:23 PM
Both of your FindWindows give me the hwnd of the mIRC window.
If you can't get this working then maybe you could use EnumWindows() to enumerate through every window on the desktop and find the mIRC one.
Posted By: orcberg Re: VB.NET and mIRC - 21/05/05 03:35 PM
Well I guess that's where I'm confused -- I'm not sure where else my bug can be, because that there is the entire code for the program (minus the normal windows form code that's inserted in there). The only other thing I can think of, am I possibly missing some Imports that I should be doing?
Posted By: orcberg Re: VB.NET and mIRC - 21/05/05 03:52 PM
By the way, just tried the same code with another machine. Same problem. The entire code is this

Code:
Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
<<snip>>
#End Region

    Public Declare Auto Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Public Declare Auto Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim lhWnd As Long
        lhWnd = FindWindow("mIRC", vbNullString)
        MsgBox(lhWnd)

    End Sub

End Class
© mIRC Discussion Forums