CWinAppEx CleanState - Reset Layout - layout

I migrated my MFC MDI application to use the new MFC Feature Pack. I have many toolbars and dockable panes. As far as I understand, the location and size of each of them is saved in the registry when closing the application, and loaded when loading the main frame.
I want to add a feature in my application to reset the layout of the toolbars/panes to the original layout.
I added a menu item whose command is handled in my CWinAppEx derived class as follows:
CleanState();
LoadState((CMDIFrameWndEx*)m_pMainWnd);
But it does not seem to work properly.
However, if I put the CleanState() function call before the call to the LoadMainFrame(), the application loads with the default layout (the one I want).
Is there a way to actually reset the layout of my application AFTER it has been loaded?
Thank you so much.

I don't have an easy answer for you. I had 3 docking windows using MFC Feature Pack in Visual Studio 2017. I called CleanSlate and then positioned the docking panes making sure they are visible. I experimented with the size of the main frame window and the docking windows to get it to look right.
void CMainFrame::OnButtonWindowResetLayout()
{
theApp.CleanSlate();
CRect rcInputsOutputs(0, 0, 400, 50);
m_wndPaneInputsOutputs.DockToFrameWindow(CBRS_ALIGN_RIGHT, rcInputsOutputs, DT_DOCK_LAST, NULL, -1, FALSE);
m_wndPaneInputsOutputs.ShowPane(TRUE);
CRect rcDeviceStatus(0, 0, 600, 180);
m_wndPaneDeviceStatus.DockToFrameWindow(CBRS_ALIGN_BOTTOM, rcDeviceStatus, DT_DOCK_LAST, NULL, -1, TRUE);
m_wndPaneDeviceStatus.ShowPane(TRUE);
CRect rcOutput(0, 0, 600, 70);
m_wndOutput.DockToFrameWindow(CBRS_ALIGN_BOTTOM, rcOutput, DT_DOCK_LAST, NULL, -1, TRUE);
m_wndOutput.ShowPane(TRUE);
AdjustDockingLayout();
SetWindowPos(&CWnd::wndTop, 0, 0, 900, 680, SWP_NOMOVE | SWP_NOACTIVATE | SWP_SHOWWINDOW);
}
Each pane class has the function:
void CPaneDialogEx::ShowPane(BOOL showPane)
{
if (showPane != IsVisible()) {
CMainFrame* pMainFrame = DYNAMIC_DOWNCAST(CMainFrame, GetTopLevelFrame());
if (pMainFrame != NULL) {
pMainFrame->SetFocus();
pMainFrame->ShowPane(this, showPane, FALSE, FALSE);
pMainFrame->RecalcLayout();
}
}
}

Yes, just delete the registry entry assigned with layout saving.

Related

C# - Graphics.DrawImage Method - Image hides on console refresh

I'm trying to draw an image on the console window, it works correctly,
but for some reason, the image hides when I unfocus the app and refocus it & when I scroll down and up, it will just disappear,
is there a better way to fix it rather than just looping the display method again and again?
here's the code:
public static void Display()
{
var handler = GetConsoleHandle();
using (var graphics = Graphics.FromHwnd(handler))
using (var image = Image.FromStream(Img))
graphics.DrawImage(image, 362, 30, 250, 200);
}

Extend GCKUICastContainerViewController below the Home Indicator

I'm integrating GoogleCast to my app. Its root view controller is a UITabBarController, with a custom white tab bar.
After I wrapped it with a GCKUICastContainerViewController, the Home Indicator background area became black (and the indicator is white).
How can I make this Container VC extend its child VC (my tab bar controller) below the home indicator?
Note: There is an ugly workaround that I tried, which is to set castContainerVC.view.backgroundColor = .white. This would work if the tab bar was always visible, but some parts of my navigation stack may choose to hide it. When it happens, I'd end with a white Home Indicator area, but whatever color the presented view controller has above the indicator.
extension GCKUICastContainerViewController {
open override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
if let window = UIApplication.shared.keyWindow, miniMediaControlsViewController?.view.bounds.height ?? 0 == 0 {
contentViewController?.view.frame = window.frame
} else {
contentViewController?.view.frame = (view.subviews.first! as UIView).frame
}
}
}
Yes, it appears Google wants us to have the GCKUICastContainerViewController as the root view controller. And it looks like it has some layout issue when there is safe area inset at the bottom of the display.
I solved this by changing the view's frame manually in viewDidLayoutSubviews. You can do it with an extension like this
extension GCKUICastContainerViewController {
open override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
if let window = UIApplication.shared.keyWindow {
contentViewController?.view.frame = window.frame
}
}
}
This way you will get rid of the space at the bottom of the screen. Works for me.

Xamarin.iOS Design Suggestion

New to Xamarin world.
Need a suggestion on how to design a screen.
I need to design a login screen which has a 1 dropdown, 2 text boxes and 1 button - all vertically centre aligned.
It shall run on both portrait / landscape mode on all iPhone and iPads
as well.
I had faced problem in landscape mode. Background image gets squeezed and content gets hidden and it doesn't have a scrollbar.
Thanks in Advance !
You can resize the controls when the device rotate to landscape via code.
ViewWillTransitionToSize() will be fired when the device is rotated. You can resize the controls here, like this:
public override void ViewWillTransitionToSize(CGSize toSize, IUIViewControllerTransitionCoordinator coordinator)
{
base.ViewWillTransitionToSize(toSize, coordinator);
coordinator.AnimateAlongsideTransition((IUIViewControllerTransitionCoordinatorContext) => {
if (UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.Portrait || UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.PortraitUpsideDown)
{
//Update UI
}
if (UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.LandscapeLeft|| UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.LandscapeRight)
{
//Update UI
}
}, (IUIViewControllerTransitionCoordinatorContext) => {
//Transition Completion
});
}

BarButtonItems not visible in iOS 11

I have an iOS app developed using Xamarin. Now I am trying to migrate it to iOS 11. My problem is that none of the BarButtonItems in navigation bars are visible in any controller, yet they are functional and I can tap them.
some of those button items are set in storyboard, by adding Navigation Item into the controller. titles of those button items are also invisible. even the standard back button.
the other bar button items are set in code by SetRightBarButtonItem or SetLeftBarButtonItem. I have both custom icon buttons and system item buttons. an example for system item button is:
this.NavigationItem.SetLeftBarButtonItem(new UIBarButtonItem(UIBarButtonSystemItem.Stop, (sender, e) => { ... }), true);
and another with custom icon button:
this.NavigationItem.SetRightBarButtonItem(new UIBarButtonItem(UIImage.FromBundle("gear"), UIBarButtonItemStyle.Plain, (sender, e) => { ... }), true);
These navigation bar button items have been working without problems for a long time. how can I fix them with the new navigation bar structure in iOS 11? (I do not enable large titles in navigation bars)
Just do something like this.
var button = new UIBarButtonItem(UIImage.FromBundle("gear"),UIBarButtonItemStyle.Plain, (sender, e) => { ... });
button.SetTitleTextAttributes(new UITextAttributes()
{
TextColor = UIColor.Blue,
TextShadowColor = UIColor.Clear
}, UIControlState.Normal);
this.NavigationItem.SetRightBarButtonItem(button, true);

Is it possible to call setBadgeText on pageAction in a chrome extension?

I'm trying to set the badge text for my chrome extension with the code below:
chrome.pageAction.setBadgeText({"text":'3'})
This throws an error Object #<Object> has no method setBadgeText.
I have used the canvas feature to get the same result. Here the code that i used.
window.setInterval(function() {
chrome.pageAction.setIcon({imageData: draw(10, 0), tabId: tabId});
}, 1000);
function draw(starty, startx) {
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
var img = new Image();
img.src = "icon_16.png"
img.onload = function () {
context.drawImage(img,0,2);
}
//context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "rgba(255,0,0,1)";
context.fillRect(startx % 19, starty % 19, 10, 10);
context.fillStyle = "white";
context.font = "11px Arial";
context.fillText("3",0,19);
return context.getImageData(0, 0, 19, 19);
}
here you can chage the positon and color of text you want to show.
No, it is not possible with page actions
But it is possible with browser actions.
Excerpt:
page action docs
Parts of the UI Like browser actions, page actions can have an icon, a
tooltip, and popup; they can't have badges, however. In addition, page
actions can be grayed out. You can find information about icons,
tooltips, and popups by reading about the browser action UI.
What you can do is to replace the current image with another that has a badge included in the image.
Rumor has it that you can use chrome.browserAction.setBadgeText to set a badge on a page action. Since you can only have either a page action or a browser action in your extension, if you opt for the former this method acts on the page action even though it is part of the browserAction API.

Resources