GUIFramework 1.1.0
Framework for desktop GUI applications in C++.
Loading...
Searching...
No Matches
ITextOperations.cpp
Go to the documentation of this file.
1#include "ITextOperations.h"
2
4
5using namespace std;
6
7namespace gui_framework
8{
9 namespace interfaces
10 {
11 ITextOperations::ITextOperations(HWND handle, const wstring& text) :
12 textHandle(handle)
13 {
14 this->setText(text);
15 }
16
17 ITextOperations::ITextOperations(HWND handle, const string& localizationKey)
18 {
19 this->setText(localizationKey);
20 }
21
22 void ITextOperations::setText(wstring_view text)
23 {
24 SetWindowTextW(textHandle, text.data());
25 }
26
27 void ITextOperations::setText(string_view localizationKey)
28 {
29 this->setText(localization::WTextLocalization::get()[localizationKey]);
30 }
31
32 wstring ITextOperations::getText() const
33 {
34 int textLength = GetWindowTextLengthW(textHandle);
35 wstring text;
36
37 if (!textLength)
38 {
39 DWORD errorCode = GetLastError();
40
41 if (errorCode)
42 {
43 throw exceptions::GetLastErrorException(errorCode, __FILE__, __FUNCTION__, __LINE__);
44 }
45 }
46
47 text.resize(++textLength);
48
49 GetWindowTextW(textHandle, text.data(), textLength);
50
51 text.pop_back();
52
53 return text;
54 }
55 }
56}
Exception that receive error code from GetLastError function.
ITextOperations(HWND handle, const std::wstring &text=L"")