Use Unicode Character Set与Use Multi-Byte Character Set下的编程是完全不同的,自我认为Unicode 比较让人头疼!
下面,我写了一个改变窗口标题的小程序:
BOOL CALLBACK EnumWindowProc(HWND hwnd,LPARAM lParam);
void CqwDlg::OnBnClickedButton2()
{
// TODO: Add your control notification handler code here
UpdateData();
int len = m_name.GetLength();
EnumWindows(EnumWindowProc,(LPARAM)(m_name.GetBuffer(len)));
}
BOOL CALLBACK EnumWindowProc(HWND hwnd,LPARAM lParam)
{
CString we = (LPCTSTR)lParam;
CString str;
GetWindowText(hwnd,str.GetBuffer(100),100);
if(str==_T("计算器"))
{
SendMessage(hwnd,WM_SETTEXT,0,(LPARAM)(LPCTSTR)(we));
}
return true;
}
其中Unicode下的SendMessage(hwnd,WM_SETTEXT,0,(LPARAM)(LPCTSTR)(we));
起初我写成了SendMessage(hwnd,WM_SETTEXT,(LPARAM)we.Getbuffer(0));只能发送一个字符。