Probleme d'affichage en creant un menu api

Signaler
Messages postés
6
Date d'inscription
dimanche 7 décembre 2003
Statut
Membre
Dernière intervention
4 janvier 2004
-
Messages postés
6
Date d'inscription
dimanche 7 décembre 2003
Statut
Membre
Dernière intervention
4 janvier 2004
-
bonjour
voila j'ai deux souci, je cree un menu popup avec sous menu dynamiquement sur une form en utilisant les api
et mon probleme est que je veux l'afficher sur l'autre form
lorsque je met ma fonction de chargement de mon menu dans form load ya pas de souci
par contre si je le met ailleurs alors un menu apparait en haut de ma form et cela ne m'interresse pas

mon deuxieme probleme est que je souhaiterai recuperer l'item du menu ou sous menu selectionne

merci de votre aide

2 réponses

Messages postés
188
Date d'inscription
mercredi 9 avril 2003
Statut
Membre
Dernière intervention
10 août 2009

pourriez vous m'envoyer votre code svp, car je ne vois pas trop votre pb...merci
Messages postés
6
Date d'inscription
dimanche 7 décembre 2003
Statut
Membre
Dernière intervention
4 janvier 2004

voila mon prog se decompose en 3 parti un module et deux form

voici le module

Type MENUITEMINFO
cbSize As Long
fMask As Long
fType As Long
fState As Long
wID As Long
hSubMenu As Long
hbmpChecked As Long
hbmpUnchecked As Long
dwItemData As Long
dwTypeData As String
cch As Long
End Type

Type POINTAPI
X As Long
Y As Long
End Type

Const MIIM_STATE = &H1
Const MIIM_ID = &H2
Const MIIM_SUBMENU = &H4
Const MIIM_CHECKMARKS = &H8
Const MIIM_TYPE = &H10
Const MIIM_DATA = &H20

Const MF_STRING = &H0
Declare Function CreateMenu Lib "user32" () As Long
Declare Function CreatePopupMenu Lib "user32" () As Long
Declare Function InsertMenuItem Lib "user32" Alias "InsertMenuItemA" (ByVal hMenu As Long, ByVal un As Long, ByVal bool As Boolean, ByRef lpcMenuItemInfo As MENUITEMINFO) As Long
Declare Function SetMenu Lib "user32" (ByVal hwnd As Long, ByVal hMenu As Long) As Long
Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long

Declare Function TrackPopupMenu Lib "user32" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal X As Long, ByVal Y As Long, ByVal nReserved As Long, ByVal hwnd As Long, lprc As Any) As Long

Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long

Public hMenu As Long
Public hSubMenu As Long
Public ret As Long
Type menu_principal
couleur_menu_principal As ColorConstants
nom_menu_principal As String
check_menu As Boolean
sousmenu(0 To 9) As String
End Type
Public menu(0 To 9) As menu_principal
Public Temp(0 To 9) As menu_principal

Public Sub menu_temp()
For i = 0 To 9
Temp(i) = menu(i)
Next i
End Sub
Public Sub temp_menu()
For i = 0 To 9
menu(i) = Temp(i)
Next i
End Sub
Public Sub cache(f As Form)
f.Combo2.Visible = False
f.Command10.Visible = False
f.Command11.Visible = False
f.Command12.Visible = False
End Sub
Public Sub montre(f As Form)
f.Combo2.Visible = True
f.Command10.Visible = True
f.Command11.Visible = True
f.Command12.Visible = True
End Sub
Public Sub interdit(f As Form)
f.Check1.Enabled = False
f.Command8.Enabled = False
f.Command2.Enabled = False
f.Command3.Enabled = False
f.Command4.Enabled = False
f.Command6.Enabled = False
f.Command7.Enabled = False
End Sub
Public Sub autorise(f As Form)
f.Check1.Enabled = True
f.Command8.Enabled = True
f.Command2.Enabled = True
f.Command3.Enabled = True
f.Command4.Enabled = True
f.Command6.Enabled = True
f.Command7.Enabled = True

End Sub

Public Sub chargement_menu(f As Form)
Dim MII As MENUITEMINFO

'Create Menu
hMenu = CreatePopupMenu

For i = 0 To 9
If menu(i).nom_menu_principal <> "" Then
If menu(i).check_menu Then
hSubMenu = CreateMenu
For j = 0 To 9
If menu(i).sousmenu(j) <> "" Then
With MII
.cbSize = Len(MII)
.fMask = MIIM_TYPE
.fType = MF_STRING
.dwTypeData = CStr(menu(i).sousmenu(j))
.cch = Len(.dwTypeData)
End With
InsertMenuItem hSubMenu, j, True, MII
End If
Next
With MII
.cbSize = Len(MII)
.fMask = MIIM_TYPE Or MIIM_SUBMENU
.fType = MF_STRING
.dwTypeData = CStr(menu(i).nom_menu_principal)
.cch = Len(.dwTypeData)
.hSubMenu = hSubMenu
End With
InsertMenuItem hMenu, i, True, MII
Else
With MII

.cbSize = Len(MII)
.fMask = MIIM_TYPE
.fType = MF_STRING
.dwTypeData = CStr(menu(i).nom_menu_principal)
.cch = Len(.dwTypeData)

End With

ret = InsertMenuItem(hMenu, i, True, MII)
End If
End If
Next

SetMenu f.hwnd, hMenu
End Sub
Public Sub souris(Button As Integer, Shift As Integer, X As Single, Y As Single, f As Form)
Dim Pos As POINTAPI
Pos.X = X / Screen.TwipsPerPixelX
Pos.Y = Y / Screen.TwipsPerPixelY
ClientToScreen f.hwnd, Pos
ret = TrackPopupMenu(hMenu, 0&, Pos.X, Pos.Y, 0&, f.hwnd, 0&)

End Sub

ma form1 est ma form principale et ma form2 est ma form ou je regle mes menus et je veux que mon menu regle sur la form2 apparait en popup sur la form 1

or quand je realise : form1_load
call chargement(me) tout fonctionne seulement je veut utiliser ce menu sans avoir a loader form1 qui reste toujours visible
si je met call chargement(me) ds form_activate alors il apparait un menu an haut de ma form