-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexportToJpeg_Form.frm
executable file
·988 lines (834 loc) · 34.5 KB
/
exportToJpeg_Form.frm
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
VERSION 5.00
Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} exportToJpeg_Form
Caption = "expJpg"
ClientHeight = 5430
ClientLeft = 45
ClientTop = 405
ClientWidth = 3600
OleObjectBlob = "exportToJpeg_Form.frx":0000
StartUpPosition = 1 'CenterOwner
End
Attribute VB_Name = "exportToJpeg_Form"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public myWidth&, myBatExe$, sAspectRat$
Public wBool As Boolean, hBool As Boolean
Private sanUI&
Private macroAdURL$, IsOwer As Boolean
Private r0 As wRECT, cp0 As wPOINT, sx&, sy&
#If VBA7 Then
Private Declare PtrSafe Function FindWindowExW& Lib "user32" (ByVal hParent&, ByVal hChildAfter&, ByVal lpClassW&, ByVal lpTitleW&)
Private Declare PtrSafe Function SendMessageW& Lib "user32" (ByVal hwnd&, ByVal msg&, ByVal wParam&, ByVal lParam&)
Private Declare PtrSafe Function GetSystemMetrics& Lib "user32" (ByVal Index As wEnumSystemMetrics)
Private Declare PtrSafe Function SetWindowPos& Lib "user32" (ByVal hwnd&, ByVal hAfter&, ByVal X&, ByVal Y&, ByVal cx&, ByVal cy&, ByVal wFlags As wEnumSetWindowPos)
Private Declare PtrSafe Function GetWindowRect& Lib "user32" (ByVal hwnd&, r As wRECT)
Private Declare PtrSafe Function GetCursorPos& Lib "user32" (p As wPOINT)
Private Declare PtrSafe Function SetWindowLongW& Lib "user32" (ByVal hwnd&, ByVal nIndex%, ByVal dwNewLong&)
Private Declare PtrSafe Function GetWindowLongW& Lib "user32" (ByVal hwnd&, ByVal nIndex%)
Private Declare PtrSafe Function SetLayeredWindowAttributes& Lib "user32" (ByVal hwnd&, ByVal crKey%, ByVal bAlpha As Byte, ByVal dwFlags&)
Private Declare PtrSafe Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare PtrSafe Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare PtrSafe Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
Private Declare PtrSafe Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare PtrSafe Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Private Declare PtrSafe Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
#Else
Private Declare Function FindWindowExW& Lib "user32" (ByVal hParent&, ByVal hChildAfter&, ByVal lpClassW&, ByVal lpTitleW&)
Private Declare Function SendMessageW& Lib "user32" (ByVal hwnd&, ByVal msg&, ByVal wParam&, ByVal lParam&)
Private Declare Function GetSystemMetrics& Lib "user32" (ByVal Index As wEnumSystemMetrics)
Private Declare Function SetWindowPos& Lib "user32" (ByVal hwnd&, ByVal hAfter&, ByVal X&, ByVal Y&, ByVal cx&, ByVal cy&, ByVal wFlags As wEnumSetWindowPos)
Private Declare Function GetWindowRect& Lib "user32" (ByVal hwnd&, r As wRECT)
Private Declare Function GetCursorPos& Lib "user32" (p As wPOINT)
Private Declare Function SetWindowLongW& Lib "user32" (ByVal hwnd&, ByVal nIndex%, ByVal dwNewLong&)
Private Declare Function GetWindowLongW& Lib "user32" (ByVal hwnd&, ByVal nIndex%)
Private Declare Function SetLayeredWindowAttributes& Lib "user32" (ByVal hwnd&, ByVal crKey%, ByVal bAlpha As Byte, ByVal dwFlags&)
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
#End If
Private Enum wEnumSystemMetrics: SM_CXScreen = 0: SM_CYScreen = 1: End Enum
Private Enum wEnumSetWindowPos: SWP_NOSIZE = 1: SWP_NOMOVE = 2: SWP_NOZORDER = 4: SWP_NOREDRAW = 8: SWP_NOACTIVATE = 16: _
SWP_DRAWFRAME = 32: SWP_SHOWWINDOW = 64: SWP_HIDEWINDOW = 128: SWP_NOCOPYBITS = 256: SWP_NOREPOSITION = 512: _
SWP_NOSENDCHANGING = 1024: SWP_DEFERERASE = 8192: SWP_ASYNCWINDOWPOS = 16384: End Enum
Private Type wPOINT: X As Long: Y As Long: End Type
Private Type wRECT: l As Long: t As Long: r As Long: b As Long: End Type
Const REG_SZ = 1 ' Unicode nul terminated string
Const REG_BINARY = 3 ' Free form binary
Private Sub cm_close_Click()
Unload Me
End Sub
Private Sub Command_OK_Click()
Dim d As Document, opt As New StructExportOptions, p$, p2$
Dim myColorType&, sn$, myPage As Page, oldPage As Page, myFold$, c&, c2&
Dim myStrPage$
Me.meHead.Caption = Me.meHead.Caption & " (%)"
IsOwer = False
Set d = ActiveDocument: c2 = 1
Set oldPage = ActivePage
If myWorkMetod = "Selection" Then _
If ActiveShape Is Nothing Then MsgBox "Not selected! ", vbCritical, "Exp2JPG": Exit Sub
If d.Pages.Count = 1 And myWorkMetod = "All Page" Then myWorkMetod = "Active Page": Exit Sub
'=============================================================================
sn = nameprefix_TextBox.Text
If myWorkMetod = "Selection" Then sn = sn & "_" & tb_AfterName.Text
'If myWorkMetod <> "All Page" Then sn = tb_AfterName.Text Else sn = ""
'If prefix_CheckBox.Value = True Then & sn
'=============================================================================
If myCmpress.Value < 0 Or myCmpress.Value > 100 Then MsgBox "Wrong values are set!": Exit Sub
If Smoot.Value < 0 Or Smoot.Value > 100 Then MsgBox "Wrong values are set!": Exit Sub
Select Case myColorMode.ListIndex
Case 0: myColorType = 2
Case 1: myColorType = 5
Case 2: myColorType = 4
End Select
With opt
.AntiAliasingType = AntiAliasing_CheckBox.Value
'.Compression = cdrCompressionJPEG
.ImageType = myColorType
.MaintainAspect = CLng(sAspectRat)
.MaintainLayers = False
.ResolutionX = CLng(Dpi_TextBox.Text)
.ResolutionY = CLng(Dpi_TextBox.Text)
.SizeX = CLng(bwidth.Text)
.SizeY = CLng(bheight.Text)
.Transparent = False
.UseColorProfile = profile_CheckBox.Value
.Overwrite = False
End With
myFold = folder_TextBox.Text
If Right$(myFold, 1) <> "\" Then myFold = myFold & "\"
'=============================================================================
Select Case myWorkMetod
Case "Selection"
p = myFold & sn & ".jpg"
If exportToJpeg2(p, opt) Then
If mUse = True Then mySendMail p
End If
Case "Active Page"
If ActivePage.Shapes.Count = 0 Then MsgBox "Shapes Count = 0": Exit Sub
p = myFold & sn & "_" & ActivePage.Index & ".jpg"
If exportToJpeg2(p, opt) Then
If mUse = True Then mySendMail p
End If
Case "All Page"
If d.Pages.Count < 2 Then Exit Sub
For c = 1 To d.Pages.Count
If d.Pages(c).Shapes.Count > 0 Then
d.Pages(c).Activate
p = myFold & sn & "_" & c2 & ".jpg": c2 = c2 + 1
If exportToJpeg2(p, opt) Then
If mUse = True And myMultSend = False Then
If c = 1 Then p2 = p
If c > 1 Then p2 = p2 & "|" & p
End If
If mUse = True And myMultSend = True Then mySendMail p
End If
End If
Next c
If mUse = True And myMultSend = False Then mySendMail p2
Case "Page:"
myStrPage = getNumPage(myPageIndex.Text)
For Each a In Split(myStrPage, ",")
c = CLng(a)
If d.Pages(c).Shapes.Count > 0 Then
d.Pages(c).Activate
p = myFold & sn & "_" & c & ".jpg"
If exportToJpeg2(p, opt) Then
If mUse = True And myMultSend = False Then
If c = 1 Then p2 = p
If c > 1 Then p2 = p2 & "|" & p
End If
If mUse = True And myMultSend = True Then mySendMail p
End If
End If
Next a
If mUse = True And myMultSend = False Then mySendMail p2
End Select
'=============================================================================
oldPage.Activate
myListsSave
Me.meHead.Caption = Left$(Me.meHead.Caption, Len(Me.meHead.Caption) - 4)
End Sub
Private Function exportToJpeg2(p$, opt As StructExportOptions) As Boolean
Dim ex As ExportFilter, d As Document, myMsg&
Set d = ActiveDocument
If FileSystem.Dir(p) <> "" And IsOwer = False Then
myMsg = MsgBox("File already exists" & vbCr & "Overwrite (all)?", vbOKCancel + vbExclamation, "Warning...")
If myMsg = 1 Then
opt.Overwrite = True
IsOwer = True
Else
exportToJpeg2 = False
Exit Function
End If
End If
If myWorkMetod = "Selection" Then
Set ex = d.ExportEx(p, cdrJPEG, cdrSelection, opt)
Else
Set ex = d.ExportEx(p, cdrJPEG, cdrCurrentPage, opt)
End If
With ex
If jpgEncod.Text = "Progressive" Then
.Progressive = True
.Optimized = False
ElseIf jpgEncod.Text = "Optimized" Then
.Progressive = False
.Optimized = True
End If
.SubFormat = 0
.Compression = CLng(myCmpress.Text)
.Smoothing = CLng(Smoot.Text)
.Finish
End With
exportToJpeg2 = True
End Function
Private Function getNumPage$(myPageIn$)
Dim a$(), a2$(), i&, i2&
getNumPage = ""
a = Split(myPageIn, ",", , vbTextCompare)
For i = 0 To UBound(a)
a2 = Split(a(i), "-", , vbTextCompare)
If UBound(a2) > 0 Then
If a2(UBound(a2)) > a2(0) Then
For i2 = CLng(a2(0)) To CLng(a2(UBound(a2)))
If getNumPage = "" Then getNumPage = i2 _
Else getNumPage = getNumPage & "," & i2
Next i2
Else
MsgBox "incorrect number order! ", vbCritical, "Exp2JPG"
End If
Else
If getNumPage = "" Then getNumPage = CLng(a(i)) _
Else getNumPage = getNumPage & "," & CLng(a(i))
End If
Next
End Function
Private Sub mySendMail(txtAttachementFileLocation As String)
Dim txtMainAddresses As String, txtSubject As String, txtUser$
s = txtAttachementFileLocation
s = Replace(s, "|", Chr(34) & ";ATTACH=" & Chr(34))
txtAttachementFileLocation = s
'"c:\thebat\thebat.exe" /MAIL;[email protected];USER="Íàçâàíèå ÿùèêà";SUBJECT="Hello";ATTACH="c:\thebat\tips.ini"
Dim sText As String
Dim sAddedText As String
If myBatExe = "" Then
MsgBox "TheBat not found", vbCritical
Exit Sub
End If
txtMainAddresses = mAddres.Text
txtSubject = mSubject.Text
txtUser = myAccount.Text
If Len(txtMainAddresses) Then
sText = Chr(34) & txtMainAddresses & Chr(34)
End If
If Len(txtUser) Then _
sAddedText = sAddedText & ";USER=" & Chr(34) & txtUser & Chr(34)
If Len(txtSubject) Then _
sAddedText = sAddedText & ";SUBJECT=" & Chr(34) & txtSubject & Chr(34)
If Len(txtAttachementFileLocation) Then _
sAddedText = sAddedText & ";ATTACH=" & Chr(34) & _
txtAttachementFileLocation & Chr(34)
sText = Chr(34) & myBatExe & Chr(34) & " /MAIL;TO=" & sText
sText = sText & sAddedText
If Len(sText) Then
ReturnValue = Shell(sText, vbMaximizedFocus)
End If
End Sub
Private Sub Command_OK_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Command_OK.SpecialEffect = fmSpecialEffectSunken
End Sub
Private Sub Command_OK_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Command_OK.BackColor = vbWhite
Command_OK.SpecialEffect = fmSpecialEffectRaised
End Sub
Private Sub folder_TextBox_Change()
SaveSetting "SanchoCorelVBA", "ExportToJpg", "folder2", folder_TextBox
folder_TextBox.ControlTipText = "Folder: " & folder_TextBox.Text
End Sub
Private Sub folder_TextBox_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
folder_TextBox.Text = ActiveDocument.FilePath
SaveSetting "SanchoCorelVBA", "ExportToJpg", "folder2", folder_TextBox
End Sub
Private Sub mAddres_Change()
SaveSetting "SanchoCorelVBA", "ExportToJpg", "mAddres2", mAddres
End Sub
Private Sub mSubject_Change()
SaveSetting "SanchoCorelVBA", "ExportToJpg", "mSubject2", mSubject
End Sub
Private Sub myPageIndex_Change()
s = myPageIndex.Text
s = Replace(s, ".", ",")
myPageIndex.Text = s
SaveSetting "SanchoCorelVBA", "ExportToJpg", "myPageIndex", myPageIndex
myPageIndex.ControlTipText = "Pages: " & myPageIndex.Text
End Sub
Private Sub tb_AfterName_Change()
SaveSetting "SanchoCorelVBA", "ExportToJpg", "name", tb_AfterName
End Sub
Private Sub Command_folder_Click()
Dim myFolder$
myFolder = Application.CorelScriptTools.GetFolder(folder_TextBox.Text, "Export to...")
If myFolder = "" Then Exit Sub
folder_TextBox.Text = myFolder
End Sub
Private Sub Dpi_TextBox_Change()
SaveSetting "SanchoCorelVBA", "ExportToJpg", "dpi", Dpi_TextBox.Text
If Dpi_TextBox.Value < 0 Or Dpi_TextBox.Value > 600 Then
Dpi_TextBox.ForeColor = vbRed
Else
Dpi_TextBox.ForeColor = &H80000012
End If
If bwidth.Text = "0" Then myColculateSizeNull
End Sub
Private Sub nameprefix_TextBox_Change()
SaveSetting "SanchoCorelVBA", "ExportToJpg", "name prefix text", nameprefix_TextBox
End Sub
Private Sub nameprefix_TextBox_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
nameprefix_TextBox.Text = Replace(CorelDRAW.ActiveDocument.Name, ".cdr", "")
End Sub
'Private Sub prefix_CheckBox_Click()
' SaveSetting "SanchoCorelVBA", "ExportToJpg", "name prefix", IIf(prefix_CheckBox, "1", "0")
' namePrefixEn
'End Sub
'Private Sub namePrefixEn()
' If prefix_CheckBox = False Then
' nameprefix_TextBox.Enabled = False
' Else
' nameprefix_TextBox.Enabled = True
' End If
'End Sub
Private Sub myColorMode_Change()
SaveSetting "SanchoCorelVBA", "ExportToJpg", "ColorMode", myColorMode
End Sub
Private Sub bwidth_Change()
SaveSetting "SanchoCorelVBA", "ExportToJpg", "width", bwidth
If bwidth.Value < 0 Or bwidth.Value > 10000 Then
bwidth.ForeColor = vbRed
Else
bwidth.ForeColor = &H80000012
End If
If sAspectRat = "1" Then _
If wBool Then If bwidth.Text <> "" Then myColculateSize "w"
If bwidth.Text = "0" Then myColculateSizeNull Else bwidth.ControlTipText = ""
End Sub
Private Sub bwidth_Enter()
wBool = True
End Sub
Private Sub bwidth_Exit(ByVal Cancel As MSForms.ReturnBoolean)
wBool = False
End Sub
Private Sub bheight_Change()
SaveSetting "SanchoCorelVBA", "ExportToJpg", "height", bheight
If bheight.Value < 0 Or bheight.Value > 10000 Then
bheight.ForeColor = vbRed
Else
bheight.ForeColor = &H80000012
End If
If sAspectRat = "1" Then _
If hBool Then If bheight.Text <> "" Then myColculateSize "h"
If bheight.Text = "0" Then myColculateSizeNull Else bheight.ControlTipText = ""
End Sub
Private Sub bheight_Enter()
hBool = True
End Sub
Private Sub bheight_Exit(ByVal Cancel As MSForms.ReturnBoolean)
hBool = False
End Sub
Private Sub myColculateSize(st$)
Dim sr As ShapeRange, w#, h#, d As Document, oldUn As cdrUnit, myPes#
Set sr = New ShapeRange
Set d = ActiveDocument
oldUn = d.Unit: d.Unit = cdrInch
Select Case myWorkMetod
Case "Selection"
Set sr = ActiveSelectionRange
If sr.Count = 0 Then Exit Sub
sr.GetSize w, h
w = w * Dpi_TextBox.Value
h = h * Dpi_TextBox.Value
If st = "w" Then
myPes = bwidth.Value * 100 / w
bheight.Value = CLng((myPes * h) / 100)
ElseIf st = "h" Then
myPes = bheight.Value * 100 / h
bwidth.Value = CLng((myPes * w) / 100)
End If
'Case "Active Page"
'Case "All Page"
'Case "Page:"
End Select
d.Unit = oldUn
End Sub
Private Sub myColculateSizeNull()
Dim sr As ShapeRange, w#, h#, d As Document, oldUn As cdrUnit
Set sr = New ShapeRange
Set d = ActiveDocument
oldUn = d.Unit: d.Unit = cdrInch
Set sr = ActiveSelectionRange
If sr.Count = 0 Then Exit Sub
sr.GetSize w, h
bwidth.ControlTipText = CLng(w * Dpi_TextBox.Value)
bheight.ControlTipText = CLng(h * Dpi_TextBox.Value)
d.Unit = oldUn
End Sub
Private Sub cm_AspectRat_dis_Click()
cm_AspectRat_dis.Move 137, 79
cm_AspectRat_en.Move 90, 79
SaveSetting "SanchoCorelVBA", "ExportToJpg", "sAspectRat", "0"
sAspectRat = "0"
End Sub
Private Sub cm_AspectRat_en_Click()
cm_AspectRat_en.Move 137, 79
cm_AspectRat_dis.Move 90, 79
SaveSetting "SanchoCorelVBA", "ExportToJpg", "sAspectRat", "1"
sAspectRat = "1"
If bwidth.Text <> "" Then myColculateSize "w"
End Sub
Private Sub cm_AspectRatMove()
If sAspectRat = "1" Then
cm_AspectRat_en.Move 137, 79
cm_AspectRat_dis.Move 90, 79
Else
cm_AspectRat_dis.Move 137, 79
cm_AspectRat_en.Move 90, 79
End If
End Sub
Private Sub profile_CheckBox_Click()
SaveSetting "SanchoCorelVBA", "ExportToJpg", "profile", IIf(profile_CheckBox, "1", "0")
End Sub
Private Sub AntiAliasing_CheckBox_Click()
SaveSetting "SanchoCorelVBA", "ExportToJpg", "AntiAliasing", IIf(AntiAliasing_CheckBox, "1", "0")
End Sub
Private Sub jpgEncod_Change()
SaveSetting "SanchoCorelVBA", "ExportToJpg", "EncodingMethod", jpgEncod
End Sub
Private Sub myCmpress_Change()
SaveSetting "SanchoCorelVBA", "ExportToJpg", "myCmpress", myCmpress
If myCmpress.Value < 0 Or myCmpress.Value > 100 Then
myCmpress.ForeColor = vbRed
Else
myCmpress.ForeColor = &H80000012
End If
End Sub
Private Sub Smoot_Change()
SaveSetting "SanchoCorelVBA", "ExportToJpg", "Smoot", Smoot
If Smoot.Value < 0 Or Smoot.Value > 100 Then
Smoot.ForeColor = vbRed
Else
Smoot.ForeColor = &H80000012
End If
End Sub
Private Sub myWorkMetod_Change()
SaveSetting "SanchoCorelVBA", "ExportToJpg", "myWorkMetod", myWorkMetod
myWorkMetod2
End Sub
Private Sub myWorkMetod2()
If myWorkMetod.Text = "All Page" Then
If mUse = 0 Then
myMultSend.Enabled = False
Else
myMultSend.Enabled = True
End If
myPageIndex.Enabled = False
myPageIndex.BackColor = &H8000000F
ElseIf myWorkMetod.Text = "Page:" Then
If mUse = 0 Then
myMultSend.Enabled = False
Else
myMultSend.Enabled = True
End If
myPageIndex.Enabled = True
myPageIndex.BackColor = &H80000005
ElseIf myWorkMetod.Text = "Selection" Then
myMultSend.Enabled = False
myPageIndex.Enabled = False
myPageIndex.BackColor = &H8000000F
If bwidth.Text <> "" Then myColculateSize "w"
If bwidth.Text = "0" Then myColculateSizeNull
ElseIf myWorkMetod.Text = "Active Page" Then
myMultSend.Enabled = False
myPageIndex.Enabled = False
myPageIndex.BackColor = &H8000000F
End If
End Sub
Private Sub mTheBatEXE_Click()
Dim myFolder$
myTheBat_exe = Application.CorelScriptTools.GetFileBox("TheBat (*.exe)|*.exe", "TheBat.exe...", 1, , , , "OK")
If myTheBat_exe = "" Then Exit Sub
myBatExe = myTheBat_exe
SaveSetting "SanchoCorelVBA", "ExportToJpg", "myBatExe", myBatExe
End Sub
Private Sub mUse_Click()
SaveSetting "SanchoCorelVBA", "ExportToJpg", "mUse", IIf(mUse, "1", "0")
If mUse = 0 Then
mAddres.Enabled = False
mSubject.Enabled = False
mTheBatEXE.Enabled = False
myAccount.Enabled = False
myMultSend.Enabled = False
Else
mAddres.Enabled = True
mSubject.Enabled = True
mTheBatEXE.Enabled = True
myAccount.Enabled = True
If myWorkMetod.Text = "All Page" Or myWorkMetod.Text = "Page:" Then myMultSend.Enabled = True
End If
End Sub
Private Sub myMultSend_Click()
SaveSetting "SanchoCorelVBA", "ExportToJpg", "myMultSend", IIf(myMultSend, "1", "0")
End Sub
Private Sub myAccount_Change()
SaveSetting "SanchoCorelVBA", "ExportToJpg", "myAccount", myAccount
End Sub
Private Sub UserForm_Initialize()
Dim meCap$, s$, lng1&, lng2&
On Error Resume Next
Me.DesignMode = fmModeOff
meCap = Me.Caption
Me.Caption = Me.Caption & Hex$(Now) & Hex$(Timer)
lng1 = CLng(StrPtr("ThunderDFrame"))
lng2 = CLng(StrPtr(Me.Caption))
sanUI = FindWindowExW(0, 0, lng1, lng2)
Me.Caption = meCap
windowSetStyle
Me.Height = 245: Me.Width = 122.25
windowTransparent 220
Me.meHead.Caption = " Exp2jpg " & jpgVer
Me.meHead.ControlTipText = "Exp2jpg " & jpgVer & " " & jpgDate & " " & Chr(169) & " Sancho"
s = GetSetting("SanchoCorelVBA", "ExportToJpg", "Pos")
If Len(s) Then
StartUpPosition = 0
'Move CSng(Split(s, " ")(0)), CSng(Split(s, " ")(1))
Me.Left = CSng(Split(s, " ")(0))
Me.Top = CSng(Split(s, " ")(1))
End If
'namePrefixEn
wBool = False
hBool = False
myWorkMetod.AddItem "Selection"
myWorkMetod.AddItem "Active Page"
myWorkMetod.AddItem "All Page"
myWorkMetod.AddItem "Page:"
myWorkMetod = GetSetting("SanchoCorelVBA", "ExportToJpg", "myWorkMetod", "Selection")
myWorkMetod2
Dpi_TextBox.AddItem "300"
Dpi_TextBox.AddItem "200"
Dpi_TextBox.AddItem "150"
Dpi_TextBox.AddItem "100"
Dpi_TextBox.AddItem "96"
Dpi_TextBox.AddItem "72"
Dpi_TextBox = GetSetting("SanchoCorelVBA", "ExportToJpg", "dpi", "100")
tb_AfterName = GetSetting("SanchoCorelVBA", "ExportToJpg", "name", "")
folder_TextBox.List = Split(GetSetting("SanchoCorelVBA", "ExportToJpg", "folder"), "|", 20)
If folder_TextBox.ListCount = 20 Then folder_TextBox.RemoveItem 19
If folder_TextBox.ListCount = 0 Then
folder_TextBox.Text = "C:\"
Else
folder_TextBox.Text = GetSetting("SanchoCorelVBA", "ExportToJpg", "folder2")
End If
'prefix_CheckBox = (GetSetting("SanchoCorelVBA", "ExportToJpg", "name prefix", "0") = "1")
nameprefix_TextBox = GetSetting("SanchoCorelVBA", "ExportToJpg", "name prefix text", "maket_")
myColorMode.List = Array("Grayscale", "CMYKColor", "RGBColor")
myColorMode = GetSetting("SanchoCorelVBA", "ExportToJpg", "ColorMode", "RGBColor")
bwidth = GetSetting("SanchoCorelVBA", "ExportToJpg", "width", "0")
bheight = GetSetting("SanchoCorelVBA", "ExportToJpg", "height", "0")
sAspectRat = GetSetting("SanchoCorelVBA", "ExportToJpg", "sAspectRat", "1")
cm_AspectRatMove
profile_CheckBox = (GetSetting("SanchoCorelVBA", "ExportToJpg", "profile", "1") = "1")
AntiAliasing_CheckBox = (GetSetting("SanchoCorelVBA", "ExportToJpg", "AntiAliasing", "1") = "1")
jpgEncod.List = Array("Progressive", "Optimized")
jpgEncod = GetSetting("SanchoCorelVBA", "ExportToJpg", "EncodingMethod", "Optimized")
myCmpress = GetSetting("SanchoCorelVBA", "ExportToJpg", "myCmpress", "50")
Smoot = GetSetting("SanchoCorelVBA", "ExportToJpg", "Smoot", "10")
mUse = (GetSetting("SanchoCorelVBA", "ExportToJpg", "mUse", "0") = "1")
myMultSend = (GetSetting("SanchoCorelVBA", "ExportToJpg", "myMultSend", "0") = "1")
myBatExe = GetSetting("SanchoCorelVBA", "ExportToJpg", "myBatExe", "")
mTheBatEXE.ControlTipText = "Find TheBat.exe " & Chr(40) & myBatExe & Chr(41)
myAccount = GetSetting("SanchoCorelVBA", "ExportToJpg", "myAccount", "what's your mail account name?")
mAddres.List = Split(GetSetting("SanchoCorelVBA", "ExportToJpg", "mAddres"), "|", 20)
If mAddres.ListCount = 20 Then mAddres.RemoveItem 19
If mAddres.ListCount = 0 Then
mAddres = ""
Else
mAddres = GetSetting("SanchoCorelVBA", "ExportToJpg", "mAddres2", mAddres)
End If
mSubject.List = Split(GetSetting("SanchoCorelVBA", "ExportToJpg", "mSubject"), "|", 20)
If mSubject.ListCount = 20 Then mSubject.RemoveItem 19
If mSubject.ListCount = 0 Then
mSubject = ""
Else
mSubject = GetSetting("SanchoCorelVBA", "ExportToJpg", "mSubject2", mSubject)
End If
If mUse = 0 Then
mAddres.Enabled = False
mSubject.Enabled = False
mTheBatEXE.Enabled = False
myAccount.Enabled = False
End If
myPageIndex.Text = GetSetting("SanchoCorelVBA", "ExportToJpg", "myPageIndex")
myPageIndex.ControlTipText = "Pages: " & myPageIndex.Text
myLoadPresets
'MY ===============================
If GetSetting("SanchoCorelVBA", "ExportToJpg", "AutoChange", "0") = "1" Then
nameprefix_TextBox.Text = Replace(CorelDRAW.ActiveDocument.Name, ".cdr", "")
folder_TextBox.Text = ActiveDocument.FilePath
If ActiveDocument.Pages.Count > 1 Then myWorkMetod = "All Page" Else myWorkMetod = "Selection"
End If
Select Case Random(0, 3)
Case 0
cm_aboutCdrPreflight.Caption = "CdrPreflight. Read more..."
macroAdURL = "http://cdrpro.ru/en/macros/cdrpreflight/"
Case 1
cm_aboutCdrPreflight.Caption = "CardGenerator. Read more..."
macroAdURL = "http://cdrpro.ru/en/macros/cardgenerator/"
Case Else
cm_aboutCdrPreflight.Caption = "CorelDRAW Macros"
macroAdURL = "http://cdrpro.ru/en/"
End Select
End Sub
Private Sub windowSetStyle()
Const WS_EX_LAYERED& = &H80000, GWL_STYLE& = -16
SetWindowLongW sanUI, GWL_STYLE, GetWindowLongW(sanUI, GWL_STYLE) And Not &HCF0000
End Sub
Private Sub windowTransparent(Optional ByVal level As Byte)
Const WS_EX_LAYERED& = &H80000, LWA_COLORKEY& = &H1, LWA_ALPHA& = &H2, GWL_EXSTYLE& = -20
If level Then
SetWindowLongW sanUI, GWL_EXSTYLE, GetWindowLongW(sanUI, GWL_EXSTYLE) Or WS_EX_LAYERED
SetLayeredWindowAttributes sanUI, 0, level, LWA_ALPHA
Else
SetWindowLongW sanUI, GWL_EXSTYLE, GetWindowLongW(sanUI, GWL_EXSTYLE) And Not WS_EX_LAYERED
End If
End Sub
Private Sub meHead_MouseDown(ByVal Button%, ByVal Shift%, ByVal X!, ByVal Y!)
If Button = 1 Then
On Error Resume Next
Tag = "1"
GetWindowRect sanUI, r0
GetCursorPos cp0
sx = GetSystemMetrics(SM_CXScreen)
sy = GetSystemMetrics(SM_CYScreen)
End If
End Sub
Private Sub meHead_MouseMove(ByVal Button%, ByVal Shift%, ByVal X!, ByVal Y!)
If Len(Tag) = 0 Then Exit Sub
On Error Resume Next
Dim cp As wPOINT
GetCursorPos cp
cp.X = r0.l + cp.X - cp0.X: If cp.X < 0 Then cp.X = 0 Else If cp.X > sx - 26 Then cp.X = sx - 26
cp.Y = r0.t + cp.Y - cp0.Y: If cp.Y < 0 Then cp.Y = 0 Else If cp.Y > sy - 26 Then cp.Y = sy - 26
SetWindowPos sanUI, 0, cp.X, cp.Y, 0, 0, SWP_NOACTIVATE Or SWP_NOSIZE Or SWP_NOSENDCHANGING
End Sub
Private Sub meHead_MouseUp(ByVal Button%, ByVal Shift%, ByVal X!, ByVal Y!)
On Error Resume Next
Select Case Button
Case 1:
If Len(Tag) Then
Tag = vbNullString
GetWindowRect sanUI, r0
Exit Sub
End If
End Select
End Sub
Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Command_OK.BackColor = &H8000000F
Command_OK.SpecialEffect = fmSpecialEffectEtched
Command_OK.ForeColor = &H80000012
cm_aboutCdrPreflight.SpecialEffect = fmSpecialEffectEtched
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
SaveSetting "SanchoCorelVBA", "ExportToJpg", "Pos", Left & " " & Top
End Sub
Private Function Random(Lowerbound As Long, Upperbound As Long) As Long
Randomize
Random = Int(Rnd * Upperbound) + Lowerbound
End Function
Private Sub myListsSave()
If folder_TextBox.ListCount > 0 Then
For Count = 0 To folder_TextBox.ListCount - 1
If folder_TextBox = folder_TextBox.List(Count) Then yn = True
Next Count
If yn = False Then
For i = 1 To folder_TextBox.ListCount
s = s + folder_TextBox.List(i - 1) + "|"
Next
s = Left$(s, Len(s) - 1)
If InStr(1, "|" + s + "|", "|" + folder_TextBox + "|", vbTextCompare) = 0 Then _
folder_TextBox.AddItem folder_TextBox, 0
s = folder_TextBox + IIf(s = sEmpty, sEmpty, "|") + s
SaveSetting "SanchoCorelVBA", "ExportToJpg", "folder", s
End If
Else
SaveSetting "SanchoCorelVBA", "ExportToJpg", "folder", folder_TextBox
End If
s = ""
If mAddres.ListCount > 0 Then
For Count = 0 To mAddres.ListCount - 1
If mAddres = mAddres.List(Count) Then yn2 = True
Next Count
If yn2 = False Then
For i = 1 To mAddres.ListCount
s = s + mAddres.List(i - 1) + "|"
Next
s = Left$(s, Len(s) - 1)
If InStr(1, "|" + s + "|", "|" + mAddres + "|", vbTextCompare) = 0 Then _
mAddres.AddItem mAddres, 0
s = mAddres + IIf(s = sEmpty, sEmpty, "|") + s
SaveSetting "SanchoCorelVBA", "ExportToJpg", "mAddres", s
End If
Else
SaveSetting "SanchoCorelVBA", "ExportToJpg", "mAddres", mAddres
End If
s = ""
If mSubject.ListCount > 0 Then
For Count = 0 To mSubject.ListCount - 1
If mSubject = mSubject.List(Count) Then yn3 = True
Next Count
If yn3 = False Then
For i = 1 To mSubject.ListCount
s = s + mSubject.List(i - 1) + "|"
Next
s = Left$(s, Len(s) - 1)
If InStr(1, "|" + s + "|", "|" + mSubject + "|", vbTextCompare) = 0 Then _
mSubject.AddItem mSubject, 0
s = mSubject + IIf(s = sEmpty, sEmpty, "|") + s
SaveSetting "SanchoCorelVBA", "ExportToJpg", "mSubject", s
End If
Else
SaveSetting "SanchoCorelVBA", "ExportToJpg", "mSubject", mSubject
End If
End Sub
Private Sub myLoadPresets()
Dim c&, i&, presName$
c = GetSetting("SanchoCorelVBA", "ExportToJpg", "PresetsCount", 0)
For i = 1 To c
presName = GetSetting("SanchoCorelVBA", "ExportToJpg", "Presets" & i & "Name")
If presName <> "" Then cb_presList.AddItem i & "| " & presName
Next i
End Sub
Private Sub cb_presList_Change()
Dim i&, a$(), c1&, a2$()
If cb_presList.SelLength = 0 Then Exit Sub
For c1 = 0 To cb_presList.ListCount - 1 Step 1
If cb_presList.SelText = cb_presList.List(c1) Then
a2 = Split(cb_presList.SelText, "|")
i = CLng(a2(0))
Exit For
End If
Next c1
a = Split(GetSetting("SanchoCorelVBA", "ExportToJpg", "Presets" & i), "|")
nameprefix_TextBox = a(1)
'prefix_CheckBox = a(2)
tb_AfterName = a(3)
folder_TextBox = a(4)
Dpi_TextBox = a(5)
profile_CheckBox = a(6)
AntiAliasing_CheckBox = a(7)
bwidth = a(8)
bheight = a(9)
sAspectRat = a(10): cm_AspectRatMove
myColorMode = a(11)
jpgEncod = a(12)
myCmpress = a(13)
Smoot = a(14)
mUse = a(15)
If a(15) = "1" Then
mAddres = a(16)
mSubject = a(17)
myMultSend = a(18)
myAccount = a(19)
End If
'If a(0) = "2" Then
'FtFillToBit = a(58)
'End If
End Sub
Private Sub cm_presAdd_Click()
Dim strPres$, strPresN$, c&
c = GetSetting("SanchoCorelVBA", "ExportToJpg", "PresetsCount", 0)
c = c + 1
strPresN = InputBox("Name for Preset", "Name...")
If strPresN = "" Then Exit Sub
strPres = jpgPresVer & "|" & nameprefix_TextBox.Text & "|" & "1" & "|" & tb_AfterName.Text & "|" & folder_TextBox.Text & "|" & Dpi_TextBox.Text & "|" & _
IIf(profile_CheckBox, "1", "0") & "|" & IIf(AntiAliasing_CheckBox, "1", "0") & "|" & bwidth.Text & "|" & bheight.Text & "|" & sAspectRat & "|" & myColorMode.Text & "|" & _
jpgEncod.Text & "|" & myCmpress.Text & "|" & Smoot.Text & "|" & IIf(mUse, "1", "0") & "|" & mAddres.Text & "|" & mSubject.Text & "|" & IIf(myMultSend, "1", "0") & "|" & myAccount.Text
SaveSetting "SanchoCorelVBA", "ExportToJpg", "Presets" & c, strPres
SaveSetting "SanchoCorelVBA", "ExportToJpg", "Presets" & c & "Name", strPresN
cb_presList.AddItem c & "| " & strPresN
cb_presList.Text = c & "| " & strPresN
SaveSetting "SanchoCorelVBA", "ExportToJpg", "PresetsCount", c
End Sub
Private Sub cm_presDel_Click()
Dim i&, c&, i2&, a$()
If cb_presList.SelLength = 0 Then Exit Sub
For c1 = 0 To cb_presList.ListCount - 1 Step 1
If cb_presList.SelText = cb_presList.List(c1) Then
a = Split(cb_presList.SelText, "|")
i = CLng(a(0))
Exit For
End If
Next c1
cb_presList.Clear
c = CLng(GetSetting("SanchoCorelVBA", "ExportToJpg", "PresetsCount", 0))
If i < c Then
For i2 = i + 1 To c Step 1
SaveSetting "SanchoCorelVBA", "ExportToJpg", "Presets" & i, _
GetSetting("SanchoCorelVBA", "ExportToJpg", "Presets" & i2)
SaveSetting "SanchoCorelVBA", "ExportToJpg", "Presets" & i & "Name", _
GetSetting("SanchoCorelVBA", "ExportToJpg", "Presets" & i2 & "Name")
i = i + 1
Next i2
DeleteSetting "SanchoCorelVBA", "ExportToJpg", "Presets" & c
DeleteSetting "SanchoCorelVBA", "ExportToJpg", "Presets" & c & "Name"
Else
DeleteSetting "SanchoCorelVBA", "ExportToJpg", "Presets" & i
DeleteSetting "SanchoCorelVBA", "ExportToJpg", "Presets" & i & "Name"
End If
SaveSetting "SanchoCorelVBA", "ExportToJpg", "PresetsCount", c - 1
myLoadPresets
End Sub
Private Sub Image3_Click()
uf_about.Show
End Sub
Private Sub cm_aboutCdrPreflight_Click()
On Error Resume Next
Dim RetVal#
RetVal = Shell(GetString(HKEY_CLASSES_ROOT, "HTTP\shell\open\command", "") & _
" " & macroAdURL, 1)
'"http://cdrpro.ru/en/macros/cdrpreflight/"
AppActivate RetVal
End Sub
Private Sub cm_aboutCdrPreflight_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
cm_aboutCdrPreflight.SpecialEffect = fmSpecialEffectSunken
End Sub
Private Sub cm_aboutCdrPreflight_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
cm_aboutCdrPreflight.SpecialEffect = fmSpecialEffectRaised
End Sub
Function GetString(hKey As Long, strPath As String, strValue As String)
Dim Ret
RegOpenKey hKey, strPath, Ret
GetString = RegQueryStringValue(Ret, strValue)
RegCloseKey Ret
End Function
Function RegQueryStringValue(ByVal hKey As Long, ByVal strValueName As String) As String
Dim lResult As Long, lValueType As Long, strBuf As String, lDataBufSize As Long
lResult = RegQueryValueEx(hKey, strValueName, 0, lValueType, ByVal 0, lDataBufSize)
If lResult = 0 Then
If lValueType = REG_SZ Then
strBuf = String(lDataBufSize, Chr$(0))
lResult = RegQueryValueEx(hKey, strValueName, 0, 0, ByVal strBuf, lDataBufSize)
If lResult = 0 Then
RegQueryStringValue = Left$(strBuf, InStr(1, strBuf, Chr$(0)) - 1)
End If
ElseIf lValueType = REG_BINARY Then
Dim strData As Integer
lResult = RegQueryValueEx(hKey, strValueName, 0, 0, strData, lDataBufSize)
If lResult = 0 Then
RegQueryStringValue = strData
End If
End If
End If
End Function