Icon-Menü ohne Subclassing
Mit den bekannten API-Funktionen GetMenu und GetSubMenu sowie GetMenuItemID und ModifyMenu lassen sich Icons aus einer ImageListBox und die Inhalte einer PictureBox in das Menü einbinden. Mit den Einstellungen der PictureBoxen kann man dann die Schrift sowie Farben verändern.
Laden Sie sich die Zip-Datei mit VB 6 Source Code hinunter und probieren Sie es mal aus.

Projekt - Download
© FienauBerlin   Web-ComputerEcke.de
 

Quell-Code
Option Explicit
 
'API-Deklarationen
Private Declare Function GetMenu Lib "user32" ( _
       ByVal hwnd As Long) As Long
Private Declare Function GetSubMenu Lib "user32" ( _
       ByVal hMenu As Long, ByVal nPos As Long) As Long
Private Declare Function GetMenuItemID Lib "user32" ( _
       ByVal hMenu As Long, ByVal nPos As Long) As Long
 
Private Declare Function ModifyMenu Lib "user32" _
       Alias "ModifyMenuA" (ByVal hMenu As Long, _
       ByVal nPosition As Long, ByVal wFlags As Long, _
       ByVal wIDNewItem As Long, ByVal lpString As Any _
       ) As Long
 
'Private Declare Function SetMenuItemBitmaps Lib "user32" ( _
       ByVal hMenu As Long, ByVal nPosition As Long, _
       ByVal wFlags As Long, ByVal hBitmapUnchecked As Long, _
       ByVal hBitmapChecked As Long) As Long
 
'Private Const BI_MENU = &H400&

Private Sub Form_Load() SetMenu End Sub
Private Sub SetMenu() Dim mHandle As Long, lRet As Long, _ sHandle As Long, MenuID As Long, x%, D% 'Handle des Hauptmenus ermitteln mHandle = GetMenu(hwnd) 'Menü 111111111111111111111111111111111111111111111 'Handle des zweiten Untermenus ermitteln sHandle = GetSubMenu(mHandle, 0) 'Anzahl der Menueinträge bestimmen For x = 1 To 13 Load mnuDummy(x) 'Null = mnuDummy Load Picture1(x) Picture1(x).BackColor = &H80000004 'Menu-Hintergrund 'Bitmaps in PictureBox setzen. ' Picture1(x).Picture = LoadPicture("icons/" & x & ".ico") Picture1(x).Picture = IL.ListImages(x + 1).Picture Next x 'Jetzt noch das Originak füllen Picture1(0).BackColor = &H80000004 ' Picture1(0).Picture = LoadPicture("icons/0.ico") Picture1(0).Picture = IL.ListImages(1).Picture 'Bitmaps setzen - Alte Methode ' For x = 0 To 13 ' lRet = SetMenuItemBitmaps(sHandle, x, BI_MENU, _ menu.ListImages(x + 1).Picture, _ menu.ListImages(x + 1).Picture) ' Next x 'Schriftfabbe Picture1(2).ForeColor = vbBlue Picture1(5).ForeColor = vbBlue Picture1(13).ForeColor = vbRed 'Schrifteinstellungen Picture1(13).FontBold = True 'Bildfelder mit neuen Texten Picture1(0).Print " Enabled" Picture1(1).Print " Öffnen" Picture1(2).Print " Thumbnails" Picture1(3).Print " Icon extrahieren" Picture1(4).Print " Scannen/Kamera" Picture1(5).Print " Quelle wählen" Picture1(6).Print " Als Icon konvert" Picture1(7).Print " Speichern" Picture1(8).Print " Speichern unter..." Picture1(9).Print " Schreibschutz entf." Picture1(10).Print " Attribute" Picture1(11).Print " Explorer öffnen" Picture1(12).Print " Drucken" Picture1(13).Print " Beenden" 'Bildfelder zuweisen For x = 0 To 13 Picture1(x).Picture = Picture1(x).Image MenuID = GetMenuItemID(sHandle, x) D% = ModifyMenu(sHandle, MenuID, &H0 Or &H4, _ MenuID, CLng(Picture1(x).Picture)) Next x ' Menu 2222222222222222222222222222222222222222222 ' sHandle = GetSubMenu(mHandle, 1) ' For x = 1 To 13 'Null = mnuDummy ' Load mnuDummy2(x) ' Load Picture2(x) ' Picture2(x).BackColor = &H80000004 ' Picture2(x).Picture = LoadPicture("icons2/" & x & ".ico") ' Next x ' Picture2(0).BackColor = &H80000004 ' Picture2(0).Picture = LoadPicture("icons2/0.ico") ' u.s.w. End Sub
Private Sub mnuDummy_Click(Index As Integer) 'Menu Auswertung Select Case Index Case 0 If mnuDummy(13).Enabled = True Then mnuDummy(13).Enabled = False Else mnuDummy(13).Enabled = True End If Case 1 Case 3 Case 4 Case 5 Case 6 Case 7 Case 13 End End Select 'Anzeige lbl.Caption = "Menu item " & CStr(Index) & " wurde ausgewählt." End Sub