?
Solved

System Menu anywhere in dialog with right click

Posted on 2003-02-28
13
Medium Priority
?
334 Views
Last Modified: 2013-11-20
How can I show System Menu anywhere in dialog with right click in a Dialog Based app?
0
Comment
Question by:bkuyucu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 4
13 Comments
 
LVL 11

Accepted Solution

by:
KurtVon earned 80 total points
ID: 8043980
This seems to work fine

void CTestDlg::OnRButtonDown(UINT nFlags, CPoint point)
{
    CMenu* pSysMenu = GetSystemMenu(FALSE);

    ClientToScreen(&point);
    pSysMenu->TrackPopupMenu(TPM_RIGHTBUTTON, point.x, point.y, this, NULL);
}

The real trick is reponding to the events since this sends a WM_COMMAND instead of a WM_SYSCOMMAND message.  To respond you need to save all the sys command IDs and then catch them in the OnCommand function and change them back to WM_SYSCOMMANDs.  I created a member

CArray<WPARAM, WPARAM> m_wpaSysCommands;

then added

    m_wpaSysCommands.RemoveAll();
    for (int nIndex = 0;nIndex < pSysMenu->GetMenuItemCount();++nIndex)
        m_wpaSysCommands.Add(pSysMenu->GetMenuItemID(nIndex));

before the TrackPopupMenu command above.  In on command just add the following

    for (int nIndex = 0;nIndex < m_wpaSysCommands.GetSize();++nIndex)
    {
         if (wParam == m_wpaSysCommands.GetAt(nIndex))
        {
            m_wpaSysCommands.RemoveAll();
            PostMessage(WM_SYSCOMMAND, wParam, lParam);
            return TRUE;
        }
    }

before the call to the base class.
0
 

Author Comment

by:bkuyucu
ID: 8057880
I want something more straight. A message combination must result in the system menu to be displayed. For example WM_NCRBUTTONUP + smthg. Cause only posting WM_NCRBUTTONUP did not work.

This is like moving a dialog by clicking anywhere in the client region. U just deceive windows by sending WM_NCLBUTTONDOWN with a parameter HT_CAPTION and coordinates. I want something like this.
Best Regards
0
 
LVL 11

Expert Comment

by:KurtVon
ID: 8058007
Well, you could override OnNCHitTest to return HTCAPTION, but that also will allow left button dragging anywhere in the dialog.

Oh, and you could try the posting of WM_NCLBUTTONDOWN with HTSYSMENU.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:bkuyucu
ID: 8058062
I have tried
PostMessage (WM_NCRBUTTONDOWN, HTSYSMENU, MAKELPARAM(point.x,point.y));    
in OnRButtonDown.
This does not work.
For an example of what i want u can look at Windows Cdplayer. When u dblclick on caption bar, title bar disappears and u can right-click anywhere on client region to get system menu.
I traced it with Spy++ for messages going in and out. But couldnt catch the secret.
Thanks for replies.
0
 
LVL 11

Expert Comment

by:KurtVon
ID: 8058082
Sorry, that should be WM_NCLBUTTONUP.
0
 

Author Comment

by:bkuyucu
ID: 8058093
I have tried
PostMessage (WM_NCRBUTTONDOWN, HTSYSMENU, MAKELPARAM(point.x,point.y));    
in OnRButtonDown.
This does not work.
For an example of what i want u can look at Windows Cdplayer. When u dblclick on caption bar, title bar disappears and u can right-click anywhere on client region to get system menu.
I traced it with Spy++ for messages going in and out. But couldnt catch the secret.
Thanks for replies.
0
 
LVL 11

Expert Comment

by:KurtVon
ID: 8058104
Sorry, that should be WM_NCLBUTTONUP.
0
 
LVL 11

Expert Comment

by:KurtVon
ID: 8058107
Sorry, that should be WM_NCLBUTTONUP.
0
 
LVL 11

Expert Comment

by:KurtVon
ID: 8058167
Sorry about the multiple post.
0
 

Author Comment

by:bkuyucu
ID: 8058212
No problem I think its not related to us. My comment was posted twice too.

So where we are? I tried everything possible so far.
PostMessage (WM_NCLBUTTONUP, HTCAPTION, MAKELPARAM(point.x,point.y));    
or
PostMessage (WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(point.x,point.y));    
or
PostMessage (WM_NCLBUTTONUP, HTSYSMENU, MAKELPARAM(point.x,point.y));    
or
PostMessage (WM_NCRBUTTONDOWN, HTSYSMENU, MAKELPARAM(point.x,point.y));    
or
PostMessage (WM_NCRBUTTONUP, HTSYSMENU, MAKELPARAM(point.x,point.y));          

I got nothing so far.
Do u have another advice?
0
 
LVL 11

Expert Comment

by:KurtVon
ID: 8058324
Nope, the sys menu just doesn't respond to posted messages or NCHitTest faking.  It must be handled externally in some way.

Like I said, the technique I used above works.  I still can't remember when or why I first used it, but retesting this stuff does explain the convolution.  I suspect I just got frustrated and went with the brute force method (actually it was a button message I was responding to in the original code).

I can promise you it works.  I had to tweak it for sub-menus on the system menu, like for NVidia cards, but that code is owned by someone else, and pretty easy to figure out anyway.

If you find more elegant way around it I'd be glad to hear it, but sometimes elegant has to be set aside for a solution that just works.
0
 
LVL 11

Expert Comment

by:KurtVon
ID: 8058706
Actually, I take that back.  Except for the positioning, you can always bring up the Sys Menu by faking the sys menu message:

PostMessage(WM_SYSCOMMAND, SC_KEYMENU, VK_SPACE);

Of course, like I said, that only brings it up in the normal sys menu position.  I suppose you could get the handle and move it after it is up, though.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

764 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