M
Marcus Kwok
I was following the tutorial given at:
http://msdn.microsoft.com/netframew.../library/en-us/dndotnet/html/mdiappsmenus.asp
except writing Managed C++ instead of VB.NET. In particular, under
"Using Menu Groups", they have this code to implement radio-button-like
functionality in menu items:
Private Sub RadioCheck_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles mnuWArrange.Click, mnuWCascade.Click, _
mnuWHorizontal.Click, mnuWVertical.Click
mnuWArrange.Checked = False
mnuWCascade.Checked = False
mnuWHorizontal.Checked = False
mnuWVertical.Checked = False
CType(sender, MenuItem).Checked = True
End Sub
In MC++, is it correct to replace CType() with a __try_cast<>? Is the
only difference between __try_cast<> and dynamic_cast<>, that
__try_cast<> will throw an exception whereas dynamic_cast<> will return
a null pointer?
private:
RadioCheck_Click(System::Object* sender, System::EventArgs* e)
{
mnuWArrange->Checked = false;
mnuWCascade->Checked = false;
mnuWHorizontal->Checked = false;
mnuWVertical->Checked = false;
// this next line is the one in question:
__try_cast<MenuItem*>(sender)->Checked = true;
}
http://msdn.microsoft.com/netframew.../library/en-us/dndotnet/html/mdiappsmenus.asp
except writing Managed C++ instead of VB.NET. In particular, under
"Using Menu Groups", they have this code to implement radio-button-like
functionality in menu items:
Private Sub RadioCheck_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles mnuWArrange.Click, mnuWCascade.Click, _
mnuWHorizontal.Click, mnuWVertical.Click
mnuWArrange.Checked = False
mnuWCascade.Checked = False
mnuWHorizontal.Checked = False
mnuWVertical.Checked = False
CType(sender, MenuItem).Checked = True
End Sub
In MC++, is it correct to replace CType() with a __try_cast<>? Is the
only difference between __try_cast<> and dynamic_cast<>, that
__try_cast<> will throw an exception whereas dynamic_cast<> will return
a null pointer?
private:
RadioCheck_Click(System::Object* sender, System::EventArgs* e)
{
mnuWArrange->Checked = false;
mnuWCascade->Checked = false;
mnuWHorizontal->Checked = false;
mnuWVertical->Checked = false;
// this next line is the one in question:
__try_cast<MenuItem*>(sender)->Checked = true;
}