-
Notifications
You must be signed in to change notification settings - Fork 139
/
Copy pathGridOcx.ctl
4745 lines (3953 loc) · 171 KB
/
GridOcx.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 GridOcx
AutoRedraw = -1 'True
ClientHeight = 4125
ClientLeft = 0
ClientTop = 0
ClientWidth = 5565
ControlContainer= -1 'True
KeyPreview = -1 'True
ScaleHeight = 275
ScaleMode = 3 'Pixel
ScaleWidth = 371
ToolboxBitmap = "GridOcx.ctx":0000
End
Attribute VB_Name = "GridOcx"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
'查询API的网址http://vbworld.sxnw.gov.cn/vbapi/
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (ByRef lpVersionInformation As OSVERSIONINFO) As Long
Private Declare Function GetTickCount Lib "kernel32" () As Long
'Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function SendMessageAsLong Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) 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 SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function SetRectRgn Lib "gdi32" (ByVal hRgn As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function SelectClipRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long) As Long
Private Declare Function DrawTextA Lib "user32" (ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long
Private Declare Function DrawTextW Lib "user32" (ByVal hdc As Long, ByVal lpStr As Long, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long
Private Declare Function MoveTo Lib "gdi32" Alias "MoveToEx" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As Any) As Long
Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As POINTAPI) As Long
Private Declare Function CreatePen Lib "gdi32" (ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As Long
Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function OleTranslateColor Lib "olepro32.dll" (ByVal OLE_COLOR As Long, ByVal hPalette As Long, pccolorref As Long) As Long
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Private Declare Function DrawFocusRect Lib "user32" (ByVal hdc As Long, lpRect As RECT) As Long
Private Declare Function DrawFrameControl Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal un1 As Long, ByVal un2 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 FrameRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
Private Declare Function GradientFill Lib "msimg32" (ByVal hdc As Long, pVertex As Any, ByVal dwNumVertex As Long, pMesh As Any, ByVal dwNumMesh As Long, ByVal dwMode As Long) As Long
'XP
Private Declare Function CloseThemeData Lib "uxtheme.dll" (ByVal hTheme As Long) As Long
Private Declare Function DrawThemeBackground Lib "uxtheme.dll" (ByVal hTheme As Long, ByVal lhDC As Long, ByVal iPartId As Long, ByVal iStateId As Long, pRect As RECT, pClipRect As RECT) As Long
Private Declare Function OpenThemeData Lib "uxtheme.dll" (ByVal hWnd As Long, ByVal pszClassList As Long) As Long
Private Const CB_SETITEMHEIGHT = &H153
Private Const CB_SHOWDROPDOWN = &H14F
Private Const DT_BOTTOM = &H8
Private Const DT_CENTER = &H1
Private Const DT_LEFT = &H0
Private Const DT_RIGHT = &H2
Private Const DT_TOP = &H0
Private Const DT_VCENTER = &H4
Private Const DT_WORD_ELLIPSIS = &H40000
Private Const DT_SINGLELINE = &H20
Private Const DT_WORDBREAK = &H10
'download by http://www.codefans.net
Private Const DFC_BUTTON As Long = &H4
Private Const DFCS_FLAT As Long = &H4000
Private Const DFCS_BUTTONCHECK As Long = &H0
Private Const DFCS_CHECKED As Long = &H400
Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128 ' Maintenance string for PSS usage
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type TRIVERTEX
x As Long
y As Long
Red As Integer
Green As Integer
Blue As Integer
Alpha As Integer
End Type
Private Type GRADIENT_RECT
UPPERLEFT As Long
LOWERRIGHT As Long
End Type
'Subclassing
Private Enum eMsgWhen
[MSG_AFTER] = 1
[MSG_BEFORE] = 2
[MSG_BEFORE_AND_AFTER] = MSG_AFTER Or MSG_BEFORE
End Enum
Private Const GWL_WNDPROC As Long = -4 'Get/SetWindow offset to the WndProc procedure address
Private Const PATCH_04 As Long = 88 'Table B (before) address patch offset
Private Const PATCH_05 As Long = 93 'Table B (before) entry count patch offset
Private Const PATCH_08 As Long = 132 'Table A (after) address patch offset
Private Const PATCH_09 As Long = 137 'Table A (after) entry count patch offset
Private Type tSubData 'Subclass data type
hWnd As Long 'Handle of the window being subclassed
nAddrSub As Long 'The address of our new WndProc (allocated memory).
nAddrOrig As Long 'The address of the pre-existing WndProc
nMsgCntA As Long 'Msg after table entry count
nMsgCntB As Long 'Msg before table entry count
aMsgTblA() As Long 'Msg after table array
aMsgTblB() As Long 'Msg Before table array
End Type
Private sc_aSubData() As tSubData 'Subclass data array
Private sc_aBuf(1 To 200) As Byte 'Code buffer byte array
Private sc_pCWP As Long 'Address of the CallWindowsProc
Private sc_pEbMode As Long 'Address of the EbMode IDE break/stop/running function
Private sc_pSWL As Long 'Address of the SetWindowsLong function
Private Declare Sub RtlMoveMemory Lib "kernel32" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function GetModuleHandleA Lib "kernel32" (ByVal lpModuleName As String) As Long
Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function GlobalFree Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function SetWindowLongA Lib "user32" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetWindowLongW Lib "user32" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function IsWindowUnicode Lib "user32.dll" (ByVal hWnd As Long) As Long
Private Declare Function VirtualProtect Lib "kernel32" (lpAddress As Any, ByVal dwSize As Long, ByVal flNewProtect As Long, lpflOldProtect As Long) As Long
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Private Declare Function TrackMouseEvent Lib "user32" (lpEventTrack As TRACKMOUSEEVENT_STRUCT) As Long
Private Declare Function TrackMouseEventComCtl Lib "Comctl32" Alias "_TrackMouseEvent" (lpEventTrack As TRACKMOUSEEVENT_STRUCT) As Long
Private Declare Function LoadLibraryA Lib "kernel32" (ByVal lpLibFileName As String) As Long
Private Declare Function LoadLibraryW Lib "kernel32" (ByVal lpLibFileName As String) As Long
Private Declare Function GetModuleHandleW Lib "kernel32" (ByVal lpModuleName As String) As Long
Private Enum TRACKMOUSEEVENT_FLAGS
TME_HOVER = &H1&
TME_LEAVE = &H2&
TME_QUERY = &H40000000
TME_CANCEL = &H80000000
End Enum
Private Const WM_SETFOCUS As Long = &H7
Private Const WM_KILLFOCUS As Long = &H8
Private Const WM_MOUSELEAVE As Long = &H2A3
Private Const WM_MOUSEMOVE As Long = &H200
Private Const WM_MOUSEHOVER As Long = &H2A1
Private Const WM_MOUSEWHEEL As Long = &H20A
Private Const WM_VSCROLL As Long = &H115
Private Const WM_HSCROLL As Long = &H114
Private Const WM_THEMECHANGED As Long = &H31A
Private Const WM_ACTIVATE As Long = &H6
Private Const WM_ACTIVATEAPP As Long = &H1C
Private Type TRACKMOUSEEVENT_STRUCT
cbSize As Long
dwFlags As TRACKMOUSEEVENT_FLAGS
hwndTrack As Long
dwHoverTime As Long
End Type
Private bTrack As Boolean
Private bTrackUser32 As Boolean
'API Scroll Bars
Private Declare Function InitialiseFlatSB Lib "comctl32.dll" Alias "InitializeFlatSB" (ByVal lhWnd As Long) As Long
Private Declare Function SetScrollInfo Lib "user32" (ByVal hWnd As Long, ByVal n As Long, lpcScrollInfo As SCROLLINFO, ByVal BOOL As Boolean) As Long
Private Declare Function GetScrollInfo Lib "user32" (ByVal hWnd As Long, ByVal n As Long, LPSCROLLINFO As SCROLLINFO) As Long
Private Declare Function EnableScrollBar Lib "user32" (ByVal hWnd As Long, ByVal wSBflags As Long, ByVal wArrows As Long) As Long
Private Declare Function ShowScrollBar Lib "user32" (ByVal hWnd As Long, ByVal wBar As Long, ByVal bShow As Long) As Long
Private Declare Function FlatSB_EnableScrollBar Lib "comctl32.dll" (ByVal hWnd As Long, ByVal int2 As Long, ByVal UINT3 As Long) As Long
Private Declare Function FlatSB_ShowScrollBar Lib "comctl32.dll" (ByVal hWnd As Long, ByVal code As Long, ByVal fRedraw As Boolean) As Long
Private Declare Function FlatSB_GetScrollInfo Lib "comctl32.dll" (ByVal hWnd As Long, ByVal code As Long, LPSCROLLINFO As SCROLLINFO) As Long
Private Declare Function FlatSB_SetScrollInfo Lib "comctl32.dll" (ByVal hWnd As Long, ByVal code As Long, LPSCROLLINFO As SCROLLINFO, ByVal fRedraw As Boolean) As Long
Private Declare Function FlatSB_SetScrollProp Lib "comctl32.dll" (ByVal hWnd As Long, ByVal Index As Long, ByVal NewValue As Long, ByVal fRedraw As Boolean) As Long
Private Declare Function UninitializeFlatSB Lib "comctl32.dll" (ByVal hWnd As Long) As Long
Public Enum ScrollBarOrienationEnum
Scroll_Horizontal
Scroll_Vertical
Scroll_Both
End Enum
Public Enum ScrollBarStyleEnum
Style_Regular = 1&
Style_Flat = 0&
End Enum
Public Enum EFSScrollBarConstants
efsHorizontal = 0 'SB_HORZ
efsVertical = 1 'SB_VERT
End Enum
Private Const SB_BOTTOM = 7
Private Const SB_ENDSCROLL = 8
Private Const SB_HORZ = 0
Private Const SB_LEFT = 6
Private Const SB_LINEDOWN = 1
Private Const SB_LINELEFT = 0
Private Const SB_LINERIGHT = 1
Private Const SB_LINEUP = 0
Private Const SB_PAGEDOWN = 3
Private Const SB_PAGELEFT = 2
Private Const SB_PAGERIGHT = 3
Private Const SB_PAGEUP = 2
Private Const SB_RIGHT = 7
Private Const SB_THUMBTRACK = 5
Private Const SB_TOP = 6
Private Const SB_VERT = 1
Private Const SIF_RANGE = &H1
Private Const SIF_PAGE = &H2
Private Const SIF_POS = &H4
Private Const SIF_TRACKPOS = &H10
Private Const SIF_ALL = (SIF_RANGE Or SIF_PAGE Or SIF_POS Or SIF_TRACKPOS)
Private Const ESB_DISABLE_BOTH = &H3
Private Const ESB_ENABLE_BOTH = &H0
Private Const MK_CONTROL = &H8
Private Const WSB_PROP_VSTYLE = &H100&
Private Const WSB_PROP_HSTYLE = &H200&
'滚动条结构体
Private Type SCROLLINFO
cbSize As Long
fMask As Long
nMin As Long
nMax As Long
nPage As Long
nPos As Long
nTrackPos As Long
End Type
Private m_bInitialised As Boolean
Private m_eOrientation As ScrollBarOrienationEnum
Private m_eStyle As ScrollBarStyleEnum
Private m_hWnd As Long
Private m_lSmallChangeHorz As Long
Private m_lSmallChangeVert As Long
Private m_bEnabledHorz As Boolean
Private m_bEnabledVert As Boolean
Private m_bVisibleHorz As Boolean
Private m_bVisibleVert As Boolean
Private m_bNoFlatScrollBars As Boolean
'枚举
Private Enum lgFlagsEnum
lgFLChecked = 2
lgFLSelected = 4
lgFLChanged = 8
lgFLFontBold = 16
lgFLFontItalic = 32
lgFLFontUnderline = 64
lgFLWordWrap = 128
End Enum
'枚举
Private Enum lgCellFormatEnum
lgCFBackColor = 2
lgCFForeColor = 4
lgCFImage = 8
End Enum
'枚举
Private Enum lgHeaderStateEnum
lgNormal = 1
lgHot = 2
lgDown = 3
End Enum
'枚举
Private Enum lgRectTypeEnum
lgRTColumn = 0
lgRTCheckBox = 1
lgRTImage = 2
End Enum
'枚举
Public Enum lgAllowResizingEnum
NotResize = 0
Resize = 1
End Enum
'枚举
Public Enum lgAlignmentEnum
lgAlignLeftTop = DT_LEFT Or DT_TOP
lgAlignLeftCenter = DT_LEFT Or DT_VCENTER
lgAlignLeftBottom = DT_LEFT Or DT_BOTTOM
lgAlignCenterTop = DT_CENTER Or DT_TOP
lgAlignCenterCenter = DT_CENTER Or DT_VCENTER
lgAlignCenterBottom = DT_CENTER Or DT_BOTTOM
lgAlignRightTop = DT_RIGHT Or DT_TOP
lgAlignRightCenter = DT_RIGHT Or DT_VCENTER
lgAlignRightBottom = DT_RIGHT Or DT_BOTTOM
End Enum
'枚举
Public Enum lgBorderStyleEnum
无 = 0
边框 = 1
End Enum
Public Enum lgDataTypeEnum
lgString = 0
lgNumeric = 1
lgDate = 2
lgBoolean = 3
lgProgressBar = 4
lgCustom = 5
End Enum
'枚举
Public Enum lgEditTypeEnum
None = 0
EnterKey = 2
F2Key = 4
MouseClick = 8
MouseDblClick = 16
End Enum
'枚举
Public Enum SelectModeEnum
无 = 0
行 = 1
列 = 2
End Enum
'枚举
Public Enum FocusStyleEnum
Light = 0
Heavy = 1
End Enum
'枚举
Public Enum lgMoveControlEnum
lgBCNone = 0
lgBCHeight = 1
lgBCWidth = 2
lgBCLeft = 4
lgBCTop = 8
End Enum
'选择模式枚举
Public Enum lgSearchModeEnum
lgSMEqual = 0
lgSMGreaterEqual = 1
lgSMLike = 2
lgSMNavigate = 4
End Enum
'排序方式枚举
Public Enum lgSortTypeEnum
lgSTAscending = 0
lgSTDescending = 1
End Enum
#If False Then
Private lgFLChecked, lgFLSelected, lgFLChanged, lgFLFontBold, lgFLFontItalic, lgFLFontUnderline, lgFLWordWrap
Private lgNormal, lgHot, lgDown
Private NotResize, Resize
Private lgAlignLeftTop, lgAlignLeftCenter, lgAlignLeftBottom, lgAlignCenterTop, lgAlignCenterCenter, lgAlignCenterBottom, lgAlignRightTop, lgAlignRightCenter, lgAlignRightBottom
Private lgString, lgNumeric, lgDate, lgBoolean, lgProgressBar, lgCustom
Private None, EnterKey, F2Key, MouseClick, MouseDblClick
Private None, lgRow, lgCol
Private lgFRLight, lgFRHeavy
Private lgSMEqual, lgSMGreaterEqual, lgSMLike, lgSMNavigate
Private lgSTAscending, lgSTDescending
#End If
'列的结构体
Private Type udtColumn
EditCtrl As Object
dCustomWidth As Single
lWidth As Long
lX As Long
nAlignment As lgAlignmentEnum
nImageAlignment As lgAlignmentEnum
nSortOrder As lgSortTypeEnum
nType As Integer
nFlags As Integer
MoveControl As Integer
bVisible As Boolean
sCaption As String
sFormat As String
sTag As String
End Type
'单元格的结构体
Private Type udtCell
nAlignment As Integer
nFormat As Integer
nFlags As Integer
sValue As String
End Type
'行的结构体
Private Type udtItem
lHeight As Long
lImage As Long
lItemData As Long
nFlags As Integer
sTag As String
Cell() As udtCell
End Type
'格式的结构体
Private Type udtFormat
lBackColor As Long
lForeColor As Long
nImage As Integer
nCount As Long
End Type
'整体渲染的结构体
Private Type udtRender
DTFlag As Long
CheckBoxSize As Long '复选框的大小
ImageSpace As Long '图片的空白所占的像素
ImageHeight As Long '图片的高度
ImageWidth As Long '图片的宽度
LeftImage As Long '图片的左边位置
LeftText As Long '文本的左边位置
HeaderHeight As Long '表头的高度
TextHeight As Long '文本的高度
End Type
Private WithEvents txtEdit As TextBox
Attribute txtEdit.VB_VarHelpID = -1
'Data & Columns
Private mCols() As udtColumn
Private mItems() As udtItem
Private mColPtr() As Long
Private mRowPtr() As Long
Private mCF() As udtFormat
Private mItemCount As Long
Private mItemsVisible As Long
Private mSortColumn As Long
Private mSortSubColumn As Long
Private mEditCol As Long
Private mEditRow As Long
Private mCol As Long
Private mRow As Long
Private mMouseCol As Long
Private mMouseRow As Long
Private mMouseDownCol As Long
Private mMouseDownRow As Long
Private mMouseDownX As Long
Private mSelectedRow As Long
Private mR As udtRender
Private mEditPending As Boolean
Private mMouseDown As Boolean
Private mDragCol As Long
Private mResizeCol As Long
Private mEditParent As Long
'Appearance Properties
Private mSelectBackColor As Long
Private mForeColor As Long
Private mHeadForeColor As Long
Private mSelectForeColor As Long
Private mForeColorTotals As Long
Private mFocusColor As Long
Private mGridColor As Long
Private mAlphaBlendSelection As Boolean
Private mBorderStyle As lgBorderStyleEnum
Private mDisplayEllipsis As Boolean
Private mSelectMode As SelectModeEnum
Private mFocusStyle As FocusStyleEnum
Private mFont As Font
Private mGridLines As Boolean
Private mGridLineWidth As Long
'Behaviour Properties
Private mAllowResizing As lgAllowResizingEnum
Private mCheckboxes As Boolean
Private mColumnDrag As Boolean
Private mColumnHeaders As Boolean
Private mColumnSort As Boolean
Private mEditable As Boolean
Private mEditType As lgEditTypeEnum
Private mFullRowSelect As Boolean
Private mHotHeaderTracking As Boolean
Private mMultiSelect As Boolean
Private mRedraw As Boolean
Private mScrollTrack As Boolean
Private mTrackEdits As Boolean
'Miscellaneous Properties
Private mCacheIncrement As Long
Private mEnabled As Boolean
Private mLocked As Boolean
Private mRowHeight As Long
Private mImageList As Object
Private mImageListScaleMode As Integer
'Control State Variables
Private mInCtrl As Boolean
Private mInFocus As Boolean
Private mWindowsNT As Boolean
Private mWindowsXP As Boolean
Private mUnicode As Boolean
Private mPendingRedraw As Boolean
Private mPendingScrollBar As Boolean
Private mClipRgn As Long
Private hTheme As Long
Private mScrollAction As Long
Private mScrollTick As Long
Private mHotColumn As Long
Private mIgnoreKeyPress As Boolean
'Events - Standard VB
Public Event Click()
Public Event DblClick()
Public Event KeyDown(KeyCode As Integer, Shift As Integer)
Public Event KeyPress(KeyAscii As Integer)
Public Event KeyUp(KeyCode As Integer, Shift As Integer)
Public Event MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Public Event MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Public Event MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
'Events - Control Specific
Public Event CellImageClick(ByVal Row As Long, ByVal Col As Long)
Public Event ColumnClick(Col As Long)
Public Event ColumnSizeChanged(Col As Long, MoveControl As lgMoveControlEnum)
Public Event CustomSort(Ascending As Boolean, Col As Long, Value1 As String, Value2 As String, Swap As Boolean)
Public Event ItemChecked(Row As Long)
Public Event ItemCountChanged()
Public Event MouseEnter()
Public Event MouseLeave()
Public Event RowColChanged()
Public Event Scroll()
Public Event SelectionChanged()
Public Event SortComplete()
Public Event ThemeChanged()
Public Event EnterCell()
Public Event RequestEdit(ByVal Row As Long, ByVal Col As Long, Cancel As Boolean)
Public Event RequestUpdate(ByVal Row As Long, ByVal Col As Long, NewValue As String, Cancel As Boolean)
Private Function IsColumnTruncated(Col As Long) As Boolean
If (mR.LeftText > 3) And (Col = 0) Then IsColumnTruncated = True
End Function
'Subclass handler
Public Sub zSubclass_Proc(ByVal bBefore As Boolean, ByRef bHandled As Boolean, ByRef lReturn As Long, ByRef lng_hWnd As Long, ByRef uMsg As Long, ByRef wParam As Long, ByRef lParam As Long)
Dim eBar As EFSScrollBarConstants
Dim lV As Long, lSC As Long
Dim lScrollCode As Long
Dim tSI As SCROLLINFO
Dim zDelta As Long
Dim lHSB As Long
Dim lVSB As Long
Dim bRedraw As Boolean
Select Case uMsg
Case WM_VSCROLL, WM_HSCROLL, WM_MOUSEWHEEL
lScrollCode = (wParam And &HFFFF&)
lHSB = SBValue(efsHorizontal)
lVSB = SBValue(efsVertical)
Select Case uMsg
Case WM_HSCROLL ' Get the scrollbar type
eBar = efsHorizontal
Case WM_VSCROLL
eBar = efsVertical
Case Else 'WM_MOUSEWHEEL
eBar = IIf(lScrollCode And MK_CONTROL, efsHorizontal, efsVertical)
lScrollCode = IIf(wParam / 65536 < 0, SB_LINEDOWN, SB_LINEUP)
End Select
bRedraw = True
Select Case lScrollCode
Case SB_THUMBTRACK
' Is vertical/horizontal?
pSBGetSI eBar, tSI, SIF_TRACKPOS
SBValue(eBar) = tSI.nTrackPos
bRedraw = mScrollTrack
Case SB_LEFT, SB_BOTTOM
SBValue(eBar) = IIf(lScrollCode = 7, SBMax(eBar), SBMin(eBar))
Case SB_RIGHT, SB_TOP
SBValue(eBar) = SBMin(eBar)
Case SB_LINELEFT, SB_LINEUP
If SBVisible(eBar) Then
lV = SBValue(eBar)
If (eBar = efsHorizontal) Then
lSC = m_lSmallChangeHorz
Else
lSC = m_lSmallChangeVert
End If
If (lV - lSC < SBMin(eBar)) Then
SBValue(eBar) = SBMin(eBar)
Else
SBValue(eBar) = lV - lSC
End If
End If
Case SB_LINERIGHT, SB_LINEDOWN
If SBVisible(eBar) Then
lV = SBValue(eBar)
If (eBar = efsHorizontal) Then
lSC = m_lSmallChangeHorz
Else
lSC = m_lSmallChangeVert
End If
If (lV + lSC > SBMax(eBar)) Then
SBValue(eBar) = SBMax(eBar)
Else
SBValue(eBar) = lV + lSC
End If
End If
Case SB_PAGELEFT, SB_PAGEUP
SBValue(eBar) = SBValue(eBar) - SBLargeChange(eBar)
Case SB_PAGERIGHT, SB_PAGEDOWN
SBValue(eBar) = SBValue(eBar) + SBLargeChange(eBar)
Case SB_ENDSCROLL
If Not mScrollTrack Then DrawGrid True
End Select
If (lHSB <> SBValue(efsHorizontal)) Or (lVSB <> SBValue(efsVertical)) Then
UpdateCell
If bRedraw Then DrawGrid True
RaiseEvent Scroll
End If
Case WM_MOUSEWHEEL
Case WM_MOUSEMOVE
If Not mInCtrl Then
mInCtrl = True
Call TrackMouseLeave(lng_hWnd)
RaiseEvent MouseEnter
End If
Case WM_MOUSELEAVE
If mInCtrl Then
mInCtrl = False
DrawHeaderRow
UserControl.Refresh
RaiseEvent MouseLeave
End If
Case WM_SETFOCUS
If mEnabled Then
If Not mInFocus Then
'Debug.Print "WM_SETFOCUS"
mInFocus = True
DrawGrid True
End If
End If
Case WM_KILLFOCUS
If lng_hWnd = UserControl.hWnd Then
If mEnabled Then
If mInFocus Then
'Debug.Print "WM_KILLFOCUS"
mInFocus = False
DrawGrid True
End If
End If
ElseIf Not mInCtrl Then
UpdateCell
End If
Case WM_THEMECHANGED
DrawGrid True
RaiseEvent ThemeChanged
End Select
End Sub
Public Function AddColumn(Optional Caption As String, Optional Width As Single = 1000, Optional Alignment As lgAlignmentEnum = lgAlignLeftCenter, Optional DataType As lgDataTypeEnum = lgString, Optional Format As String, Optional ImageAlignment As lgAlignmentEnum = lgAlignLeftCenter, Optional WordWrap As Boolean, Optional Index As Long = 0) As Long
Dim lCount As Long
Dim lNewCol As Long
If mCols(0).nAlignment <> 0 Then
lNewCol = UBound(mCols) + 1
ReDim Preserve mCols(lNewCol)
ReDim Preserve mColPtr(lNewCol)
End If
If (Index > 0) And (Index < lNewCol) Then
If lNewCol > 1 Then
For lCount = lNewCol To Index + 1 Step -1
mColPtr(lCount) = mColPtr(lCount - 1)
Next lCount
mColPtr(Index) = lNewCol
End If
AddColumn = Index
Else
mColPtr(lNewCol) = lNewCol
AddColumn = lNewCol
End If
With mCols(lNewCol)
.sCaption = Caption
.dCustomWidth = Width
'lWidth is always Pixels (because thats what API functions require) and
'is calculated to prevent repeated Width Scaling calculations
.lWidth = ScaleX(.dCustomWidth, vbTwips, vbPixels)
.nAlignment = Alignment
.nImageAlignment = ImageAlignment
.nSortOrder = lgSTAscending
.nType = DataType
.sFormat = Format
If WordWrap Then .nFlags = lgFLWordWrap
.bVisible = True
End With
DisplayChange
End Function
Public Function AddItem(Optional ByVal Item As String, Optional Index As Long = 0, Optional Checked As Boolean) As Long
Dim lCol As Long
Dim lCount As Long
Dim sText() As String
mItemCount = mItemCount + 1
If mItemCount > UBound(mItems) Then
ReDim Preserve mItems(mItemCount + mCacheIncrement)
ReDim Preserve mRowPtr(mItemCount + mCacheIncrement)
End If
If (Index > 0) And (Index < mItemCount) Then
If mItemCount > 1 Then
For lCount = mItemCount To Index + 1 Step -1
mRowPtr(lCount) = mRowPtr(lCount - 1)
Next lCount
mRowPtr(Index) = mItemCount
End If
AddItem = Index
Else
mRowPtr(mItemCount) = mItemCount
AddItem = mItemCount
End If
If mRowHeight > 0 Then
mItems(mItemCount).lHeight = ScaleY(mRowHeight, vbTwips, vbPixels)
Else
mItems(mItemCount).lHeight = 300
End If
ReDim mItems(mItemCount).Cell(UBound(mCols))
For lCount = LBound(mCols) To UBound(mCols)
With mItems(mItemCount).Cell(lCount)
.nAlignment = mCols(lCount).nAlignment
.nFormat = -1
.nFlags = mCols(lCount).nFlags
End With
ApplyCellFormat mItemCount, lCount, lgCFBackColor, vbWhite
ApplyCellFormat mItemCount, lCount, lgCFForeColor, mForeColor
Next lCount
If UBound(mCols) > 0 Then
lCol = 0
sText() = Split(Item, vbTab)
For lCount = LBound(sText) To UBound(sText)
With mItems(mItemCount).Cell(lCol)
.sValue = sText(lCount)
End With
lCol = lCol + 1
If lCol > UBound(mCols) Then
Exit For
End If
Next lCount
Else
mItems(mItemCount).Cell(0).sValue = Item
End If
If Checked Then
SetFlag mItems(mItemCount).nFlags, lgFLChecked, True
End If
DisplayChange
RaiseEvent ItemCountChanged
End Function
Public Property Get AllowResizing() As lgAllowResizingEnum
Attribute AllowResizing.VB_ProcData.VB_Invoke_Property = ";Behavior"
AllowResizing = mAllowResizing
End Property
Public Property Let AllowResizing(ByVal NewValue As lgAllowResizingEnum)
mAllowResizing = NewValue
PropertyChanged "AllowResizing"
End Property
Private Sub ApplyCellFormat(ByVal Row As Long, ByVal Col As Long, Apply As lgCellFormatEnum, ByVal NewValue As Long)
Dim lBackColor As Long
Dim lForeColor As Long
Dim nImage As Integer
Dim lCount As Long
Dim nIndex As Integer
Dim nFreeIndex As Integer
Dim nNewIndex As Integer
Dim bMatch As Boolean
nIndex = mItems(Row).Cell(Col).nFormat
If nIndex >= 0 Then
'Get current properties
With mCF(nIndex)
lBackColor = .lBackColor
lForeColor = .lForeColor
nImage = .nImage
End With
Else
'Set default properties
lBackColor = vbWhite
lForeColor = mForeColor
End If
Select Case Apply
Case lgCFBackColor
lBackColor = NewValue
Case lgCFForeColor
lForeColor = NewValue
Case lgCFImage
nImage = NewValue
End Select
nFreeIndex = -1
For lCount = 0 To UBound(mCF)
If (mCF(lCount).lBackColor = lBackColor) And (mCF(lCount).lForeColor = lForeColor) And (mCF(lCount).nImage = nImage) Then
'Existing Entry matches what we required
bMatch = True
nNewIndex = lCount
Exit For
ElseIf (mCF(lCount).nCount = 0) And (nFreeIndex = -1) Then
'An unused entry
nFreeIndex = lCount
End If
Next lCount
'No existing matches
If Not bMatch Then
'Is there an unused Entry?
If nFreeIndex >= 0 Then
nNewIndex = nFreeIndex
Else
nNewIndex = UBound(mCF) + 1
ReDim Preserve mCF(nNewIndex + 9)
End If
With mCF(nNewIndex)
.lBackColor = lBackColor
.lForeColor = lForeColor
.nImage = nImage
End With
End If
'Has the Format Entry Index changed?
If (nIndex <> nNewIndex) Then
'Increment reference count for new entry
mCF(nNewIndex).nCount = mCF(nNewIndex).nCount + 1
If nIndex >= 0 Then
'Decrement reference count for previous entry
mCF(nIndex).nCount = mCF(nIndex).nCount - 1
End If
End If
mItems(Row).Cell(Col).nFormat = nNewIndex
End Sub
Public Property Get SelectBackColor() As OLE_COLOR
SelectBackColor = mSelectBackColor
End Property
Public Property Let SelectBackColor(ByVal NewValue As OLE_COLOR)
mSelectBackColor = NewValue
DisplayChange
PropertyChanged "SelectBackColor"
End Property
Public Sub BindControl(ByVal Col As Long, Ctrl As Object, Optional MoveControl As lgMoveControlEnum = lgBCHeight Or lgBCLeft Or lgBCTop Or lgBCWidth)
Set mCols(Col).EditCtrl = Ctrl
mCols(Col).MoveControl = MoveControl
End Sub
Private Function BlendColor(ByVal oColorFrom As OLE_COLOR, ByVal oColorTo As OLE_COLOR, Optional ByVal Alpha As Long = 128) As Long
Dim lCFrom As Long
Dim lCTo As Long
Dim lSrcR As Long
Dim lSrcG As Long
Dim lSrcB As Long
Dim lDstR As Long
Dim lDstG As Long
Dim lDstB As Long
lCFrom = oColorFrom
lCTo = oColorTo
lSrcR = lCFrom And &HFF
lSrcG = (lCFrom And &HFF00&) \ &H100&
lSrcB = (lCFrom And &HFF0000) \ &H10000
lDstR = lCTo And &HFF
lDstG = (lCTo And &HFF00&) \ &H100&
lDstB = (lCTo And &HFF0000) \ &H10000
BlendColor = RGB(((lSrcR * Alpha) / 255) + ((lDstR * (255 - Alpha)) / 255), ((lSrcG * Alpha) / 255) + ((lDstG * (255 - Alpha)) / 255), ((lSrcB * Alpha) / 255) + ((lDstB * (255 - Alpha)) / 255))
End Function
Public Property Get BorderStyle() As lgBorderStyleEnum
Attribute BorderStyle.VB_ProcData.VB_Invoke_Property = ";Appearance"
BorderStyle = mBorderStyle
End Property
Public Property Let BorderStyle(ByVal NewValue As lgBorderStyleEnum)
mBorderStyle = NewValue
UserControl.BorderStyle = mBorderStyle
PropertyChanged "BorderStyle"
End Property
Public Property Get CacheIncrement() As Long
CacheIncrement = mCacheIncrement
End Property
Public Property Let CacheIncrement(ByVal NewValue As Long)
If NewValue < 0 Then
mCacheIncrement = 1
Else
mCacheIncrement = NewValue
End If
PropertyChanged "CacheIncrement"
End Property
Public Property Let CellAlignment(ByVal Row As Long, ByVal Col As Long, NewValue As lgAlignmentEnum)
mItems(mRowPtr(Row)).Cell(Col).nAlignment = NewValue
DrawGrid mRedraw
End Property
Public Property Get CellAlignment(ByVal Row As Long, ByVal Col As Long) As lgAlignmentEnum
CellAlignment = mItems(mRowPtr(Row)).Cell(Col).nAlignment
End Property
Public Property Let CellBackColor(ByVal Row As Long, ByVal Col As Long, NewValue As Long)
ApplyCellFormat Row, Col, lgCFBackColor, NewValue
DrawGrid mRedraw
End Property
Public Property Get CellBackColor(ByVal Row As Long, ByVal Col As Long) As Long
CellBackColor = mCF(mItems(mRowPtr(Row)).Cell(Col).nFormat).lBackColor
End Property
Public Property Let CellChecked(ByVal Row As Long, ByVal Col As Long, NewValue As Boolean)
SetFlag mItems(mRowPtr(Row)).Cell(Col).nFlags, lgFLChecked, NewValue
DrawGrid mRedraw
End Property
Public Property Get CellChecked(ByVal Row As Long, ByVal Col As Long) As Boolean
CellChecked = mItems(mRowPtr(Row)).Cell(Col).nFlags And lgFLChecked