Opening system menu with code don’t work
-
Hi, I want to open the system menu of a window from code instead of as usual letting the user do it by right mouse-clicking on the top left icon. I use GetSystemMenu() to get the system menu and TrackPopupMenu() to display it. The system menu shows up but when I click on any menu item, nothing is routed back to the window. OnSysCommand() which normally receives system menu clicks is not called. However if the system menu is opened by the user as usual, everything works fine. What do I do wrong? How do I trap the menu item clicks? Here’s the code from my test project, a standard dialog based application, TestDlg inherits from CDialog so this pointer is the dialog itself with the OnSysCommand() method. void TestDlg::OnButton() { CMenu* pSysMenu = GetSystemMenu(FALSE); pSysMenu->TrackPopupMenu(0, 100, 100, this); } /Thanks, Patric /Patric My C# blog: C# Coach
-
Hi, I want to open the system menu of a window from code instead of as usual letting the user do it by right mouse-clicking on the top left icon. I use GetSystemMenu() to get the system menu and TrackPopupMenu() to display it. The system menu shows up but when I click on any menu item, nothing is routed back to the window. OnSysCommand() which normally receives system menu clicks is not called. However if the system menu is opened by the user as usual, everything works fine. What do I do wrong? How do I trap the menu item clicks? Here’s the code from my test project, a standard dialog based application, TestDlg inherits from CDialog so this pointer is the dialog itself with the OnSysCommand() method. void TestDlg::OnButton() { CMenu* pSysMenu = GetSystemMenu(FALSE); pSysMenu->TrackPopupMenu(0, 100, 100, this); } /Thanks, Patric /Patric My C# blog: C# Coach
-
Try this instead:
void TestDlg::OnButton()
{
SendMessage( WM_SYSCHAR, VK_SPACE, 0x20000000 );
}