-
Notifications
You must be signed in to change notification settings - Fork 2
/
MyButton.ctl
1481 lines (1251 loc) · 53.6 KB
/
MyButton.ctl
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
VERSION 5.00
Begin VB.UserControl MyButton
AutoRedraw = -1 'True
ClientHeight = 1770
ClientLeft = 0
ClientTop = 0
ClientWidth = 1860
ClipBehavior = 0 'None
FillStyle = 0 'Solid
PropertyPages = "MyButton.ctx":0000
ScaleHeight = 118
ScaleMode = 3 'Pixel
ScaleWidth = 124
ToolboxBitmap = "MyButton.ctx":0035
End
Attribute VB_Name = "MyButton"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'developed by edin omeragic
'from: Bosnia and Hercegovina, Srebrenik
'my email: edoo_ba@hotmail.com
'datum: (20.11 - 3.12) 2002 godine
'type: small project
'==================================================================
'this code is totaly free,
'if you dont like this you may copy it on flopy and throw it away ;},
'If you Like it Then please vote on planetsourcecode
'and also search for:
' - iMenu (old project but good) or
' - iList (cool list)
'==================================================================
'DrawButton(State) - draws button (main function)
'DrawText(...) - draws text (called from drawbutton)
'DrawPicture(...) - draws picture
'DrawPictureDisabled - draws picture grayed
'TilePicture() - tiles picture
'SetRect (left, top, right, bottom) as RECT 'makes rectangle on flay
'ModyfyRect(RECT,left,top,right,bottom) as RECT
'i.e.
'R = SetRect (0,0,1,1)
'R = ModifyRect(R,1,1,1,1)
'R is (1,1,2,2)
'==================================================================
'-for default skin, name the picture box "MyButtonDefSkin"
'-for changing skin in design time set property
' "SkinPictureName" same as picture box name
'==================================================================
Option Explicit
'Default Property Values:
Const m_def_TextAlign = vbCenter
Const m_def_PictureTColor = &HFF00FF
Const m_def_PicturePos = 0
Const m_def_TextColorDisabled2 = 0
Const m_def_DrawFocus = 0
Const m_def_DisplaceText = 0
'Const m_def_DownTextDX = 0
'Const m_def_DownTextDY = 0
Const m_def_DisableHover = False
Const m_def_TextColorEnabled = 0
Const m_def_TextColorDisabled = 0
Const m_def_FillWithColor = True
Const m_def_SizeCW = 3
Const m_def_SizeCH = 3
Const m_def_Text = vbNullString
'Property Variables:
Dim m_TextAlign As AlignmentConstants
Dim m_PictureTColor As Ole_Color
Dim m_PicturePos As Integer
Dim m_Picture As StdPicture
Dim m_TextColorDisabled2 As Ole_Color
Dim m_DrawFocus As Integer
Dim m_DisplaceText As Integer
Dim m_DisableHover As Boolean
Dim m_TextColorEnabled As Ole_Color
Dim m_TextColorDisabled As Ole_Color
Dim m_FillWithColor As Boolean
Dim m_SizeCW As Long
Dim m_SizeCH As Long
Dim m_SkinPicture As PictureBox
Dim m_Text As String
Dim m_State As Integer
Dim m_HasFocus As Boolean
Dim m_BtnDown As Boolean
Dim m_SpcDown As Boolean
Dim m_SkinPictureName As String
Public Enum EnumPicturePos
ppLeft
ppTop
ppBottom
ppRight
ppCenter
End Enum
Private Const DI_NORMAL As Long = &H3
Const BTN_NORMAL = 1
Const BTN_FOCUS = 2
Const BTN_HOVER = 3
Const BTN_DOWN = 4
Const BTN_DISABLED = 5
'Event Declarations:
Event Click() 'MappingInfo=UserControl,UserControl,-1,Click
Attribute Click.VB_Description = "Occurs when the user presses and then releases a mouse button over an object."
Event MouseHover()
Event MouseOut()
Event MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Event MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Event MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Event KeyPress(KeyAscii As Integer)
Event KeyDown(KeyCode As Integer, Shift As Integer)
Event KeyUp(KeyCode As Integer, Shift As Integer)
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public Enum EnumDrawTextFormat
DT_BOTTOM = &H8
DT_CALCRECT = &H400
DT_CENTER = &H1
DT_CHARSTREAM = 4
DT_DISPFILE = 6
DT_EXPANDTABS = &H40
DT_EXTERNALLEADING = &H200
DT_INTERNAL = &H1000
DT_LEFT = &H0
DT_METAFILE = 5
DT_NOCLIP = &H100
DT_NOPREFIX = &H800
DT_PLOTTER = 0
DT_RASCAMERA = 3
DT_RASDISPLAY = 1
DT_RASPRINTER = 2
DT_RIGHT = &H2
DT_SINGLELINE = &H20
DT_TABSTOP = &H80
DT_TOP = &H0
DT_VCENTER = &H4
DT_WORDBREAK = &H10
DT_WORD_ELLIPSIS = &H40000
DT_END_ELLIPSIS = 32768
DT_PATH_ELLIPSIS = &H4000
DT_EDITCONTROL = &H2000
'===================
DT_INCENTER = DT_CENTER Or DT_VCENTER Or DT_SINGLELINE
End Enum
Private Const SRCCOPY = &HCC0020
Private Const RGN_AND = 1
Private Declare Function BeginPath Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function EndPath Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function Rectangle Lib "gdi32" (ByVal hdc As Long, ByVal x1 As Long, ByVal y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal XSrc As Long, ByVal YSrc As Long, ByVal dwRop As Long) As Long
Private Declare Function SelectClipPath Lib "gdi32" (ByVal hdc As Long, ByVal iMode As Long) As Long
Private Declare Function SelectClipRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long) As Long
Private Declare Function apiDrawText Lib "user32" Alias "DrawTextA" (ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Private Declare Function FillRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function apiTranslateColor Lib "olepro32.dll" Alias "OleTranslateColor" (ByVal clr As Ole_Color, ByVal palet As Long, Col As Long) As Long
Private Declare Function DrawFocusRect Lib "user32" (ByVal hdc As Long, lpRect As RECT) As Long
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
'Private Declare Function TransparentBlt Lib "msimg32.dll" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal crTransparent As Long) As Boolean
'MY NOTE: TransparentBlt on Win98 leavs some garbage in memory...
'
'Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function GdiTransparentBlt Lib "gdi32.dll" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal XSrc As Long, ByVal YSrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal crTransparent As Long) As Boolean
Private Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long
Private Declare Function SetDIBColorTable Lib "gdi32" (ByVal hdc As Long, ByVal un1 As Long, ByVal un2 As Long, pcRGBQuad As RGBQUAD) As Long
'for picture
Private Declare Function GetDIBits Lib "gdi32" (ByVal aHDC As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As BITMAPINFO, ByVal wUsage As Long) As Long
Private Declare Function SetDIBitsToDevice Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal dx As Long, ByVal dy As Long, ByVal SrcX As Long, ByVal SrcY As Long, ByVal Scan As Long, ByVal NumScans As Long, Bits As Any, BitsInfo As BITMAPINFO, ByVal wUsage As Long) As Long
Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
'Private Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long
'Private Declare Function SetDIBitsToDevice Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal dx As Long, ByVal dy As Long, ByVal SrcX As Long, ByVal SrcY As Long, ByVal Scan As Long, ByVal NumScans As Long, Bits As Any, BitsInfo As BITMAPINFO, ByVal wUsage As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function CreateDIBSection Lib "gdi32" (ByVal hdc As Long, pBitmapInfo As BITMAPINFO, ByVal un As Long, ByVal lplpVoid As Long, ByVal Handle As Long, ByVal dw As Long) As Long
Private Declare Function RealizePalette Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function DrawIconEx Lib "user32" (ByVal hdc As Long, ByVal xLeft As Long, ByVal yTop As Long, ByVal hIcon As Long, ByVal cxWidth As Long, ByVal cyWidth As Long, ByVal istepIfAniCur As Long, ByVal hbrFlickerFreeDraw As Long, ByVal diFlags As Long) As Long
Private Declare Function CreateBitmap Lib "gdi32" (ByVal nWidth As Long, ByVal nHeight As Long, ByVal nPlanes As Long, ByVal nBitCount As Long, lpBits As Any) As Long
'never enough
Private Declare Function GetBkColor Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function GetTextColor Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function SetBkColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
Private Declare Function SetTextColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
Private Type BITMAPINFOHEADER
biSize As Long
biWidth As Long
biHeight As Long
biPlanes As Integer
biBitCount As Integer
biCompression As Long
biSizeImage As Long
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Long
biClrImportant As Long
End Type
Private Type RGBQUAD
rgbBlue As Byte
rgbGreen As Byte
rgbRed As Byte
rgbReserved As Byte
End Type
Private Type BITMAP
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
Private Type BITMAPINFO
bmiHeader As BITMAPINFOHEADER
bmiColors(1) As RGBQUAD
End Type
'windows version
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
'#############################################
'//GDI + SOMETHING ELSE#######################
Private Sub TransBlt(ByVal hdcDest As Long, ByVal XDest As Long, ByVal YDest As Long, _
ByVal nWidth As Long, ByVal nHeight As Long, ByVal hdcSrc As Long, _
ByVal XSrc As Long, ByVal YSrc As Long, ByVal clrMask As Ole_Color)
'one check to see if GdiTransparentblt is supported
'better way to check if function is suported is using LoadLibrary and GetProcAdress
'than using GetVersion or GetVersionEx
'=====================================================
Dim Lib As Long
Dim ProcAdress As Long
Dim lMaskColor As Long
lMaskColor = TranslateColor(clrMask)
Lib = LoadLibrary("gdi32.dll")
'-------------------------------->make sure to specify corect name for function
ProcAdress = GetProcAddress(Lib, "GdiTransparentBlt")
FreeLibrary Lib
If ProcAdress <> 0 Then
'works on XP
GdiTransparentBlt hdcDest, XDest, YDest, nWidth, nHeight, hdcSrc, XSrc, YSrc, nWidth, nHeight, lMaskColor
'Debug.Print "Gdi transparent blt"
Exit Sub 'make it short
End If
'=====================================================
Const DSna As Long = &H220326
Dim hdcMask As Long
Dim hdcColor As Long
Dim hbmMask As Long
Dim hbmColor As Long
Dim hbmColorOld As Long
Dim hbmMaskOld As Long
Dim hdcScreen As Long
Dim hdcScnBuffer As Long
Dim hbmScnBuffer As Long
Dim hbmScnBufferOld As Long
hdcScreen = UserControl.hdc
lMaskColor = TranslateColor(clrMask)
hbmScnBuffer = CreateCompatibleBitmap(hdcScreen, nWidth, nHeight)
hdcScnBuffer = CreateCompatibleDC(hdcScreen)
hbmScnBufferOld = SelectObject(hdcScnBuffer, hbmScnBuffer)
BitBlt hdcScnBuffer, 0, 0, nWidth, nHeight, hdcDest, XDest, YDest, vbSrcCopy
hbmColor = CreateCompatibleBitmap(hdcScreen, nWidth, nHeight)
hbmMask = CreateBitmap(nWidth, nHeight, 1, 1, ByVal 0&)
hdcColor = CreateCompatibleDC(hdcScreen)
hbmColorOld = SelectObject(hdcColor, hbmColor)
Call SetBkColor(hdcColor, GetBkColor(hdcSrc))
Call SetTextColor(hdcColor, GetTextColor(hdcSrc))
Call BitBlt(hdcColor, 0, 0, nWidth, nHeight, hdcSrc, XSrc, YSrc, vbSrcCopy)
hdcMask = CreateCompatibleDC(hdcScreen)
hbmMaskOld = SelectObject(hdcMask, hbmMask)
SetBkColor hdcColor, lMaskColor
SetTextColor hdcColor, vbWhite
BitBlt hdcMask, 0, 0, nWidth, nHeight, hdcColor, 0, 0, vbSrcCopy
SetTextColor hdcColor, vbBlack
SetBkColor hdcColor, vbWhite
BitBlt hdcColor, 0, 0, nWidth, nHeight, hdcMask, 0, 0, DSna
BitBlt hdcScnBuffer, 0, 0, nWidth, nHeight, hdcMask, 0, 0, vbSrcAnd
BitBlt hdcScnBuffer, 0, 0, nWidth, nHeight, hdcColor, 0, 0, vbSrcPaint
BitBlt hdcDest, XDest, YDest, nWidth, nHeight, hdcScnBuffer, 0, 0, vbSrcCopy
'clear
DeleteObject SelectObject(hdcColor, hbmColorOld)
DeleteDC hdcColor
DeleteObject SelectObject(hdcScnBuffer, hbmScnBufferOld)
DeleteDC hdcScnBuffer
DeleteObject SelectObject(hdcMask, hbmMaskOld)
DeleteDC hdcMask
'ReleaseDC 0, hdcScreen
End Sub
Private Function GetRgbQuad(ByVal r As Byte, ByVal G As Byte, ByVal b As Byte) As RGBQUAD
With GetRgbQuad
.rgbBlue = b
.rgbGreen = G
.rgbRed = r
End With
End Function
Private Function DrawPictureDisabled(ByVal p As StdPicture, x As Long, y As Long, _
w As Long, H As Long, _
Optional ColHighlight As Long = vb3DHighlight, _
Optional ColShadow As Long = vb3DShadow)
Dim MemDC As Long
Dim MyBmp As Long
Dim cShadow As Long
Dim cHiglight As Long
Dim ColPal(0 To 1) As RGBQUAD
Dim rgbBlack As RGBQUAD
Dim rgbWhite As RGBQUAD
Dim BI As BITMAPINFO
Dim hdc As Long
Dim hPicDc As Long
Dim hPicBmp As Long
hdc = UserControl.hdc
cHiglight = TranslateColor(vb3DHighlight)
cShadow = TranslateColor(vb3DShadow)
'rgbBlack = GetRgbQuad(0, 0, 0)
rgbWhite = GetRgbQuad(255, 255, 255)
With BI.bmiHeader
.biSize = 40 'size of bmiHeader structure
.biHeight = -H
.biWidth = w
.biPlanes = 1
.biCompression = 0 'BI_RGB
.biClrImportant = 0
.biBitCount = 1 'monohrome bitmap
End With
'color palete
With BI
.bmiColors(0) = rgbBlack
.bmiColors(1) = rgbWhite
End With
Dim hMonoSec As Long
Dim pBits As Long
Dim hdcMono As Long
hMonoSec = CreateDIBSection(hdc, BI, 0, pBits, 0&, 0&)
'Debug.Print "MonoSec:"; hMonoSec
hdcMono = CreateCompatibleDC(hdc)
SelectObject hdcMono, hMonoSec
'create dc for picture
hPicDc = CreateCompatibleDC(hdc)
If p.Type = vbPicTypeIcon Then
hPicBmp = CreateCompatibleBitmap(hdc, w, H)
SelectObject hPicDc, hPicBmp
DeleteObject hPicBmp
ClearRect hPicDc, SetRect(0, 0, w, H), TranslateColor(m_PictureTColor)
DrawIconEx hPicDc, 0, 0, p.Handle, w, H, 0, 0, DI_NORMAL
'Debug.Print "DRAW ICON"
ElseIf p.Type = vbPicTypeBitmap Then
SelectObject hPicDc, p.Handle
End If
'copy hPicDc to hdcMono
BitBlt hdcMono, 0, 0, w, H, hPicDc, 0, 0, SRCCOPY
DeleteDC hPicDc
Dim r As Integer, G As Integer, b As Integer
GetRgb cHiglight, r, G, b
'change black color in palete to highlight(r,g,b) color
ColPal(0) = GetRgbQuad(r, G, b)
ColPal(1) = rgbBlack 'change white color in palete to black color
SetDIBColorTable hdcMono, 0, 2, ColPal(0) 'set new palete
RealizePalette hdcMono 'update it
'BitBlt Me.hdc, 1, 1, W, H, hdcMono, 0, 0, SRCCOPY
'transparent blit to dest hDC using black as transparent colour
'x+1 and y+1 - moves down and left for 1 pixel
TransBlt hdc, x + 1, y + 1, w, H, hdcMono, 0, 0, 0
'get rgb components of shadow color
GetRgb cShadow, r, G, b
'change black color to shadow color in palete
ColPal(0) = GetRgbQuad(r, G, b)
ColPal(1) = rgbWhite 'change back to white
'set new palete
SetDIBColorTable hdcMono, 0, 2, ColPal(0)
RealizePalette hdcMono ' then update
'transparent blit do dest hdc using white color as transparent
TransBlt hdc, x, y, w, H, hdcMono, 0, 0, RGB(255, 255, 255)
'BitBlt Me.hDC, 0, 0, W, H, hdcMono, 0, 0, SRCCOPY
'Debug.Print DeleteObject(hMonoSec)
'Debug.Print DeleteObject(hdcMono)
End Function
Sub GetRgb(Color As Long, r As Integer, G As Integer, b As Integer)
r = Color And 255 'clear bites from 9 to 32
G = (Color \ 256) And 255 'shift right 8 bits and clear
b = (Color \ 65536) And 255 'shift 16 bits and clear for any case
End Sub
Private Function GetBmpSize(Bmp As StdPicture, w As Long, H As Long) As Long
' Dim B As BITMAP
' GetBmpSize = GetObject(Bmp, Len(B), B)
w = ScaleX(Bmp.Width, vbHimetric, vbPixels)
H = ScaleY(Bmp.Height, vbHimetric, vbPixels)
' Debug.Print W, H
' W = B.bmWidth
' H = B.bmHeight
' Debug.Print B.bmType
' Debug.Print W, H
End Function
Private Sub DrawPicture(hdc As Long, p As StdPicture, x As Long, y As Long, w As Long, H As Long, TOleCol As Long)
'check picture format
If p.Type = vbPicTypeIcon Then
DrawIconEx hdc, x, y, p.Handle, w, H, 0, 0, DI_NORMAL
Exit Sub
End If
'creting dc with the same format as screen dc
Dim MemDC As Long
MemDC = CreateCompatibleDC(0)
'select a picture into memdc
SelectObject MemDC, p.Handle '
'tranparent blit memdc on usercontrol
TransBlt UserControl.hdc, x, y, w, H, MemDC, 0, 0, TranslateColor(TOleCol)
DeleteDC MemDC 'its clear, heh
End Sub
Private Function ModifyRect(lpRect As RECT, ByVal Left As Long, ByVal Top As Long, _
ByVal Right As Long, ByVal Bottom As Long) As RECT
With ModifyRect
.Left = lpRect.Left + Left
.Top = lpRect.Top + Top
.Right = lpRect.Right + Right
.Bottom = lpRect.Bottom + Bottom
End With
End Function
Private Function TranslateColor(ByVal Ole_Color As Long) As Long
apiTranslateColor Ole_Color, 0, TranslateColor
End Function
Private Function SetRect(ByVal Left As Long, ByVal Top As Long, ByVal Right As Long, ByVal Bottom As Long) As RECT
With SetRect
.Left = Left
.Top = Top
.Right = Right
.Bottom = Bottom
End With
End Function
Private Sub NormalizeRect(r As RECT)
Dim C As Long
If r.Left > r.Right Then
C = r.Right
r.Right = r.Left
r.Left = C
End If
If r.Top > r.Bottom Then
C = r.Top
r.Top = r.Bottom
r.Bottom = C
End If
End Sub
Private Function RoundUp(ByVal Num As Single) As Long
If Int(Num) < Num Then
RoundUp = Int(Num) + 1
Else
RoundUp = Num
End If
End Function
Private Function RectHeight(r As RECT) As Long
RectHeight = r.Bottom - r.Top
End Function
Private Function RectWidth(r As RECT) As Long
RectWidth = r.Right - r.Left
End Function
Private Sub DrawText(ByVal hdc As Long, ByVal strText As String, r As RECT, ByVal Format As Long)
apiDrawText UserControl.hdc, strText, Len(strText), r, Format
End Sub
Private Sub TilePicture(DestRect As RECT, SrcRect As RECT, ByVal SrcDC As Long, Optional UseCliper As Boolean = True, Optional ROp As Long = SRCCOPY)
Dim i As Integer
Dim j As Integer
Dim rows As Integer
Dim ColS As Integer
Dim destW As Long
Dim destH As Long
Dim hdc As Long
hdc = UserControl.hdc
NormalizeRect DestRect
NormalizeRect SrcRect
'calculates row and cols
rows = RoundUp(RectHeight(DestRect) / RectHeight(SrcRect))
ColS = RoundUp(RectWidth(DestRect) / RectWidth(SrcRect))
destW = RectWidth(SrcRect)
destH = RectHeight(SrcRect)
'prevents drawing out of specified rectangle
If UseCliper Then
SelectClipRgn hdc, ByVal 0
BeginPath hdc
With DestRect
Rectangle hdc, .Left, .Top, .Right + 1, .Bottom + 1
End With
EndPath hdc
SelectClipPath hdc, RGN_AND
End If
For i = 0 To rows - 1
For j = 0 To ColS - 1
BitBlt hdc, j * destW + DestRect.Left, i * destH + DestRect.Top, destW, destH, SrcDC, _
SrcRect.Left, SrcRect.Top, ROp
Next
Next
If UseCliper Then
SelectClipRgn hdc, ByVal 0
End If
End Sub
Private Sub ClearRect(ByVal hdc As Long, lRect As RECT, ByVal Color As Long)
Dim Brush As Long
Dim PBrush As Long
Brush = CreateSolidBrush(Color)
PBrush = SelectObject(hdc, Brush)
FillRect hdc, lRect, Brush
DeleteObject SelectObject(hdc, PBrush)
End Sub
'//END GDI####################################
'#############################################
'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
'MemberInfo=8,0,0,3
Public Property Get SizeCW() As Long
Attribute SizeCW.VB_Description = "Corner width."
Attribute SizeCW.VB_ProcData.VB_Invoke_Property = ";Position"
SizeCW = m_SizeCW
End Property
Public Property Let SizeCW(ByVal New_SizeCW As Long)
m_SizeCW = New_SizeCW
PropertyChanged "SizeCW"
Refresh
End Property
'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
'MemberInfo=8,0,0,3
Public Property Get SizeCH() As Long
Attribute SizeCH.VB_Description = "Corner height."
Attribute SizeCH.VB_ProcData.VB_Invoke_Property = ";Position"
SizeCH = m_SizeCH
End Property
Public Property Let SizeCH(ByVal New_SizeCH As Long)
m_SizeCH = New_SizeCH
PropertyChanged "SizeCH"
Refresh
End Property
'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
'MemberInfo=9,0,0,0
Public Property Get SkinPicture() As Object
Attribute SkinPicture.VB_Description = "Reference to picture box object."
Set SkinPicture = m_SkinPicture
End Property
Public Property Set SkinPicture(New_SkinPicture As Object)
If (TypeName(New_SkinPicture) <> "PictureBox") And _
(New_SkinPicture Is Nothing = False) Then
Err.Raise 5, "MyButton::SkinPicture", Err.description
Exit Property
End If
Set m_SkinPicture = New_SkinPicture
If m_SkinPicture Is Nothing = False Then
m_SkinPictureName = m_SkinPicture.Name
Else
m_SkinPictureName = vbNullString
End If
Refresh
PropertyChanged "SPN"
End Property
'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
'MemberInfo=13,0,0,
Public Property Get Text() As String
Attribute Text.VB_Description = "Button text."
Attribute Text.VB_ProcData.VB_Invoke_Property = ";Text"
Text = m_Text
End Property
Public Property Let Text(ByVal New_Text As String)
m_Text = New_Text
Refresh
PropertyChanged "Text"
'setting access key (allows alt + accesskey)
Dim i As Long
Dim C As String
For i = 1 To Len(New_Text) - 1
If Mid(New_Text, i, 1) = "&" Then
C = Mid(New_Text, i + 1, 1)
If C <> "&" Or C <> " " Then
UserControl.AccessKeys = C
PropertyChanged "AccessKey"
End If
End If
Next
End Property
'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
'MemberInfo=13,0,0,
Public Property Get SkinPictureName() As String
Attribute SkinPictureName.VB_Description = "Allows you to set reference at design time."
Attribute SkinPictureName.VB_ProcData.VB_Invoke_Property = ";Appearance"
'If m_SkinPicture Is Nothing = False Then
'SkinPictureName = m_SkinPicture.Name
SkinPictureName = m_SkinPictureName
'End If
End Property
Public Property Let SkinPictureName(ByVal New_SkinPictureName As String)
On Error GoTo NotLegalName
Dim p As Object
'Debug.Print New_SkinPictureName
If New_SkinPictureName <> "" Then
Set p = UserControl.Parent.Controls(New_SkinPictureName)
If p Is Nothing = False Then
Set SkinPicture = p
'Debug.Print "Setting p"; P.Name
End If
Else
Set m_SkinPicture = Nothing
'Debug.Print "P is nothing"
Refresh
End If
' m_SkinPictureName = New_SkinPictureName
PropertyChanged "SPN"
NotLegalName:
End Property
Private Sub UserControl_Click()
RaiseEvent Click
End Sub
Private Sub UserControl_DblClick()
DrawButton BTN_DOWN
End Sub
Private Sub UserControl_GotFocus()
m_HasFocus = True
If m_BtnDown = False Then DrawButton BTN_FOCUS
End Sub
Private Sub UserControl_Initialize()
' SkinPictureName = m_SkinPictureName
' MsgBox "Initialize..." + m_SkinPictureName
End Sub
'Initialize Properties for User Control
Private Sub UserControl_InitProperties()
m_SizeCW = m_def_SizeCW
m_SizeCH = m_def_SizeCH
m_Text = Extender.Name
m_FillWithColor = m_def_FillWithColor
m_TextColorEnabled = m_def_TextColorEnabled
m_TextColorDisabled = m_def_TextColorDisabled
Set UserControl.Font = Ambient.Font
m_DisableHover = m_def_DisableHover
m_DisplaceText = m_def_DisplaceText
m_DrawFocus = m_def_DrawFocus
m_TextColorDisabled2 = m_def_TextColorDisabled2
Set m_Picture = LoadPicture("")
m_PicturePos = m_def_PicturePos
m_PictureTColor = m_def_PictureTColor
m_SkinPictureName = "MyButtonDefSkin"
m_TextAlign = m_def_TextAlign
End Sub
Private Sub UserControl_KeyDown(KeyCode As Integer, Shift As Integer)
RaiseEvent KeyDown(KeyCode, Shift)
If KeyCode = vbKeySpace Then
m_SpcDown = True
DrawButton BTN_DOWN
Else
m_SpcDown = False
DrawButton BTN_FOCUS
End If
End Sub
Private Sub UserControl_KeyPress(KeyAscii As Integer)
RaiseEvent KeyPress(KeyAscii)
If KeyAscii = vbKeyReturn Then
RaiseEvent Click
End If
End Sub
Private Sub UserControl_KeyUp(KeyCode As Integer, Shift As Integer)
RaiseEvent KeyUp(KeyCode, Shift)
If KeyCode = 32 And m_SpcDown And m_State = BTN_DOWN Then
m_SpcDown = False
DrawButton BTN_NORMAL
RaiseEvent Click
DrawButton BTN_FOCUS
End If
End Sub
Private Sub UserControl_LostFocus()
m_HasFocus = False
DrawButton BTN_NORMAL
End Sub
Private Sub UserControl_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
RaiseEvent MouseDown(Button, Shift, x, y)
If Button = 1 Then m_BtnDown = True
UserControl_MouseMove Button, Shift, x, y
End Sub
Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If m_SpcDown Then Exit Sub
RaiseEvent MouseMove(Button, Shift, x, y)
SetCapture hwnd
If PointInControl(x, y) Then
'if pointer is on control
If m_BtnDown Then
If m_State <> BTN_DOWN Then
DrawButton BTN_DOWN
End If
Else
If m_State <> BTN_HOVER Then
RaiseEvent MouseHover
DrawButton BTN_HOVER
End If
End If
Else
'if pointer is out of control
If m_BtnDown Then
RaiseEvent MouseHover
DrawButton BTN_HOVER
Else
RaiseEvent MouseOut
If m_HasFocus Then
DrawButton BTN_FOCUS
Else
DrawButton BTN_NORMAL
End If
ReleaseCapture
End If
End If
End Sub
Private Sub UserControl_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
m_BtnDown = False
' If m_State <> BTN_NORMAL Then
DrawButton BTN_NORMAL
' End If
RaiseEvent MouseUp(Button, Shift, x, y)
If Button = vbLeftButton Then
'aqui cambie yo el codigo
'If PointInControl(x, Y) Then RaiseEvent Click
'lnunez
' If m_State <> BTN_FOCUS Then
DrawButton BTN_FOCUS
' End If
End If
End Sub
Private Sub UserControl_Paint()
Me.Refresh
End Sub
'Load property values from storage
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
m_SizeCW = PropBag.ReadProperty("SizeCW", m_def_SizeCW)
m_SizeCH = PropBag.ReadProperty("SizeCH", m_def_SizeCH)
m_SkinPictureName = PropBag.ReadProperty("SPN", "")
'Debug.Print "ReadProp SPN:"; m_SkinPictureName
m_Text = PropBag.ReadProperty("Text", m_def_Text)
m_FillWithColor = PropBag.ReadProperty("FillWithColor", m_def_FillWithColor)
UserControl.Enabled = PropBag.ReadProperty("Enabled", True)
UserControl.AccessKeys = PropBag.ReadProperty("AccessKey", "")
m_TextColorEnabled = PropBag.ReadProperty("TextColorEnabled", m_def_TextColorEnabled)
m_TextColorDisabled = PropBag.ReadProperty("TextColorDisabled", m_def_TextColorDisabled)
Set UserControl.Font = PropBag.ReadProperty("Font", Ambient.Font)
UserControl.MousePointer = PropBag.ReadProperty("MousePointer", 0)
Set MouseIcon = PropBag.ReadProperty("MouseIcon", Nothing)
m_DisableHover = PropBag.ReadProperty("DisableHover", m_def_DisableHover)
' m_DownTextDX = PropBag.ReadProperty("DownTextDX", m_def_DownTextDX)
' m_DownTextDY = PropBag.ReadProperty("DownTextDY", m_def_DownTextDY)
m_DisplaceText = PropBag.ReadProperty("DisplaceText", m_def_DisplaceText)
m_DrawFocus = PropBag.ReadProperty("DrawFocus", m_def_DrawFocus)
m_TextColorDisabled2 = PropBag.ReadProperty("TextColorDisabled2", m_def_TextColorDisabled2)
Set m_Picture = PropBag.ReadProperty("Picture", Nothing)
m_PicturePos = PropBag.ReadProperty("PicturePos", m_def_PicturePos)
m_PictureTColor = PropBag.ReadProperty("PictureTColor", m_def_PictureTColor)
m_TextAlign = PropBag.ReadProperty("TextAlign", m_def_TextAlign)
UserControl.BackColor = PropBag.ReadProperty("BackColor", &H8000000F)
End Sub
Private Sub UserControl_Resize()
Refresh
End Sub
Private Sub UserControl_Show()
SkinPictureName = m_SkinPictureName
' Refresh
End Sub
Private Sub UserControl_Terminate()
Set m_SkinPicture = Nothing
Set m_Picture = Nothing
'Set UserControl = Nothing
'Set Me = Nothing
'Debug.Print "TERMINATE"
End Sub
'Write property values to storage
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
Call PropBag.WriteProperty("SizeCW", m_SizeCW, m_def_SizeCW)
Call PropBag.WriteProperty("SizeCH", m_SizeCH, m_def_SizeCH)
'If m_SkinPicture Is Nothing = False Then
Call PropBag.WriteProperty("SPN", m_SkinPictureName, "")
'End If
'Debug.Print "Write :"; m_SkinPictureName
Call PropBag.WriteProperty("Text", m_Text, m_def_Text)
Call PropBag.WriteProperty("FillWithColor", m_FillWithColor, m_def_FillWithColor)
Call PropBag.WriteProperty("Enabled", UserControl.Enabled, True)
Call PropBag.WriteProperty("AccessKey", UserControl.AccessKeys, "")
Call PropBag.WriteProperty("TextColorEnabled", m_TextColorEnabled, m_def_TextColorEnabled)
Call PropBag.WriteProperty("TextColorDisabled", m_TextColorDisabled, m_def_TextColorDisabled)
Call PropBag.WriteProperty("Font", UserControl.Font, Ambient.Font)
Call PropBag.WriteProperty("MousePointer", UserControl.MousePointer, 0)
Call PropBag.WriteProperty("MouseIcon", MouseIcon, Nothing)
Call PropBag.WriteProperty("DisableHover", m_DisableHover, m_def_DisableHover)
Call PropBag.WriteProperty("DisplaceText", m_DisplaceText, m_def_DisplaceText)
Call PropBag.WriteProperty("DrawFocus", m_DrawFocus, m_def_DrawFocus)
Call PropBag.WriteProperty("TextColorDisabled2", m_TextColorDisabled2, m_def_TextColorDisabled2)
Call PropBag.WriteProperty("Picture", m_Picture, Nothing)
Call PropBag.WriteProperty("PicturePos", m_PicturePos, m_def_PicturePos)
Call PropBag.WriteProperty("PictureTColor", m_PictureTColor, m_def_PictureTColor)
Call PropBag.WriteProperty("TextAlign", m_TextAlign, m_def_TextAlign)
Call PropBag.WriteProperty("BackColor", UserControl.BackColor, &H8000000F)
End Sub
Private Sub DrawButton(ByVal State As Integer)
If m_DisableHover Then
If State = BTN_HOVER Then Exit Sub
'dont draw hover state if m_DisableHover is true
End If
' Debug.Print "State1 "; State
On Error GoTo UnknownError
Dim PicW As Long
Dim PicH As Long 'width and height of picture
Dim PicX As Long
Dim PicY As Long 'picture pos
Dim DH As Long 'button height
Dim dw As Long 'button width
Dim Align As Long 'text aligment
Dim bDrawText As Boolean ' if picture is in center text is not drawn
bDrawText = True
Align = DT_VCENTER Or DT_SINGLELINE Or DT_END_ELLIPSIS
Select Case m_TextAlign
Case Is = vbLeftJustify: Align = Align Or DT_LEFT
Case Is = vbRightJustify: Align = Align Or DT_RIGHT
Case Is = vbCenter: Align = Align Or DT_CENTER
End Select
dw = UserControl.ScaleWidth
DH = UserControl.ScaleHeight
m_State = State
'if skin picture is not set then just draw text on control
If m_SkinPicture Is Nothing Then
ClearRect hdc, SetRect(0, 0, dw, DH), TranslateColor(UserControl.BackColor)
DrawText hdc, m_Text, SetRect(0, 0, dw, DH), Align
If UserControl.AutoRedraw = True Then
UserControl.Refresh
End If
Exit Sub
End If
m_SkinPicture.ScaleMode = vbPixels
Dim SrcLeft As Long 'left cordinate of skin in skinpicture
Dim SrcRight As Long 'right -II-
Dim FillColor As Long 'color to fill middle area of button
'used if m_FillWithColor is true
Dim H As Long 'height of skinpicture
Dim w As Long 'width of button skin
H = m_SkinPicture.ScaleHeight
w = m_SkinPicture.ScaleWidth / 5
'Debug.Print H, W
'
SrcLeft = (State - 1) * w
SrcRight = State * w
If m_FillWithColor Then
'get color to fill with from (SrcLeft+m_SizeCW +1 , m_SizeCH+1) on
'skin picture
FillColor = m_SkinPicture.Point(SrcLeft + m_SizeCW + 1, m_SizeCH + 1)
End If
'Exit Sub