I have a Button control wrapper class, which allows you to pass an existing handle to it, provided it is of the WC_BUTTON
class. I use GetClassName()
to determine this. But I have a problem, the comments in the code should help describe it:
// 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
is a std::wstring
by the way, program is in Unicode.
But both the string I get from GetClassName()
and WC_BUTTON
are both unicode strings, are both 6
characters long, and both equal "Button"
, how on earth is the line if (cls == WC_BUTTON)
returning false
??
Could someone explain how two seemingly exactly identical strings could be in-equal to each-other?
Or how can I determine if a HWND
belongs to a button/edit/etc. control?