-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello_wchar_t.c
241 lines (202 loc) · 6.31 KB
/
hello_wchar_t.c
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/* SPDX-License-Identifier: Zlib
Copyright (c) 2014 - 2024 Guillaume Vareille http://ysengrin.com
________________________________________________________________
| |
| 100% compatible C C++ -> You can rename this .c file as .cpp |
|________________________________________________________________|
********* TINY FILE DIALOGS OFFICIAL WEBSITE IS ON SOURCEFORGE *********
_________
/ \ hello_wchar_t.c v3.18.2 [Jun 10, 2024]
|tiny file| Hello WCHAR_T windows only file created [November 9, 2014]
| dialogs |
\____ ___/ http://tinyfiledialogs.sourceforge.net
\| git clone http://git.code.sf.net/p/tinyfiledialogs/code tinyfd
____________________________________________
| |
| email: tinyfiledialogs at ysengrin.com |
|____________________________________________|
________________________________________________________________
| |
| this file is for windows only it uses wchar_t UTF-16 functions |
|________________________________________________________________|
If you like tinyfiledialogs, please upvote my stackoverflow answer
https://stackoverflow.com/a/47651444
- License -
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
See compilation instructions at the end of this file
__________________________________________
| ______________________________________ |
| | | |
| | DO NOT USE USER INPUT IN THE DIALOGS | |
| |______________________________________| |
|__________________________________________|
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "tinyfiledialogs.h"
#ifdef _MSC_VER
#pragma warning(disable:4996) /* silences warning about wcscpy*/
#endif
int main(void) /* WINDOWS ONLY */
{
wchar_t * lPassword;
wchar_t * lTheSaveFileName;
wchar_t * lTheOpenFileName;
wchar_t * lTheSelectFolderName;
wchar_t * lTheHexColor;
wchar_t * lWillBeGraphicMode;
unsigned char lRgbColor[3];
FILE * lIn;
wchar_t lWcharBuff[1024];
wchar_t lBuffer[1024];
wchar_t const * lFilterPatterns[2] = { L"*.txt", L"*.text" };
tinyfd_beep();
lWillBeGraphicMode = tinyfd_inputBoxW(L"tinyfd_query", NULL, NULL);
wcscpy(lBuffer, L"v");
mbstowcs(lWcharBuff, tinyfd_version, strlen(tinyfd_version) + 1);
wcscat(lBuffer, lWcharBuff);
if (lWillBeGraphicMode)
{
wcscat(lBuffer, L"\ngraphic mode: ");
}
else
{
wcscat(lBuffer, L"\nconsole mode: ");
}
mbstowcs(lWcharBuff, tinyfd_response, strlen(tinyfd_response)+1);
wcscat(lBuffer, lWcharBuff);
wcscat(lBuffer, L"\n");
mbstowcs(lWcharBuff, tinyfd_needs + 78, strlen(tinyfd_needs + 78) + 1);
wcscat(lBuffer, lWcharBuff);
tinyfd_messageBoxW(L"hello", lBuffer, L"ok", L"info", 0);
tinyfd_notifyPopupW(L"the title", L"the message\n\tfrom outer-space", L"info");
lPassword = tinyfd_inputBoxW(
L"a password box", L"your password will be revealed later", NULL);
if (!lPassword) return 1;
lTheSaveFileName = tinyfd_saveFileDialogW(
L"let us save this password",
L"passwordFile.txt",
2,
lFilterPatterns,
NULL);
if (! lTheSaveFileName)
{
tinyfd_messageBoxW(
L"Error",
L"Save file name is NULL",
L"ok",
L"error",
1);
return 1 ;
}
lIn = _wfopen(lTheSaveFileName, L"wt, ccs=UNICODE");
if (!lIn)
{
tinyfd_messageBoxW(
L"Error",
L"Can not open this file in write mode",
L"ok",
L"error",
1);
return 1 ;
}
fputws(lPassword, lIn);
fclose(lIn);
lTheOpenFileName = tinyfd_openFileDialogW(
L"let us read the password back",
L"",
2,
lFilterPatterns,
NULL,
0);
if (! lTheOpenFileName)
{
tinyfd_messageBoxW(
L"Error",
L"Open file name is NULL",
L"ok",
L"error",
1);
return 1 ;
}
lIn = _wfopen(lTheOpenFileName, L"rt, ccs=UNICODE");
if (!lIn)
{
tinyfd_messageBoxW(
L"Error",
L"Can not open this file in read mode",
L"ok",
L"error",
1);
return(1);
}
lBuffer[0] = '\0';
fgetws(lBuffer, sizeof(lBuffer), lIn);
fclose(lIn);
tinyfd_messageBoxW(L"your password is",
lBuffer, L"ok", L"info", 1);
lTheSelectFolderName = tinyfd_selectFolderDialogW(
L"let us just select a directory", L"C:\\");
if (!lTheSelectFolderName)
{
tinyfd_messageBoxW(
L"Error",
L"Select folder name is NULL",
L"ok",
L"error",
1);
return 1;
}
tinyfd_messageBoxW(L"The selected folder is",
lTheSelectFolderName, L"ok", L"info", 1);
lTheHexColor = tinyfd_colorChooserW(
L"choose a nice color",
L"#FF0077",
lRgbColor,
lRgbColor);
if (!lTheHexColor)
{
tinyfd_messageBoxW(
L"Error",
L"hexcolor is NULL",
L"ok",
L"error",
1);
return 1;
}
tinyfd_messageBoxW(L"The selected hexcolor is",
lTheHexColor, L"ok", L"info", 1);
tinyfd_messageBoxW(L"your password was", lPassword, L"ok", L"info", 1);
return 0;
}
#ifdef _MSC_VER
#pragma warning(default:4996)
#endif
/*
MinGW needs gcc >= v4.9 otherwise some headers are incomplete
> gcc -o hello.exe hello.c tinyfiledialogs.c -LC:/mingw/lib -lcomdlg32 -lole32
TinyCC needs >= v0.9.27 (+ tweaks - contact me) otherwise some headers are missing
> tcc -o hello.exe hello.c tinyfiledialogs.c ^
-isystem C:\tcc\winapi-full-for-0.9.27\include\winapi ^
-lcomdlg32 -lole32 -luser32 -lshell32
Borland C: > bcc32c -o hello.exe hello.c tinyfiledialogs.c
OpenWatcom v2: create a character-mode executable project.
VisualStudio :
Create a console application project,
it links against comdlg32.lib & ole32.lib.
VisualStudio command line :
> cl hello.c tinyfiledialogs.c comdlg32.lib ole32.lib user32.lib shell32.lib /W4
*/