MFC - Adding event handler for dialog button - events

I have a CView class and a dialog in it, and I want to get some data from the dialog object once the user clicks on its "Accept" button, so I have added an event for the button and its handler in the CView class, all done through Visual Studio 2010 menus, so I haven't screwed up the code.
CView clas:
BEGIN_MESSAGE_MAP(CSurface3DView, CView)
ON_BN_CLICKED(ID_RANGE_OK, &CSurface3DView::OnBnClickedRangeOk)
END_MESSAGE_MAP()
...
void CSurface3DView::OnBnClickedRangeOk()
{
//things i need to do
}
The thing is, it doesn't call the OnBnClickedRangeOk() function when I the OK button is clicked.
I could also call a function from CView class from the Dialog class, but I can't use an instance for the parent class because I would need to include its header and that causes a circular inclusion, which can be solved by declaring the CView class in the Dialog header without including it, but then its methods can't be accesed.
Maybe it's not possible to put the message handle for the dialog button outside the dialog class? How do I run a certain function in the CView class only when the Dialog button is pressed?
EDIT:
Well it's solved now, I used SendMessage(hWnd, MESSAGE ,...) method of CDialog to send a message to the parent which pointer I get in the constructor of CDialog, so I don't have to declare the specific Class of the parent and I don't get inclusion problems.
The specifics to do that I found here: http://forums.codeguru.com/showthread.php?385590-How-to-SendMessage-from-child-window-to-parent

Related

Using bootstrap calendar inside slickgrid then Calendar is stuck issue

I am using bootstrap calendar inside slickgrid. When calendar popup is opened and use Alt+tab or scope out of slickgrid then calendar gets stuck. I have to reload application to get rid of calendar popup. I want to close calendar pop up as soon as user scopes out of slickgrid. Please suggest way to do it.
Not sure if it's your problem but you can't use just a z-index in SlickGrid that won't work and won't do anything, you need to use position: absolute on your Editor (each editor has a args.position passed to their constructor) that you can use to reposition your editor next to the cell that you clicked, however make sure that you also add a position() method that will be called if it exist and of course you need to add proper code to reposition the DOM element inside that method. Also when you click on a different cell then the previous Editor will call the destroy method, so make sure you remove the Editor properly by adding necessary code in your destroy() method.
All of that position usage can be seen in 1 of the built-in Editor which is the LongText defined in the slick.editors.js on this line
The absolute style is applied here
and the position(cellPosition) method is defined here
If your problem is really that your Editor doesn't get removed from the DOM, then it's because you didn't code the destroy() properly and here is the LongText destroy() method for reference. Also you might want to add an onBlur event that will call your destroy() method after a blur or any other event that you choose.
and here's a print screen of the LongText Editor that is repositioned over the cell you clicked and you can test it yourself in this Example - Editing

Is there a way to trigger an action without a button click

I'm about to develop an add-in that will automatically pull some data from emails and modify some fields in our database. However this extraction could be a bit error prone so we wanted a layer of human verification when it occurred.
We do this in gmail already, when the user open an email and we find something we want to extract we display a confirmation pop-up, and this feature is very well received by our clients.
I am planning on using the dialogbox but it seems to trigger this the action to display the box needs to be attached to a ui element for the user to click.
Is there any way to tigger an action pragmatically, without a users click?
Take a look at the pinnable task pane available for Outlook add-ins, see Implement a pinnable task pane in Outlook for more information. There you can implement the ItemChanged event handler. The event handler should accept a single parameter, which is an object literal. The type property of this object will be set to Office.EventType.ItemChanged. When the event is called, the Office.context.mailbox.item object is already updated to reflect the currently selected item.
Office.initialize = function (reason) {
$(document).ready(function () {
// Set up ItemChanged event
Office.context.mailbox.addHandlerAsync(Office.EventType.ItemChanged, itemChanged);
UpdateTaskPaneUI(Office.context.mailbox.item);
});
};
// Example implementation
function UpdateTaskPaneUI(item)
{
// Assuming that item is always a read item (instead of a compose item).
if (item != null) console.log(item.subject);
}

Accessing on-screen elements from delegate function in WP7

Suppose that I have a registration screen, and when the user clicks the "Register" button an asynchronous operation takes place, at the end of which a delegate method is invoked. I want the button to be turned off when the user clicks it (that part is easy), and for the button to be re-enabled if the registration fails (server declined the registration). How do I access this button's properties from the delegate function?
Assuming you've declared the Button's name in XAML, in the delegate callback function, I'd do something like (The Dispatcher.BeginInvoke is necessary to execute the code on the UI thread):
Dispatcher.BeginInvoke(() =>
{
MyRegisterButton.IsEnabled = true;
});

Two way databinding from TextBox doesn't update when button in ApplicationBar is clicked

I have a TextBox in my app, and an ApplicationBarIconButton in the ApplicationBar which acts as a "submit" for the contents of the TextBox.
When editing the TextBox using the virtual keyboard, the ApplicationBarIconButton is still visible below the SIP, so you can submit straight away without dismissing the keyboard: nice!
However, when clicking the button, the viewmodel to which the TextBox is bound does not update.
I found someone else with the same problem here, and they have used the pretty nasty workaround of manually updating the viewmodel on the TextBox's TextChanged event.
Removes all the elegance of using databound view models!
Is this a bug in WP7?
Or is there a nicer way around this that I haven't found yet?
The problem is that silverlight bindings do not support the PropertyChanged value for UpdateSourceTrigger. This means that by default a TextBox will update the property bound to Text when the TextBox loses focus and the only other possibility is to update it explicitly in code as is done in the example from your link.
You only really have two options here: Update the binding when the button is clicked or remove focus from the TextBox when the button is clicked.
I usually update the binding on the TextChanged event. I use an extension method to do this:
public static void UpdateBinding(this TextBox textBox)
{
BindingExpression bindingExpression =
textBox.GetBindingExpression(TextBox.TextProperty);
if (bindingExpression != null)
{
bindingExpression.UpdateSource();
}
}
allowing me to just call this in code behind:
textBox.UpdateBinding();
You may also be able to use a custom behaviour for this.
Summary of the steps to allow binding to work for each keypress of a textbox, instead of just when the text box loses focus. Uses Prism. It is a slightly indirect solution to the original problem.
In NuGet package manager, search for Prism. Add "Prism.Phone" created by "Microsoft patterns & practices"
Add the following to the page's phone:PhoneApplicationPage tag
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:prismInteractivity="clr-namespace:Microsoft.Practices.Prism.Interactivity;assembly=Microsoft.Practices.Prism.Interactivity"
Give your textbox a separate closing tag, and add the following between the opening and closing TextBox tags
<i:Interaction.Behaviors>
<prismInteractivity:UpdateTextBindingOnPropertyChanged/>
</i:Interaction.Behaviors>
I guess this will work but you should check if it is really necessary having an ApplicationBarIconButton (or simply a button on the page) for that.
Often you should avoid this when you like to have a good Metro design in your app you may prefer using InputScope="Search" + Hiding the SIP is easily done using Page.Focus()
e.g. (an old article; InputScope="Search" worked for me)
http://4mkmobile.com/2011/02/wp7-devs-stop-adding-search-buttons/
See also: http://forums.create.msdn.com/forums/p/70506/619517.aspx#619517
private void SearchTextBox_KeyUp(object sender, KeyEventArgs e) handler:
Using InputScope="Search" for my search field
Using DataBinding Mode=TwoWay
Focus(); // hides the SIP
UpdateBinding(SearchTextBox); // the trick mentioned in here
App.ViewModel.ExecuteSearch();
Works fine in my MVVM app.

Is there a way to inherit from parent class without overwriting methods with same name?

I need to inject a new behaviour for every dropDownList control of my web app (asp.net/C#).
Each time a new value is selected in the dropdown a web method (using Ajax/JSON) is invoked.
Since I have "normal" controls of type DropDownList and custom controls using DropDownList within them, I planned to create a class inheriting from DropDownList class with the new behaviour and then switch all the currrent DropDownList instances to this one.
In this way all my normal and custom drop downs would automatically get the new feature.
However the custom control has already an impementation for the "onselectedindexchanged" event, where some other functions are implemented.
Since I would use the same event for the new (parent) class, it would be overwritten in the custom control.
Of course I can write in the custom control the same code as in the parent, but is there a way to avoid duplicate code?
Thanks,
Luca
Of course I can write in the custom
control the same code as in the
parent, but is there a way to avoid
duplicate code?
C#:
public void doSomething() {
base.doSomething(); //parent class
//My stuff here
}
Java
public void doSomething() {
parent.doSomething(); //parent class
//My stuff here
}

Resources