Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to add entries to System pop up menu

Posted on 2003-03-27
14
Medium Priority
?
209 Views
Last Modified: 2013-11-28
How can I add entires to system pop up menu.
and how can I handle the events and messages
when an user clicks on it...?

-Prash
0
Comment
Question by:prashanthgn
  • 5
  • 3
  • 3
11 Comments
 
LVL 31

Expert Comment

by:Zoppo
ID: 8223275
What exactly do you mean with 'system pop up menu'?

The system-menu of a window of your app which pops up when
clicking on the little icon in the top-left corner of the window (which contains i.e. 'Restore', 'Move', 'Size' ... 'Close')?

You can access this menu somehow like this:

1. Add a new resource symbol via 'View->Resource Symbols',
i.e. IDM_TEST.

This is from MSDN:
---------------------
In WM_SYSCOMMAND messages, the four low-order bits of the
wParam parameter are used internally by the system. To
obtain the correct result when testing the value of wParam,
 an application must combine the value 0xFFF0 with the
wParam value by using the bitwise AND operator.
---------------------

So, set the value of IDM_TEST to something like 0x...0, i.e. 0x1230.

Then add two message handlers to your window for
WM_SYSCOMMAND and WM_INITMENUPOPUP.

In your window's OnCreate() add code like:
 ...
 CMenu* pMenu = GetSystemMenu( FALSE );
 ASSERT( pMenu );

 if ( NULL == pMenu )
 return -1;

 // This tests if the menu item is in system-command range
 ASSERT((IDM_TEST & 0xFFF0) == IDM_TEST);
 ASSERT(IDM_TEST < 0xF000);

 pMenu->AppendMenu( MF_STRING, IDM_TEST, "Test" );
 return 0;
}

In the handler for WM_SYSCOMMAND add the functionality you
want to happen when the item is clicked, i.e.

void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam)
{
 if ( nID == IDM_TEST )
  AfxMessageBox( "Test" );
 CMDIFrameWnd::OnSysCommand(nID, lParam);
}

In the handler for WM_INITMENUPOPUP you can control the state
of the item to en-/disable an (un-)check it, i.e.:
void CMainFrame::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
{
 CMDIFrameWnd::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
     
 // We disable the item if no MDI child is present
 if ( NULL == MDIGetActive() )
  pPopupMenu->EnableMenuItem( IDM_TEST, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED );
 else
 pPopupMenu->EnableMenuItem( IDM_TEST, MF_BYCOMMAND | MF_ENABLED );
}


hope that helps,

ZOPPO
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 8223286
Adding Commands
===============

First we need to define a unique variable to represent each menu item. This can be done in the Resource.h file, or in any standard header file. If the commands already exist as part of another standard or conext menu, then this step can be skipped because the definitions already exist. However, it's important to note that even if we use the pre-existing definitions, the message handlers for the commands on the regular menu will NOT be automatically called. System commands are routed differently. So, in the end, it doesn't matter if we use the existing or define our own.

For our example, we'll define two:

#define IDM_ABOUT 16
#define IDM_EXIT  17
 



The IDM just means this is a menu-item ID.

We add these commands in our window's initializing function (OnInitDialog(), OnCreate()). My example is in a dialog class, so this is what the function looks like:


BOOL CBabelOnDlg::OnInitDialog()
{
    CDialog::OnInitDialog();

    // Add "About..." and "Exit" menu items to system menu.

    // Command IDs must be in system range
    // the ANDing is because of a bug in Windows 95

    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000);

    ASSERT((IDM_EXIT & 0xFFF0) == IDM_EXIT);
    ASSERT(IDM_EXIT < 0xF000);

    CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
        pSysMenu->AppendMenu(MF_STRING,IDM_EXIT,"E&xit Program");
        pSysMenu->AppendMenu(MF_SEPARATOR);
        pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, "A&bout BabelOn");
    }
.
.
.other initialization
 




Processing Custom Commands
==========================

In order to have those commands do anything, we can't rely on the normal message-handling mechanism, even if we have handlers for the same items in other menus. We have to handle the WM_SYSCOMMAND message in our dialog/window class.


void CBabelOnDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
    //trap our own system menu messages
    if ((nID & 0xFFF0) == IDM_ABOUTBOX)
    {
        CAboutDlg dlgAbout;
        dlgAbout.DoModal();
    } else if ((nID & 0xFFF0)==SC_CLOSE){
        OnClose();
    } else if ((nID & 0xFFF0)==IDM_EXIT) {
        ::PostQuitMessage(0);
    }

     else {
   
        CDialog::OnSysCommand(nID, lParam);
    }
}
 

Good Luck
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 8223302
to Roshmon: did you test your code?

#define IDM_EXIT 17
ASSERT((IDM_EXIT & 0xFFF0) == IDM_EXIT);

will assert!
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 31

Expert Comment

by:Zoppo
ID: 8223307
BTW, it's never a good idea to define resource IDs outside
of resource.h since then there's no way to grant resource
IDs are unique.

0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 8223315
Hi Zoppo,
    I just got this document from the net. http://www.devhood.com It is a good site. I didn't tested the code.

Roshmon
0
 

Author Comment

by:prashanthgn
ID: 8223588
Hi,

 I ahd asked for the menu which will be shown on right clicking on any of the files/directories in the Explorer
window, not for a specific application

-Prash
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 8223641
The below Registry is for right click on exe and then register…

So u can do the same for Jpeg through program using the APIs RegOpen, RegSet etc

 

 

REGEDIT4

 

; regsvr.reg, Copyright (c) 1997-1998, Chris Sells.

; All rights reserved. NO WARRANTIES ARE EXTENDED. USE AT YOUR OWN RISK.

; P.S. Enjoy and send comments to csells@sellsbrothers.com.

;

; History:

; 10/25/98

; Replaced %1 with %L to get long file name support.

; (Thanks to Sergey Tetkin for the suggestion!)

;

; Sometime in early 1997: 1st release

; Don, Tim, Keith and I were sitting around at a GCOM talking about

; what a pain it was to perform self-registeration and couldn't I

; add a shell extension to augment the context menu (I had written

; the Win95 course)? I said I could do even better than that and

; this regfile was born.

 

; Register and Unregister DLLs and OCXs

[HKEY_CLASSES_ROOT\.dll]

@="dllfile"

 

[HKEY_CLASSES_ROOT\.ocx]

@="dllfile"

 

[HKEY_CLASSES_ROOT\dllfile\shell\Register COM Server\command]

@="regsvr32 \"%L\""

 

[HKEY_CLASSES_ROOT\dllfile\shell\Unregister COM Server\command]

@="regsvr32 /u \"%L\""

 

; Register and Unregister EXEs

[HKEY_CLASSES_ROOT\.exe]

@="exefile"

 

[HKEY_CLASSES_ROOT\exefile\shell\Register COM Server\command]

@="\"%L\" /regserver"

 

[HKEY_CLASSES_ROOT\exefile\shell\Unregister COM Server\command]

@="\"%L\" /unregserver"



Good Luck
0
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 1000 total points
ID: 8223660
Try This Link "The Complete Idiot's Guide to Writing Shell Extensions - Part II"
http://codeproject.com/shell/shellextguide2.asp?target=unregister%7Ccom%7Cserver

Good Luck
0
 

Author Comment

by:prashanthgn
ID: 8223757
Hi,

 I ahd asked for the menu which will be shown on right clicking on any of the files/directories in the Explorer
window, not for a specific application

-Prash
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 8223825
Try This Link "The Complete Idiot's Guide to Writing Shell Extensions - Part II"
http://codeproject.com/shell/shellextguide2.asp?target=unregister%7Ccom%7Cserver

Good Luck
0
 

Author Comment

by:prashanthgn
ID: 8224073
Hi,

 I ahd asked for the menu which will be shown on right clicking on any of the files/directories in the Explorer
window, not for a specific application

-Prash
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over time, the online landscape has altered considerably, but that’s nothing compared to the up-and-coming trends that will shape the web design industry in the coming year. Keep reading to find out which trends will shape B2B web design in 2018.
Advertising is a powerful thing. The important question is, how to create advertisement people would willingly want to share on their social media? This article gives you essential tips on how to launch successful viral ad and increase substantially…
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question