How to programmatically create/build up a CTabCtrl? - c++

Without using the "Graphic Resources" how can I create and build up a CTabCtrl?
What I have so far creates it, but I don't know the MESSAGE_MAP for it. Also how to create different views for each "tab" as apposed to displaying/hiding controls depending upon what tab was selected?
thx
CTabCtrl *tabMain = new CTabCtrl();
tabMain->Create(WS_CHILD|WS_VISIBLE|TCS_TABS|TCS_SINGLELINE,CRect(700,100,1000,600),this,5);
TC_ITEM ti;
ti.mask = TCIF_TEXT;
ti.pszText = _T("Tab0");
tabMain->InsertItem(0,&ti);
ti.pszText = _T("Tab1");
tabMain->InsertItem(1,&ti);
ti.pszText = _T("Tab2");
tabMain->InsertItem(2,&ti);

The last parameter you pass to the Create function is the Id which you should use in the MESSAGE_MAP .
For eg:
ON_NOTIFY(TCN_SELCHANGE, 5 , OnSelchangeTab)

Related

How to use Delegate with QCalendarWidget?

I need modify the delegate in a QCalenderWidget. I want to change the background-color of cell when the user select a specific day.
I would like getting a simple example.
You could use QWidget::setStyleSheet(const QString & styleSheet) and set selection-background-color value:
auto calendar = new QCalendarWidget(this);
calendar->setStyleSheet("selection-background-color:black");

Make single items editable in a list control (C++, MFC)

I have a list control (CListCtrl) with two columns (Name, Value). I add entries dynamically from a xml file. Now i want to make the Value-Column editable and subscribe the Edit-Event to write the changes to the xml. How i do this?
My Code now:
LVITEM item_value;
item_value.iItem = row;
item_value.iSubItem = 1;
item_value.mask = LVIF_TEXT;
item_value.pszText = value;
ctrl->SetItem(&item_value);
Placing an edit control in CListCtrl is easier by setting the LVS_EDITLABELS style. Use EditLabel() function to place an edit control for a specific item, and retrieve the new text from edit control using GetEditControl() function by listening to the notification LVN_ENDLABELEDIT.

MFC, How do I change the capiton of TabCtrl

I know the InsertItem is for add new tab in tabctrl, but I need change the caption of tab after create, I use keyword tabctrl and caption to search the old article ,but no relation problem to solve it, hot do I change the caption of tab page...
OK,
I got the solution, as follow code
TC_ITEM TabCtrlItem;
switch(m_tabCtrl.GetCurSel())
{
case TAB1:
TabCtrlItem.mask = TCIF_TEXT;
TabCtrlItem.pszText = _T("Some Text");
m_tabCtrl.SetItem(TAB1, &TabCtrlItem );

How to split a Window dynamically in MFC without using CSplitterWnd::Create

I create a MFC MDI application, and want to split a window into two parts at a time dynamically by right click and choosing a "AddSplitWnd" pop menu item. I try to use CSplitterWnd::CreateStatic to implement it, once the window is split, it need to create a new view, but I want to use the previous view instead, so does anyone know how to implement it. Thank you.
Here is a code snippet to exchange views in a splitter in a SDI environment. This should be adaptable to work in MDI as well.
CView* CDoc::SwitchToView(CView* pNewView)
{
CFrameWndEx* pMainWnd = (CFrameWndEx*)AfxGetMainWnd();
CView* pOldActiveView;
pOldActiveView = pMainWnd->GetActiveView();
CSplitterWnd* pSplitter = (CSplitterWnd *)pOldActiveView->GetParent();
// in this case Pane 0,0 is exchanged
pOldActiveView = (CView*) pSplitter->GetPane(0,0);
// set flag so that document will not be deleted when view is destroyed
m_bAutoDelete = FALSE;
// Dettach existing view
RemoveView(pOldActiveView);
// set flag back to default
m_bAutoDelete = TRUE;
// Set the child window ID of the active view to the ID of the corresponding
// pane. Set the child ID of the previously active view to some other ID.
::SetWindowLong(pOldActiveView->m_hWnd, GWL_ID, 0);
::SetWindowLong(pNewView->m_hWnd, GWL_ID, pSplitter->IdFromRowCol(0,0));
// Show the newly active view and hide the inactive view.
pNewView->ShowWindow(SW_SHOW);
pOldActiveView->ShowWindow(SW_HIDE);
// Attach new view
AddView(pNewView);
// Set active
pSplitter->GetParentFrame()->SetActiveView(pNewView);
pSplitter->RecalcLayout();
return pOldActiveView;
}
HTH

JList in JScrollPane messes up JPanel height

I have a weird problem that I can't seem to solve. I've got a JList which has to be able to scroll if there are more items in it then can be displayed. However if I put the JList in a JScrollPane, it doesn't utilise the full height of the EAST part of the BorderLayout it's in.
Example without JScrollPane:
public UsersPanel(){
String[] userList = new String[]{"Foo","Bar","Foo","Bar","Foo","Bar","Foo","Bar","Foo","Bar","Foo","Bar","Foo","Bar"};
JList users = new JList(userList);
add(users);
}
Example with JScrollPane:
public UsersPanel(){
String[] userList = new String[]{"Foo","Bar","Foo","Bar","Foo","Bar","Foo","Bar","Foo","Bar","Foo","Bar","Foo","Bar"};
JList users = new JList(userList);
JScrollPane sp = new JScrollPane(users);
add(sp);
}
I want a JList that utilises the full available height of the EAST part of the BorderLayout it's in. I've tried wrapping my JList inside another JPanel, but that doesn't solve my problem either.
use setVisibleRowCount() method to set number of visible rows in Jlist.
users.setVisibleRowCount(10);
One hack that I've used successfully before is to add a ComponentListener to parent component of the JList / JScrollPane, and as it changes reset the preferred size of the JList and/or Jscrollpane via (pseudo-code) setPreferredSize(getPreferredSize().width, parentHeight)