×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Help needed: Handling dynamic popup menu items

Help needed: Handling dynamic popup menu items

Help needed: Handling dynamic popup menu items

(OP)
Hi there!

I'd call myself rather a fan of programming, than a programmer, and most of my knowledge concerning C++ is based on C++Builder. During Christmas break I decided to finally try some programming in pure WinAPI.

I wrote a tiny application which sits in the shell notification area an provides a popup menu with all available drives. Divided with separators when drive type changes - I'm that good! ;) Each of these items are added dynamically before popping up a menu and are meant to simply open an exlorer's window with the contents of target drive. Everything through building a menu and adding the drives is done. Opening the corresponding windows? Here my programming stops.

How to define a unique ID for each menu item and process messages sent by this ID (or any other solution)? This cannot be done by reading item's string. Those are not drive letters but their explorer's equivalents read with SHGetFileInfo(...).

In C++Builder this was not a problem at all. I simply saved drive letter string in a hint property and a custom OnClick event (the code below) which passed the hint to ShellExecute(...).

CODE

void __fastcall TFormMain::MenuItemClick(TObject *Sender)
{
    TMenuItem *ClickedItem = dynamic_cast<TMenuItem *>(Sender);

    if(ClickedItem)
    {
        ShellExecute(0, "open", ClickedItem->Hint.c_str(), "", "", SW_SHOWNORMAL);
    }
}

I'd be very grateful for help in doing the same thing in WinAPI. A sample source code would be very appreciated. Thank you.

RE: Help needed: Handling dynamic popup menu items

When you create a popup menu and insert items using InsertMenu or InsertMenuItem function, you specify a menu item Id, to uniquely identify each item in the menu.

When you show your menu using TrackPopupMenu function and user clicks a menu item, Windows sends a WM_COMMAND message to your window. You should handle this message in your window procedure and identify the menu item which was clicked.

See WM_COMMAND for more info.

Based on this info, you can show the contents of the selected drive in Explorer.

If you do not want to handle WM_COMMAND message in your window procedure, there is an alternate method. Call the PeekMessage function immediately after the TrackPopupMenu function and look for the WM_COMMAND message in the message queue. In this way you get the message info pending in the queue (if any). Again you can examine the message parameters to identify the menu item and open the contents of the selected drive.

See some VB code in thread222-556072 using the same method. If you do VB and have VB installed, you will find it useful.

RE: Help needed: Handling dynamic popup menu items

(OP)
That helped. Thank you.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close