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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
|
////////////////////////////////////////////////////////////////////////////////
// Gadu-Gadu Plugin for Miranda IM
//
// Copyright (c) 2003-2009 Adam Strzelecki <ono+miranda@java.pl>
// Copyright (c) 2009-2012 Bartosz Białek
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
////////////////////////////////////////////////////////////////////////////////
#include "gg.h"
#include <io.h>
#define WM_ADDIMAGE WM_USER + 1
#define WM_SENDIMG WM_USER + 2
#define WM_CHOOSEIMG WM_USER + 3
#define TIMERID_FLASHWND WM_USER + 4
////////////////////////////////////////////////////////////////////////////
// Image Window : Data
// tablica zawiera uin kolesia i uchwyt do okna, okno zawiera GGIMAGEDLGDATA
// ktore przechowuje handle kontaktu, i wskaznik na pierwszy obrazek
// obrazki sa poukladane jako lista jednokierunkowa.
// przy tworzeniu okna podaje sie handle do kontaktu
// dodajac obrazek tworzy sie element listy i wysyla do okna
// wyswietlajac obrazek idzie po liscie jednokierunkowej
typedef struct _GGIMAGEENTRY
{
HBITMAP hBitmap;
wchar_t *lpszFileName;
char *lpData;
unsigned long nSize;
struct _GGIMAGEENTRY *lpNext;
uint32_t crc32;
} GGIMAGEENTRY;
typedef struct
{
MCONTACT hContact;
HANDLE hEvent;
HWND hWnd;
uin_t uin;
int nImg, nImgTotal;
GGIMAGEENTRY *lpImages;
SIZE minSize;
BOOL bReceiving;
GGPROTO *gg;
} GGIMAGEDLGDATA;
// Prototypes
int gg_img_remove(GGIMAGEDLGDATA *dat);
////////////////////////////////////////////////////////////////////////////
// Image Module : Adding item to contact menu, creating sync objects
//
int GGPROTO::img_init()
{
// Send image contact menu item
CMenuItem mi;
SET_UID(mi,0xab238938, 0xed85, 0x4cfe, 0x93, 0xb5, 0xb8, 0x83, 0xf4, 0x32, 0xa0, 0xec);
mi.position = -2000010000;
mi.hIcolibItem = iconList[11].hIcolib;
mi.name.a = LPGEN("&Image");
mi.pszService = GGS_SENDIMAGE;
hImageMenuItem = Menu_AddContactMenuItem(&mi, m_szModuleName);
// Receive image
CreateProtoService(GGS_RECVIMAGE, &GGPROTO::img_recvimage);
return FALSE;
}
////////////////////////////////////////////////////////////////////////////
// Image Module : closing dialogs, sync objects
//
int GGPROTO::img_shutdown()
{
list_t l;
#ifdef DEBUGMODE
debugLogA("img_shutdown(): Closing all dialogs...");
#endif
// Rather destroy window instead of just removing structures
for (l = imagedlgs; l;)
{
GGIMAGEDLGDATA *dat = (GGIMAGEDLGDATA *)l->data;
l = l->next;
if (dat && dat->hWnd)
{
if (IsWindow(dat->hWnd))
{
// Post message async, since it maybe be different thread
if (!PostMessage(dat->hWnd, WM_CLOSE, 0, 0))
debugLogA("img_shutdown(): Image dlg %x cannot be released !!", dat->hWnd);
}
else
debugLogA("img_shutdown(): Image dlg %x not exists, but structure does !!", dat->hWnd);
}
}
return FALSE;
}
////////////////////////////////////////////////////////////////////////////
// Image Module : destroying list
//
int GGPROTO::img_destroy()
{
// Release all dialogs
while (imagedlgs && gg_img_remove((GGIMAGEDLGDATA *)imagedlgs->data));
// Destroy list
list_destroy(imagedlgs, 1);
Menu_RemoveItem(hImageMenuItem);
return FALSE;
}
////////////////////////////////////////////////////////////////////////////
// Image Window : Frees image entry structure
//
static int gg_img_releasepicture(void *img)
{
if (!img)
return FALSE;
free(((GGIMAGEENTRY *)img)->lpszFileName);
if (((GGIMAGEENTRY *)img)->hBitmap)
DeleteObject(((GGIMAGEENTRY *)img)->hBitmap);
free(((GGIMAGEENTRY *)img)->lpData);
free(img);
return TRUE;
}
////////////////////////////////////////////////////////////////////////////
// Painting image
//
int gg_img_paint(HWND hwnd, GGIMAGEENTRY *dat)
{
PAINTSTRUCT paintStruct;
HDC hdc = BeginPaint(hwnd, &paintStruct);
RECT rc;
GetWindowRect(GetDlgItem(hwnd, IDC_IMG_IMAGE), &rc);
ScreenToClient(hwnd, (POINT *)&rc.left);
ScreenToClient(hwnd, (POINT *)&rc.right);
FillRect(hdc, &rc, (HBRUSH)GetSysColorBrush(COLOR_WINDOW));
if (dat->hBitmap)
{
HDC hdcBmp = nullptr;
int nWidth, nHeight;
BITMAP bmp;
GetObject(dat->hBitmap, sizeof(bmp), &bmp);
nWidth = bmp.bmWidth; nHeight = bmp.bmHeight;
hdcBmp = CreateCompatibleDC(hdc);
SelectObject(hdcBmp, dat->hBitmap);
if (hdcBmp)
{
SetStretchBltMode(hdc, HALFTONE);
// Draw bitmap
if (nWidth > (rc.right-rc.left) || nHeight > (rc.bottom-rc.top))
{
if ((double)nWidth / (double)nHeight > (double) (rc.right-rc.left) / (double)(rc.bottom-rc.top))
{
StretchBlt(hdc,
rc.left,
((rc.top + rc.bottom) - (rc.right - rc.left) * nHeight / nWidth) / 2,
(rc.right - rc.left),
(rc.right - rc.left) * nHeight / nWidth,
hdcBmp, 0, 0, nWidth, nHeight, SRCCOPY);
}
else
{
StretchBlt(hdc,
((rc.left + rc.right) - (rc.bottom - rc.top) * nWidth / nHeight) / 2,
rc.top,
(rc.bottom - rc.top) * nWidth / nHeight,
(rc.bottom - rc.top),
hdcBmp, 0, 0, nWidth, nHeight, SRCCOPY);
}
}
else
{
BitBlt(hdc,
(rc.left + rc.right - nWidth) / 2,
(rc.top + rc.bottom - nHeight) / 2,
nWidth, nHeight,
hdcBmp, 0, 0, SRCCOPY);
}
DeleteDC(hdcBmp);
}
}
EndPaint(hwnd, &paintStruct);
return FALSE;
}
////////////////////////////////////////////////////////////////////////////////
// Returns supported image filters
//
wchar_t *gg_img_getfilter(wchar_t *szFilter, int nSize)
{
wchar_t *szFilterName, *szFilterMask;
wchar_t *pFilter = szFilter;
// Match relative to ImgDecoder presence
szFilterName = TranslateT("Image files (*.bmp,*.gif,*.jpeg,*.jpg,*.png)");
szFilterMask = L"*.bmp;*.gif;*.jpeg;*.jpg;*.png";
// Make up filter
wcsncpy(pFilter, szFilterName, nSize);
pFilter += mir_wstrlen(pFilter) + 1;
if (pFilter >= szFilter + nSize) return nullptr;
wcsncpy(pFilter, szFilterMask, nSize - (pFilter - szFilter));
pFilter += mir_wstrlen(pFilter) + 1;
if (pFilter >= szFilter + nSize) return nullptr;
*pFilter = 0;
return szFilter;
}
////////////////////////////////////////////////////////////////////////////////
// Save specified image entry
//
int gg_img_saveimage(HWND hwnd, GGIMAGEENTRY *dat)
{
if (!dat)
return FALSE;
GGPROTO* gg = ((GGIMAGEDLGDATA *)GetWindowLongPtr(hwnd, GWLP_USERDATA))->gg;
wchar_t szFilter[128];
gg_img_getfilter(szFilter, _countof(szFilter));
wchar_t szFileName[MAX_PATH];
wcsncpy(szFileName, dat->lpszFileName, _countof(szFileName));
OPENFILENAME ofn = {0};
ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
ofn.hwndOwner = hwnd;
ofn.hInstance = hInstance;
ofn.lpstrFile = szFileName;
ofn.lpstrFilter = szFilter;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR | OFN_OVERWRITEPROMPT;
if (GetSaveFileName(&ofn))
{
FILE *fp = _wfopen(szFileName, L"w+b");
if (fp)
{
fwrite(dat->lpData, dat->nSize, 1, fp);
fclose(fp);
gg->debugLogW(L"gg_img_saveimage(): Image saved to %s.", szFileName);
}
else
{
gg->debugLogW(L"gg_img_saveimage(): Cannot save image to %s.", szFileName);
MessageBox(hwnd, TranslateT("Image cannot be written to disk."), gg->m_tszUserName, MB_OK | MB_ICONERROR);
}
}
return 0;
}
////////////////////////////////////////////////////////////////////////////
// Fit window size to image size
//
BOOL gg_img_fit(HWND hwndDlg)
{
GGIMAGEDLGDATA *dat = (GGIMAGEDLGDATA *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
RECT dlgRect, imgRect, wrkRect;
int nWidth, nHeight;
int rWidth = 0, rHeight = 0;
int oWidth = 0, oHeight = 0;
BITMAP bmp;
GGIMAGEENTRY *img = nullptr;
HDC hdc;
// Check if image is loaded
if (!dat || !dat->lpImages || !dat->lpImages->hBitmap)
return FALSE;
img = dat->lpImages;
// Go to last image
while (img->lpNext && dat->lpImages->hBitmap)
img = img->lpNext;
// Get rects of display
GetWindowRect(hwndDlg, &dlgRect);
GetClientRect(GetDlgItem(hwndDlg, IDC_IMG_IMAGE), &imgRect);
hdc = GetDC(hwndDlg);
GetObject(img->hBitmap, sizeof(bmp), &bmp);
nWidth = bmp.bmWidth; nHeight = bmp.bmHeight;
SystemParametersInfo(SPI_GETWORKAREA, 0, &wrkRect, 0);
ReleaseDC(hwndDlg, hdc);
if ((imgRect.right - imgRect.left) < nWidth)
rWidth = nWidth - imgRect.right + imgRect.left;
if ((imgRect.bottom - imgRect.top) < nHeight)
rHeight = nHeight - imgRect.bottom + imgRect.top;
// Check if anything needs resize
if (!rWidth && !rHeight)
return FALSE;
oWidth = dlgRect.right - dlgRect.left + rWidth;
oHeight = dlgRect.bottom - dlgRect.top + rHeight;
if (oHeight > wrkRect.bottom - wrkRect.top)
{
oWidth = (int)((double)(wrkRect.bottom - wrkRect.top + imgRect.bottom - imgRect.top - dlgRect.bottom + dlgRect.top) * nWidth / nHeight)
- imgRect.right + imgRect.left + dlgRect.right - dlgRect.left;
if (oWidth < dlgRect.right - dlgRect.left)
oWidth = dlgRect.right - dlgRect.left;
oHeight = wrkRect.bottom - wrkRect.top;
}
if (oWidth > wrkRect.right - wrkRect.left)
{
oHeight = (int)((double)(wrkRect.right - wrkRect.left + imgRect.right - imgRect.left - dlgRect.right + dlgRect.left) * nHeight / nWidth)
- imgRect.bottom + imgRect.top + dlgRect.bottom - dlgRect.top;
if (oHeight < dlgRect.bottom - dlgRect.top)
oHeight = dlgRect.bottom - dlgRect.top;
oWidth = wrkRect.right - wrkRect.left;
}
SetWindowPos(hwndDlg, nullptr,
(wrkRect.left + wrkRect.right - oWidth) / 2,
(wrkRect.top + wrkRect.bottom - oHeight) / 2,
oWidth, oHeight,
SWP_SHOWWINDOW | SWP_NOZORDER /* | SWP_NOACTIVATE */);
return TRUE;
}
////////////////////////////////////////////////////////////////////////////
// Dialog resizer procedure
//
static int sttImageDlgResizer(HWND, LPARAM, UTILRESIZECONTROL *urc)
{
switch (urc->wId)
{
case IDC_IMG_PREV:
case IDC_IMG_NEXT:
case IDC_IMG_DELETE:
case IDC_IMG_SAVE:
return RD_ANCHORX_RIGHT | RD_ANCHORY_TOP;
case IDC_IMG_IMAGE:
return RD_ANCHORX_LEFT | RD_ANCHORY_TOP | RD_ANCHORY_HEIGHT | RD_ANCHORX_WIDTH;
case IDC_IMG_SEND:
case IDC_IMG_CANCEL:
return RD_ANCHORX_RIGHT | RD_ANCHORY_BOTTOM;
}
return RD_ANCHORX_LEFT | RD_ANCHORY_TOP;
}
////////////////////////////////////////////////////////////////////////////
// Send / Recv main dialog procedure
//
static INT_PTR CALLBACK gg_img_dlgproc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
GGIMAGEDLGDATA *dat = (GGIMAGEDLGDATA *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
switch (msg) {
case WM_INITDIALOG:
{
RECT rect;
TranslateDialogDefault(hwndDlg);
// This should be already initialized
// InitCommonControls();
// Get dialog data
dat = (GGIMAGEDLGDATA *)lParam;
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat);
// Save dialog handle
dat->hWnd = hwndDlg;
// Send event if someone's waiting
if (dat->hEvent) SetEvent(dat->hEvent);
else dat->gg->debugLogA("gg_img_dlgproc(): WM_INITDIALOG Creation event not found, but someone might be waiting.");
// Making buttons flat
SendDlgItemMessage(hwndDlg, IDC_IMG_PREV, BUTTONSETASFLATBTN, TRUE, 0);
SendDlgItemMessage(hwndDlg, IDC_IMG_PREV, BM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadIconEx("previous", FALSE));
SendDlgItemMessage(hwndDlg, IDC_IMG_PREV, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Previous image"), BATF_UNICODE);
SendDlgItemMessage(hwndDlg, IDC_IMG_NEXT, BUTTONSETASFLATBTN, TRUE, 0);
SendDlgItemMessage(hwndDlg, IDC_IMG_NEXT, BM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadIconEx("next", FALSE));
SendDlgItemMessage(hwndDlg, IDC_IMG_NEXT, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Next image"), BATF_UNICODE);
SendDlgItemMessage(hwndDlg, IDC_IMG_SAVE, BUTTONSETASFLATBTN, TRUE, 0);
SendDlgItemMessage(hwndDlg, IDC_IMG_SAVE, BM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadIconEx("save", FALSE));
SendDlgItemMessage(hwndDlg, IDC_IMG_SAVE, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Save image to disk"), BATF_UNICODE);
SendDlgItemMessage(hwndDlg, IDC_IMG_DELETE, BUTTONSETASFLATBTN, TRUE, 0);
SendDlgItemMessage(hwndDlg, IDC_IMG_DELETE, BM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadIconEx("delete", FALSE));
SendDlgItemMessage(hwndDlg, IDC_IMG_DELETE, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Delete image from the list"), BATF_UNICODE);
// Set main window image
Window_SetIcon_IcoLib(hwndDlg, GetIconHandle(IDI_IMAGE));
wchar_t *szName = pcli->pfnGetContactDisplayName(dat->hContact, 0), szTitle[128];
if (dat->bReceiving)
mir_snwprintf(szTitle, TranslateT("Image from %s"), szName);
else
mir_snwprintf(szTitle, TranslateT("Image for %s"), szName);
SetWindowText(hwndDlg, szTitle);
// Store client extents
GetClientRect(hwndDlg, &rect);
dat->minSize.cx = rect.right - rect.left;
dat->minSize.cy = rect.bottom - rect.top;
}
return TRUE;
case WM_SIZE:
Utils_ResizeDialog(hwndDlg, hInstance, dat->bReceiving ? MAKEINTRESOURCEA(IDD_IMAGE_RECV) : MAKEINTRESOURCEA(IDD_IMAGE_SEND), sttImageDlgResizer);
if (wParam == SIZE_RESTORED || wParam == SIZE_MAXIMIZED)
InvalidateRect(hwndDlg, nullptr, FALSE);
return 0;
case WM_SIZING:
{
RECT *pRect = (RECT *)lParam;
if (pRect->right - pRect->left < dat->minSize.cx)
{
if (wParam == WMSZ_BOTTOMLEFT || wParam == WMSZ_LEFT || wParam == WMSZ_TOPLEFT)
pRect->left = pRect->right - dat->minSize.cx;
else
pRect->right = pRect->left + dat->minSize.cx;
}
if (pRect->bottom - pRect->top < dat->minSize.cy)
{
if (wParam == WMSZ_TOPLEFT || wParam == WMSZ_TOP || wParam == WMSZ_TOPRIGHT)
pRect->top = pRect->bottom - dat->minSize.cy;
else
pRect->bottom = pRect->top + dat->minSize.cy;
}
}
return TRUE;
case WM_CLOSE:
EndDialog(hwndDlg, 0);
break;
// Flash the window
case WM_TIMER:
if (wParam == TIMERID_FLASHWND)
FlashWindow(hwndDlg, TRUE);
break;
// Kill the timer
case WM_ACTIVATE:
if (LOWORD(wParam) != WA_ACTIVE)
break;
case WM_MOUSEACTIVATE:
if (KillTimer(hwndDlg, TIMERID_FLASHWND))
FlashWindow(hwndDlg, FALSE);
break;
case WM_PAINT:
if (dat->lpImages)
{
GGIMAGEENTRY *img = dat->lpImages;
int i;
for (i = 1; img && (i < dat->nImg); i++)
img = img->lpNext;
if (!img)
{
dat->gg->debugLogA("gg_img_dlgproc(): WM_PAINT Image was not found on the list. Cannot paint the window.");
return FALSE;
}
if (dat->bReceiving)
{
wchar_t szTitle[128];
mir_snwprintf(szTitle, L"%s (%d / %d)", img->lpszFileName, dat->nImg, dat->nImgTotal);
SetDlgItemText(hwndDlg, IDC_IMG_NAME, szTitle);
}
else
SetDlgItemText(hwndDlg, IDC_IMG_NAME, img->lpszFileName);
gg_img_paint(hwndDlg, img);
}
break;
case WM_DESTROY:
if (dat)
{
// Deleting all image entries
GGIMAGEENTRY *temp, *img = dat->lpImages;
GGPROTO *gg = dat->gg;
while (temp = img)
{
img = img->lpNext;
gg_img_releasepicture(temp);
}
ReleaseIconEx("previous", FALSE);
ReleaseIconEx("next", FALSE);
ReleaseIconEx("delete", FALSE);
ReleaseIconEx("save", FALSE);
Window_FreeIcon_IcoLib(hwndDlg);
gg->gg_EnterCriticalSection(&gg->img_mutex, "gg_img_dlgproc", 58, "img_mutex", 1);
list_remove(&gg->imagedlgs, dat, 1);
gg->gg_LeaveCriticalSection(&gg->img_mutex, "gg_img_dlgproc", 58, 1, "img_mutex", 1);
}
return TRUE;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDC_IMG_CANCEL:
EndDialog(hwndDlg, 0);
return TRUE;
case IDC_IMG_PREV:
if (dat->nImg > 1)
{
dat->nImg--;
InvalidateRect(hwndDlg, nullptr, FALSE);
}
return TRUE;
case IDC_IMG_NEXT:
if (dat->nImg < dat->nImgTotal)
{
dat->nImg++;
InvalidateRect(hwndDlg, nullptr, FALSE);
}
return TRUE;
case IDC_IMG_DELETE:
{
GGIMAGEENTRY *del, *img = dat->lpImages;
if (dat->nImg == 1)
{
del = dat->lpImages;
dat->lpImages = img->lpNext;
}
else
{
for (int i = 1; img && (i < dat->nImg - 1); i++)
img = img->lpNext;
if (!img)
{
dat->gg->debugLogA("gg_img_dlgproc(): IDC_IMG_DELETE Image was not found on the list. Cannot delete it from the list.");
return FALSE;
}
del = img->lpNext;
img->lpNext = del->lpNext;
dat->nImg --;
}
if ((-- dat->nImgTotal) == 0)
EndDialog(hwndDlg, 0);
else
InvalidateRect(hwndDlg, nullptr, FALSE);
gg_img_releasepicture(del);
}
return TRUE;
case IDC_IMG_SAVE:
{
GGIMAGEENTRY *img = dat->lpImages;
for (int i = 1; img && (i < dat->nImg); i++)
img = img->lpNext;
if (!img)
{
dat->gg->debugLogA("gg_img_dlgproc(): IDC_IMG_SAVE Image was not found on the list. Cannot launch saving.");
return FALSE;
}
gg_img_saveimage(hwndDlg, img);
}
return TRUE;
case IDC_IMG_SEND:
{
unsigned char format[20];
char *msg = "\xA0\0";
GGPROTO *gg = dat->gg;
if (dat->lpImages && gg->isonline())
{
uin_t uin = (uin_t)gg->getDword(dat->hContact, GG_KEY_UIN, 0);
struct gg_msg_richtext_format *r = nullptr;
struct gg_msg_richtext_image *p = nullptr;
int len;
((struct gg_msg_richtext*)format)->flag = 2;
r = (struct gg_msg_richtext_format *)(format + sizeof(struct gg_msg_richtext));
r->position = 0;
r->font = GG_FONT_IMAGE;
p = (struct gg_msg_richtext_image *)(format + sizeof(struct gg_msg_richtext) + sizeof(struct gg_msg_richtext_format));
p->unknown1 = 0x109;
p->size = dat->lpImages->nSize;
dat->lpImages->crc32 = p->crc32 = gg_fix32(gg_crc32(0, (BYTE*)dat->lpImages->lpData, dat->lpImages->nSize));
len = sizeof(struct gg_msg_richtext_format) + sizeof(struct gg_msg_richtext_image);
((struct gg_msg_richtext*)format)->length = len;
gg->gg_EnterCriticalSection(&gg->sess_mutex, "gg_img_dlgproc", 59, "sess_mutex", 1);
gg_send_message_richtext(gg->sess, GG_CLASS_CHAT, (uin_t)uin, (unsigned char*)msg, format, len + sizeof(struct gg_msg_richtext));
gg->gg_LeaveCriticalSection(&gg->sess_mutex, "gg_img_dlgproc", 59, 1, "sess_mutex", 1);
// Protect dat from releasing
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0);
EndDialog(hwndDlg, 0);
}
return TRUE;
}
break;
}
break;
case WM_ADDIMAGE: // lParam == GGIMAGEENTRY *dat
{
GGIMAGEENTRY *lpImage = (GGIMAGEENTRY *)lParam;
GGIMAGEENTRY *lpImages = dat->lpImages;
if (!dat->lpImages) // first image entry
dat->lpImages = lpImage;
else // adding at the end of the list
{
while (lpImages->lpNext)
lpImages = lpImages->lpNext;
lpImages->lpNext = lpImage;
}
dat->nImg = ++ dat->nImgTotal;
}
// Fit window to image
if (!gg_img_fit(hwndDlg))
InvalidateRect(hwndDlg, nullptr, FALSE);
return TRUE;
case WM_CHOOSEIMG:
{
wchar_t szFilter[128];
wchar_t szFileName[MAX_PATH];
OPENFILENAME ofn = {0};
gg_img_getfilter(szFilter, _countof(szFilter));
*szFileName = 0;
ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
ofn.hwndOwner = hwndDlg;
ofn.hInstance = hInstance;
ofn.lpstrFilter = szFilter;
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrTitle = TranslateT("Select picture to send");
ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
if (GetOpenFileName(&ofn))
{
if (dat->lpImages)
gg_img_releasepicture(dat->lpImages);
if (!(dat->lpImages = (GGIMAGEENTRY *)dat->gg->img_loadpicture(nullptr, szFileName)))
{
EndDialog(hwndDlg, 0);
return FALSE;
}
if (!gg_img_fit(hwndDlg))
InvalidateRect(hwndDlg, nullptr, FALSE);
}
else
{
EndDialog(hwndDlg, 0);
return FALSE;
}
return TRUE;
}
}
return FALSE;
}
////////////////////////////////////////////////////////////////////////////
// Image dialog call thread
//
void __cdecl GGPROTO::img_dlgcallthread(void *param)
{
HWND hMIWnd = nullptr;
debugLogA("img_dlgcallthread(): started.");
GGIMAGEDLGDATA *dat = (GGIMAGEDLGDATA *)param;
DialogBoxParam(hInstance, dat->bReceiving ? MAKEINTRESOURCE(IDD_IMAGE_RECV) : MAKEINTRESOURCE(IDD_IMAGE_SEND),
hMIWnd, gg_img_dlgproc, (LPARAM) dat);
#ifdef DEBUGMODE
debugLogA("img_dlgcallthread(): end.");
#endif
}
////////////////////////////////////////////////////////////////////////////
// Open dialog receive for specified contact
//
GGIMAGEDLGDATA *gg_img_recvdlg(GGPROTO *gg, MCONTACT hContact)
{
// Create dialog data
GGIMAGEDLGDATA *dat = (GGIMAGEDLGDATA *)calloc(1, sizeof(GGIMAGEDLGDATA));
dat->hContact = hContact;
dat->hEvent = CreateEvent(nullptr, TRUE, FALSE, nullptr);
dat->bReceiving = TRUE;
dat->gg = gg;
ResetEvent(dat->hEvent);
#ifdef DEBUGMODE
gg->debugLogA("gg_img_recvdlg(): ForkThread 18 GGPROTO::img_dlgcallthread");
#endif
gg->ForkThread(&GGPROTO::img_dlgcallthread, dat);
return dat;
}
////////////////////////////////////////////////////////////////////////////
// Checks if an image is already saved to the specified path
// Returns 1 if yes, 0 if no or -1 if different image on this path is found
//
int gg_img_isexists(wchar_t *szPath, GGIMAGEENTRY *dat)
{
struct _stat st;
if (_wstat(szPath, &st) != 0)
return 0;
if (st.st_size == dat->nSize)
{
FILE *fp = _wfopen(szPath, L"rb");
if (!fp) return 0;
char *lpData = (char*)mir_alloc(dat->nSize);
if (fread(lpData, 1, dat->nSize, fp) == dat->nSize)
{
if (dat->crc32 == gg_fix32(gg_crc32(0, (BYTE*)lpData, dat->nSize)) ||
memcmp(lpData, dat->lpData, dat->nSize) == 0)
{
mir_free(lpData);
fclose(fp);
return 1;
}
}
mir_free(lpData);
fclose(fp);
}
return -1;
}
////////////////////////////////////////////////////////////////////////////
// Determine if image's file name has the proper extension
//
wchar_t *gg_img_hasextension(wchar_t *filename)
{
if (filename != nullptr && *filename != '\0')
{
wchar_t *imgtype = wcsrchr(filename, '.');
if (imgtype != nullptr)
{
size_t len = mir_wstrlen(imgtype);
imgtype++;
if (len == 4 && (mir_wstrcmpi(imgtype, L"bmp") == 0 ||
mir_wstrcmpi(imgtype, L"gif") == 0 ||
mir_wstrcmpi(imgtype, L"jpg") == 0 ||
mir_wstrcmpi(imgtype, L"png") == 0))
return --imgtype;
if (len == 5 && mir_wstrcmpi(imgtype, L"jpeg") == 0)
return --imgtype;
}
}
return nullptr;
}
////////////////////////////////////////////////////////////////////////////////
// Display received image using message with [img] BBCode
//
int GGPROTO::img_displayasmsg(MCONTACT hContact, void *img)
{
GGIMAGEENTRY *dat = (GGIMAGEENTRY *)img;
wchar_t szPath[MAX_PATH], path[MAX_PATH], *pImgext, imgext[6];
size_t tPathLen;
int i, res;
if (hImagesFolder == nullptr || FoldersGetCustomPathT(hImagesFolder, path, MAX_PATH, L"")) {
wchar_t *tmpPath = Utils_ReplaceVarsW( L"%miranda_userdata%");
tPathLen = mir_snwprintf(szPath, L"%s\\%s\\ImageCache", tmpPath, m_tszUserName);
mir_free(tmpPath);
}
else {
mir_wstrcpy(szPath, path);
tPathLen = mir_wstrlen(szPath);
}
if ( _waccess(szPath, 0)){
int ret = CreateDirectoryTreeW(szPath);
if (ret == 0){
debugLogW(L"img_displayasmsg(): Created new directory for image cache: %s.", szPath);
} else {
debugLogW(L"img_displayasmsg(): Can not create directory for image cache: %s. errno=%d: %s", szPath, errno, strerror(errno));
wchar_t error[512];
mir_snwprintf(error, TranslateT("Cannot create image cache directory. ERROR: %d: %s\n%s"), errno, _tcserror(errno), szPath);
showpopup(m_tszUserName, error, GG_POPUP_ERROR | GG_POPUP_ALLOW_MSGBOX | GG_POPUP_ONCE);
}
}
mir_snwprintf(szPath + tPathLen, MAX_PATH - tPathLen, L"\\%s", dat->lpszFileName);
if ((pImgext = gg_img_hasextension(szPath)) == nullptr)
pImgext = szPath + mir_wstrlen(szPath);
wcsncpy_s(imgext, pImgext, _TRUNCATE);
for (i = 1; ; ++i)
{
if ((res = gg_img_isexists(szPath, dat)) != -1) break;
mir_snwprintf(szPath, L"%.*s (%u)%s", pImgext - szPath, szPath, i, imgext);
}
if (res == 0) {
// Image file not found, thus create it
FILE *fp = _wfopen(szPath, L"w+b");
if (fp) {
res = fwrite(dat->lpData, dat->nSize, 1, fp) > 0;
fclose(fp);
} else {
debugLogW(L"img_displayasmsg(): Cannot open file %s for write image. errno=%d: %s", szPath, errno, strerror(errno));
wchar_t error[512];
mir_snwprintf(error, TranslateT("Cannot save received image to file. ERROR: %d: %s\n%s"), errno, _tcserror(errno), szPath);
showpopup(m_tszUserName, error, GG_POPUP_ERROR);
return 0;
}
}
if (res != 0) {
wchar_t image_msg[MAX_PATH + 11];
mir_snwprintf(image_msg, L"[img]%s[/img]", szPath);
T2Utf szMessage(image_msg);
PROTORECVEVENT pre = {0};
pre.timestamp = time(nullptr);
pre.szMessage = szMessage;
ProtoChainRecvMsg(hContact, &pre);
debugLogW(L"img_displayasmsg(): Image saved to %s.", szPath);
}
else debugLogW(L"img_displayasmsg(): Cannot save image to %s.", szPath);
return 0;
}
////////////////////////////////////////////////////////////////////////////
// Return if uin has it's window already opened
//
BOOL GGPROTO::img_opened(uin_t uin)
{
list_t l = imagedlgs;
while (l)
{
GGIMAGEDLGDATA *dat = (GGIMAGEDLGDATA *)l->data;
if (dat->uin == uin)
return TRUE;
l = l->next;
}
return FALSE;
}
////////////////////////////////////////////////////////////////////////////
// Image Module : Looking for window entry, create if not found
//
int GGPROTO::img_display(MCONTACT hContact, void *img)
{
list_t l = imagedlgs;
GGIMAGEDLGDATA *dat = nullptr;
if (!img) return FALSE;
// Look for already open dialog
gg_EnterCriticalSection(&img_mutex, "img_display", 60, "img_mutex", 1);
while (l)
{
dat = (GGIMAGEDLGDATA *)l->data;
if (dat->bReceiving && dat->hContact == hContact)
break;
l = l->next;
}
if (!l) dat = nullptr;
if (!dat)
{
dat = gg_img_recvdlg(this, hContact);
dat->uin = getDword(hContact, GG_KEY_UIN, 0);
while (WaitForSingleObjectEx(dat->hEvent, INFINITE, TRUE) != WAIT_OBJECT_0);
CloseHandle(dat->hEvent);
dat->hEvent = nullptr;
list_add(&imagedlgs, dat, 0);
}
gg_LeaveCriticalSection(&img_mutex, "img_display", 60, 1, "img_mutex", 1);
SendMessage(dat->hWnd, WM_ADDIMAGE, 0, (LPARAM)img);
if (/*db_get_b(NULL, "Chat", "bFlashWindowHighlight", 0) != 0 && */
GetActiveWindow() != dat->hWnd && GetForegroundWindow() != dat->hWnd)
SetTimer(dat->hWnd, TIMERID_FLASHWND, 900, nullptr);
return TRUE;
}
////////////////////////////////////////////////////////////////////////////
// Helper function to determine image file format and the right extension
//
const wchar_t *gg_img_guessfileextension(const char *lpData)
{
if (lpData != nullptr)
{
if (memcmp(lpData, "BM", 2) == 0)
return L".bmp";
if (memcmp(lpData, "GIF8", 4) == 0)
return L".gif";
if (memcmp(lpData, "\xFF\xD8", 2) == 0)
return L".jpg";
if (memcmp(lpData, "\x89PNG", 4) == 0)
return L".png";
}
return L"";
}
////////////////////////////////////////////////////////////////////////////
// Image Window : Loading picture and sending for display
//
void* GGPROTO::img_loadpicture(gg_event* e, wchar_t *szFileName)
{
if (!szFileName &&
(!e || !e->event.image_reply.size || !e->event.image_reply.image || !e->event.image_reply.filename))
return nullptr;
GGIMAGEENTRY *dat = (GGIMAGEENTRY *)calloc(1, sizeof(GGIMAGEENTRY));
if (dat == nullptr)
return nullptr;
// Copy the file name
if (szFileName)
{
FILE *fp = _wfopen(szFileName, L"rb");
if (!fp) {
free(dat);
debugLogW(L"img_loadpicture(): fopen(\"%s\", \"rb\" failed. errno=%d: %s)", szFileName, errno, strerror(errno));
wchar_t error[512];
mir_snwprintf(error, TranslateT("Cannot open image file. ERROR: %d: %s\n%s"), errno, _tcserror(errno), szFileName);
showpopup(m_tszUserName, error, GG_POPUP_ERROR);
return nullptr;
}
fseek(fp, 0, SEEK_END);
dat->nSize = ftell(fp);
if (dat->nSize <= 0)
{
fclose(fp);
free(dat);
debugLogW(L"img_loadpicture(): Zero file size \"%s\" failed.", szFileName);
return nullptr;
}
// Maximum acceptable image size
if (dat->nSize > 255 * 1024)
{
fclose(fp);
free(dat);
debugLogW(L"img_loadpicture(): Image size of \"%s\" exceeds 255 KB.", szFileName);
MessageBox(nullptr, TranslateT("Image exceeds maximum allowed size of 255 KB."), m_tszUserName, MB_OK | MB_ICONEXCLAMATION);
return nullptr;
}
fseek(fp, 0, SEEK_SET);
dat->lpData = (char*)malloc(dat->nSize);
if (fread(dat->lpData, 1, dat->nSize, fp) < dat->nSize)
{
free(dat->lpData);
fclose(fp);
free(dat);
debugLogW(L"img_loadpicture(): Reading file \"%s\" failed.", szFileName);
return nullptr;
}
fclose(fp);
dat->lpszFileName = wcsdup(szFileName);
}
// Copy picture from packet
else if (e && e->event.image_reply.filename)
{
dat->nSize = e->event.image_reply.size;
dat->lpData = (char*)malloc(dat->nSize);
memcpy(dat->lpData, e->event.image_reply.image, dat->nSize);
ptrW tmpFileName( mir_a2u(e->event.image_reply.filename));
if (!gg_img_hasextension(tmpFileName)) {
// Add missing file extension
const wchar_t *szImgType = gg_img_guessfileextension(dat->lpData);
if (*szImgType) {
dat->lpszFileName = (wchar_t*)calloc(sizeof(wchar_t), mir_wstrlen(tmpFileName) + mir_wstrlen(szImgType) + 1);
if (dat->lpszFileName != nullptr) {
mir_wstrcpy(dat->lpszFileName, tmpFileName);
mir_wstrcat(dat->lpszFileName, szImgType);
}
}
}
if (dat->lpszFileName == nullptr)
dat->lpszFileName = wcsdup( _A2T( e->event.image_reply.filename));
}
////////////////////////////////////////////////////////////////////
// Loading picture using Miranda Image services
// Load image from memory
if (!szFileName)
{
IMGSRVC_MEMIO memio;
memio.iLen = dat->nSize;
memio.pBuf = (void *)dat->lpData;
memio.fif = FIF_UNKNOWN; /* detect */
memio.flags = 0;
dat->hBitmap = (HBITMAP) CallService(MS_IMG_LOADFROMMEM, (WPARAM) &memio, 0);
}
// Load image from file
else
dat->hBitmap = (HBITMAP) CallService(MS_IMG_LOAD, (WPARAM) szFileName, IMGL_WCHAR);
// If everything is fine return the handle
if (dat->hBitmap) return dat;
debugLogA("img_loadpicture(): MS_IMG_LOAD(MEM) failed.");
if (dat)
{
free(dat->lpData);
free(dat->lpszFileName);
free(dat);
}
return nullptr;
}
////////////////////////////////////////////////////////////////////////////
// Image Recv : AddEvent proc
//
INT_PTR GGPROTO::img_recvimage(WPARAM wParam, LPARAM lParam)
{
CLISTEVENT *cle = (CLISTEVENT *)lParam;
GGIMAGEENTRY *img = (GGIMAGEENTRY *)cle->lParam;
debugLogA("img_recvimage(%x, %x): Popup new image.", wParam, lParam);
if (!img) return FALSE;
img_display(cle->hContact, img);
return FALSE;
}
////////////////////////////////////////////////////////////////////////////
// Windows queue management
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
// Removes dat structure
//
int gg_img_remove(GGIMAGEDLGDATA *dat)
{
GGIMAGEENTRY *temp = nullptr, *img = nullptr;
GGPROTO *gg;
if (!dat) return FALSE;
gg = dat->gg;
gg->gg_EnterCriticalSection(&gg->img_mutex, "gg_img_remove", 61, "img_mutex", 1);
// Remove the structure
img = dat->lpImages;
// Destroy picture handle
while (temp = img)
{
img = img->lpNext;
gg_img_releasepicture(temp);
}
// Remove from list
list_remove(&gg->imagedlgs, dat, 1);
gg->gg_LeaveCriticalSection(&gg->img_mutex, "gg_img_remove", 61, 1, "img_mutex", 1);
return TRUE;
}
////////////////////////////////////////////////////////////////////////////
//
GGIMAGEDLGDATA* gg_img_find(GGPROTO *gg, uin_t uin, uint32_t crc32)
{
list_t l = gg->imagedlgs;
GGIMAGEDLGDATA *dat;
gg->gg_EnterCriticalSection(&gg->img_mutex, "gg_img_find", 62, "img_mutex", 1);
while (l)
{
uin_t c_uin;
dat = (GGIMAGEDLGDATA *)l->data;
if (!dat) break;
c_uin = dat->gg->getDword(dat->hContact, GG_KEY_UIN, 0);
if (!dat->bReceiving && dat->lpImages && dat->lpImages->crc32 == crc32 && c_uin == uin)
{
gg->gg_LeaveCriticalSection(&gg->img_mutex, "gg_img_find", 62, 1, "img_mutex", 1);
return dat;
}
l = l->next;
}
gg->gg_LeaveCriticalSection(&gg->img_mutex, "gg_img_find", 62, 2, "img_mutex", 1);
gg->debugLogA("gg_img_find(): Image not found on the list. It might be released before calling this function.");
return nullptr;
}
////////////////////////////////////////////////////////////////////////////
// Image Module : Send on Request
//
BOOL GGPROTO::img_sendonrequest(gg_event* e)
{
GGIMAGEDLGDATA *dat = gg_img_find(this, e->event.image_request.sender, e->event.image_request.crc32);
if (!dat || !isonline())
return FALSE;
char* lpszFileNameA = mir_u2a(dat->lpImages->lpszFileName);
gg_EnterCriticalSection(&sess_mutex, "img_sendonrequest", 63, "sess_mutex", 1);
gg_image_reply(sess, e->event.image_request.sender, lpszFileNameA, dat->lpImages->lpData, dat->lpImages->nSize);
gg_LeaveCriticalSection(&sess_mutex, "img_sendonrequest", 63, 1, "sess_mutex", 1);
mir_free(lpszFileNameA);
gg_img_remove(dat);
return TRUE;
}
////////////////////////////////////////////////////////////////////////////
// Send Image : Run (Thread and main)
//
INT_PTR GGPROTO::img_sendimg(WPARAM hContact, LPARAM)
{
GGIMAGEDLGDATA *dat = nullptr;
gg_EnterCriticalSection(&img_mutex, "img_sendimg", 64, "img_mutex", 1);
if (!dat)
{
dat = (GGIMAGEDLGDATA *)calloc(1, sizeof(GGIMAGEDLGDATA));
dat->hContact = hContact;
dat->hEvent = CreateEvent(nullptr, TRUE, FALSE, nullptr);
dat->gg = this;
ResetEvent(dat->hEvent);
// Create new dialog
#ifdef DEBUGMODE
debugLogA("img_sendimg(): ForkThread 19 GGPROTO::img_dlgcallthread");
#endif
ForkThread(&GGPROTO::img_dlgcallthread, dat);
while (WaitForSingleObjectEx(dat->hEvent, INFINITE, TRUE) != WAIT_OBJECT_0);
CloseHandle(dat->hEvent);
dat->hEvent = nullptr;
list_add(&imagedlgs, dat, 0);
}
// Request choose dialog
SendMessage(dat->hWnd, WM_CHOOSEIMG, 0, 0);
gg_LeaveCriticalSection(&img_mutex, "img_sendimg", 64, 1, "img_mutex", 1);
return 0;
}
|