-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwinwrappers.cpp
More file actions
110 lines (93 loc) · 2.85 KB
/
Copy pathwinwrappers.cpp
File metadata and controls
110 lines (93 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "winwrappers.h"
#include <WinUser.h>
using namespace std;
std::wstring wndctrl::get_window_text()
{
wstring s;
int len = SendDlgItemMessageW(_hDlg, _id, WM_GETTEXTLENGTH, (WPARAM)0, (LPARAM)0);
if (len > 0) {
wchar_t* lpwstr = new wchar_t[++len];
wmemset(lpwstr, (wchar_t)0x00, len);
SendDlgItemMessageW(_hDlg, _id, WM_GETTEXT, (WPARAM)len, (LPARAM)lpwstr);
s.assign(lpwstr);
delete[] lpwstr;
}
return s;
}
void wndctrl::set_window_text(const std::wstring& s)
{
HRESULT result = SendDlgItemMessage(_hDlg, _id, WM_SETTEXT, 0, (LPARAM)s.c_str());
}
void wndcombobox::reset_content()
{
SendDlgItemMessage(_hDlg, _id, CB_RESETCONTENT, 0, 0);
}
int wndcombobox::get_current_selection_index()
{
return (int)SendDlgItemMessage(_hDlg, _id, CB_GETCURSEL, 0, 0);
}
int wndcombobox::select_index(const int index)
{
if (index < 0)
return CB_ERR;
return (int)SendDlgItemMessage(_hDlg, _id, CB_SETCURSEL, index, 0);
}
int wndcombobox::select_string(const std::wstring& s)
{
int cnt = (int)SendDlgItemMessage(_hDlg, _id, CB_GETCOUNT, 0, 0);
for (int i = 0; i < cnt; i++) {
int len = SendDlgItemMessageW(_hDlg, _id, CB_GETLBTEXTLEN, (WPARAM)i, (LPARAM)0);
wchar_t* lpwstr = new wchar_t[++len];
wmemset(lpwstr, (wchar_t)0x00, len);
SendDlgItemMessageW(_hDlg, _id, CB_GETLBTEXT, (WPARAM)i, (LPARAM)lpwstr);
wstring item_text;
item_text.assign(lpwstr);
delete[] lpwstr;
if (item_text == s) {
return select_index(i);
}
}
return CB_ERR;
}
LPARAM wndcombobox::get_item_data(const int index)
{
return SendDlgItemMessage(_hDlg, _id, CB_GETITEMDATA, index, 0);
}
void wndcombobox::set_item_data(const int index, const LPARAM data)
{
if (index < 0)
return;
HRESULT result = SendDlgItemMessage(_hDlg, _id, CB_SETITEMDATA, index, data);
}
int wndcombobox::add_string(const std::wstring& s, const LPARAM data)
{
int index = (int)SendDlgItemMessage(_hDlg, _id, CB_ADDSTRING, 0, (LPARAM)s.c_str());
if (index == CB_ERR || index == CB_ERRSPACE) {
return CB_ERR;
}
HRESULT result = SendDlgItemMessage(_hDlg, _id, CB_SETITEMDATA, index, data);
return index;
}
std::wstring wndcombobox::get_current_selection_text()
{
int index = (int)SendDlgItemMessage(_hDlg, _id, CB_GETCURSEL, 0, 0);
if (index < 0) {
return L"";
}
int len = SendDlgItemMessageW(_hDlg, _id, CB_GETLBTEXTLEN, (WPARAM)index, (LPARAM)0);
wchar_t* lpwstr = new wchar_t[++len];
wmemset(lpwstr, (wchar_t)0x00, len);
SendDlgItemMessageW(_hDlg, _id, CB_GETLBTEXT, (WPARAM)index, (LPARAM)lpwstr);
wstring s;
s.assign(lpwstr);
delete[] lpwstr;
return s;
}
LPARAM wndcombobox::get_current_selection_data()
{
int index = (int)SendDlgItemMessage(_hDlg, _id, CB_GETCURSEL, 0, 0);
if (index < 0) {
return (LPARAM)0;
}
return SendDlgItemMessage(_hDlg, _id, CB_GETITEMDATA, index, 0);
}