Important alert: (current site time 7/16/2013 3:13:04 AM EDT)
 

winzip icon

Titled PopupMenu

Email
Submitted on: 6/2/2001 12:14:23 PM
By: Mick Doherty 
Level: Intermediate
User Rating: By 48 Users
Compatibility: VB 5.0
Views: 32356
 
     This turned out to be more difficult to work out than the drawing of a button on the titlebar. Of course once I'd got it it was simple. Once again this code uses subclassing so always use the forms close button or the menus exit to stop the project, or you will crash.

 

Windows API/Global Declarations:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
'Windows API/Global Declarations for :Titled PopupMenu
'**************************************
CreatePopupMenu
TrackPopupMenu
AppendMenu
ModifyMenu
DestroyMenu
GetCursorPos
CopyMemory
BitBlt
SetRect
DrawCaption
GetMenuItemRect
GetMenuItemCount
GetPixel
SetPixel
CallWindowProc
SetWindowLong
winzip iconDownload code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
  3. Scan the source code with Minnow's Project Scanner

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com

 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.


Other 7 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

6/2/2001 2:30:18 PMBrandon McPherson

Nice work, man!

5 globes from me.... clean code, well documented and runs like a champ! It's nice to see someone coming up with cool interface ideas!
(If this comment was disrespectful, please report it.)

 
6/2/2001 2:46:07 PMJonathan Jarvis

This is great! It is the simplist and most understandable menu drawing example I've ever seen!
(If this comment was disrespectful, please report it.)

 
6/3/2001 7:40:27 AMJ Stover

Great Code! I've been trying to figure out how it was done. You really set my mind at ease. Thanks
(If this comment was disrespectful, please report it.)

 
6/4/2001 1:21:41 PMElias from NY

Cool effect.
Simple to implement.
Clean code.
Fairly commented.

What else could I ask for?

I am giving 5 planets for you!
(If this comment was disrespectful, please report it.)

 
6/6/2001 5:52:04 AMValenitn

Voted five - your piece is nicely commented, idea is good, code is comprehendable; in a word, ideal PSC item. But... (1) by it you introduce a style, and no element of style could exists in isolation. Means the same style must apply to the form, and normal menus as well, and maybe to the other controls (2) what value you add? E.g., bitmaps in menus shorten learning curve for toolbar icons, so they justified. But what purpose this feature can serve?
(If this comment was disrespectful, please report it.)

 
6/6/2001 7:23:12 AMMr.B

It is a amazing work indeed. I'm not sure if this is a bug or not. I'm using Korean version of Windows 98 Second Edition. The first I clicked, the side bar of the menu always appeared 'wrong.' The second time I tried it, it was working fine. If this is a bug, I think it should be easy to fix.
(If this comment was disrespectful, please report it.)

 
6/6/2001 10:24:15 AMMick Doherty

I have not seen this incorrect drawing so I cannot comment on this.

You should note however, that I have made no attempt to account for a second Ownerdraw MenuItem or other OwnerDraw Controls. It was meant simply to introduce you to the basics of OwnerDraw. Hopefully from here you will learn more about MeasureItemStruct and DrawItemStruct so that you can build Case statements into the MeasureMenu and DrawMenu subroutines and then modify only the desired item.

You will notice that if you remove the Titlebar from the form you will have no picture. I am hoping that you are going to adapt this code for your own requirements, and BitBlt a picture to the sidebar. I used the DrawCaption method here for simplicity, rather than correctness.
(If this comment was disrespectful, please report it.)

 
6/7/2001 1:35:22 AMNathan Chere

Just out of curiosity is this the same way the Start menu does it? Or the ICQ menu?
(If this comment was disrespectful, please report it.)

 
6/7/2001 8:36:57 AMMick Doherty

Using a Spy Tool on the Start Menu will show you that the Menu is of class "ToolbarWindow32" and the SideBar is of Class "BaseBar".

ICQ menu uses custom controls.

So the simple answer is no.
(If this comment was disrespectful, please report it.)

 
6/11/2001 5:02:37 PMSyntax

Great code. 5 globes from me:-)
(If this comment was disrespectful, please report it.)

 
6/15/2001 2:28:28 PMDoctor Evil

I great menu modification solution is availible from vbAccelerator. You can use ICQ-sytle seperators, icons, and easy OwnerDraw options, with an example on gradient sidebars. Menu: http://vbaccelerator.com/codelib/cpopmenu/cnewmenu.htm; Sidebar: http://vbaccelerator.com/codelib/cpopmenu/icqmenu.htm
(If this comment was disrespectful, please report it.)

 
6/16/2001 2:29:17 AMBenji

great code though is there away to attach it to form menus without the popups???
(If this comment was disrespectful, please report it.)

 
6/18/2001 7:13:39 AMMick Doherty

vbAccelerator's example is indeed excellent, however, it uses it's own menu dll, probably written in C++, so you do not really get an Idea of what is going on. If you just want pretty menus without knowing how they are created then use their sample.

Benji: I haven't tried that but I will look into it. I am sure it is just a case of using InsertMenuItem and ModifyMenu to update the flag for the first menuitem.

(If this comment was disrespectful, please report it.)

 
6/28/2001 2:23:14 AMChris Hatton

good work, this will come in handy 5/5 globes
(If this comment was disrespectful, please report it.)

 
7/9/2001 11:47:40 PMGreg C.

Mick Doherty, all of vbAccelerator's controls are made from Pure VB (not C++ or somthing else, like said above)!! you can download the source to, for free!
(If this comment was disrespectful, please report it.)

 
7/21/2001 8:40:11 AMVerburgh Peter

Great stuff ! 5/5 !

(If this comment was disrespectful, please report it.)

 
8/3/2001 4:48:28 PMVerburgh Peter

Tnx For sharing this amazing code.
I have use it in my application on PSC called NetWatch
Tnx !!!!!!!!!!!!!
(If this comment was disrespectful, please report it.)

 
8/31/2001 11:41:00 AMNickels

How to put Icons next to menus like this one??
(If this comment was disrespectful, please report it.)

 
9/1/2001 7:34:30 AMMick Doherty

Take a look at my other submission to see how to add icons to this type of menu.
(If this comment was disrespectful, please report it.)

 
7/31/2004 11:45:13 AMsmozgur

Very nice!
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.