我的目标是Windows,但我没有看到为什么我正在编写的某些API代码无法使用基本的C++类型.我想要做的是公开返回字符串和整数的方法.在C#世界中我只使用字符串,并且有一个unicode字符串,但在VC++中我可以选择使用std :: string,std :: wstring或MFC/ATL CStrings.
我应该只使用std :: wstring来支持unicode,还是可以使用std :: string根据我的构建设置将其编译为unicode?我倾向于后者.我更喜欢在我的对象上为其他字符串类型提供Get [Item] AsCString()方法.
我应该使用size_t而不是整数吗?
我将使用API,也许是未来的开发人员在C++ GUI上工作.这是一种分离问题的方法.我的偏好:
任何指南将不胜感激.
我有一个基本的WPF/Silverlight用户控制代码,其中包含一个标签,我想设置使用该控件的代码的值.有没有办法简化依赖属性和相关事件的定义要求?看似简单的编码任务(属性,方法和相关布线)似乎非常嘈杂.
private static DependencyProperty CountProperty;
public MyWpfUserControl()
{
InitializeComponent();
PropertyChangedCallback countChangedCallback = CountChanged;
var metaData = new PropertyMetadata(countChangedCallback);
CountProperty = DependencyProperty.Register("Count", typeof (int), typeof (MyWpfUserControl), metaData);
}
public int ItemsCount
{
get { return (int) GetValue(CountProperty); }
set { SetValue(CountProperty, value); }
}
private void CountChanged(DependencyObject property,
DependencyPropertyChangedEventArgs args)
{
// Set the value of another control to this property
label1.Content = ItemsCount;
}
Run Code Online (Sandbox Code Playgroud)