static std::string getTextFromBuffer(const ZLUnicodeUtil::Ucs2String &buffer) { ZLUnicodeUtil::Ucs2String copy = buffer; copy.pop_back(); std::string txt; ZLUnicodeUtil::ucs2ToUtf8(txt, copy); return txt; }
LRESULT CALLBACK ZLWin32ApplicationWindow::TextEditParameter::ComboBoxCallback(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { TextEditParameter ¶meter = *(TextEditParameter*)GetWindowLong(hWnd, GWL_USERDATA); if ((uMsg == WM_COMMAND) && (HIWORD(wParam) == CBN_SELCHANGE)) { HWND comboBox = parameter.myComboBox; const int index = SendMessage(comboBox, CB_GETCURSEL, 0, 0); const int length = SendMessage(comboBox, CB_GETLBTEXTLEN, index, 0); ZLUnicodeUtil::Ucs2String buffer; if (length > 0) { buffer.assign(length + 1, '\0'); SendMessage(comboBox, CB_GETLBTEXT, index, (LPARAM)&buffer.front()); buffer.pop_back(); } std::string value; ZLUnicodeUtil::ucs2ToUtf8(value, buffer); parameter.setValue(value); parameter.myApplication.doAction(parameter.myParameterItem.actionId()); SetFocus(parameter.myMainWindow); } WndProc orig = parameter.myOriginalComboBoxCallback; return orig(hWnd, uMsg, wParam, lParam); }
std::string ZLWin32ApplicationWindow::TextEditParameter::internalValue() const { int len = GetWindowTextLengthW(myComboBox); if (len == 0) { return ""; } static ZLUnicodeUtil::Ucs2String buffer; buffer.assign(len + 1, '\0'); GetWindowTextW(myComboBox, (WCHAR*)::wchar(buffer), len + 1); buffer.pop_back(); std::string text; ZLUnicodeUtil::ucs2ToUtf8(text, buffer); return text; }