Since couple weeks I'm trying to figure out how can I select (choose) item on popup menu which is extended to another popup submenu. For example:
HMENU hMenu,hSubMenu;
hMenu = CreatePopupMenu();
hSubMenu = CreatePopupMenu();
AppendMenu(hMenu , MF_POPUP | MF_STRING | MF_ENABLED, (UINT_PTR) hSubMenu, name.c_str()); // this one i want to select and choose on callback
AppendMenu(hMenu , MF_POPUP | MF_STRING, (UINT_PTR) count, name.c_str());
Than I'm trying to get Callback with: WM_MENUSELECT to catch the name of hover element.
But when I click on this hSubMenu element - menu don't want disappear, but is still active and extends submenu elements.
WM_INITMENUPOPUP will not help.
I just want to close this popup menu when i get message back from WM_MENUSELECT.
WM_LBUTTONUP doesn't work on popup menu...
Could You give me some advice? I'm coding with pure winapi.
Related
I have some code which creates a modeless dialog:
m_ReminderDialog = new CReminderDialog();
m_ReminderDialog->Create(CReminderDialog::IDD, GetDesktopWindow());
m_ReminderDialog->SetForegroundWindow();
Using a dialog template with this style:
STYLE DS_SETFONT | WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
EXSTYLE WS_EX_APPWINDOW | WS_EX_NOACTIVATE
This works; the dialog window is foregrounded (or flashed).
However, if the dialog window is minimized or put into the background,
m_ReminderDialog->ShowWindow(SW_SHOWNORMAL);
m_ReminderDialog->SetForegroundWindow();
doesn't work to foreground it, unless the main window has been minimized or disabled.
Why, and how to fix it?
So my problem is pretty much that when I click on the menu, and then quickly click on the menuItem2 (that contains submenu items), the submenu items will appear for 0.5 seconds and then hide. I have to click again or hover again on the menuItem2 to make the submenu items appear correctly.
The only way to clearly make the submenu items appear is by hovering over menuItem2 without clicking at all.
This is a problem if I want to release my program on a touch screen, since clicking will make the submenu items to hide (the concept of hovering doesn't really work...).
Menu {
id: menu
MenuItem {
text: "menuItem1"
}
Menu{
title: "menuItem2"
MenuItem {
id: subMenuItem1
objectName: "subMenuItem1"
text: "subMenuItem1"
}
MenuItem {
id: subMenuItem2
objectName: "subMenuItem2"
text: "subMenuItem2"
}
}
}
Thank you for any solution to this problem.
I want to save properties of controls in a window such as text or checked or etc in WinAPI.
How can i test the button controls that has BS_AUTORADIOBUTTON style (Is it CheckBox or RadioButton )?
You can use GetWindowLong() to get the style of a window:
LONG style = GetWindowLong(hWnd, GWL_STYLE);
if(0 != (style & BS_AUTORADIOBUTTON))
{
// radio button logic here
}
I am using the default CButton and created 3 buttons programmatically..
BOOL CTestDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
CRect rect;
GetClientRect(&rect);
CRect btnRect = CRect(rect.left+50,100,rect.left+150,150);
button1.Create(_T("ONE"),BS_FLAT | WS_VISIBLE,btnRect,this,1);
btnRect.MoveToX(200);
button2.Create(_T("TWO"),BS_FLAT | WS_VISIBLE,btnRect,this,2);
btnRect.MoveToX(350);
button3.Create(_T("THREE"),BS_FLAT | WS_VISIBLE,btnRect,this,3);
return TRUE;
}
If i see the O/P, always the Buton ONE is highlighted and no TAB is working.
How to support TAB order and how to change the focus. Can someone please help.
Thanks
You've created the buttons without the necessary windows styles.
From MSDN:
Apply the following window styles to a button control:
WS_CHILD Always
WS_VISIBLE Usually
WS_DISABLED Rarely
WS_GROUP To group controls
WS_TABSTOP To include the button in the tabbing order
I have created a dialog box containing a textbox and a button.
And when the button is pressed , a message box with the textbox content should appear.....but it is not getting displayed.
void dilg::OnBnClickedButton1()
{
CString str;
tx1.GetWindowText(str);
MessageBox(str);
}