What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Plug-Ins » Button in chat window Part 2

Button in chat window Part 2
Author: Message:
posseke
New Member
*


Posts: 14
41 / Male / –
Joined: Nov 2005
O.P. Button in chat window Part 2
Hi, a while ago I posted a thread about how to implement my own command button on a IM window of MSN.

This seems to work, at least the part of showing the button on the window.

I'm having problems with positioning the new button into the window:

[Image: msnfragbutton.JPG]

The button is allways in the upper left corner of each window, and no matter what code i write to position the button, it doesn't work...

frustrating, I know :d

Maybe good to know: I'm programming in VBNET so the code I'm giving you is probably a lil different from VB6 syntax

code:
Private WithEvents oMessenger As Messenger
    Private Declare Function SetParent Lib "user32.dll" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr
    Public Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As IntPtr, ByVal lpRect As RECT) As IntPtr

    Public Structure RECT
        Dim x As Long
        Dim y As Long
        Dim Width As Long
        Dim Height As Long
    End Structure

    Public R As RECT = New RECT
    Public newBtn As FragMsnIMButton

    Private Sub FragMsnIMButton_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        oMessenger = New Messenger
    End Sub

    Private Sub oMessenger_OnIMWindowCreated(ByVal pIMWindow As Object) Handles oMessenger.OnIMWindowCreated
        '
        Try
            newBtn = New FragMsnIMButton ' create a copy of FragMsnIMButton
            Dim child As System.IntPtr = Me.btnFrag.Handle
            Dim par As System.IntPtr = pIMWindow.hwnd.ToString
            '
            SetParent(child, par)
            '
            Try
                'GetWindowRect(par, R)
            Catch ex As Exception
                MsgBox(ex.Message.ToString)
            End Try
            '
            newBtn.Left = 13500
            newBtn.Top = 2800
            '
        Catch ex As Exception
            MsgBox(ex.Message.ToString)
        End Try

    End Sub


So that is my main concern. Another concern is the error I'm getting while executing the 'GetWindowRect(par, R)' method.
It's something like 'attempt to overwrite protected memory'... If anyone knows anything about that, all help is welcome.


Thanks,

Kenny

12-27-2005 01:19 PM
Profile E-Mail PM Web Find Quote Report
TheBlasphemer
Senior Member
****

Avatar

Posts: 714
Reputation: 47
36 / – / –
Joined: Mar 2004
RE: Button in chat window Part 2
Such things should really not be done in VB.NET,
All the pointers and the likes needed are either not supported or very difficult to use.
I suggest you try it in C++, or if you really want .NET, Managed C++.
[Image: theblasp.png]
12-27-2005 01:50 PM
Profile PM Find Quote Report
J-Thread
Full Member
***

Avatar

Posts: 467
Reputation: 8
– / Male / –
Joined: Jul 2004
RE: Button in chat window Part 2
code:
        Try
            newBtn = New FragMsnIMButton ' create a copy of FragMsnIMButton
            newBtn.Left = 13500
            newBtn.Top = 2800
            Dim child As System.IntPtr = Me.newBtn .Handle
            Dim par As System.IntPtr = pIMWindow.hwnd.ToString
            '
            SetParent(child, par)
            '
            Try
                'GetWindowRect(par, R)
            Catch ex As Exception
                MsgBox(ex.Message.ToString)
            End Try
            '
        Catch ex As Exception
            MsgBox(ex.Message.ToString)
        End Try
How about that?
12-27-2005 02:55 PM
Profile E-Mail PM Find Quote Report
posseke
New Member
*


Posts: 14
41 / Male / –
Joined: Nov 2005
O.P. RE: Button in chat window Part 2
TheBlasphemer, I'm well experienced in C++, but the graphical part is not my finest point ^^; drivers and stuff will do, but all that paintin' works better for me in VB.NET ^:p


J-Thread, seems like your code does the trick, beats me; but hey, you're my new god now :d

Thanks a lot for your support ;)
12-27-2005 02:58 PM
Profile E-Mail PM Web Find Quote Report
J-Thread
Full Member
***

Avatar

Posts: 467
Reputation: 8
– / Male / –
Joined: Jul 2004
RE: Button in chat window Part 2
WOW didn't know I was that important for some people :D

Btw, about the getWindowRect part, try to declare R within the function... So Public R As RECT;

and in the function:
R = New RECT;

This post was edited on 12-27-2005 at 04:12 PM by J-Thread.
12-27-2005 03:53 PM
Profile E-Mail PM Find Quote Report
posseke
New Member
*


Posts: 14
41 / Male / –
Joined: Nov 2005
O.P. RE: Button in chat window Part 2
R is a structure

    Public Structure RECT
        Dim x As Long
        Dim y As Long
        Dim Width As Long
        Dim Height As Long
    End Structure

to hold all the window positioning data stuff :p

But guess what, this must be my lucky day, I solved this one to, seems that VBNET needs a different type of declaration of the API function:

Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Integer, ByRef lpRect As RECT) As Integer

So when I use this one, and parse the handler I received from the IM window to Int32, I get the fabulous non erroneous result of a working button inside the IM window, at the exact same spot I wanted...

Isn't life great ^^

Thanks ;)
12-27-2005 04:12 PM
Profile E-Mail PM Web Find Quote Report
J-Thread
Full Member
***

Avatar

Posts: 467
Reputation: 8
– / Male / –
Joined: Jul 2004
RE: Button in chat window Part 2
Nice! Problem solved, and it's usefull for other people who do want to add a button to the IM window(Y)
12-27-2005 04:16 PM
Profile E-Mail PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: RE: Button in chat window Part 2
quote:
Originally posted by posseke
But guess what, this must be my lucky day, I solved this one to, seems that VBNET needs a different type of declaration of the API function
It doesn't need a different declaration than otherwise VB.NET is no different than other languages in that... it needs the proper declaration though ;)

quote:
Originally posted by posseke
So when I use this one, and parse the handler I received from the IM window to Int32, I get the fabulous non erroneous result of a working button inside the IM window, at the exact same spot I wanted...
Because GetWindowRect returns a boolean, not a pointer or handle like SetParent or whatever.

code:
From the MSDN Library: GetWindowRect

Syntax:
BOOL GetWindowRect(
    HWND hWnd,
    LPRECT lpRect
);
code:
From the MSDN Library: SetParent

Syntax:
HWND SetParent(
    HWND hWndChild,
    HWND hWndNewParent
);

For working with API's, always refer to the MSDN library.

;)

This post was edited on 12-27-2005 at 04:26 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
12-27-2005 04:23 PM
Profile PM Find Quote Report
posseke
New Member
*


Posts: 14
41 / Male / –
Joined: Nov 2005
O.P. RE: Button in chat window Part 2
thx cookie, hey, I'm not the allmighty source of wisdom, so I think ur right about visiting MSDN :p

Thx for the tip ;)

En voor de nederlandstaligen hetzelfde :d
12-27-2005 05:17 PM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On