PDA

Click to See Complete Forum and Search --> : XP Smart Menu - Adding icons


Madboy
Feb 17th, 2004, 04:32 PM
THIS EXAMPLE I MADE SHOWS YOU HOW TO ADD ICONS EVEN EASIER. USING AN IMAGE CONTROL

FIRST WE MAKE THE SUB, IT TELLS US WHERE THE IMAGE LIST IS AND EXTRACTS THE ICONS

Option Explicit

Private Function pGetPicture(sFileName As String) As StdPicture
Dim c As Long

For c = 1 To frmMain.imlMain.ListImages.Count
If LCase(frmMain.imlMain.ListImages(c).Key) = LCase(sFileName) Then
Set pGetPicture = frmMain.imlMain.ListImages(c).ExtractIcon
End If
Next

End Function

NOW WE BUILD THE MENU, HERE IS A COPIED PART OF MY PROJECT

Public Sub BuildMainMenu()
With frmMain.mnuMain.MenuItems

.Add 0, "KeyFile", , "&File"
.Add "KeyFile", "KeyExit", , "E&xit", pGetPicture("EXIT"), vbAltMask, vbKeyQ

End With
End Sub


HOPE THIS WAS USEFUL, ITS MUCH BETTER THAN USING RESOURCE FILES!

manavo11
Feb 17th, 2004, 04:49 PM
Originally posted by Madboy
HOPE THIS WAS USEFUL, ITS MUCH BETTER THAN USING RESOURCE FILES!

Why? :confused:

Madboy
Feb 17th, 2004, 05:59 PM
Because,

a) the way i used resource files, made the icons appearance slightly dodgee

b) you dont have to mess about adding them to the resource file

c) You dont need a huge module like i did just to load the icons

d) Resource Hacker cant view your icons as they are stored internally into a Image List

e) The compiled file size is slightly less, no big difference.

f) Resource Editor is fussy when loading icons, they have to be a falid format or they wont load.


Does that conclude my original post;)

manavo11
Feb 18th, 2004, 07:17 AM
Yep :afrog:

Madboy
May 4th, 2004, 02:16 PM
Good:wave:

vbNeo
Jun 1st, 2004, 09:26 AM
I changed your function to use the Index integer value instead, I find it a lot easier to use =) :


Private Function pGetPicture(iIndex As Integer) As StdPicture
Dim c As Long
For c = 1 To frmMain.imlMain.ListImages.Count
If LCase(frmMain.imlMain.ListImages(c).Index) = LCase(iIndex) Then
Set pGetPicture = frmMain.imlMain.ListImages(c).ExtractIcon
End If
Next
End Function

Madboy
Jun 3rd, 2004, 04:08 AM
Ah, ok cheers

Do you use the XP Smart Menu?

vbNeo
Jun 3rd, 2004, 04:19 AM
Not often, but yes, sometimes I do - mostly to spice up the boring interfaces I make =).

Zelot
Mar 4th, 2005, 12:04 PM
Can you post a sample program? I always get a method or data not found on the ".menuItems" part. :blush: . Newbie here

Madboy
Aug 9th, 2005, 06:41 PM
Well im no longer a VB programmer, but maybe someone else could help you?