2
ITmages upload client for Windows
3
Copyright (C) 2011 Dmitriy Simbiriatin <slpiv@itmages.ru>
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License
7
as published by the Free Software Foundation; either version 2
8
of the License, or (at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
#define _WIN32_WINNT 0x0501
21
#define _WIN32_IE 0x0501
31
#include "itmagesgui.h"
32
#include "itmagescmd.h"
33
#include "imagefunc.h"
34
#include "errorshandler.h"
37
// Window classes --------------------------------------------------------------
38
const char g_LoginWindowClass[] = "ITmagesLogin";
39
const char g_AboutWindowClass[] = "ITmagesAbout";
40
const char g_ReadyWindowClass[] = "ITmagesReady";
41
// -----------------------------------------------------------------------------
43
// Main windows ----------------------------------------------------------------
44
HWND login_wnd = NULL;
45
HWND ready_wnd = NULL;
46
HWND about_wnd = NULL;
47
// -----------------------------------------------------------------------------
49
HINSTANCE g_ItmagesInst = NULL;
51
// Default system's font.
52
HFONT g_SystemFont = NULL;
54
// Application's icon.
55
HICON g_AppIcon = NULL;
57
// Static control's background brush.
58
HBRUSH g_StaticBrush = NULL;
61
HBITMAP previewImage = NULL;
63
// Indicates if the new visual style is enabled or not.
64
short g_ThemeActive = 0;
66
ItmagesImageInfo imageInfo;
67
ItmagesImageLinks imageLinks;
68
ItmagesImageData imageData;
69
ItmagesUserInfo userInfo;
70
ItmagesConfig configFiles;
80
// Loading application's icon.
81
g_AppIcon = LoadIcon(g_ItmagesInst, MAKEINTRESOURCE(ID_APPICON));
83
// Loading default system's font.
84
g_SystemFont = (HFONT) GetStockObject(DEFAULT_GUI_FONT);
86
// Getting directory with the localization files and choose an appropriate one.
87
char *locale_dir = GetLocaleDir();
88
if (locale_dir != NULL) {
89
setlocale(LC_ALL, "");
90
bindtextdomain("itmages", locale_dir);
91
textdomain("itmages");
98
// Retrieving a path to the image from the command line.
99
arg_list = CommandLineToArgvW(GetCommandLineW(), &arg_count);
100
if (arg_list == NULL) {
101
ErrorsHandler(ERROR_GETIMGPATH);
105
if (arg_count == 1) {
106
// If the path was not provided, loading the open file dialog.
107
char *image_path = CreateOpenImageDialog();
108
imageData.path = AcpToWide(image_path);
111
size_t path_len = wcslen(arg_list[1]);
112
imageData.path = (wchar_t*) malloc((path_len + 1) * sizeof (wchar_t));
113
if (imageData.path == NULL) {
114
ErrorsHandler(ERROR_MEMALLOC);
117
wmemcpy(imageData.path, arg_list[1], path_len + 1);
121
imageData.basename = (wchar_t*) calloc(_MAX_FNAME + 1, sizeof (wchar_t));
122
if (imageData.basename == NULL) {
123
ErrorsHandler(ERROR_MEMALLOC);
126
imageData.ext = (wchar_t*) calloc(_MAX_EXT + 1, sizeof (wchar_t));
127
if (imageData.ext == NULL) {
128
ErrorsHandler(ERROR_MEMALLOC);
131
// Retrieving the image's basename and extension from the image's path.
132
_wsplitpath(imageData.path, NULL, NULL, imageData.basename, imageData.ext);
134
// Retrieving an information about the image(e.g name, width, height, size etc.)
135
if (GetImageInfo(imageData.path, imageData.basename,
136
imageData.ext, &imageInfo) == -1) {
137
ErrorsHandler(ERROR_GETIMGINFO);
141
// Setting the image's extension to the lower case
142
SetExtToLower(imageData.ext);
144
/* Checking the image's extension. ITmages supports only
145
*.jpg, *.jpeg, *.png, *.gif images. */
146
if (CheckImageExtension(imageData.ext) == -1) {
147
ErrorsHandler(ERROR_SUPPORTEDIMG);
151
// Checking the image's size. The size of the image has to be less than 6 Mb.
152
if (imageInfo.size == -1) {
153
ErrorsHandler(ERROR_MAXIMGSIZE);
155
} else if (imageInfo.size == 0) {
156
ErrorsHandler(ERROR_BADIMGSIZE);
160
// Retrieving the system's default path for the config and cookies files.
161
GetConfigFiles(&configFiles);
163
// Registering window classes.
169
ErrorsHandler(ERROR_REGISTERWNDCLS);
176
while (GetMessage(&msg, NULL, 0, 0)) {
178
!IsDialogMessage(login_wnd, &msg) &&
179
!IsDialogMessage(about_wnd, &msg) &&
180
!IsDialogMessage(ready_wnd, &msg)
182
TranslateMessage(&msg);
183
DispatchMessage(&msg);
186
return (DWORD) msg.wParam;
189
INT APIENTRY WinLogin()
191
WNDCLASSEX itmagesLogin;
192
memset(&itmagesLogin, 0, sizeof (itmagesLogin));
194
itmagesLogin.cbSize = sizeof (itmagesLogin);
195
itmagesLogin.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
196
itmagesLogin.lpfnWndProc = WinMainProc;
197
itmagesLogin.cbClsExtra = 0;
198
itmagesLogin.cbWndExtra = 0;
199
itmagesLogin.hInstance = g_ItmagesInst;
200
itmagesLogin.hIcon = g_AppIcon;
201
itmagesLogin.hCursor = LoadCursor(NULL, IDC_ARROW);
202
itmagesLogin.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
203
itmagesLogin.lpszMenuName = NULL;
204
itmagesLogin.lpszClassName = g_LoginWindowClass;
205
itmagesLogin.hIconSm = NULL;
207
if (RegisterClassEx(&itmagesLogin) == 0) {
213
void CreateLoginWnd()
215
size_t desk_width = GetSystemMetrics(SM_CXSCREEN);
216
size_t desk_height = GetSystemMetrics(SM_CYSCREEN);
218
login_wnd = CreateWindowEx(
221
gettext("ITmages - Login"),
222
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_CLIPCHILDREN,
223
desk_width / 2 - LOGIN_WND_WIDTH / 2,
224
desk_height / 2 - LOGIN_WND_HEIGHT / 2,
232
// Disabling maximize button.
233
long wnd_style = GetWindowLong(login_wnd, GWL_STYLE);
234
SetWindowLong(login_wnd, GWL_STYLE, wnd_style & ~WS_MAXIMIZEBOX);
236
// Creating Tab control inside the Login window.
237
CreateLoginTabControl();
239
ShowWindow(login_wnd, SW_SHOW);
240
UpdateWindow(login_wnd);
243
void CreateLoginTabControl()
245
HWND login_tab = CreateWindowEx(
249
WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_CLIPCHILDREN,
252
LOGIN_TABCONTROL_WIDTH,
253
LOGIN_TABCONTROL_HEIGHT,
255
(HMENU) ID_LOGIN_TABCONTROL,
260
SendMessage(login_tab, WM_SETFONT, (WPARAM) g_SystemFont, 0);
263
memset(&tie, 0, sizeof (tie));
265
tie.mask = TCIF_TEXT;
266
tie.pszText = gettext("Account");
267
TabCtrl_InsertItem(login_tab, 0, &tie);
268
tie.pszText = gettext("Image settings");
269
TabCtrl_InsertItem(login_tab, 1, &tie);
270
tie.pszText = gettext("Proxy");
271
TabCtrl_InsertItem(login_tab, 2, &tie);
273
UpdateBackgroundBrush(login_tab);
276
LRESULT CALLBACK WinMainProc(
282
HWND login_tab = GetDlgItem(login_wnd, ID_LOGIN_TABCONTROL);
283
static HWND login, login_txt,
285
without_login, save_data,
286
resize_img, resize_size,
287
resize_updown, resize_filter,
288
rotate_img, rotate_angle,
289
use_proxy, proxy_addrss,
290
proxy_addrss_txt, proxy_port, proxy_port_txt,
291
about, upload, upload_progress,
292
login_tool, passwd_tool;
294
static HWND withoutlogin_tool,
304
login = CreateWindowEx(
308
WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS,
318
login_txt = CreateWindowEx(
322
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS,
328
(HMENU) ID_LOGIN_TXT,
332
passwd = CreateWindowEx(
336
WS_CHILD | WS_VISIBLE | ES_PASSWORD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS,
345
passwd_txt = CreateWindowEx(
348
gettext("Password:"),
349
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS,
355
(HMENU) ID_PASSWD_TXT,
359
without_login = CreateWindowEx(
362
gettext("Without account"),
363
WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX | WS_TABSTOP | WS_CLIPSIBLINGS,
364
CHECK_WITHOUTLOGIN_X,
365
CHECK_WITHOUTLOGIN_Y,
366
CHECK_WITHOUTLOGIN_WIDTH,
367
CHECK_WITHOUTLOGIN_HEIGHT,
369
(HMENU) ID_CHECK_WITHOUTLOGIN,
372
save_data = CreateWindowEx(
375
gettext("Save account settings"),
376
WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX | WS_TABSTOP | WS_CLIPSIBLINGS,
379
CHECK_SAVEDATA_WIDTH,
380
CHECK_SAVEDATA_HEIGHT,
382
(HMENU) ID_CHECK_SAVEDATA,
385
resize_img = CreateWindowEx(
388
gettext("Reduce to:"),
389
WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX | WS_TABSTOP | WS_CLIPSIBLINGS,
392
CHECK_RESIZEIMG_WIDTH,
393
CHECK_RESIZEIMG_HEIGHT,
395
(HMENU) ID_CHECK_RESIZEIMG,
398
resize_size = CreateWindowEx(
402
WS_CHILD | WS_VISIBLE | ES_LEFT | ES_NUMBER | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS,
405
RESIZEIMG_SIZE_WIDTH,
406
RESIZEIMG_SIZE_HEIGHT,
408
(HMENU) ID_RESIZEIMG_SIZE,
411
resize_updown = CreateWindow(
414
WS_CHILD | WS_VISIBLE | UDS_ARROWKEYS | UDS_ALIGNRIGHT | UDS_SETBUDDYINT | UDS_NOTHOUSANDS,
420
(HMENU) ID_RESIZEIMGSIZE_UPDOWN,
423
resize_filter = CreateWindowEx(
427
WS_CHILD | WS_VISIBLE | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_TABSTOP | WS_CLIPSIBLINGS,
431
RESIZE_FILTER_HEIGHT,
433
(HMENU) ID_RESIZE_FILTER,
436
rotate_img = CreateWindowEx(
440
WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX | WS_TABSTOP | WS_CLIPSIBLINGS,
443
CHECK_ROTATEIMG_WIDTH,
444
CHECK_ROTATEIMG_HEIGHT,
446
(HMENU) ID_CHECK_ROTATEIMG,
449
rotate_angle = CreateWindowEx(
453
WS_CHILD | WS_VISIBLE | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_TABSTOP | WS_CLIPSIBLINGS,
456
ROTATEIMG_ANGLE_WIDTH,
457
ROTATEIMG_ANGLE_HEIGHT,
459
(HMENU) ID_ROTATEIMG_ANGLE,
462
use_proxy = CreateWindowEx(
465
gettext("Use proxy server"),
466
WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX | WS_TABSTOP | WS_CLIPSIBLINGS,
469
CHECK_USEPROXY_WIDTH,
470
CHECK_USEPROXY_HEIGHT,
472
(HMENU) ID_CHECK_USEPROXY,
475
proxy_addrss = CreateWindowEx(
479
WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS,
483
PROXY_ADDRESS_HEIGHT,
485
(HMENU) ID_PROXY_ADDRESS,
488
proxy_addrss_txt = CreateWindowEx(
492
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS,
495
PROXYADDRESS_TXT_WIDTH,
496
PROXYADDRESS_TXT_HEIGHT,
498
(HMENU) ID_PROXYADDRESS_TXT,
501
proxy_port = CreateWindowEx(
505
WS_CHILD | WS_VISIBLE | ES_NUMBER | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS,
511
(HMENU) ID_PROXY_PORT,
514
proxy_port_txt = CreateWindowEx(
518
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS,
522
PROXYPORT_TXT_HEIGHT,
524
(HMENU) ID_PROXYPORT_TXT,
527
upload_progress = CreateWindowEx(
531
WS_CHILD | WS_VISIBLE | PBS_SMOOTH | WS_CLIPSIBLINGS,
532
UPLOAD_PROGRESSBAR_X,
533
UPLOAD_PROGRESSBAR_Y,
534
UPLOAD_PROGRESSBAR_WIDTH,
535
UPLOAD_PROGRESSBAR_HEIGHT,
537
(HMENU) ID_UPLOAD_PROGRESSBAR,
541
about = CreateWindowEx(
545
WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_CLIPSIBLINGS,
551
(HMENU) ID_ABOUT_BUTTON,
554
upload = CreateWindowEx(
558
WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_CLIPSIBLINGS,
562
UPLOAD_BUTTON_HEIGHT,
564
(HMENU) ID_UPLOAD_BUTTON,
571
gettext("Enter your login here"));
575
gettext("Enter your password here"));
579
gettext("Upload the image without authentification"));
583
gettext("Store the login and password in the configuration file"));
587
gettext("Respectively rescales the image to the selected width"));
591
gettext("Enter the new image's width here"));
595
gettext("Select the type of the rescale filter"));
599
gettext("Enter the address of the proxy server here"));
603
gettext("Enter the port of the proxy server here"));
605
// User's login and password have to be less than 32 characters.
606
SendMessage(login, EM_SETLIMITTEXT, (WPARAM) 32, 0);
607
SendMessage(passwd, EM_SETLIMITTEXT, (WPARAM) 32, 0);
609
// Limiting width value of the image to 4 digits.
610
SendMessage(resize_size, EM_SETLIMITTEXT, (WPARAM) 4, 0);
612
/* Limiting possible lenght of the proxy addres and port to
613
15 and 4 chacters respectively. */
614
SendMessage(proxy_addrss, EM_SETLIMITTEXT, (WPARAM) 15, 0);
615
SendMessage(proxy_port, EM_SETLIMITTEXT, (WPARAM) 4, 0);
617
// Configuring Up-Down control.
618
SendMessage(resize_updown, UDM_SETBUDDY, (LONG) resize_size, 0L);
619
SendMessage(resize_updown, UDM_SETRANGE, 0, MAKELONG(9999, 0));
620
SendMessage(resize_updown, UDM_SETPOS, 0, MAKELONG(0, 0));
622
// Resize and rotate image checkboxes are disabled by default.
623
SendMessage(resize_img, BM_SETCHECK, (WPARAM) BST_UNCHECKED, 0);
624
SendMessage(rotate_img, BM_SETCHECK, (WPARAM) BST_UNCHECKED, 0);
626
// Setting possible rescale filters.
627
SendMessage(resize_filter, CB_ADDSTRING, 0, (LPARAM) gettext("Lanczos"));
628
SendMessage(resize_filter, CB_ADDSTRING, 0, (LPARAM) gettext("Box"));
629
SendMessage(resize_filter, CB_ADDSTRING, 0, (LPARAM) gettext("Bilinear"));
630
SendMessage(resize_filter, CB_ADDSTRING, 0, (LPARAM) gettext("B-Spline"));
632
// Setting possible rotate angles.
633
SendMessage(rotate_angle, CB_ADDSTRING, 0, (LPARAM) gettext("Do not rotate"));
634
SendMessage(rotate_angle, CB_ADDSTRING, 0, (LPARAM) gettext("Left"));
635
SendMessage(rotate_angle, CB_ADDSTRING, 0, (LPARAM) gettext("Right"));
636
SendMessage(rotate_angle, CB_ADDSTRING, 0, (LPARAM) gettext("Flip"));
638
// Setting the default values for the resize filter and rotate angle.
639
SendMessage(resize_filter, CB_SETCURSEL, 0, 0);
640
SendMessage(rotate_angle, CB_SETCURSEL, 0, 0);
642
EnableWindow(resize_size, 0);
643
EnableWindow(resize_updown, 0);
644
EnableWindow(resize_filter, 0);
645
EnableWindow(rotate_angle, 0);
647
// Seting default system font for the child windows.
648
SetSystemFont(login_wnd, ID_LOGIN, ID_UPLOAD_BUTTON);
650
// Hidding child windows placed on the 2nd and 3rd tab.
651
HideWindows(login_wnd, ID_CHECK_RESIZEIMG, ID_PROXYPORT_TXT);
653
// Seting focus on Upload button by default.
656
char *config_path = WideToAcp(configFiles.config);
658
char state[MAX_STATE];
659
memset(state, 0, MAX_STATE);
661
if (GetPrivateProfileString("Settings", "savedata", NULL, state, MAX_STATE + 1, config_path) == 0) {
662
memcpy(state, "false", 6);
665
// If the "Save account setting" checkbox was checked.
666
if (memcmp(state, "true", 5) == 0) {
667
userInfo.login = (char*) calloc(MAX_LOGIN + 1, sizeof (char));
668
if (userInfo.login == NULL) {
669
ErrorsHandler(ERROR_MEMALLOC);
673
userInfo.passwd = (char*) calloc(MAX_PASSWD + 1, sizeof (char));
674
if (userInfo.passwd == NULL) {
675
ErrorsHandler(ERROR_MEMALLOC);
679
// Retrieving the user's login and password from the configuration file and putting them into the Edit controls.
680
if (GetPrivateProfileString("Settings", "login", NULL, userInfo.login, MAX_LOGIN + 1, config_path) == 0 ||
681
GetPrivateProfileString("Settings", "passwd", NULL, userInfo.passwd, MAX_PASSWD + 1, config_path) == 0) {
682
ErrorsHandler(ERROR_READCONFFILE);
684
SetWindowText(login, userInfo.login);
685
SetWindowText(passwd, userInfo.passwd);
687
SendMessage(save_data, BM_SETCHECK, (WPARAM) TRUE, 0);
689
EnableWindow(login, 0);
690
EnableWindow(passwd, 0);
691
SendMessage(without_login, BM_SETCHECK, (WPARAM) TRUE, 0);
694
memset(state, 0, MAX_STATE);
696
if (GetPrivateProfileString("Proxy", "useproxy", NULL, state, MAX_STATE + 1, config_path) == 0) {
697
memcpy(state, "false", 6);
700
// If "Use proxy server" checkbox was checked.
701
if (memcmp(state, "true", 5) == 0) {
702
userInfo.address = (char*) calloc(MAX_ADDRSS + 1, sizeof (char));
703
if (userInfo.address == NULL) {
704
ErrorsHandler(ERROR_MEMALLOC);
708
userInfo.port = (char*) calloc(MAX_PORT + 1, sizeof (char));
709
if (userInfo.port == NULL) {
710
ErrorsHandler(ERROR_MEMALLOC);
714
// Retrieving proxy address and port from the configuration file and putting them into the Edit controls.
715
if (GetPrivateProfileString("Proxy", "address", NULL, userInfo.address, MAX_ADDRSS + 1, config_path) == 0 ||
716
GetPrivateProfileString("Proxy", "port", NULL, userInfo.port, MAX_PORT + 1, config_path) == 0) {
717
ErrorsHandler(ERROR_READCONFFILE);
719
SetWindowText(proxy_addrss, userInfo.address);
720
SetWindowText(proxy_port, userInfo.port);
722
SendMessage(use_proxy, BM_SETCHECK, (WPARAM) TRUE, 0);
724
EnableWindow(proxy_addrss, 0);
725
EnableWindow(proxy_port, 0);
726
SendMessage(use_proxy, BM_SETCHECK, (WPARAM) FALSE, 0);
732
if (LOWORD(wParam) == ID_CHECK_WITHOUTLOGIN) {
733
LRESULT result = SendMessage(without_login, BM_GETCHECK, 0, 0);
734
if (result == BST_CHECKED) {
735
EnableWindow(login, 0);
736
EnableWindow(passwd, 0);
737
SendMessage(login, EM_SETSEL, 0, -1);
738
SendMessage(login, WM_CLEAR, 0, 0);
739
SendMessage(passwd, EM_SETSEL, 0, -1);
740
SendMessage(passwd, WM_CLEAR, 0, 0);
741
SendMessage(save_data, BM_SETCHECK, (WPARAM) FALSE, 0);
743
EnableWindow(login, 1);
744
EnableWindow(passwd, 1);
745
SendMessage(without_login, BM_SETCHECK, (WPARAM) FALSE, 0);
749
if (LOWORD(wParam) == ID_CHECK_SAVEDATA) {
750
LRESULT result = SendMessage(without_login, BM_GETCHECK, 0, 0);
751
if (result == BST_CHECKED) {
752
EnableWindow(login, 1);
753
EnableWindow(passwd, 1);
754
SendMessage(without_login, BM_SETCHECK, (WPARAM) FALSE, 0);
758
if (LOWORD(wParam) == ID_LOGIN && HIWORD(wParam) == EN_CHANGE) {
759
if (userInfo.login == NULL) {
760
userInfo.login = (char*) calloc(MAX_LOGIN + 1, sizeof (char));
761
if (userInfo.login == NULL) {
762
ErrorsHandler(ERROR_MEMALLOC);
766
memset(userInfo.login, 0, MAX_LOGIN + 1);
768
GetWindowText(login, userInfo.login, MAX_LOGIN + 1);
771
if (LOWORD(wParam) == ID_PASSWD && HIWORD(wParam) == EN_CHANGE) {
772
if (userInfo.passwd == NULL) {
773
userInfo.passwd = (char*) calloc(MAX_PASSWD + 1, sizeof (char));
774
if (userInfo.passwd == NULL) {
775
ErrorsHandler(ERROR_MEMALLOC);
779
memset(userInfo.passwd, 0, MAX_PASSWD + 1);
781
GetWindowText(passwd, userInfo.passwd, MAX_PASSWD + 1);
784
if (LOWORD(wParam) == ID_CHECK_RESIZEIMG) {
785
LRESULT result = SendMessage(resize_img, BM_GETCHECK, 0, 0);
786
if (result == BST_CHECKED) {
787
EnableWindow(resize_size, 1);
788
EnableWindow(resize_updown, 1);
789
EnableWindow(resize_filter, 1);
791
EnableWindow(resize_size, 0);
792
EnableWindow(resize_updown, 0);
793
EnableWindow(resize_filter, 0);
797
if (LOWORD(wParam) == ID_CHECK_ROTATEIMG) {
798
LRESULT result = SendMessage(rotate_img, BM_GETCHECK, 0, 0);
799
if (result == BST_CHECKED) {
800
EnableWindow(rotate_angle, 1);
802
EnableWindow(rotate_angle, 0);
806
if (LOWORD(wParam) == ID_RESIZEIMG_SIZE && HIWORD(wParam) == EN_CHANGE) {
807
if (imageInfo.width == 0) {
808
ErrorsHandler(ERROR_GETIMGWIDTH);
810
char width[MAX_DIM_CHARS];
811
memset(width, 0, MAX_DIM_CHARS);
813
GetWindowText(resize_size, width, MAX_DIM_CHARS + 1);
814
size_t new_width = atoi(width);
816
// Reduce value have to be less than actual width of the image.
817
if (new_width > imageInfo.width) {
818
ErrorsHandler(ERROR_BIGWIDTH);
819
SendMessage(resize_size, EM_SETSEL, 0, -1);
820
SendMessage(resize_size, WM_CLEAR, 0, 0);
825
if (LOWORD(wParam) == ID_CHECK_USEPROXY) {
826
LRESULT result = SendMessage(use_proxy, BM_GETCHECK, 0, 0);
827
if (result == BST_CHECKED) {
828
EnableWindow(proxy_addrss, 1);
829
EnableWindow(proxy_port, 1);
831
EnableWindow(proxy_addrss, 0);
832
EnableWindow(proxy_port, 0);
833
SendMessage(proxy_addrss, EM_SETSEL, 0, -1);
834
SendMessage(proxy_addrss, WM_CLEAR, 0, 0);
835
SendMessage(proxy_port, EM_SETSEL, 0, -1);
836
SendMessage(proxy_port, WM_CLEAR, 0, 0);
840
if (LOWORD(wParam) == ID_PROXY_ADDRESS && HIWORD(wParam) == EN_CHANGE) {
841
GetWindowText(proxy_addrss, userInfo.address, 16);
844
if (LOWORD(wParam) == ID_PROXY_PORT && HIWORD(wParam) == EN_CHANGE) {
845
GetWindowText(proxy_port, userInfo.port, 5);
848
// If the "About" button was pressed.
849
if (LOWORD(wParam) == ID_ABOUT_BUTTON) {
851
EnableWindow(login_wnd, 0);
854
// If the "Upload" button was pressed.
855
if (LOWORD(wParam) == ID_UPLOAD_BUTTON) {
856
EnableWindow(upload, 0);
858
char *config_path = WideToAcp(configFiles.config);
860
LRESULT resize_result = SendMessage(resize_img, BM_GETCHECK, 0, 0);
861
LRESULT rotate_result = SendMessage(rotate_img, BM_GETCHECK, 0, 0);
863
if (resize_result == BST_CHECKED || rotate_result == BST_CHECKED) {
864
size_t choise = MessageBox(
866
gettext("The current image was modified.\nApply the changes?"),
867
gettext("ITmages - Image"),
868
MB_YESNO | MB_ICONQUESTION);
870
if (choise == IDYES) {
871
if (resize_result == BST_CHECKED) {
872
char width[MAX_DIM_CHARS];
873
memset(width, 0, MAX_DIM_CHARS);
875
GetWindowText(resize_size, width, MAX_DIM_CHARS + 1);
877
size_t new_width = atoi(width);
878
size_t filter_index = SendMessage(resize_filter, CB_GETCURSEL, 0, 0);
880
ResizeImageTo(imageData.path, new_width, filter_index);
881
imageInfo.size = GetImageSize(imageData.path);
884
if (rotate_result == BST_CHECKED) {
887
size_t selected_index = SendMessage(rotate_angle, CB_GETCURSEL, 0, 0);
888
switch (selected_index) {
889
case 0: angle = 0; // Do not rotate
891
case 1: angle = 90; // Left
893
case 2: angle = -90; // Rigth
895
case 3: angle = 180; // Flip
898
RotateImageTo(imageData.path, angle);
899
imageInfo.size = GetImageSize(imageData.path);
902
/* Retrieving the information about the image again, coz the
903
image's properties was changed. */
904
FreeImageInfo(&imageInfo);
905
if (GetImageInfo(imageData.path, imageData.basename,
906
imageData.ext, &imageInfo) == -1) {
907
ErrorsHandler(ERROR_GETIMGINFO);
913
/* If the "Save account settings" checkbox was checked - saving login
914
and password to the configuration file. */
915
LRESULT result_savedata = SendMessage(save_data, BM_GETCHECK, 0, 0);
916
if (result_savedata == BST_CHECKED) {
917
if (WritePrivateProfileString("Settings", "login", userInfo.login, config_path) == 0 ||
918
WritePrivateProfileString("Settings", "passwd", userInfo.passwd, config_path) == 0 ||
919
WritePrivateProfileString("Settings", "savedata", "true", config_path) == 0) {
920
ErrorsHandler(ERROR_WRITECONFFILE);
923
if (WritePrivateProfileString("Settings", "savedata", "false", config_path) == 0) {
924
ErrorsHandler(ERROR_WRITECONFFILE);
928
/* If the "Use proxy server" checkbox was checked - saving proxy
929
address and port to the configuration file. */
930
LRESULT result_useproxy = SendMessage(use_proxy, BM_GETCHECK, 0, 0);
931
if (result_useproxy == BST_CHECKED) {
932
if (WritePrivateProfileString("Proxy", "address", userInfo.address, config_path) == 0 ||
933
WritePrivateProfileString("Proxy", "port", userInfo.port, config_path) == 0 ||
934
WritePrivateProfileString("Proxy", "useproxy", "true", config_path) == 0) {
935
ErrorsHandler(ERROR_WRITECONFFILE);
938
if (WritePrivateProfileString("Proxy", "useproxy", "false", config_path) == 0) {
939
ErrorsHandler(ERROR_WRITECONFFILE);
943
/* Checking the image's size again to be sure that the image still
944
has an appropriate size. */
945
if (imageInfo.size == -1) {
946
ErrorsHandler(ERROR_MAXIMGSIZE);
948
} else if (imageInfo.size == 0) {
949
ErrorsHandler(ERROR_BADIMGSIZE);
952
// Starting the upload threads.
953
LRESULT result_withoutlogin = SendMessage(without_login, BM_GETCHECK, 0, 0);
954
if (result_withoutlogin == BST_CHECKED) {
955
HANDLE withoutlogin_thread = (HANDLE) _beginthreadex(NULL, 0, (void*) UploadWithoutLoginThread, login_wnd, 0, NULL);
956
if (withoutlogin_thread == NULL) {
957
ErrorsHandler(ERROR_CREATETHREAD);
959
CloseHandle(withoutlogin_thread);
961
HANDLE withlogin_thread = (HANDLE) _beginthreadex(NULL, 0, (void*) UploadWithLoginThread, login_wnd, 0, NULL);
962
if (withlogin_thread == NULL) {
963
ErrorsHandler(ERROR_CREATETHREAD);
965
CloseHandle(withlogin_thread);
973
LPNMHDR lpnmhdr = (LPNMHDR) lParam;
974
if (lpnmhdr->code == TCN_SELCHANGE) {
975
size_t nTab = TabCtrl_GetCurSel(login_tab);
1005
case WM_FINISHTHREAD:
1006
/* If image upload was successful - creating the Ready window and minimizing
1007
the Login window into the taskbar. */
1009
EnableWindow(login_wnd, 0);
1011
case WM_SYSCOLORCHANGE:
1012
/* Updating the statics' and checkboxes' background if the system's
1013
visual style was changed. */
1014
UpdateBackgroundBrush(login_tab);
1016
case WM_CTLCOLORSTATIC:
1017
/* If the visual style is enabled - drawing an appropriate background
1018
for the static controls and checkboxes. */
1019
if (g_ThemeActive == 1) {
1020
SetThemedBackground(login_tab, (HWND) lParam, (HDC) wParam);
1021
return (LRESULT) (g_StaticBrush);
1023
SetBkColor((HDC) wParam, (COLORREF) GetSysColor(COLOR_BTNFACE));
1024
return (LRESULT) GetSysColorBrush(COLOR_BTNFACE);
1028
FreeImageInfo(&imageInfo);
1029
FreeImageLinks(&imageLinks);
1030
FreeImageData(&imageData);
1031
FreeUserInfo(&userInfo);
1032
FreeConfig(&configFiles);
1037
return DefWindowProc(login_wnd, message, wParam, lParam);
1042
INT APIENTRY WinAbout()
1044
WNDCLASSEX itmagesAbout;
1045
memset(&itmagesAbout, 0, sizeof (itmagesAbout));
1047
itmagesAbout.cbSize = sizeof (itmagesAbout);
1048
itmagesAbout.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
1049
itmagesAbout.lpfnWndProc = WinAboutProc;
1050
itmagesAbout.cbClsExtra = 0;
1051
itmagesAbout.cbWndExtra = 0;
1052
itmagesAbout.hInstance = g_ItmagesInst;
1053
itmagesAbout.hIcon = g_AppIcon;
1054
itmagesAbout.hCursor = LoadCursor(NULL, IDC_ARROW);
1055
itmagesAbout.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
1056
itmagesAbout.lpszMenuName = NULL;
1057
itmagesAbout.lpszClassName = g_AboutWindowClass;
1058
itmagesAbout.hIconSm = NULL;
1060
if (RegisterClassEx(&itmagesAbout) == 0) {
1066
void CreateAboutWnd()
1068
size_t frame_width = GetSystemMetrics(SM_CXSIZEFRAME);
1069
size_t frame_height = GetSystemMetrics(SM_CYSIZEFRAME);
1072
GetWindowRect(login_wnd, &parent_rect);
1074
about_wnd = CreateWindowEx(
1075
WS_EX_DLGMODALFRAME,
1077
gettext("ITmages - About"),
1078
WS_POPUP | WS_VISIBLE | WS_SYSMENU | WS_CAPTION | WS_THICKFRAME | WS_CLIPCHILDREN,
1079
(parent_rect.left + LOGIN_WND_WIDTH / 2) - ABOUT_WND_WIDTH / 2,
1080
(parent_rect.top + LOGIN_WND_HEIGHT / 2) - ABOUT_WND_HEIGHT / 2,
1081
ABOUT_WND_WIDTH + frame_width,
1082
ABOUT_WND_HEIGHT + frame_height,
1088
// Creating the Tab conrol for the About window
1089
CreateAboutTabControl();
1091
ShowWindow(about_wnd, SW_SHOW);
1092
UpdateWindow(about_wnd);
1095
void CreateAboutTabControl()
1097
HWND about_tab = CreateWindowEx(
1101
WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_CLIPCHILDREN,
1104
ABOUT_TABCONTROL_WIDTH,
1105
ABOUT_TABCONTROL_HEIGHT,
1107
(HMENU) ID_ABOUT_TABCONTROL,
1111
SendMessage(about_tab, WM_SETFONT, (WPARAM) g_SystemFont, 0);
1114
memset(&tie, 0, sizeof (tie));
1116
tie.mask = TCIF_TEXT;
1117
tie.pszText = gettext("About");
1118
TabCtrl_InsertItem(about_tab, 0, &tie);
1119
tie.pszText = gettext("License");
1120
TabCtrl_InsertItem(about_tab, 1, &tie);
1121
tie.pszText = gettext("Credits");
1122
TabCtrl_InsertItem(about_tab, 2, &tie);
1124
UpdateBackgroundBrush(about_tab);
1127
LRESULT CALLBACK WinAboutProc(
1133
HWND about_tab = GetDlgItem(about_wnd, ID_ABOUT_TABCONTROL);
1134
static HWND itmages_img,
1140
size_t frame_width = GetSystemMetrics(SM_CXSIZEFRAME);
1141
size_t frame_height = GetSystemMetrics(SM_CYSIZEFRAME);
1145
itmages_img = CreateWindowEx(
1149
WS_CHILD | WS_VISIBLE | SS_ICON | WS_CLIPSIBLINGS,
1155
(HMENU) ID_ITMAGES_IMG,
1158
about_info = CreateWindowEx(
1161
gettext("ITmages upload client\n"
1163
"Author : Dmitriy Simbiriatin\n"
1164
"E - mail : slpiv@itmages.ru\n"
1165
"Copyright(c) 2011 Dmitriy Simbiriatin\n"
1166
"License : GPL version 2"),
1167
WS_CHILD | WS_VISIBLE | ES_LEFT | WS_CLIPSIBLINGS,
1173
(HMENU) ID_ABOUT_INFO,
1176
license_info = CreateWindowEx(
1180
WS_CHILD | WS_VISIBLE | ES_LEFT | ES_MULTILINE |
1181
WS_VSCROLL | ES_READONLY | ES_WANTRETURN |
1182
ES_AUTOVSCROLL | WS_CLIPSIBLINGS,
1186
LICENSE_INFO_HEIGHT,
1188
(HMENU) ID_LICENSE_INFO,
1191
credits_info = CreateWindowEx(
1195
WS_CHILD | WS_VISIBLE | ES_LEFT | ES_MULTILINE |
1196
WS_VSCROLL | ES_READONLY | ES_WANTRETURN |
1197
ES_AUTOVSCROLL | WS_CLIPSIBLINGS,
1201
CREDITS_INFO_HEIGHT,
1203
(HMENU) ID_CREDITS_INFO,
1206
close = CreateWindowEx(
1210
WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_CLIPSIBLINGS,
1214
CLOSE_BUTTON_HEIGHT,
1216
(HMENU) ID_CLOSE_BUTTON,
1220
// Putting ITmages logo into the static control.
1221
SendMessage(itmages_img, STM_SETIMAGE, IMAGE_ICON, (LPARAM) g_AppIcon);
1223
// Hiding the windows that are placed on the 2nd and the 3rd tabs.
1224
HideWindows(about_wnd, ID_LICENSE_INFO, ID_CREDITS_INFO);
1226
// Setting the system's default font for the child windows.
1227
SetSystemFont(about_wnd, ID_ABOUT_INFO, ID_CLOSE_BUTTON);
1229
// Loading the documentation files.
1230
if (LoadDocFile(license_info, DOCS_DIR, "COPYING.txt") == -1) {
1231
SetWindowText(license_info, gettext("Failed to open the file."));
1233
if (LoadDocFile(credits_info, DOCS_DIR, "CREDITS.txt") == -1) {
1234
SetWindowText(credits_info, gettext("Failed to open the file."));
1238
if (LOWORD(wParam) == ID_CLOSE_BUTTON) {
1239
DestroyWindow(about_wnd);
1244
LPNMHDR lpnmhdr = (LPNMHDR) lParam;
1245
if (lpnmhdr->code == TCN_SELCHANGE) {
1246
size_t nTab = TabCtrl_GetCurSel(about_tab);
1276
case WM_SYSCOLORCHANGE:
1277
/* Updating the statics' and checkboxes' background if the system's
1278
visual style was changed. */
1279
UpdateBackgroundBrush(about_tab);
1281
case WM_CTLCOLORSTATIC:
1282
/* If the visual style is enabled - drawing an appropriate background
1283
for the static controls and checkboxes. */
1284
if (g_ThemeActive == 1) {
1285
SetThemedBackground(about_tab, (HWND) lParam, (HDC) wParam);
1286
return (LRESULT) g_StaticBrush;
1288
SetBkColor((HDC) wParam, (COLORREF) GetSysColor(COLOR_BTNFACE));
1289
return (LRESULT) GetSysColorBrush(COLOR_BTNFACE);
1294
UpdateBackgroundBrush(about_tab);
1297
GetWindowRect(about_wnd, &about_rect);
1299
// Difference between the initial size of the window and the new one.
1300
int delta_width = ((about_rect.right - about_rect.left) - ABOUT_WND_WIDTH);
1301
int delta_height = ((about_rect.bottom - about_rect.top) - ABOUT_WND_HEIGHT);
1303
MoveWindow(about_tab,
1306
ABOUT_TABCONTROL_WIDTH + delta_width - frame_width,
1307
ABOUT_TABCONTROL_HEIGHT + delta_height - frame_height,
1309
MoveWindow(about_info,
1312
ABOUT_INFO_WIDTH + delta_width - frame_width,
1313
ABOUT_INFO_HEIGHT + delta_height - frame_height,
1315
MoveWindow(license_info,
1318
LICENSE_INFO_WIDTH + delta_width - frame_width,
1319
LICENSE_INFO_HEIGHT + delta_height - frame_height,
1321
MoveWindow(credits_info,
1324
CREDITS_INFO_WIDTH + delta_width - frame_width,
1325
CREDITS_INFO_HEIGHT + delta_height - frame_height,
1328
CLOSE_BUTTON_X + delta_width - frame_width,
1329
CLOSE_BUTTON_Y + delta_height - frame_height,
1331
CLOSE_BUTTON_HEIGHT,
1335
case WM_GETMINMAXINFO:
1337
// Setting the minimal width and height of the About window.
1338
((MINMAXINFO*) lParam)->ptMinTrackSize.x = ABOUT_WND_WIDTH + frame_width;
1339
((MINMAXINFO*) lParam)->ptMinTrackSize.y = ABOUT_WND_HEIGHT + frame_height;
1343
EnableWindow(login_wnd, 1);
1344
SetFocus(login_wnd);
1345
DestroyWindow(about_wnd);
1348
return DefWindowProc(about_wnd, message, wParam, lParam);
1353
INT APIENTRY WinReady()
1355
WNDCLASSEX itmagesReady;
1356
memset(&itmagesReady, 0, sizeof (itmagesReady));
1358
itmagesReady.cbSize = sizeof (itmagesReady);
1359
itmagesReady.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
1360
itmagesReady.lpfnWndProc = WinReadyProc;
1361
itmagesReady.cbClsExtra = 0;
1362
itmagesReady.cbWndExtra = 0;
1363
itmagesReady.hInstance = g_ItmagesInst;
1364
itmagesReady.hIcon = g_AppIcon;
1365
itmagesReady.hCursor = LoadCursor(NULL, IDC_ARROW);
1366
itmagesReady.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
1367
itmagesReady.lpszMenuName = NULL;
1368
itmagesReady.lpszClassName = g_ReadyWindowClass;
1369
itmagesReady.hIconSm = NULL;
1371
if (RegisterClassEx(&itmagesReady) == 0) {
1377
void CreateReadyWnd()
1380
GetWindowRect(login_wnd, &parent_rect);
1382
ready_wnd = CreateWindowEx(
1383
WS_EX_DLGMODALFRAME,
1385
gettext("ITmages - Ready!"),
1386
WS_POPUP | WS_VISIBLE | WS_SYSMENU | WS_CAPTION | WS_CLIPCHILDREN,
1387
(parent_rect.left + LOGIN_WND_WIDTH / 2) - READY_WND_WIDTH / 2,
1388
(parent_rect.top + LOGIN_WND_HEIGHT / 2) - READY_WND_HEIGHT / 2,
1396
// Creating a preview for the uploaded image.
1397
HWND preview = GetDlgItem(ready_wnd, ID_IMAGE_PREVIEW);
1398
previewImage = (HBITMAP) HBITMAPFromFile(
1401
IMAGE_PREVIEW_WIDTH,
1402
IMAGE_PREVIEW_HEIGHT);
1404
if (previewImage != NULL) {
1405
SendMessage(preview, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM) previewImage);
1408
ShowWindow(ready_wnd, SW_SHOW);
1409
UpdateWindow(ready_wnd);
1412
LRESULT CALLBACK WinReadyProc(
1418
static HWND preview,
1424
static HWND links_list_tool,
1429
static char image_info[MAX_INFO];
1430
static char preview_buffer[MAX_PREVIEW];
1435
DefWindowProc(ready_wnd, message, wParam, lParam);
1437
HDC ready_wnd_dc = GetDC(ready_wnd);
1442
SetRect(&text_rect, 18, 8, 165, 25);
1443
SetRect(&edge_rect, 10, 15, 170, 140);
1445
SetBkColor(ready_wnd_dc, GetSysColor(COLOR_BTNFACE));
1446
SelectObject(ready_wnd_dc, g_SystemFont);
1448
// Drawing the groupbox around the preview image.
1449
DrawEdge(ready_wnd_dc, &edge_rect, BDR_SUNKENINNER | BDR_RAISEDOUTER, BF_RECT | BF_FLAT);
1450
DrawText(ready_wnd_dc, gettext("Preview"), -1, &text_rect, DT_LEFT | DT_VCENTER);
1452
DeleteDC(ready_wnd_dc);
1453
ReleaseDC(ready_wnd, ready_wnd_dc);
1457
preview = CreateWindowEx(
1461
WS_CHILD | WS_VISIBLE | SS_BITMAP | SS_NOTIFY | WS_BORDER | WS_CLIPSIBLINGS,
1464
IMAGE_PREVIEW_WIDTH,
1465
IMAGE_PREVIEW_HEIGHT,
1467
(HMENU) ID_IMAGE_PREVIEW,
1470
links_list = CreateWindowEx(
1474
WS_CHILD | WS_VISIBLE | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_TABSTOP | WS_CLIPSIBLINGS,
1480
(HMENU) ID_LINKS_LIST,
1483
link_preview = CreateWindowEx(
1487
WS_CHILD | WS_VISIBLE | ES_READONLY | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS,
1491
LINK_PREVIEW_HEIGHT,
1493
(HMENU) ID_LINK_PREVIEW,
1496
copy_to_clip = CreateWindowEx(
1499
gettext("Copy to Clipboard"),
1500
WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_CLIPSIBLINGS,
1503
COPYTOCLIPBOARD_WIDTH,
1504
COPYTOCLIPBOARD_HEIGHT,
1506
(HMENU) ID_COPYTOCLIPBOARD,
1509
open_in_bsr = CreateWindowEx(
1512
gettext("Open in Browser"),
1513
WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_CLIPSIBLINGS,
1516
OPENINBROWSER_WIDTH,
1517
OPENINBROWSER_HEIGHT,
1519
(HMENU) ID_OPENINBROWSER,
1526
gettext("Choose the link type"));
1530
gettext("Copy the selected link into clipboard"));
1534
gettext("Open the selected link in the default web browser"));
1536
// Putting information about the image inside the preview's tooltip.
1537
wchar_t *fullname_wide = Utf8ToWide(imageInfo.fullname);
1538
char *fullname_mb = WideToAcp(fullname_wide);
1539
free(fullname_wide);
1543
gettext("Name: %s\nWidth: %d\nHeight: %d\nSize: %d Kb"),
1547
(imageInfo.size / 1024));
1555
// Setting the system's default font for the child windows.
1556
SetSystemFont(ready_wnd, ID_IMAGE_PREVIEW, ID_OPENINBROWSER);
1558
// Adding the supported link types to the list.
1559
SendMessage(links_list, CB_ADDSTRING, 0, (LPARAM) gettext("Link"));
1560
SendMessage(links_list, CB_ADDSTRING, 0, (LPARAM) gettext("Direct Link"));
1561
SendMessage(links_list, CB_ADDSTRING, 0, (LPARAM) gettext("BB code thumbnail"));
1562
SendMessage(links_list, CB_ADDSTRING, 0, (LPARAM) gettext("HTML Code thumbnail"));
1564
char *config_path = WideToAcp(configFiles.config);
1566
char index_buffer[MAX_INDEX];
1567
memset(index_buffer, 0, MAX_INDEX);
1569
// Retrieving an index of the previously chosen link type from the configuration file.
1570
if (GetPrivateProfileString("Settings", "linkindex", NULL, index_buffer, MAX_INDEX + 1, config_path) == 0) {
1571
SendMessage(links_list, CB_SETCURSEL, 0, 0);
1572
ShowSelectedLink(link_preview, open_in_bsr, preview_buffer, 0);
1574
size_t selected_index = atoi(index_buffer);
1575
SendMessage(links_list, CB_SETCURSEL, selected_index, 0);
1576
ShowSelectedLink(link_preview, open_in_bsr, preview_buffer, selected_index);
1581
if (LOWORD(wParam) == ID_LINKS_LIST && HIWORD(wParam) == CBN_SELCHANGE) {
1582
size_t selected_index = SendMessage(links_list, CB_GETCURSEL, 0, 0);
1583
ShowSelectedLink(link_preview, open_in_bsr, preview_buffer, selected_index);
1585
if (LOWORD(wParam) == ID_COPYTOCLIPBOARD) {
1586
if (OpenClipboard(ready_wnd) == 0) {
1587
ErrorsHandler(ERROR_OPENCLIPBOARD);
1589
HGLOBAL clip_buffer;
1593
clip_buffer = GlobalAlloc(GMEM_DDESHARE, sizeof (preview_buffer));
1594
tmp_buffer = (char*) GlobalLock(clip_buffer);
1595
memcpy(tmp_buffer, preview_buffer, strlen(preview_buffer) + 1);
1596
GlobalUnlock(clip_buffer);
1597
SetClipboardData(CF_TEXT, clip_buffer);
1601
if (LOWORD(wParam) == ID_OPENINBROWSER) {
1602
size_t selected_index = SendMessage(links_list, CB_GETCURSEL, 0, 0);
1603
if (selected_index == 0 || selected_index == 1) {
1604
ShellExecute(NULL, "open", preview_buffer, NULL, NULL, SW_SHOWNORMAL);
1610
char index_buffer[MAX_INDEX];
1611
memset(index_buffer, 0, MAX_INDEX);
1613
size_t selected_index = SendMessage(links_list, CB_GETCURSEL, 0, 0);
1614
itoa(selected_index, index_buffer, 10);
1616
char *config_path = WideToAcp(configFiles.config);
1618
// Saving the last chosen link type index to the configuration file.
1619
if (WritePrivateProfileString("Settings", "linkindex", index_buffer, config_path) == 0) {
1620
ErrorsHandler(ERROR_WRITECONFFILE);
1624
DeleteObject(previewImage);
1626
FreeImageInfo(&imageInfo);
1627
FreeImageLinks(&imageLinks);
1628
FreeImageData(&imageData);
1629
FreeUserInfo(&userInfo);
1630
FreeConfig(&configFiles);
1632
EnableWindow(login_wnd, 1);
1633
SetFocus(login_wnd);
1639
return DefWindowProc(ready_wnd, message, wParam, lParam);
1644
UINT APIENTRY UploadWithLoginThread(HWND login_wnd)
1646
short thread_success = 1;
1649
char *cookies_path = WideToAcp(configFiles.cookies);
1651
result = ItmagesCheckConnection(cookies_path, userInfo.address, userInfo.port);
1653
ErrorsHandler(ERROR_CONNECTION);
1655
} else if (result == -1) {
1658
result = ItmagesLogin(userInfo.login, userInfo.passwd, cookies_path,
1659
userInfo.address, userInfo.port);
1661
ErrorsHandler(ERROR_LOGIN);
1663
} else if (result == -1) {
1666
FreeImageLinks(&imageLinks);
1667
HWND upload_progress = GetDlgItem(login_wnd, ID_UPLOAD_PROGRESSBAR);
1668
result = ItmagesUpload(upload_progress, imageData.path, imageInfo.fullname, imageInfo.mime,
1669
cookies_path, userInfo.address, userInfo.port, imageInfo.size, &imageLinks);
1673
result = ItmagesLogout(cookies_path, userInfo.address, userInfo.port);
1675
ErrorsHandler(ERROR_LOGOUT);
1681
if (thread_success == 1) {
1682
SendMessage(login_wnd, WM_FINISHTHREAD, 0, 0);
1684
HWND upload = GetDlgItem(login_wnd, ID_UPLOAD_BUTTON);
1685
EnableWindow(upload, 1);
1689
UINT APIENTRY UploadWithoutLoginThread(HWND login_wnd)
1691
short thread_success = 1;
1694
char *cookies_path = WideToAcp(configFiles.cookies);
1696
result = ItmagesCheckConnection(cookies_path, userInfo.address, userInfo.port);
1698
ErrorsHandler(ERROR_CONNECTION);
1700
} else if (result == -1) {
1703
FreeImageLinks(&imageLinks);
1704
HWND upload_progress = GetDlgItem(login_wnd, ID_UPLOAD_PROGRESSBAR);
1705
result = ItmagesUpload(upload_progress, imageData.path, imageInfo.fullname, imageInfo.mime,
1706
cookies_path, userInfo.address, userInfo.port, imageInfo.size, &imageLinks);
1713
if (thread_success == 1) {
1714
SendMessage(login_wnd, WM_FINISHTHREAD, 0, 0);
1716
HWND upload = GetDlgItem(login_wnd, ID_UPLOAD_BUTTON);
1717
EnableWindow(upload, 1);
1726
tooltip_wnd = CreateWindowEx(
1730
TTS_NOPREFIX | TTS_ALWAYSTIP,
1744
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
1747
memset(&ti, 0, sizeof (ti));
1749
ti.cbSize = sizeof (TOOLINFO);
1750
ti.uFlags = TTF_IDISHWND | TTF_SUBCLASS | TTF_TRANSPARENT;
1751
ti.hwnd = parent_wnd;
1752
ti.uId = (UINT_PTR) parent_wnd;
1753
ti.hinst = g_ItmagesInst;
1754
ti.lpszText = tooltip_txt;
1756
GetClientRect(parent_wnd, &ti.rect);
1758
SendMessage(tooltip_wnd, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) & ti);
1759
SendMessage(tooltip_wnd, TTM_ACTIVATE, TRUE, 0);
1760
SendMessage(tooltip_wnd, TTM_SETMAXTIPWIDTH, 0, (WPARAM) 180);
1763
char *CreateOpenImageDialog()
1766
memset(&ofn, 0, sizeof (OPENFILENAME));
1768
char *image_path = (char*) calloc(_MAX_PATH + 1, sizeof (char));
1769
if (image_path == NULL) {
1770
ErrorsHandler(ERROR_MEMALLOC);
1774
ofn.lStructSize = sizeof (OPENFILENAME);
1775
ofn.lpstrFile = image_path;
1776
ofn.nMaxFile = _MAX_PATH;
1777
ofn.lpstrFilter = "*.png,*.jpeg,*.jpg,*.gif\0*.jpg;*.jpeg;*.png;*.gif\0";
1778
ofn.nFilterIndex = 1;
1779
ofn.lpstrTitle = gettext("Choose the image...");
1780
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
1781
if (GetOpenFileName(&ofn) == FALSE) {
1787
void ShowSelectedLink(
1790
char *preview_buffer,
1797
"http://itmages.ru/image/view/%s/%s",
1800
SetWindowText(link_preview, preview_buffer);
1801
EnableWindow(bsr_button, 1);
1806
"http://%s.static.itmages.ru/%s",
1809
SetWindowText(link_preview, preview_buffer);
1810
EnableWindow(bsr_button, 1);
1815
"[url=http://itmages.ru/image/view/%s/%s][img]http://%s.static.itmages.ru/%s[/img][/url]",
1820
SetWindowText(link_preview, preview_buffer);
1821
EnableWindow(bsr_button, 0);
1826
"<a target=\"_blank\"; href=\"http://itmages.ru/image/view/%s/%s\"><img src=\"http://%s.static.itmages.ru/%s\" /></a>",
1831
SetWindowText(link_preview, preview_buffer);
1832
EnableWindow(bsr_button, 0);
1837
void UpdateBackgroundBrush(HWND wnd)
1839
if (IsAppThemed() == TRUE) {
1845
if (g_StaticBrush != NULL) {
1846
DeleteObject(g_StaticBrush);
1849
g_StaticBrush = NULL;
1851
if (g_ThemeActive == 1) {
1854
GetWindowRect(wnd, &wnd_rect);
1856
HDC wnd_dc = GetDC(wnd);
1857
HDC wnd_dc_mem = CreateCompatibleDC(wnd_dc);
1859
HBITMAP bitmap = CreateCompatibleBitmap(wnd_dc,
1860
wnd_rect.right - wnd_rect.left, wnd_rect.bottom - wnd_rect.top);
1861
HBITMAP bitmap_old = (HBITMAP) SelectObject(wnd_dc_mem, bitmap);
1863
SendMessage(wnd, WM_PRINTCLIENT, (WPARAM) (wnd_dc_mem),
1864
(LPARAM) (PRF_ERASEBKGND | PRF_CLIENT | PRF_NONCLIENT));
1866
g_StaticBrush = CreatePatternBrush(bitmap);
1868
SelectObject(wnd_dc_mem, bitmap_old);
1870
DeleteObject(bitmap);
1871
DeleteDC(wnd_dc_mem);
1872
ReleaseDC(wnd, wnd_dc);
1876
void SetThemedBackground(
1883
GetWindowRect(static_wnd, &wnd_rect);
1884
SetBkMode(static_hdc, TRANSPARENT);
1885
MapWindowPoints(NULL, wnd, (LPPOINT) (&wnd_rect), 2);
1886
SetBrushOrgEx(static_hdc, -wnd_rect.left, -wnd_rect.top, NULL);
1891
ItmagesWindowIds first_wnd,
1892
ItmagesWindowIds last_wnd)
1896
for (i = first_wnd; i <= last_wnd; ++i) {
1897
SendDlgItemMessage(parent_wnd, i, WM_SETFONT, (WPARAM) g_SystemFont, 0);
1903
ItmagesWindowIds first_wnd,
1904
ItmagesWindowIds last_wnd)
1909
for (i = first_wnd; i <= last_wnd; ++i) {
1910
hide_wnd = GetDlgItem(parent_wnd, i);
1911
ShowWindow(hide_wnd, SW_HIDE);
1915
void ShowTabWindows(
1917
ItmagesWindowIds first_wnd,
1918
ItmagesWindowIds last_wnd,
1919
ItmagesWindowIds first_show,
1920
ItmagesWindowIds last_show)
1925
for (i = first_wnd; i <= last_wnd; ++i) {
1926
tab_wnds = GetDlgItem(parent_wnd, i);
1927
if (i > first_show - 1 && i < last_show + 1) {
1928
ShowWindow(tab_wnds, SW_SHOW);
1930
ShowWindow(tab_wnds, SW_HIDE);
1935
void GetConfigFiles(ItmagesConfig *configFiles)
1937
size_t folder_len = wcslen(ITMAGES_DIR);
1938
size_t config_len = wcslen(CONFIG_FILE);
1939
size_t cookies_len = wcslen(COOKIES_FILE);
1941
configFiles->config = (wchar_t*) calloc(_MAX_PATH + 1, sizeof (wchar_t));
1942
if (configFiles->config == NULL) {
1943
ErrorsHandler(ERROR_MEMALLOC);
1946
if (SHGetFolderPathW(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, configFiles->config) != S_OK) {
1947
ErrorsHandler(ERROR_GETSETTINGSDIR);
1949
size_t path_len = wcslen(configFiles->config);
1950
wmemcpy(configFiles->config + path_len, ITMAGES_DIR, folder_len + 1);
1951
CreateDirectoryW(configFiles->config, NULL);
1952
wmemcpy(configFiles->config + path_len + folder_len, CONFIG_FILE, config_len + 1);
1954
configFiles->cookies = (wchar_t*) calloc(_MAX_PATH + 1, sizeof (wchar_t));
1955
if (configFiles->cookies == NULL) {
1956
ErrorsHandler(ERROR_MEMALLOC);
1959
if (SHGetFolderPathW(NULL, CSIDL_COOKIES | CSIDL_FLAG_CREATE, NULL, 0, configFiles->cookies) != S_OK) {
1960
ErrorsHandler(ERROR_GETCOOKIESDIR);
1962
size_t path_len = wcslen(configFiles->cookies);
1963
wmemcpy(configFiles->cookies + path_len, ITMAGES_DIR, folder_len + 1);
1964
CreateDirectoryW(configFiles->cookies, NULL);
1965
wmemcpy(configFiles->cookies + path_len + folder_len, COOKIES_FILE, cookies_len + 1);
1969
char *GetInstallDir()
1972
DWORD type = REG_SZ;
1973
DWORD size = _MAX_PATH;
1975
char *install_dir = (char*) calloc(_MAX_PATH + 1, sizeof (char));
1976
if (install_dir == NULL) {
1977
ErrorsHandler(ERROR_MEMALLOC);
1980
if (RegOpenKeyEx(HKEY_CURRENT_USER, ITMAGES_REG_KEY, 0L, KEY_ALL_ACCESS, &key) == ERROR_SUCCESS) {
1981
if (RegQueryValueEx(key, "", NULL, &type, (LPBYTE) install_dir, &size) != ERROR_SUCCESS) {
1991
char *GetLocaleDir()
1993
char *locale_dir = GetInstallDir();
1994
if (locale_dir != NULL) {
1995
memcpy(locale_dir + strlen(locale_dir), LOCALE_DIR, strlen(LOCALE_DIR) + 1);
2005
char *doc_file = GetInstallDir();
2006
if (doc_file == NULL) {
2010
size_t docs_len = strlen(DOCS_DIR);
2011
size_t load_len = strlen(load_file);
2013
char *buffer = (char*) malloc((docs_len + load_len + 1) * sizeof (char));
2014
if (buffer == NULL) {
2015
ErrorsHandler(ERROR_MEMALLOC);
2018
memcpy(buffer, docs_dir, docs_len + 1);
2019
memcpy(buffer + strlen(buffer), load_file, load_len + 1);
2020
memcpy(doc_file + strlen(doc_file), buffer, docs_len + load_len + 1);
2023
wchar_t * doc_file_wide = AcpToWide(doc_file);
2029
file = _wfopen(doc_file_wide, L"rb");
2031
free(doc_file_wide);
2035
fseek(file, 0, SEEK_END);
2036
file_len = ftell(file);
2039
char *text = (char*) malloc((file_len + 1) * sizeof (char));
2041
ErrorsHandler(ERROR_MEMALLOC);
2044
fread(text, 1, file_len, file);
2045
free(doc_file_wide);
2048
SetWindowText(load_wnd, text);
2053
void FreeUserInfo(ItmagesUserInfo *userInfo)
2055
if (userInfo->login != NULL) {
2056
free(userInfo->login);
2057
userInfo->login = NULL;
2059
if (userInfo->passwd != NULL) {
2060
free(userInfo->passwd);
2061
userInfo->passwd = NULL;
2063
if (userInfo->address != NULL) {
2064
free(userInfo->address);
2065
userInfo->address = NULL;
2067
if (userInfo->port != NULL) {
2068
free(userInfo->port);
2069
userInfo->port = NULL;
2073
void FreeConfig(ItmagesConfig *configFiles)
2075
if (configFiles->config != NULL) {
2076
free(configFiles->config);
2077
configFiles->config = NULL;
2079
if (configFiles->cookies != NULL) {
2080
free(configFiles->cookies);
2081
configFiles->cookies = NULL;
2085
void FreeImageData(ItmagesImageData *imageData)
2087
if (imageData->path != NULL) {
2088
free(imageData->path);
2089
imageData->path = NULL;
2091
if (imageData->basename != NULL) {
2092
free(imageData->basename);
2093
imageData->basename = NULL;
2095
if (imageData->ext != NULL) {
2096
free(imageData->ext);
2097
imageData->ext = NULL;