我编写了一个编辑特定文件类型的程序,我想让用户选择在启动时将我的应用程序设置为此文件类型的默认编辑器(因为我不需要安装程序).
我已经尝试编写一个可重用的方法,通过向HKEY_CLASSES_ROOT添加密钥,并将其与我的应用程序一起使用,但是它不会为我关联文件(最好是在任何操作系统上,虽然我正在运行Vista)似乎工作.
public static void SetAssociation(string Extension, string KeyName, string OpenWith, string FileDescription)
{
RegistryKey BaseKey;
RegistryKey OpenMethod;
RegistryKey Shell;
RegistryKey CurrentUser;
BaseKey = Registry.ClassesRoot.CreateSubKey(Extension);
BaseKey.SetValue("", KeyName);
OpenMethod = Registry.ClassesRoot.CreateSubKey(KeyName);
OpenMethod.SetValue("", FileDescription);
OpenMethod.CreateSubKey("DefaultIcon").SetValue("", "\"" + OpenWith + "\",0");
Shell = OpenMethod.CreateSubKey("Shell");
Shell.CreateSubKey("edit").CreateSubKey("command").SetValue("", "\"" + OpenWith + "\"" + " \"%1\"");
Shell.CreateSubKey("open").CreateSubKey("command").SetValue("", "\"" + OpenWith + "\"" + " \"%1\"");
BaseKey.Close();
OpenMethod.Close();
Shell.Close();
CurrentUser = Registry.CurrentUser.CreateSubKey(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" + Extension);
CurrentUser = CurrentUser.OpenSubKey("UserChoice", RegistryKeyPermissionCheck.ReadWriteSubTree, System.Security.AccessControl.RegistryRights.FullControl);
CurrentUser.SetValue("Progid", KeyName, RegistryValueKind.String);
CurrentUser.Close();
}
Run Code Online (Sandbox Code Playgroud)
知道为什么它不起作用吗?一个示例用途可能是
SetAssociation(".ucs", "UCS_Editor_File", …Run Code Online (Sandbox Code Playgroud) 我最近安装了Visual Studio 2010,并将旧的VS2005解决方案复制并转换为VS2010
当我编辑这个解决方案时,如果我尝试更改控件的.image属性,VS2010会创建一个消息框,告诉我"已经添加了一个具有相同键的项目"(下面的屏幕截图),并且不会让我浏览一个图像.
我可以为任何其他解决方案添加图像,甚至是从VS2005移植的其他解决方案,但不是这个.知道我做错了什么吗?
已添加具有相同键的项目.http://img121.imageshack.us/img121/3592/errorsy.jpg
我有一个庞大的字符串(我们说的长度为1696108个字符),我已经从文本文件中快速阅读了.当我将它添加到我的文本框(C#)时,需要很长时间才能完成.像Notepad ++(非托管代码,我知道)这样的程序几乎可以立即完成,尽管Notepad也需要很长时间.我怎样才能有效地添加这个巨大的字符串?Notepad ++之类的内容如何快速地完成?
我刚刚注意到DataGridViews有一个默认的快捷方式,这样无论何时按Ctrl+ H,DataGridView编辑控件都会退格,并且可以删除单元格中的整个选择.
这可能会非常烦人,因为我想在按下Ctrl+ 时打开一个替换框H.有没有办法停止退格,同时还能用它来打开替换盒?
我正在运行C#2.0,但如果较新的C#有解决方案,我可以将我的应用程序更新为3.5.
就像我之前的许多程序员一样,我正在试着用C++编写通道矩阵类.我从未做过非常严重的运算符重载,这导致了问题.基本上,通过单步执行
这就是我所说的导致问题的原因.
cMatrix Kev = CT::cMatrix::GetUnitMatrix(4, true);
Kev *= 4.0f;
cMatrix Baz = Kev;
Kev = Kev+Baz; //HERE!
Run Code Online (Sandbox Code Playgroud)
根据调试器似乎正在发生的事情是添加了Kev和Baz,但随后该值丢失,当重新分配给Kev时,内存只是其默认的狡猾值.如何重载我的运算符以允许此语句?我的(精简版)代码如下.
//header
class cMatrix
{
private:
float* _internal;
UInt32 _r;
UInt32 _c;
bool _zeroindexed;
//fast, assumes zero index, no safety checks
float cMatrix::_getelement(UInt32 r, UInt32 c)
{
return _internal[(r*this->_c)+c];
}
void cMatrix::_setelement(UInt32 r, UInt32 c, float Value)
{
_internal[(r*this->_c)+c] = Value;
}
public:
cMatrix(UInt32 r, UInt32 c, bool IsZeroIndexed);
cMatrix( cMatrix& m);
~cMatrix(void);
//operators
cMatrix& operator + (cMatrix m);
cMatrix& operator += …Run Code Online (Sandbox Code Playgroud) 我在C#中有一个矢量类(下面是一个片段).我的问题是,当我叫GetMagnitude(),它总是返回0.0F - 甚至与调试运行,我检查广场有一个有效值,只要它被传递回其他功能(如:规范化()),它返回0.0f.有人可以解释这个并帮我修复它吗?我的猜测是它与double-> float转换有关,但我无法理解它.
public class float3
{
public float x;
public float y;
public float z;
public float GetMagnitude()
{
float SumSquares = (float)( Math.Pow(x, 2) + Math.Pow(y, 2) + Math.Pow(z, 2));
float Sq = (float)Math.Sqrt(SumSquares);
return Sq;
}
public void Normalize()
{
float inverse = 1.0f / GetMagnitude();
x *= inverse;
y *= inverse;
z *= inverse;
}
}
Run Code Online (Sandbox Code Playgroud) 请不要把我钉在十字架上.我决定使用char*可能会很好,因为我打算构建的字符串是已知大小的.我也知道如果timeinfo-> tm_hour返回2位以外的东西,事情就会出错.也就是说,当这个函数返回时,VIsual Studio会向我发出关于HEAP CORRUPTION的信息.出了什么问题?(另外,我应该使用stringbuilder吗?)
void cLogger::_writelogmessage(std::string Message)
{
time_t rawtime;
struct tm* timeinfo = 0;
time(&rawtime);
timeinfo = localtime(&rawtime);
char* MessageBuffer = new char[Message.length()+11];
char* msgptr = MessageBuffer;
_itoa(timeinfo->tm_hour, msgptr, 10);
msgptr+=2;
strcpy(msgptr, "::");
msgptr+=2;
_itoa(timeinfo->tm_min, msgptr, 10);
msgptr+=2;
strcpy(msgptr, "::");
msgptr+=2;
_itoa(timeinfo->tm_sec, msgptr, 10);
msgptr+=2;
strcpy(msgptr, " ");
msgptr+=1;
strcpy(msgptr, Message.c_str());
_file << MessageBuffer;
delete[] MessageBuffer;
}
Run Code Online (Sandbox Code Playgroud) 我有一堆长弦,我必须操纵.它们可以一次又一次地出现,如果它们出现两次我想忽略它们.我认为最好的方法是散列字符串并将哈希列表存储在某种有序列表中,并且查找时间很快,以便每当我的数据集向我发送新字符串时我都可以进行比较.
要求:
如果这有任何区别,我不需要倒退(键 - >值).
有关哪种.NET数据类型最有效的建议?