Mon, 02 Oct 2023 19:31:06 +0200
add listview (WinUI3)
180
f34953bf4ac7
add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | |
f34953bf4ac7
add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | |
f34953bf4ac7
add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | #include "util.h" |
f34953bf4ac7
add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | |
f34953bf4ac7
add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | #include <stdlib.h> |
f34953bf4ac7
add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | |
f34953bf4ac7
add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | #include <Windows.h> |
f34953bf4ac7
add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | |
f34953bf4ac7
add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | |
f34953bf4ac7
add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | wchar_t* str2wstr(const char* str, int* newlen) { |
f34953bf4ac7
add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | size_t len = strlen(str); |
f34953bf4ac7
add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | |
f34953bf4ac7
add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | |
f34953bf4ac7
add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | wchar_t* wstr = (wchar_t*)calloc(len + 1, sizeof(wchar_t)); |
f34953bf4ac7
add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | int wlen = MultiByteToWideChar( |
f34953bf4ac7
add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | CP_UTF8, |
f34953bf4ac7
add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | 0, |
f34953bf4ac7
add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | str, |
f34953bf4ac7
add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | len, |
f34953bf4ac7
add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | wstr, |
f34953bf4ac7
add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | len + 1 |
f34953bf4ac7
add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | ); |
f34953bf4ac7
add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | if (newlen) { |
f34953bf4ac7
add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | *newlen = wlen; |
f34953bf4ac7
add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | } |
f34953bf4ac7
add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | wstr[wlen] = 0; |
f34953bf4ac7
add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | |
f34953bf4ac7
add basic winui menu implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | return wstr; |
192
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
29 | } |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
30 | |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
31 | char* wchar2utf8(const wchar_t* wstr, size_t wlen) { |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
32 | size_t maxlen = wlen * 4; |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
33 | char* ret = (char*)malloc(maxlen + 1); |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
34 | int ret_len = WideCharToMultiByte( |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
35 | CP_UTF8, |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
36 | 0, |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
37 | wstr, |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
38 | wlen, |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
39 | ret, |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
40 | maxlen, |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
41 | NULL, |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
42 | NULL); |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
43 | ret[ret_len] = 0; |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
44 | return ret; |
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
180
diff
changeset
|
45 | } |