Button in chat window Part 2 - Printable Version
-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Forum: Plug-Ins (/forumdisplay.php?fid=28)
+------ Thread: Button in chat window Part 2 (/showthread.php?tid=54285)
Button in chat window Part 2 by posseke on 12-27-2005 at 01:19 PM
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:
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
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
RE: Button in chat window Part 2 by TheBlasphemer on 12-27-2005 at 01:50 PM
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++.
RE: Button in chat window Part 2 by J-Thread on 12-27-2005 at 02:55 PM
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?
RE: Button in chat window Part 2 by posseke on 12-27-2005 at 02:58 PM
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 ^
J-Thread, seems like your code does the trick, beats me; but hey, you're my new god now
Thanks a lot for your support
RE: Button in chat window Part 2 by J-Thread on 12-27-2005 at 03:53 PM
WOW didn't know I was that important for some people
Btw, about the getWindowRect part, try to declare R within the function... So Public R As RECT;
and in the function:
R = New RECT;
RE: Button in chat window Part 2 by posseke on 12-27-2005 at 04:12 PM
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
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
RE: Button in chat window Part 2 by J-Thread on 12-27-2005 at 04:16 PM
Nice! Problem solved, and it's usefull for other people who do want to add a button to the IM window
RE: RE: Button in chat window Part 2 by CookieRevised on 12-27-2005 at 04:23 PM
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.
RE: Button in chat window Part 2 by posseke on 12-27-2005 at 05:17 PM
thx cookie, hey, I'm not the allmighty source of wisdom, so I think ur right about visiting MSDN
Thx for the tip
En voor de nederlandstaligen hetzelfde
|