MFC: TAB order programmatically for controls - c++

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

Related

Foregrounding a modeless dialog after it's been backgrounded or minimized (MFC)

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?

How to check style BS_AUTORADIOBUTTON of button

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
}

mfc CScrollView deactivate

i wanna make a notepad(windows8)
the notepad`s scrollbar is deactivate(When not needed)
but CScrollView is hide scrollbar(When not needed)
how to change CScrollView's scrollBar like notepad's scrollBar?
Style for multi-line edit control where vertical scroll bar is hidden unless there there is overflow:
WS_CHILD | WS_VISIBLE | ES_MULTILINE | ES_WANTRETURN | ES_AUTOVSCROLL
For Notepad style:
WS_CHILD | WS_VISIBLE | ES_MULTILINE | ES_WANTRETURN | ES_VSCROLL
When using dialog editor, set the values for Auto VScroll and Vertical Scrollbar, corresponding to ES_AUTOVSCROLL and WS_VSCROLL

How to remove the border of a QDialog which I give a transparent background image?

I intended to make a un-rectangle QDialog, so I paint a png image by override QDialog::paintEvent.Everything is okay except there is a gray border shown arrond the dialog.Like this:
I am sure that border is not belong to the image,and I had setWindowFlags(Qt::FramelessWindowHint) and setAttribute(Qt::WA_TranslucentBackground, true).I tried to set a qss like border-width: 0px but didn't work.
Is there any way to remove the border?And why it is shown?
You can create a borderless dialog by setting Qt::FramelessWindowHint window flag :
setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
To make it transparent you should set these attributes :
setAttribute(Qt::WA_NoSystemBackground);
setAttribute(Qt::WA_TranslucentBackground);
setAttribute(Qt::WA_PaintOnScreen);

Select element which is extended popup menu (submenu)

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.