How to attach CFormView derived class to CMFCTabCrtl? - mfc-feature-pack

I have created MFC MDI project with base class CFormView, ribbon, caption bar etc.
In CMainFrame, OnCreate() calls EnableMDITabbedGroups() which automatically adds one tab
and attaches CMyProjectView view. Now I want to add second tab and attach second view to that tab. I created new dialog and added CFormView derived class to it.
Here is the code:
void CMainFrame::CreateViews()
{
const CObList &tabGroups = GetMDITabGroups();
CMFCTabCtrl *wndTab = (CMFCTabCtrl*)tabGroups.GetHead();
wndTab->m_bEnableWrapping = TRUE;
CRect dummyRect;
CNewFormView *pNewView = (CNewFormView*)RUNTIME_CLASS(CNewFormView)->CreateObject();
((CWnd*)pNewView)->Create(NULL, NULL, WS_CHILD, dummyRect, wndTab, IDD_NEWFORMVIEW);
wndTab->AddTab(pNewView, _T("NewTab"), -1, TRUE);
}
Now, I'm pretty sure I missed something trivial or went in wrong direction all together,
but I can't get new view to show up. Also, I can't catch AFX_WM_CHANGE_ACTIVE_TAB or AFX_WM_CHANGING_ACTIVE_TAB in CMainFrame. Message gets send from CMFCBaseTabCtrl::FireChangingActiveTab but nothing happens.

WS_VISIBLE is missing from the view's styles?
You may want to set the active view for the frame too.

Related

Change background color (of entire view) on button click in Xamarin

I'm using iOS/Xamarin
When the user clicks a button, I'd like to change the background color of my view controller's main view (View).
In the button click event, I tried this:
partial void MyButton_TouchUpInside(UIButton sender)
{
InvokeOnMainThread(() =>
{
SetBackgroundColor(View);
});
}
but it doesn't work. I tried a few other main thread/uithread things but no luck.
If I call SetBackgroundColor(View) from the ViewDidLoad of course it works. I suspect this is a UI thread issue.
Any advice?
Thanks!
You can use the BackgroundColor property on the UIViewController's View property.
partial void MyButton_TouchUpInside(UIButton sender)
{
View.BackgroundColor = UIColor.Red;
}
Turns out the above code is good - somewhere else in the code someone was setting another layer on top of the background so I never saw it =/

Navigation Drawer back button Xamarin

I am using this binding for this awesome Material Drawer Library by MikePenz.
I have implemented the Navigation Drawer with this library and I have also managed to change the hamburger menu to the back arrow when I go level deep. Now I have some problems to get the back arrow to work correctly. When I click on the back arrow, rather than going back to the previous page, it opens up the navigation drawer.
After looking into the original library, I have identified, the following code is responsible to manage the back arrow button. I would appreciate , if someone can help me a bit to write this listener code in C#.
.withOnDrawerNavigationListener(new Drawer.OnDrawerNavigationListener() {
#Override
public boolean onNavigationClickListener(View clickedView) {
//this method is only called if the Arrow icon is shown. The hamburger is automatically managed by the MaterialDrawer
//if the back arrow is shown. close the activity
AdvancedActivity.this.finish();
//return true if we have consumed the event
return true;
}
})
Here is the binding libray that I use : MaterialDrawer-Xamarin
And this is the link to the original Library : MaterialDrawer
Try something like this:
var result = new DrawerBuilder()
.WithActivity(this)
.AddDrawerItems(
//Add some items here
new DividerDrawerItem()
)
.WithOnDrawerNavigationListener(this);
and implement Drawer.IOnDrawerNavigationListener in your activity like this:
public bool OnNavigationClickListener(View clickedView)
{
this.Finish();
return true;
}

Windows Phone 7: How to notify data is updated in ListBox?

I have above scenario: If user click on ListBox, it will either have sub items (again ListBox) or detail view.
So what i did currently is: Whenever user clicks any item, made a web call and filled up the same ListBox if clicked item is having further sub items.
Now, issue comes in picture:
Suppose i am in 4th screen (detail view),
Moved to the 3rd and 2nd screen with data maintained as stack (Its working fine, yes i am maintaining data in ObservableCollection<ObservableCollection<MyObjects>> so while moving back, i am fetching data from there)
Now, if i click any item in screen 2, it will open detail view for the screen 3 ListBox data.
Means that ListBox is not getting notified that we have filled data inside OnBackKeyPress()
FYI, i am filling up ListBox and WebBrowser in the same page., so my problem is that how do i notify ListBox once i filled up data from stack which i have maintained?
Yes i have also implemented INotifyPropertyChanged but don't know why its not working.
Please check my code:
ListBox and WebView screen: http://pastebin.com/K1G27Yji
RootPageItem class file with the implementation of INotifyPropertyChanged: http://pastebin.com/E0uqLtVG
sorry for pasting code in above way, i did as question is being long.
Problem:
How do i notify ListBox that data is changed from OnBackKeyPress?
And what is the behavior if you set:
listBox1.ItemsSource = null;
before
listBox1.ItemsSource = listRootPageItems;
This is just wrong architecture. Instead of reloading the same listbox, please add a single page for each screen. Share data between them inside the App class (internal static) and use the built in navigation stack for handling "going back". Don't override OnBackKeyPress for this purpose.
You will get your desired functionality for "free" with easier to maintain and use codebase.
Oops it was a silly mistake i made.
I forgot to set items[] array inside OnBackKeyPress() but was accessing while clicking item, hence its having items[] data of last step we moved in forward direction, it was executing the same data.
Now, i have just included a single line and it has solved my problem.
items = listRootPageItems.ToArray(); // resolution point
So final code of onBackKeyPress() is:
/**
* While moving back, taking data from stack and displayed inside the same ListBox
* */
protected override void OnBackKeyPress(CancelEventArgs e)
{
listBox1.Visibility = Visibility.Visible;
webBrowser1.Visibility = Visibility.Collapsed;
listBox1.SelectedIndex = -1;
if (dataStack.Count != 0)
{
listBox1.ItemsSource = null;
listRootPageItems = dataStack[dataStack.Count-1];
listBox1.ItemsSource = listRootPageItems;
items = listRootPageItems.ToArray(); // resolution point
dataStack.Remove(listRootPageItems);
e.Cancel = true;
}
}

How to make an auto hiding menu bar with Qt4

I am trying to make a Qt application which has an auto hiding menu bar. How can i do that?
That's an interesting task ! Ok, lets see... I'd suggest you putting a code that keeps track of mouse cursor movement in QMainWindow::centralWidget(). You need to call QWidget::setMouseTracking(true) first to be able to keep track of your mouse movement (they are turned off by default). The code can look like this:
QMainWindow *mainWindow = new QMainWindow;
MyWidget * myWidget = new MyWidget(mainWindow);
myWidget->setMouseTracking(true);
mainWindow->setCentralWidget(myWidget);
And then in your widget QWidget::mouseMove() event you need to detect whether you are in the correct area. The code can look like this:
void MyWidget::mouseMoveEvent(QMouseEvent * event) {
bool menuVisible = inCorrectArea(event->pos());
mainWindow->menuBar()->setVisible(menuVisible);
...
}
There are several ways to get access to "mainWindow" in your MyWidget. One of them is to store a pointer in MyWidget private variable when you pass MainWindow in its MyWidget constructor. You can also issue a signal from your MyWidget and handle it in MainWindow.
Hope this helps.

Creating Dialogs with Silverlight Prism

I'm new to creating Silverlight applications. I have inherited a code-base that I've been told is using Prism. Based upon what I've seen in the code-base, this looks to be true. My problem is, I am just trying to open a dialog window and close a dialog window.
To open the dialog window, I'm using the following:
UserControl myDialog = new MyDialog();
IRegion region = myRegionManager.Regions["DIALOG_AREA"];
IRegionManager popupRegionManager = region.Add(myDialog, null, true);
region.Activate(myDialog);
The dialog I have designed appears. It has two buttons: "OK" and "Cancel". When a user clicks on of these dialogs, I want to close the dialog. My problem is, I have no idea how to do this. Because the dialog is not a ChildWindow, I cannot call this.Close(). But, when I change MyDialog to a ChildWindow, it is wrapped in some custom window chrome that i can't figure out how to get rid of.
How do I close a dialog in Prism? Thank you!
Instead of putting in a different region, you should make your ViewModel call a service where you call your dialog window.
public MainPageViewModel(IMainPage view,
ILoginBox loginBox )
: base(view)
{
this.view = view;
this.loginBox = loginBox;
}
public interface ILoginBox
{
void Show();
}
remember to use the IOC container and declare on your ModuleClass:
protected override void RegierTypes()
{
base.Container.RegisterType<ILoginBox , LoginBox>();
}
I hope it helps.
If you are still looking for an example, check:
another Stackoverflow sample

Resources