Visual C++ 2011-4-16
2011-04-16 16:42 Clingingboy 阅读(659) 评论(0) 编辑 收藏 举报
一.获取系统语言和位置
相关函数
void UserLCID()
{
//Returns the locale identifier for the user default locale.
LCID id=::GetUserDefaultLCID();
cout << id <<endl;
WCHAR strNameBuffer[LOCALE_NAME_MAX_LENGTH];
DWORD error = ERROR_SUCCESS;
//Converts a locale identifier to a locale name.
LCIDToLocaleName(id ,strNameBuffer,LOCALE_NAME_MAX_LENGTH,0);
cout << strNameBuffer <<endl;
//Converts a locale name to a locale identifier.
LCID id2=::LocaleNameToLCID(strNameBuffer,0);
//Returns the locale identifier for the system locale.
LCID id3=::GetSystemDefaultLCID();
}
void UserLangID()
{
//Returns the language identifier for the current user locale.
LANGID id=::GetUserDefaultLangID();
//Returns the language identifier for the system locale.
LANGID id2=::GetSystemDefaultLangID();
}
设置当前线程的Locate
void ThreadLocal()
{
//Returns the locale identifier of the current locale for the calling thread.
LCID id=::GetThreadLocale();
::SetThreadLocale(id);
}
设置线程语言偏好
二.c打印函数
printf可输出char字符,wprintf可输出宽字符
char ch = 'h', *string = "computer";
int count = -9234;
double fp = 251.7366;
wchar_t wch = L'w', *wstring = L"Unicode";
/* Display characters. */
printf("Characters in field (1):\n%10c%5hc%5C%5lc\n", ch, ch, wch, wch);
wprintf(L"Characters in field (2):\n%10C%5hc%5c%5lc\n", ch, ch, wch, wch);
wsprintf 填充一段缓冲区
TCHAR tcBuffer[1024] = {0};
wsprintf(tcBuffer,L"Age = %d,Name = %s\n",10,L"hello");
wprintf(tcBuffer);
三.DDX数据交换机制UpdateData
如果WPF的数据绑定,当UpdateData(TRUE)时则是UI更新数据,False则是数据更新UI控件数据
首先进行变量绑定,DDX_Text(pDX, IDC_EDIT, m_edit);
需要注意的是UpdateData方法是对于整个窗体范围的,而非一个控件
参考:http://hi.baidu.com/kxw102/blog/item/c3d7623599b653375ab5f55c.html
四.ZeroMemory,memset(清零操作)
memset
Sets buffers to a specified character.
char buffer[] = "This is a test of the memset function";
int a=sizeof(buffer);
printf( "Before: %s\n", buffer );
memset( buffer, '*', strlen(buffer));
printf( "After: %s\n", buffer );
ZeroMemory全部置0
char buffer[] = "This is a test of the memset function";
int a=sizeof(buffer);
printf( "Before: %s\n", buffer );
ZeroMemory(buffer,strlen(buffer));
printf( "After: %s\n", buffer );
参考:http://blog.csdn.net/yacper/archive/2010/01/25/5254294.aspx
注意是清零而已,并非改变了数据结构的大小,数据重置而已,不要对类进行此操作
五.注册表操作
1.打开注册表
int res = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",0,KEY_QUERY_VALUE,&hKey);
2.查询键值
res = ::RegQueryValueEx(hKey,"~MHz",NULL,NULL,(LPBYTE)data1,&dataSize);
3.设置键值
RegSetValueEx(hKey,"name",0,REG_SZ,(unsigned char*)name,strlen(name));
4.删除键值
RegDeleteKey(hKey,"name");
5.创建键值
rs = RegCreateKey(HKEY_LOCAL_MACHINE,"SOFTWARE\\USER\\INFO",&hKey);
6.释放句柄
RegCloseKey(hKey);