Menu MSN Messenger

vicdo Messages postés 2 Date d'inscription vendredi 4 mars 2005 Statut Membre Dernière intervention 18 mai 2005 - 21 avril 2005 à 11:11
beausicilien Messages postés 6 Date d'inscription mardi 4 février 2003 Statut Membre Dernière intervention 22 juillet 2008 - 22 juin 2005 à 23:50
Bonjour à tous.
Je tente d'ajouter un MenuItem au menu de msn messenger, en vb.net ou C# si j'ai pas le choix, mais voila le probleme est que j'arrive bien à recuperer le handle du menu de messenger mais pas l'objet Menu associé à ce handle.
Donc si quelqun peut m'aider à recuperer cette objet menu je lui en serait reconnaissant.

PS Pour réaliser ceci je veux juste utiliser la dll user32 ainsi que l'API Messenger et aucune dll de hook comme dscwpmsg.dll par exemple.

Voila ++

2 réponses

vicdo Messages postés 2 Date d'inscription vendredi 4 mars 2005 Statut Membre Dernière intervention 18 mai 2005
18 mai 2005 à 14:28
Bon j'ai trouvé la solution, je poste mon code, il n'est pas parfait mais si ca peut aider quelqun c'est le but du forum ;-)



Juste pour info, à chaque redimentionnement ou fermeture de la fenetre le menu apparait j'ai donc ajoute un timer


Option Explicit On

Public Class Form1

Inherits System.Windows.Forms.Form





Public Structure MENUITEMINFO

Dim cbSize As Integer

Dim fMask As Integer

Dim fType As Integer

Dim fState As Integer

Dim wID As Integer

Dim hSubMenu As Integer

Dim hbmpChecked As Integer

Dim hbmpUnchecked As Integer

Dim dwItemData As Integer

Dim dwTypeData As String

Dim cch As Integer

End Structure





Declare Function FindWindow Lib "user32" Alias
"FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As
String) As Integer

Declare Function CreatePopupMenu Lib "user32" () As Integer

Declare Function InsertMenu Lib "user32.dll" Alias
"InsertMenuA" (ByVal hMenu As Integer, ByVal nPosition As Integer,
ByVal wFlags As Integer, ByVal wIDNewItem As Integer, ByVal lpNewItem
As String) As Integer

Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Integer) As Integer

Declare Function GetMenu Lib "user32" (ByVal hwnd As Integer) As Integer

Declare Function AppendMenu Lib "user32" Alias
"AppendMenuA" (ByVal hMenu As Integer, ByVal wFlags As Integer, ByVal
wIDNewItem As Integer, ByVal lpNewItem As String) As Integer

Declare Function GetMenuString Lib "user32" Alias
"GetMenuStringA" (ByVal hMenu As Integer, ByVal wIDItem As Integer,
ByVal lpString As String, ByVal nMaxCount As Integer, ByVal wFlag As
Integer) As Integer







Public Const MF_BYPOSITION = &H400&

Public Const MF_STRING = &H0&

Public Const MF_POPUP = &H10&

Private Const MIIM_ID = &H2

Private Const MIIM_SUBMENU = &H4

Private Const MIIM_TYPE = &H10

Private Const MIIM_DATA = &H20

Private Const WM_COMMAND = &H111

Public Const MF_BYCOMMAND = &H0&



Public Const Offset = 2000

Public Const OffsetConv = 3000

Public HWNDWind As Integer = 0

Public HWNDPrems As Integer = 0

Public config As String = "Configurer"

Public openConf As String = "Ouvrir une conf"

Public sche As String = "Scheduler une conf"

Public ConfDN As String = "Conf DataNow"

Public ConfAudio As String = "Conf Audio"

Public Arka As String = "NomduMenu"

Public StartConf As String = "Start Conf"

Public MSN As String = "MSN Messenger"



'Public WithEvents Msgr As Messenger.MsgrObjectClass

Public WithEvents OMessengerWnd As MessengerAPI.MessengerClass



#Region " Windows Form Designer generated code "



Public Sub New()

MyBase.New()



'This call is required by the Windows Form Designer.

InitializeComponent()



'Add any initialization after the InitializeComponent() call



End Sub



'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub



'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer



'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

Friend WithEvents Timer1 As System.Windows.Forms.Timer

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Me.components = New System.ComponentModel.Container

Me.Timer1 = New System.Windows.Forms.Timer(Me.components)

'

'Timer1

'

Me.Timer1.Interval = 250

'

'Form1

'

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(292, 266)

Me.Name = "Form1"

Me.Text = "Form1"



End Sub



#End Region



Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

OMessengerWnd = New MessengerAPI.MessengerClass



Me.Timer1.Enabled = True





End Sub



Private Sub MenuLunch(ByVal HWNDWind As Integer)

Dim hNote As Integer = HWNDWind



Dim hmen As Integer =
GetMenu(hNote) '# get the menu handle of MSN
Messenger Conversation Window



Dim hsub As Integer = CreatePopupMenu '# create an own submenu

Call AppendMenu(hsub, MF_STRING, OffsetConv + 1, StartConf) '# fill submenu



'# Insert the submenu into MSN Messenger Conversation Window's menubar

Call InsertMenu(hmen, 5, MF_POPUP Or MF_BYPOSITION, hsub, Arka)



Call DrawMenuBar(hNote)

End Sub



Private Sub MainMenuLunch(ByVal HWNDWind As Integer)



Dim hNote As Integer = HWNDWind



Dim hsub2 As Integer = CreatePopupMenu

Dim hsub As Integer = CreatePopupMenu





Dim hmen As Integer =
GetMenu(hNote) '# get the menu handle of MSN Messenger







Call AppendMenu(hsub2, MF_STRING, Offset + 4, ConfDN)

Call AppendMenu(hsub2, MF_STRING, Offset + 5, ConfAudio)



'# create an own submenu

Call AppendMenu(hsub, MF_STRING, 2001, config) '# fill submenu

Call AppendMenu(hsub, MF_STRING, Offset + 2, sche)

Call AppendMenu(hsub, MF_POPUP, hsub2, openConf)



'# Insert the submenu into MSN Messenger's menubar at pos. 6

Call InsertMenu(hmen, 5, MF_POPUP Or MF_BYPOSITION, hsub, Arka)



Call DrawMenuBar(hNote)









End Sub



Public Sub OMessengerWnd_OnIMWindowCreated(ByVal pIMWindow As Object) Handles OMessengerWnd.OnIMWindowCreated

'TextBox1.Text = "ouverture"

MenuLunch(pIMWindow.HWND)

End Sub



Public Sub OMessengerWnd_OnIMWindowDestroyed(ByVal
pIMWindow As Object) Handles OMessengerWnd.OnIMWindowDestroyed

'TextBox1.Text = "fermeture"

End Sub



Public Sub OMessengerWnd_OnSignin(ByVal i As Integer) Handles OMessengerWnd.OnSignin

'TextBox1.Text = "signin"

End Sub



Public Sub OMessengerWnd_OnSignout() Handles OMessengerWnd.OnSignout

'TextBox1.Text = "signout"

End Sub



Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick



Dim conf As String



HWNDWind = FindWindow(vbNullString, MSN)

'If (OMessengerWnd Is Nothing) Then

'End If



If (HWNDWind <> 0) Then



If (HWNDWind = HWNDPrems) Then


conf = GetMenuCaptionByCommand(HWNDWind, 2001)




If (String.Compare(conf, config) <> 0) Then




MainMenuLunch(HWNDWind)



End If

Else



HWNDPrems = HWNDWind


conf = GetMenuCaptionByCommand(HWNDWind, 2001)


If (String.Compare(conf, config) <> 0) Then




MainMenuLunch(HWNDWind)

End If

End If

Else

HWNDPrems = HWNDWind

'OMessengerWnd = Nothing



End If



End Sub



Public Function GetMenuCaptionByCommand(ByVal hWnd As Integer, ByVal lngMenuCommand As Integer) As String



Dim lngRC As String

Dim lngRC2 As Long

Dim lngRC3 As Long

Dim lngMenuCount As Long

Dim hMenu As Long

Dim hSubMenu As Long

Dim lngItem As Long

Dim strString As String

Dim lngMaxCount As Long

Dim lngFlag As Long



'Get the form's menu bar

hMenu = GetMenu(hWnd)

If hMenu <> 0 Then

'Initialize the buffer

strString = Space$(256)

'lngRC gets the number of

'characters returned...


lngRC = GetMenuString(hMenu, lngMenuCommand, strString, Len(strString),
MF_BYCOMMAND)



'Return the item caption

GetMenuCaptionByCommand = Mid(strString, 1, lngRC)



Else

'Something went wrong here –

'nothing found.

GetMenuCaptionByCommand = ""

End If



End Function







End Class
0
beausicilien Messages postés 6 Date d'inscription mardi 4 février 2003 Statut Membre Dernière intervention 22 juillet 2008
22 juin 2005 à 23:50
Salut, que veux tu dire par objet associé ?

il siciliano...
0
Rejoignez-nous