Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • 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!

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

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...keep up the good work with this forum, I think this is the best one around. ...you actually try to help people learn for themselves. ...I commend you on providing a very good, open learning atmosphere, where usually egos are left behind..."

Geography

Where in the world do Tek-Tips members come from?
imagenetics (Programmer)
30 Dec 05 7:08
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.
Helpful Member!  Hypetia (Programmer)
30 Dec 05 12:19
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.
imagenetics (Programmer)
3 Jan 06 5:52
That helped. Thank you.

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!

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