我有一个 Button 控件包装类,它允许您将现有句柄传递给它,前提是它属于WC_BUTTON该类。我GetClassName()用来确定这一点。但是我有一个问题,代码中的注释应该有助于描述它:
// Initialize from existing handle
Vivify::Button::Button(HWND handle) {
TCHAR cls[256];
GetClassName(handle, cls, sizeof(cls));
Alert(cls); // MessageBox says "Button"
Alert(WC_BUTTON); // MessageBox says "Button" also
Str clsStr = cls;
Str wcStr = WC_BUTTON;
Alert(ToStr<int>(clsStr.length())); // says "6"
Alert(ToStr<int>(wcStr.length())); // says "6" also
// Problem HERE. Evaluates to false. How are they inequal??
if (cls == WC_BUTTON) {
SetHandle(handle); // Never gets executed
m_id = GetDlgCtrlID(handle);
}
}
Str顺便说一句std::wstring,程序是Unicode。但是我得到的字符串GetClassName()都是WC_BUTTONunicode 字符串,都是6字符长,而且都相等"Button",到底线是如何if (cls == WC_BUTTON)返回的false?
有人可以解释两个看似完全相同的字符串如何彼此不相等吗?或者我如何确定 a 是否HWND属于按钮/编辑/等。控制?