-
Notifications
You must be signed in to change notification settings - Fork 1
/
FlatButton.ctl
1465 lines (1284 loc) · 50.8 KB
/
FlatButton.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 FlatButton
AutoRedraw = -1 'True
ClientHeight = 705
ClientLeft = 0
ClientTop = 0
ClientWidth = 1665
DefaultCancel = -1 'True
HasDC = 0 'False
LockControls = -1 'True
PropertyPages = "FlatButton.ctx":0000
ScaleHeight = 705
ScaleWidth = 1665
ToolboxBitmap = "FlatButton.ctx":0035
Begin VB.Label lblLine
Alignment = 2 'Center
AutoSize = -1 'True
BackStyle = 0 'Transparent
Height = 180
Left = 1185
TabIndex = 1
Top = 255
UseMnemonic = 0 'False
Visible = 0 'False
Width = 90
End
Begin VB.Label lblCaption
Alignment = 2 'Center
AutoSize = -1 'True
BackStyle = 0 'Transparent
Height = 180
Left = 705
TabIndex = 0
Top = 255
UseMnemonic = 0 'False
Visible = 0 'False
Width = 90
End
Begin VB.Image imgIcon
Height = 240
Left = 315
Stretch = -1 'True
Top = 240
Visible = 0 'False
Width = 240
End
End
Attribute VB_Name = "FlatButton"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
' 平面按钮控件
' 版本: 2.0.1.2
' 作者: 赵畅
' 日期: 2003.8.14
Option Explicit
Private Declare Function SetCapture Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function GetCapture Lib "user32" () As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function GetActiveWindow Lib "user32" () As Long
Private Declare Sub InitCommonControls Lib "comctl32.dll" ()
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function DestroyWindow Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" _
(ByVal dwExStyle As Long, ByVal lpClassName As String, _
ByVal lpWindowName As String, ByVal dwStyle As Long, _
ByVal X As Long, ByVal Y As Long, _
ByVal nWidth As Long, ByVal nHeight As Long, _
ByVal hwndParent As Long, ByVal hMenu As Long, _
ByVal hInstance As Long, lpParam As Any) As Long
'Private Const WM_MOUSEMOVE = &H200
'Private Const WM_LBUTTONDOWN = &H201
'Private Const WM_LBUTTONUP = &H202
Public Enum eButtonStyle
bsNormal = 0
bsPicture = 1
bsPush = 2
bsFlat = 3
End Enum
Public Enum eUseButton
ubLeftButton = vbLeftButton
ubRightButton = vbRightButton
End Enum
Public Enum eIconSize
is16x16 = 16
is32x32 = 32
is48x48 = 48
End Enum
#Const WIN32_IE = &H400 ' 1024
Const TTDT_AUTOMATIC = 0
Const TTDT_RESHOW = 1
Const TTDT_AUTOPOP = 2
Const TTDT_INITIAL = 3
Const TOOLTIPS_CLASS = "tooltips_class32"
Const TTS_ALWAYSTIP = &H1
Const WM_USER = &H400
Private Enum TT_Msgs
TTM_SETDELAYTIME = (WM_USER + 3)
#If UNICODE Then
TTM_ADDTOOL = (WM_USER + 50)
TTM_UPDATETIPTEXT = (WM_USER + 57)
TTM_ENUMTOOLS = (WM_USER + 58)
#Else
TTM_ADDTOOL = (WM_USER + 4)
TTM_UPDATETIPTEXT = (WM_USER + 12)
TTM_ENUMTOOLS = (WM_USER + 14)
#End If ' UNICODE
#If (WIN32_IE >= &H300) Then
TTM_SETMAXTIPWIDTH = (WM_USER + 24)
#End If ' (WIN32_IE >= &H300)
End Enum ' TT_Msgs
Private Enum ttDelayTimeConstants
ttDelayDefault = TTDT_AUTOMATIC '= 0
ttDelayInitial = TTDT_INITIAL '= 3
ttDelayShow = TTDT_AUTOPOP '= 2
ttDelayReshow = TTDT_RESHOW '= 1
ttDelayMask = 3
End Enum
Private Enum TT_Flags
TTF_IDISHWND = &H1
TTF_SUBCLASS = &H10
End Enum ' TT_Flags
Private Type RECT ' rct
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type TOOLINFO
cbSize As Long
uFlags As TT_Flags
hWnd As Long
uId As Long
RECT As RECT
hinst As Long
lpszText As String ' Long
#If (WIN32_IE >= &H300) Then
lParam As Long
#End If
End Type ' TOOLINFO
Const ICON_SPACE = 80
'缺省属性值:
Const m_def_IconSize = is16x16
Const m_def_AutoSize = False
Const m_def_NormalForeColor = vbBlack
Const m_def_BackColor = vbButtonFace
Const m_def_OverBackColor = 0
Const m_def_DownBackColor = 0
Const m_def_OverBorderColor = 0
Const m_def_DownBorderColor = 0
Const m_def_BorderColor = 0
Const m_def_FocusColor = vbButtonShadow
Const m_def_ToolTip = ""
Const m_def_HotColor = vbBlue
Const m_def_EnableHot = False
Const m_def_DisableColor = vbGrayText
Const m_def_LightBorderColor1 = vb3DHighlight
Const m_def_DarkBorderColor1 = vbButtonShadow
Const m_def_LightBorderColor2 = vb3DLight
Const m_def_DarkBorderColor2 = vb3DDKShadow
Const m_def_Style = bsNormal
Const m_def_UseButton = ubLeftButton
Const m_def_Value = False
Const m_def_Caption = ""
Dim m_hWndTT As Long
Dim m_cMaxTip As Long
'属性变量:
Dim m_IconSize As eIconSize
Dim m_AutoSize As Boolean
Dim m_NormalForeColor As OLE_COLOR
Dim m_BackColor As OLE_COLOR
Dim m_OverBackColor As OLE_COLOR
Dim m_DownBackColor As OLE_COLOR
Dim m_OverBorderColor As OLE_COLOR
Dim m_DownBorderColor As OLE_COLOR
Dim m_BorderColor As OLE_COLOR
Dim m_FocusColor As OLE_COLOR
Dim m_ToolTip As String
Dim m_Icon As Picture
Dim m_HotColor As OLE_COLOR
Dim m_EnableHot As Boolean
Dim m_DisableColor As OLE_COLOR
Dim m_LightBorderColor1 As OLE_COLOR
Dim m_DarkBorderColor1 As OLE_COLOR
Dim m_LightBorderColor2 As OLE_COLOR
Dim m_DarkBorderColor2 As OLE_COLOR
Dim m_Picture As Picture
Dim m_DownPicture As Picture
Dim m_OverPicture As Picture
Dim m_Style As eButtonStyle
Dim m_UseButton As eUseButton
Dim m_Value As Boolean
Dim m_Caption As String
Dim m_MouseOver As Boolean
Dim m_MouseOut As Boolean
Dim m_Focus As Boolean
Dim m_FocusRect As Boolean
Dim m_Button As Integer
'事件声明:
Public Event Click(Button As Integer)
Public Event ValueChange(Value As Boolean)
Public Event MouseOver()
Public Event MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Public Event MouseOut()
Private Sub imgIcon_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Call ReleaseCapture
Call UserControl_MouseDown(Button, Shift, 0, 0)
End Sub
Private Sub imgIcon_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Call ReleaseCapture
Call UserControl_MouseMove(Button, Shift, 0, 0)
End Sub
Private Sub imgIcon_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Call ReleaseCapture
Call UserControl_MouseUp(Button, Shift, 0, 0)
End Sub
Private Sub UserControl_KeyDown(KeyCode As Integer, Shift As Integer)
On Error Resume Next
If (KeyCode = vbKeySpace Or KeyCode = vbKeyReturn) And UserControl.Enabled Then
RaiseEvent Click(Val(m_UseButton))
End If
End Sub
Private Sub UserControl_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim Over As Boolean
On Error Resume Next
If Not UserControl.Enabled Then Exit Sub
Over = (X >= 0) And (X <= ScaleWidth) And (Y >= 0) And (Y <= ScaleHeight)
If m_EnableHot Then
lblCaption.ForeColor = m_HotColor
lblLine.ForeColor = m_HotColor
End If
If Not m_Focus And (Button And m_UseButton) = m_UseButton And Over Then
m_Button = Button
m_Focus = True
Call ItemDown
End If
End Sub
Private Sub UserControl_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim Over As Boolean
On Error Resume Next
If Not UserControl.Enabled Then Exit Sub
Over = (X >= 0) And (X <= ScaleWidth) And (Y >= 0) And (Y <= ScaleHeight)
If Over Then
' 鼠标按钮抬起时,在按钮上。
If m_Focus Then
' 有焦点。
If (Button And m_UseButton) = m_UseButton And (Button And m_Button) = m_Button Then
Call ResetButton
RaiseEvent ValueChange(m_Value)
If m_Value Then
' 已按下
Call ItemDown
Else
Call ItemOut
End If
If m_EnableHot Then
lblCaption.ForeColor = m_NormalForeColor
lblLine.ForeColor = m_NormalForeColor
End If
RaiseEvent MouseOut
RaiseEvent Click(Button)
End If
End If
Else
' 鼠标按钮抬起时,不在按钮上。
If (Button And m_Button) = m_Button Then
Call ResetButton
If m_Value Then
Call ItemDown
Else
Call ItemOut
End If
If m_EnableHot Then
lblCaption.ForeColor = m_NormalForeColor
lblLine.ForeColor = m_NormalForeColor
End If
RaiseEvent MouseOut
End If
End If
End Sub
Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim Over As Boolean
On Error Resume Next
'If (Not UserControl.Enabled) Then Exit Sub
If (GetActiveWindow() <> UserControl.Parent.hWnd) Or (Not UserControl.Enabled) Then
'Call ResetButton
Exit Sub
End If
Over = (X >= 0) And (X <= ScaleWidth) And (Y >= 0) And (Y <= ScaleHeight)
If Over Then
' 鼠标移动到按钮上。
If GetCapture() <> UserControl.hWnd Then
Call SetCapture(UserControl.hWnd)
'UserControl.SetFocus
End If
If Not m_MouseOver Then
m_MouseOver = True
m_MouseOut = False
If m_Focus Then
' 如果移动到按钮上时有焦点(按钮设置必须相同),
' 则显示按下按钮。
If (Button And m_UseButton) = m_UseButton Then Call ItemDown
Else
' 没有焦点,则显示弹起按钮。
If m_EnableHot Then
lblCaption.ForeColor = m_HotColor
lblLine.ForeColor = m_HotColor
End If
RaiseEvent MouseOver
If m_Value Then
' 已按下
Call ItemDown
Else
Call ItemOver
End If
End If
End If
RaiseEvent MouseMove(Button, Shift, X, Y)
Else
' 鼠标移出按钮。
If Not m_MouseOut Then
m_MouseOut = True
m_MouseOver = False
If m_Focus Then
' 如果移出按钮时(按钮设置必须相同)有焦点,
' 则显示弹起按钮。
If (Button And m_UseButton) = m_UseButton Then
If m_Value Then
Call ItemDown
Else
Call ItemOver
End If
End If
Else
If m_Value Then
' 已按下
Call ItemDown
Else
Call ItemOut
End If
Call ResetButton
If m_EnableHot Then
lblCaption.ForeColor = m_NormalForeColor
lblLine.ForeColor = m_NormalForeColor
End If
RaiseEvent MouseOut
End If
End If
End If
End Sub
Private Sub lblCaption_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Call ReleaseCapture
Call UserControl_MouseDown(Button, Shift, 0, 0)
End Sub
Private Sub lblCaption_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Call ReleaseCapture
Call UserControl_MouseUp(Button, Shift, 0, 0)
End Sub
Private Sub lblCaption_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Call ReleaseCapture
Call UserControl_MouseMove(Button, Shift, 0, 0)
End Sub
Private Sub lblLine_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Call ReleaseCapture
Call UserControl_MouseDown(Button, Shift, 0, 0)
End Sub
Private Sub lblLine_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Call ReleaseCapture
Call UserControl_MouseUp(Button, Shift, 0, 0)
End Sub
Private Sub lblLine_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Call ReleaseCapture
Call UserControl_MouseMove(Button, Shift, 0, 0)
End Sub
Private Sub ItemOut()
On Error Resume Next
Select Case m_Style
Case bsNormal
'UserControl.BackColor = m_BackColor
Call ClearPicture
' 焦点框
Call DrawFocusRect(m_FocusRect)
If Not (m_Icon Is Nothing) Then
Set imgIcon.Picture = m_Icon
If m_Caption = "" Then
Call imgIcon.Move((ScaleWidth - imgIcon.Width) \ 2, (ScaleHeight - imgIcon.Height) \ 2)
Else
Call imgIcon.Move((ScaleWidth - (imgIcon.Width + lblCaption.Width + ICON_SPACE)) \ 2, (ScaleHeight - imgIcon.Height) \ 2)
End If
imgIcon.Visible = True
Call lblCaption.Move((ScaleWidth - (imgIcon.Width + lblCaption.Width + ICON_SPACE)) \ 2 + imgIcon.Width + ICON_SPACE, (ScaleHeight - lblCaption.Height) \ 2)
Else
Call lblCaption.Move((ScaleWidth - lblCaption.Width) \ 2, (ScaleHeight - lblCaption.Height) \ 2)
End If
Call DisplayLine
Case bsPicture
'UserControl.BackColor = m_BackColor
Set UserControl.Picture = m_Picture
Case bsPush
'UserControl.BackColor = m_BackColor
'Debug.Print "Out"
Call ClearPicture
If Extender.Default And UserControl.Enabled Then
Call DrawEdge(GetTwipX(1), GetTwipY(1), ScaleWidth - GetTwipX(2), ScaleHeight - GetTwipY(2), m_LightBorderColor1, m_DarkBorderColor1)
UserControl.Line (0, 0)-(ScaleWidth - GetTwipX(1), ScaleHeight - GetTwipY(1)), m_DarkBorderColor2, B
Else
Call DrawEdge(0, 0, ScaleWidth - GetTwipX(1), ScaleHeight - GetTwipY(1), m_LightBorderColor1, m_DarkBorderColor1)
End If
' 焦点框
Call DrawFocusRect(m_FocusRect)
If Not (m_Icon Is Nothing) Then
Set imgIcon.Picture = m_Icon
If m_Caption = "" Then
Call imgIcon.Move((ScaleWidth - imgIcon.Width) \ 2, (ScaleHeight - imgIcon.Height) \ 2)
Else
Call imgIcon.Move((ScaleWidth - (imgIcon.Width + lblCaption.Width + ICON_SPACE)) \ 2, (ScaleHeight - imgIcon.Height) \ 2)
End If
imgIcon.Visible = True
Call lblCaption.Move((ScaleWidth - (imgIcon.Width + lblCaption.Width + ICON_SPACE)) \ 2 + imgIcon.Width + ICON_SPACE, (ScaleHeight - lblCaption.Height) \ 2)
Else
Call lblCaption.Move((ScaleWidth - lblCaption.Width) \ 2, (ScaleHeight - lblCaption.Height) \ 2)
End If
Call DisplayLine
Case bsFlat
UserControl.BackColor = m_BackColor
Call ClearPicture
Call DrawEdge(0, 0, ScaleWidth - GetTwipX(1), ScaleHeight - GetTwipY(1), m_BorderColor, m_BorderColor)
If Not (m_Icon Is Nothing) Then
Set imgIcon.Picture = m_Icon
If m_Caption = "" Then
Call imgIcon.Move((ScaleWidth - imgIcon.Width) \ 2, (ScaleHeight - imgIcon.Height) \ 2)
Else
Call imgIcon.Move((ScaleWidth - (imgIcon.Width + lblCaption.Width + ICON_SPACE)) \ 2, (ScaleHeight - imgIcon.Height) \ 2)
End If
imgIcon.Visible = True
Call lblCaption.Move((ScaleWidth - (imgIcon.Width + lblCaption.Width + ICON_SPACE)) \ 2 + imgIcon.Width + ICON_SPACE, (ScaleHeight - lblCaption.Height) \ 2)
Else
Call lblCaption.Move((ScaleWidth - lblCaption.Width) \ 2, (ScaleHeight - lblCaption.Height) \ 2)
End If
Call DisplayLine
End Select
'Call UserControl.Refresh
End Sub
Private Sub ItemOver()
On Error Resume Next
Select Case m_Style
Case bsNormal
'UserControl.BackColor = m_BackColor
Call ClearPicture
Call DrawEdge(0, 0, ScaleWidth - GetTwipX(1), ScaleHeight - GetTwipY(1), m_LightBorderColor1, m_DarkBorderColor1)
' 焦点框
Call DrawFocusRect(m_FocusRect)
If Not (m_Icon Is Nothing) Then
Set imgIcon.Picture = m_Icon
If m_Caption = "" Then
Call imgIcon.Move((ScaleWidth - imgIcon.Width) \ 2, (ScaleHeight - imgIcon.Height) \ 2)
Else
Call imgIcon.Move((ScaleWidth - (imgIcon.Width + lblCaption.Width + ICON_SPACE)) \ 2, (ScaleHeight - imgIcon.Height) \ 2)
End If
imgIcon.Visible = True
Call lblCaption.Move((ScaleWidth - (imgIcon.Width + lblCaption.Width + ICON_SPACE)) \ 2 + imgIcon.Width + ICON_SPACE, (ScaleHeight - lblCaption.Height) \ 2)
Else
Call lblCaption.Move((ScaleWidth - lblCaption.Width) \ 2, (ScaleHeight - lblCaption.Height) \ 2)
End If
Call DisplayLine
Case bsPicture
'UserControl.BackColor = m_BackColor
If m_OverPicture Is Nothing Then
Set UserControl.Picture = m_Picture
Else
Set UserControl.Picture = m_OverPicture
End If
Case bsPush
'UserControl.BackColor = m_BackColor
Call ClearPicture
' 内框
Call DrawEdge(GetTwipX(1), GetTwipY(1), ScaleWidth - GetTwipX(2), ScaleHeight - GetTwipY(2), m_LightBorderColor2, m_DarkBorderColor1)
' 外框
Call DrawEdge(0, 0, ScaleWidth - GetTwipX(1), ScaleHeight - GetTwipY(1), m_LightBorderColor1, m_DarkBorderColor2)
' 焦点框
Call DrawFocusRect(m_FocusRect)
If Not (m_Icon Is Nothing) Then
Set imgIcon.Picture = m_Icon
If m_Caption = "" Then
Call imgIcon.Move((ScaleWidth - imgIcon.Width) \ 2, (ScaleHeight - imgIcon.Height) \ 2)
Else
Call imgIcon.Move((ScaleWidth - (imgIcon.Width + lblCaption.Width + ICON_SPACE)) \ 2, (ScaleHeight - imgIcon.Height) \ 2)
End If
imgIcon.Visible = True
Call lblCaption.Move((ScaleWidth - (imgIcon.Width + lblCaption.Width + ICON_SPACE)) \ 2 + imgIcon.Width + ICON_SPACE, (ScaleHeight - lblCaption.Height) \ 2)
Else
Call lblCaption.Move((ScaleWidth - lblCaption.Width) \ 2, (ScaleHeight - lblCaption.Height) \ 2)
End If
Call DisplayLine
Case bsFlat
UserControl.BackColor = m_OverBackColor
Call ClearPicture
Call DrawEdge(0, 0, ScaleWidth - GetTwipX(1), ScaleHeight - GetTwipY(1), m_OverBorderColor, m_OverBorderColor)
If Not (m_Icon Is Nothing) Then
Set imgIcon.Picture = m_Icon
If m_Caption = "" Then
Call imgIcon.Move((ScaleWidth - imgIcon.Width) \ 2, (ScaleHeight - imgIcon.Height) \ 2)
Else
Call imgIcon.Move((ScaleWidth - (imgIcon.Width + lblCaption.Width + ICON_SPACE)) \ 2, (ScaleHeight - imgIcon.Height) \ 2)
End If
imgIcon.Visible = True
Call lblCaption.Move((ScaleWidth - (imgIcon.Width + lblCaption.Width + ICON_SPACE)) \ 2 + imgIcon.Width + ICON_SPACE, (ScaleHeight - lblCaption.Height) \ 2)
Else
Call lblCaption.Move((ScaleWidth - lblCaption.Width) \ 2, (ScaleHeight - lblCaption.Height) \ 2)
End If
Call DisplayLine
End Select
'Call UserControl.Refresh
End Sub
Private Sub ItemDown()
On Error Resume Next
Select Case m_Style
Case bsNormal
'UserControl.BackColor = m_BackColor
Call ClearPicture
Call DrawEdge(0, 0, ScaleWidth - GetTwipX(1), ScaleHeight - GetTwipY(1), m_DarkBorderColor1, m_LightBorderColor1)
' 焦点框
Call DrawFocusRect(m_FocusRect)
If Not (m_Icon Is Nothing) Then
Set imgIcon.Picture = m_Icon
If m_Caption = "" Then
Call imgIcon.Move((ScaleWidth - imgIcon.Width) \ 2 + GetTwipX(1), (ScaleHeight - imgIcon.Height) \ 2 + GetTwipY(1))
Else
Call imgIcon.Move((ScaleWidth - (imgIcon.Width + lblCaption.Width + ICON_SPACE)) \ 2 + GetTwipX(1), (ScaleHeight - imgIcon.Height) \ 2 + GetTwipY(1))
End If
imgIcon.Visible = True
Call lblCaption.Move((ScaleWidth - (imgIcon.Width + lblCaption.Width + ICON_SPACE)) \ 2 + imgIcon.Width + ICON_SPACE + GetTwipX(1), (ScaleHeight - lblCaption.Height) \ 2 + GetTwipY(1))
Else
Call lblCaption.Move((ScaleWidth - lblCaption.Width) \ 2 + GetTwipX(1), (ScaleHeight - lblCaption.Height) \ 2 + GetTwipY(1))
End If
Call DisplayLine
Case bsPicture
'UserControl.BackColor = m_BackColor
If m_DownPicture Is Nothing Then
Set UserControl.Picture = m_Picture
Else
Set UserControl.Picture = m_DownPicture
End If
Case bsPush
'UserControl.BackColor = m_BackColor
Call ClearPicture
' 内框
Call DrawEdge(GetTwipX(1), GetTwipY(1), ScaleWidth - GetTwipX(2), ScaleHeight - GetTwipY(2), m_DarkBorderColor1, m_LightBorderColor2)
' 外框
Call DrawEdge(0, 0, ScaleWidth - GetTwipX(1), ScaleHeight - GetTwipY(1), m_DarkBorderColor2, m_LightBorderColor1)
' 焦点框
Call DrawFocusRect(m_FocusRect)
If Not (m_Icon Is Nothing) Then
Set imgIcon.Picture = m_Icon
If m_Caption = "" Then
Call imgIcon.Move((ScaleWidth - imgIcon.Width) \ 2 + GetTwipX(1), (ScaleHeight - imgIcon.Height) \ 2 + GetTwipY(1))
Else
Call imgIcon.Move((ScaleWidth - (imgIcon.Width + lblCaption.Width + ICON_SPACE)) \ 2 + GetTwipX(1), (ScaleHeight - imgIcon.Height) \ 2 + GetTwipY(1))
End If
imgIcon.Visible = True
Call lblCaption.Move((ScaleWidth - (imgIcon.Width + lblCaption.Width + ICON_SPACE)) \ 2 + imgIcon.Width + ICON_SPACE + GetTwipX(1), (ScaleHeight - lblCaption.Height) \ 2 + GetTwipY(1))
Else
Call lblCaption.Move((ScaleWidth - lblCaption.Width) \ 2 + GetTwipX(1), (ScaleHeight - lblCaption.Height) \ 2 + GetTwipY(1))
End If
Call DisplayLine
Case bsFlat
UserControl.BackColor = m_DownBackColor
Call ClearPicture
Call DrawEdge(0, 0, ScaleWidth - GetTwipX(1), ScaleHeight - GetTwipY(1), m_DownBorderColor, m_DownBorderColor)
If Not (m_Icon Is Nothing) Then
Set imgIcon.Picture = m_Icon
If m_Caption = "" Then
Call imgIcon.Move((ScaleWidth - imgIcon.Width) \ 2 + GetTwipX(1), (ScaleHeight - imgIcon.Height) \ 2 + GetTwipY(1))
Else
Call imgIcon.Move((ScaleWidth - (imgIcon.Width + lblCaption.Width + ICON_SPACE)) \ 2 + GetTwipX(1), (ScaleHeight - imgIcon.Height) \ 2 + GetTwipY(1))
End If
imgIcon.Visible = True
Call lblCaption.Move((ScaleWidth - (imgIcon.Width + lblCaption.Width + ICON_SPACE)) \ 2 + imgIcon.Width + ICON_SPACE + GetTwipX(1), (ScaleHeight - lblCaption.Height) \ 2 + GetTwipY(1))
Else
Call lblCaption.Move((ScaleWidth - lblCaption.Width) \ 2 + GetTwipX(1), (ScaleHeight - lblCaption.Height) \ 2 + GetTwipY(1))
End If
Call DisplayLine
End Select
'Call UserControl.Refresh
End Sub
Private Sub UserControl_AccessKeyPress(KeyAscii As Integer)
On Error Resume Next
If UserControl.Enabled Then
KeyAscii = 0
RaiseEvent Click(Val(m_UseButton))
End If
End Sub
Private Sub UserControl_AmbientChanged(PropertyName As String)
'Debug.Print PropertyName; " "
Call ReDraw
End Sub
Private Sub UserControl_EnterFocus()
Call DrawFocusRect(True)
End Sub
Private Sub UserControl_ExitFocus()
Call DrawFocusRect(False)
End Sub
Private Sub UserControl_Resize()
Call ReDraw
End Sub
Private Sub ReDraw()
Dim i As Long
On Error Resume Next
Select Case m_Style
Case bsNormal, bsPush, bsFlat
i = InStr(1, m_Caption, "&")
If i > 0 Then
UserControl.AccessKeys = Mid(m_Caption, i + 1, 1)
lblCaption.Caption = Left(m_Caption, i - 1) & Mid(m_Caption, i + 1)
lblLine.Caption = Space(StrLen(Left(m_Caption, i - 1))) & "_" & Space(StrLen(m_Caption) - i)
'Debug.Print UserControl.AccessKeys
'lblCaption
Else
UserControl.AccessKeys = ""
lblCaption.Caption = m_Caption
lblLine.Caption = ""
End If
Set UserControl.Picture = Nothing
lblCaption.Visible = True
lblLine.Visible = True
imgIcon.Width = GetTwipX(m_IconSize)
imgIcon.Height = GetTwipY(m_IconSize)
imgIcon.Visible = True
If m_AutoSize Then
With UserControl
.Width = lblCaption.Width + GetTwipX(10)
.Height = lblCaption.Height + GetTwipY(8)
End With
End If
If m_Value Then
Call ItemDown
Else
If Ambient.UserMode Then
' 运行模式
If m_Focus And m_MouseOver Then
Call ItemDown
ElseIf m_Focus Then
Call ItemOver
Else
Call ItemOut
End If
Else
' 设计模式
If m_Style = bsFlat Then
Call ItemOut
Else
Call ItemOver
End If
End If
End If
Case bsPicture
lblCaption.Visible = False
lblLine.Visible = False
imgIcon.Visible = False
'Set UserControl.Picture = m_Picture
If m_Value Then
' 已按下
Call ItemDown
Else
If m_Focus And m_MouseOver Then
Call ItemDown
ElseIf m_Focus Then
Call ItemOver
Else
Call ItemOut
End If
End If
If m_AutoSize Then
With UserControl
.Width = UserControl.Width
.Height = UserControl.Height
End With
End If
End Select
If Not UserControl.Enabled Then
lblCaption.ForeColor = m_DisableColor
Else
If m_EnableHot Then
If m_MouseOver Then
lblCaption.ForeColor = m_HotColor
ElseIf Not m_Focus Then
lblCaption.ForeColor = m_NormalForeColor
End If
Else
lblCaption.ForeColor = m_NormalForeColor
End If
End If
lblLine.ForeColor = lblCaption.ForeColor
Call imgIcon.Refresh
Call UserControl.Refresh
End Sub
Private Sub UserControl_Initialize()
m_MouseOver = False
m_MouseOut = False
m_Focus = False
m_Button = 0
m_hWndTT = 0
'If m_Style <> bsPicture Then lblCaption.Visible = True
End Sub
Private Sub ResetButton()
Call SetCapture(UserControl.hWnd)
Call ReleaseCapture
m_MouseOver = False
m_MouseOut = False
m_Focus = False
m_Button = 0
End Sub
Private Sub DisplayLine()
Call lblLine.Move(lblCaption.Left, lblCaption.Top)
End Sub
Private Sub ClearPicture()
Call DrawEdge(GetTwipX(1), GetTwipY(1), ScaleWidth - GetTwipX(2), ScaleHeight - GetTwipY(2), UserControl.BackColor, UserControl.BackColor)
Call DrawEdge(0, 0, ScaleWidth - GetTwipX(1), ScaleHeight - GetTwipY(1), UserControl.BackColor, UserControl.BackColor)
End Sub
Private Sub DrawEdge(ByVal X1 As Single, ByVal Y1 As Single, ByVal X2 As Single, ByVal Y2 As Single, ByVal Color1 As OLE_COLOR, ByVal Color2 As OLE_COLOR)
On Error Resume Next
UserControl.Line (X1, Y1)-(X2, Y1), Color1 ' Top Line
UserControl.Line (X1, Y1)-(X1, Y2), Color1 ' Left Line
UserControl.Line (X2, Y2)-(X1 - 10, Y2), Color2 ' Bottom Line
UserControl.Line (X2, Y2)-(X2, Y1 - 10), Color2 ' Right Line
End Sub
Private Sub DrawFocusRect(ByVal Draw As Boolean)
On Error Resume Next
If m_Style <> bsPicture And m_Style <> bsFlat Then
If Draw Then
UserControl.Line (GetTwipX(2), GetTwipY(2))-(ScaleWidth - GetTwipX(3), ScaleHeight - GetTwipY(3)), m_FocusColor, B
m_FocusRect = True
Else
UserControl.Line (GetTwipX(2), GetTwipY(2))-(ScaleWidth - GetTwipX(3), ScaleHeight - GetTwipY(3)), UserControl.BackColor, B
m_FocusRect = False
End If
End If
End Sub
'注意!不要删除或修改下列被注释的行!
'MemberInfo=0
Public Function Reset() As Boolean
If m_Value Then
Call ItemDown
Else
Call ItemOut
End If
Call ResetButton
Reset = True
End Function
'为用户控件初始化属性
Private Sub UserControl_InitProperties()
On Error Resume Next
m_Caption = Extender.Name
m_BackColor = m_def_BackColor
m_NormalForeColor = m_def_NormalForeColor
m_Value = m_def_Value
m_UseButton = m_def_UseButton
m_Style = m_def_Style
m_HotColor = m_def_HotColor
m_EnableHot = m_def_EnableHot
m_DisableColor = m_def_DisableColor
m_LightBorderColor1 = m_def_LightBorderColor1
m_DarkBorderColor1 = m_def_DarkBorderColor1
m_LightBorderColor2 = m_def_LightBorderColor2
m_DarkBorderColor2 = m_def_DarkBorderColor2
m_ToolTip = m_def_ToolTip
m_FocusColor = m_def_FocusColor
m_OverBorderColor = m_def_OverBorderColor
m_DownBorderColor = m_def_DownBorderColor
m_BorderColor = m_def_BorderColor
m_OverBackColor = m_def_OverBackColor
m_DownBackColor = m_def_DownBackColor
m_AutoSize = m_def_AutoSize
m_IconSize = m_def_IconSize
Set m_Picture = Nothing
Set m_DownPicture = Nothing
Set m_OverPicture = Nothing
Set m_Icon = Nothing
Call ReDraw
End Sub
Private Sub UserControl_Terminate()
If m_hWndTT > 0 Then
Call DestroyWindow(m_hWndTT)
End If
End Sub
'从存贮器中加载属性值
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
On Error Resume Next
'UserControl.BackColor = UserControl.BackColor
lblCaption.ForeColor = PropBag.ReadProperty("ForeColor", &H80000012)
UserControl.MousePointer = PropBag.ReadProperty("MousePointer", 0)
UserControl.Enabled = PropBag.ReadProperty("Enabled", True)
Set lblCaption.Font = PropBag.ReadProperty("Font", Ambient.Font)
Set lblLine.Font = lblCaption.Font
Set MouseIcon = PropBag.ReadProperty("MouseIcon", Nothing)
Set m_Picture = PropBag.ReadProperty("Picture", Nothing)
Set m_DownPicture = PropBag.ReadProperty("DownPicture", Nothing)
Set m_OverPicture = PropBag.ReadProperty("OverPicture", Nothing)
m_LightBorderColor1 = PropBag.ReadProperty("LightBorderColor1", m_def_LightBorderColor1)
m_DarkBorderColor1 = PropBag.ReadProperty("DarkBorderColor1", m_def_DarkBorderColor1)
m_LightBorderColor2 = PropBag.ReadProperty("LightBorderColor2", m_def_LightBorderColor2)
m_DarkBorderColor2 = PropBag.ReadProperty("DarkBorderColor2", m_def_DarkBorderColor2)
m_Value = PropBag.ReadProperty("Value", m_def_Value)
m_UseButton = PropBag.ReadProperty("UseButton", m_def_UseButton)
m_AutoSize = PropBag.ReadProperty("AutoSize", m_def_AutoSize)
m_Style = PropBag.ReadProperty("Style", m_def_Style)
m_Caption = PropBag.ReadProperty("Caption", Extender.Name)
m_DisableColor = PropBag.ReadProperty("DisableColor", m_def_DisableColor)
m_HotColor = PropBag.ReadProperty("HotColor", m_def_HotColor)
m_EnableHot = PropBag.ReadProperty("EnableHot", m_def_EnableHot)
m_BackColor = PropBag.ReadProperty("BackColor", m_def_BackColor)
m_NormalForeColor = PropBag.ReadProperty("NormalForeColor", m_def_NormalForeColor)
m_ToolTip = PropBag.ReadProperty("ToolTip", m_def_ToolTip)
m_FocusColor = PropBag.ReadProperty("FocusColor", m_def_FocusColor)
m_OverBorderColor = PropBag.ReadProperty("OverBorderColor", m_def_OverBorderColor)
m_DownBorderColor = PropBag.ReadProperty("DownBorderColor", m_def_DownBorderColor)
m_BorderColor = PropBag.ReadProperty("BorderColor", m_def_BorderColor)
m_OverBackColor = PropBag.ReadProperty("OverBackColor", m_def_OverBackColor)
m_DownBackColor = PropBag.ReadProperty("DownBackColor", m_def_DownBackColor)
m_IconSize = PropBag.ReadProperty("IconSize", m_def_IconSize)
Set m_Icon = PropBag.ReadProperty("Icon", Nothing)
' 初始化工具提示
Call SetToolTip(m_ToolTip)
Call ReDraw
End Sub
'将属性值写到存储器
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
On Error Resume Next
Call PropBag.WriteProperty("Caption", m_Caption, Extender.Name)
Call PropBag.WriteProperty("Value", m_Value, m_def_Value)
Call PropBag.WriteProperty("MousePointer", UserControl.MousePointer, 0)
Call PropBag.WriteProperty("MouseIcon", MouseIcon, Nothing)
Call PropBag.WriteProperty("UseButton", m_UseButton, m_def_UseButton)
Call PropBag.WriteProperty("Style", m_Style, m_def_Style)
Call PropBag.WriteProperty("Picture", m_Picture, Nothing)
Call PropBag.WriteProperty("DownPicture", m_DownPicture, Nothing)
Call PropBag.WriteProperty("OverPicture", m_OverPicture, Nothing)
Call PropBag.WriteProperty("Enabled", UserControl.Enabled, True)
Call PropBag.WriteProperty("Font", lblCaption.Font, Ambient.Font)
Call PropBag.WriteProperty("LightBorderColor1", m_LightBorderColor1, m_def_LightBorderColor1)
Call PropBag.WriteProperty("DarkBorderColor1", m_DarkBorderColor1, m_def_DarkBorderColor1)
Call PropBag.WriteProperty("LightBorderColor2", m_LightBorderColor2, m_def_LightBorderColor2)
Call PropBag.WriteProperty("DarkBorderColor2", m_DarkBorderColor2, m_def_DarkBorderColor2)
Call PropBag.WriteProperty("DisableColor", m_DisableColor, m_def_DisableColor)
Call PropBag.WriteProperty("HotColor", m_HotColor, m_def_HotColor)
Call PropBag.WriteProperty("EnableHot", m_EnableHot, m_def_EnableHot)
Call PropBag.WriteProperty("Icon", m_Icon, Nothing)
Call PropBag.WriteProperty("ToolTip", m_ToolTip, m_def_ToolTip)
Call PropBag.WriteProperty("FocusColor", m_FocusColor, m_def_FocusColor)
Call PropBag.WriteProperty("OverBorderColor", m_OverBorderColor, m_def_OverBorderColor)
Call PropBag.WriteProperty("DownBorderColor", m_DownBorderColor, m_def_DownBorderColor)
Call PropBag.WriteProperty("BorderColor", m_BorderColor, m_def_BorderColor)
Call PropBag.WriteProperty("OverBackColor", m_OverBackColor, m_def_OverBackColor)
Call PropBag.WriteProperty("DownBackColor", m_DownBackColor, m_def_DownBackColor)
Call PropBag.WriteProperty("BackColor", m_BackColor, m_def_BackColor)
Call PropBag.WriteProperty("ForeColor", lblCaption.ForeColor, &H80000012)
Call PropBag.WriteProperty("NormalForeColor", m_NormalForeColor, m_def_NormalForeColor)
Call PropBag.WriteProperty("AutoSize", m_AutoSize, m_def_AutoSize)
Call PropBag.WriteProperty("IconSize", m_IconSize, m_def_IconSize)
End Sub
Private Sub InitToolTip()
On Error Resume Next
If m_hWndTT = 0 Then
Call InitCommonControls
' Filling the hwndParent param below allows the tooltip window to
' be owned by the specified form and be destroyed along with it,
' but we'll cleanup in Class_Terminate anyway.
' No WS_EX_TOPMOST or TTS_ALWAYSTIP per Win95 UI rules...
m_hWndTT = CreateWindowEx(0, TOOLTIPS_CLASS, _
vbNullString, TTS_ALWAYSTIP, _
0, 0, _
0, 0, _
UserControl.Parent.hWnd, 0, _
App.hInstance, ByVal 0)
End If
Call MaxTipWidth(240)
Call TipDelayTime(ttDelayShow, 5000)
End Sub
Private Sub SetToolTip(ByVal sText As String)
Dim ti As TOOLINFO
On Error Resume Next
If m_hWndTT = 0 And sText <> "" Then
Call InitToolTip
End If
If m_hWndTT = 0 Then Exit Sub
If GetToolInfo(Me.hWnd, ti) Then
ti.lpszText = sText