home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / exclbrpr / frmdemo.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-07-11  |  17.9 KB  |  507 lines

  1. VERSION 5.00
  2. Object = "{153B6C71-E9C5-11D1-8850-BCCD2DF3481A}#1.1#0"; "ExPropList.ocx"
  3. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
  4. Begin VB.Form frmDemo 
  5.    BorderStyle     =   3  'Fixed Dialog
  6.    Caption         =   "Excalibur PropertyList Control Demo"
  7.    ClientHeight    =   5400
  8.    ClientLeft      =   2475
  9.    ClientTop       =   1515
  10.    ClientWidth     =   6285
  11.    Icon            =   "frmDemo.frx":0000
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    MinButton       =   0   'False
  15.    ScaleHeight     =   5400
  16.    ScaleWidth      =   6285
  17.    ShowInTaskbar   =   0   'False
  18.    Begin VB.PictureBox picOD 
  19.       AutoSize        =   -1  'True
  20.       ClipControls    =   0   'False
  21.       Height          =   300
  22.       Left            =   1800
  23.       Picture         =   "frmDemo.frx":000C
  24.       ScaleHeight     =   16
  25.       ScaleMode       =   3  'Pixel
  26.       ScaleWidth      =   16
  27.       TabIndex        =   17
  28.       Top             =   720
  29.       Width           =   300
  30.    End
  31.    Begin VB.OptionButton chk 
  32.       Caption         =   "Property Header"
  33.       Height          =   255
  34.       Index           =   7
  35.       Left            =   120
  36.       TabIndex        =   15
  37.       Top             =   3720
  38.       Width           =   2055
  39.    End
  40.    Begin VB.OptionButton chk 
  41.       Caption         =   "Owner-Drawn"
  42.       Height          =   255
  43.       Index           =   6
  44.       Left            =   120
  45.       TabIndex        =   14
  46.       Top             =   3480
  47.       Width           =   2055
  48.    End
  49.    Begin VB.CommandButton cmdAdd 
  50.       Caption         =   "Add Property"
  51.       Height          =   615
  52.       Left            =   120
  53.       TabIndex        =   13
  54.       Tag             =   "0"
  55.       Top             =   4200
  56.       Width           =   2055
  57.    End
  58.    Begin VB.TextBox txtValue 
  59.       Height          =   285
  60.       Left            =   120
  61.       TabIndex        =   11
  62.       Text            =   "MyPropValue"
  63.       Top             =   1680
  64.       Width           =   2055
  65.    End
  66.    Begin VB.TextBox txtName 
  67.       Height          =   285
  68.       Left            =   120
  69.       TabIndex        =   9
  70.       Text            =   "MyProperty"
  71.       Top             =   1080
  72.       Width           =   2055
  73.    End
  74.    Begin VB.OptionButton chk 
  75.       Caption         =   "Numeric Type"
  76.       Height          =   255
  77.       Index           =   1
  78.       Left            =   120
  79.       TabIndex        =   8
  80.       Top             =   2280
  81.       Width           =   2055
  82.    End
  83.    Begin VB.OptionButton chk 
  84.       Caption         =   "BrowseButton Type"
  85.       Height          =   255
  86.       Index           =   3
  87.       Left            =   120
  88.       TabIndex        =   7
  89.       Top             =   2760
  90.       Width           =   2055
  91.    End
  92.    Begin VB.OptionButton chk 
  93.       Caption         =   "String Type"
  94.       Height          =   255
  95.       Index           =   0
  96.       Left            =   120
  97.       TabIndex        =   6
  98.       Top             =   2040
  99.       Value           =   -1  'True
  100.       Width           =   2055
  101.    End
  102.    Begin VB.OptionButton chk 
  103.       Caption         =   "Boolean Type"
  104.       Height          =   255
  105.       Index           =   2
  106.       Left            =   120
  107.       TabIndex        =   5
  108.       Top             =   2520
  109.       Width           =   2055
  110.    End
  111.    Begin VB.OptionButton chk 
  112.       Caption         =   "Custom Fill"
  113.       Height          =   255
  114.       Index           =   5
  115.       Left            =   120
  116.       TabIndex        =   4
  117.       Top             =   3240
  118.       Width           =   2055
  119.    End
  120.    Begin VB.OptionButton chk 
  121.       Caption         =   "Color Picker Type"
  122.       Height          =   255
  123.       Index           =   4
  124.       Left            =   120
  125.       TabIndex        =   3
  126.       Top             =   3000
  127.       Width           =   2055
  128.    End
  129.    Begin MSComDlg.CommonDialog dlg 
  130.       Left            =   240
  131.       Top             =   2400
  132.       _ExtentX        =   847
  133.       _ExtentY        =   847
  134.       _Version        =   393216
  135.       DialogTitle     =   "Choose Picture"
  136.       Filter          =   "All Picture Files|*.gif;*.jpg;*.bmp;*.dib;*.ico;*.wmf;*.emf"
  137.       FontName        =   "MS Sans Serif"
  138.    End
  139.    Begin ExPropertyList.PropertyList prp 
  140.       Height          =   4605
  141.       Left            =   2280
  142.       TabIndex        =   1
  143.       Top             =   120
  144.       Width           =   3885
  145.       _ExtentX        =   6853
  146.       _ExtentY        =   8123
  147.       ForeColor       =   -2147483630
  148.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  149.          Name            =   "MS Sans Serif"
  150.          Size            =   8.25
  151.          Charset         =   0
  152.          Weight          =   400
  153.          Underline       =   0   'False
  154.          Italic          =   0   'False
  155.          Strikethrough   =   0   'False
  156.       EndProperty
  157.       BeginProperty FontHeader {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  158.          Name            =   "MS Sans Serif"
  159.          Size            =   8.25
  160.          Charset         =   0
  161.          Weight          =   700
  162.          Underline       =   0   'False
  163.          Italic          =   0   'False
  164.          Strikethrough   =   0   'False
  165.       EndProperty
  166.       Begin VB.CheckBox chkOD 
  167.          BackColor       =   &H80000005&
  168.          Caption         =   "1 - Visible"
  169.          ForeColor       =   &H000000FF&
  170.          Height          =   255
  171.          Left            =   1200
  172.          TabIndex        =   16
  173.          Top             =   2760
  174.          Value           =   1  'Checked
  175.          Visible         =   0   'False
  176.          Width           =   1455
  177.       End
  178.    End
  179.    Begin VB.CommandButton cmdFill 
  180.       Caption         =   "Fill PropertyList"
  181.       Height          =   495
  182.       Left            =   120
  183.       TabIndex        =   0
  184.       Top             =   120
  185.       Width           =   2055
  186.    End
  187.    Begin VB.Label Label1 
  188.       Caption         =   "Initial Value:"
  189.       Height          =   255
  190.       Index           =   1
  191.       Left            =   120
  192.       TabIndex        =   12
  193.       Top             =   1440
  194.       Width           =   1335
  195.    End
  196.    Begin VB.Label Label1 
  197.       Caption         =   "Property Name:"
  198.       Height          =   255
  199.       Index           =   0
  200.       Left            =   120
  201.       TabIndex        =   10
  202.       Top             =   840
  203.       Width           =   1335
  204.    End
  205.    Begin VB.Label lbl 
  206.       BorderStyle     =   1  'Fixed Single
  207.       Height          =   375
  208.       Left            =   120
  209.       TabIndex        =   2
  210.       Top             =   4920
  211.       Width           =   6015
  212.    End
  213. Attribute VB_Name = "frmDemo"
  214. Attribute VB_GlobalNameSpace = False
  215. Attribute VB_Creatable = False
  216. Attribute VB_PredeclaredId = True
  217. Attribute VB_Exposed = False
  218. Option Explicit
  219. 'This form will be the owner-draw sink
  220. 'for the property list control's owner-
  221. 'drawn items.
  222. Implements IPropOwnerDrawSink
  223. 'Some declarations we'll need for
  224. 'owner-drawn items...
  225. Private Type RECT
  226.     Left As Long
  227.     Top As Long
  228.     Right As Long
  229.     Bottom As Long
  230. End Type
  231. 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
  232. 'Declare Function GetTextColor Lib "gdi32" (ByVal hdc As Long) As Long
  233. Private Declare Function SetTextColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
  234. 'DrawText() Format Flags
  235. Const DT_CENTER = &H1
  236. Const DT_RIGHT = &H2
  237. Const DT_VCENTER = &H4
  238. Const DT_BOTTOM = &H8
  239. Const DT_SINGLELINE = &H20
  240. Const DT_EXPANDTABS = &H40
  241. Const DT_TABSTOP = &H80
  242. Const DT_CALCRECT = &H400
  243. Private Declare Function DrawText 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
  244. Private Declare Function DrawFrameControl Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal un1 As Long, ByVal un2 As Long) As Long
  245. '/* flags for DrawFrameControl */
  246. Const DFC_BUTTON = 4
  247. Const DFCS_BUTTONCHECK = &H0
  248. Const DFCS_BUTTONRADIOIMAGE = &H1
  249. Const DFCS_BUTTONRADIOMASK = &H2
  250. Const DFCS_BUTTONRADIO = &H4
  251. Const DFCS_BUTTON3STATE = &H8
  252. Const DFCS_BUTTONPUSH = &H10
  253. Const DFCS_INACTIVE = &H100
  254. Const DFCS_PUSHED = &H200
  255. Const DFCS_CHECKED = &H400
  256. '#if(WINVER >= =&H0500)
  257. Const DFCS_TRANSPARENT = &H800
  258. Const DFCS_HOT = &H1000
  259. '#endif /* WINVER >= =&H0500 */
  260. Const DFCS_ADJUSTRECT = &H2000
  261. Const DFCS_FLAT = &H4000
  262. Const DFCS_MONO = &H8000
  263. Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
  264. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
  265. Private Declare Function FillRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Integer
  266. Private Declare Function GetSysColor Lib "user32" (ByVal nIndex As Integer) As Long
  267. Const COLOR_HIGHLIGHT = 13
  268. Const COLOR_HIGHLIGHTTEXT = 14
  269. Const COLOR_WINDOW = 5
  270. Const COLOR_WINDOWTEXT = 8
  271. Private Sub chk_Click(Index As Integer)
  272. cmdAdd.Tag = Index
  273. End Sub
  274. Private Sub chkOD_Click()
  275. 'This is where we change the value of our
  276. 'owner-drawn item.
  277. If chkOD.Value = 0 Then
  278.     chkOD.Caption = "0 - Invisible"
  279.     chkOD.Caption = "1 - Visible"
  280. End If
  281. prp.Value(prp.Selected) = chkOD.Caption
  282. End Sub
  283. Private Sub cmdAdd_Click()
  284. prp.Add txtName.Text, txtValue.Text, False, Val(Trim$(cmdAdd.Tag))
  285. End Sub
  286. Private Sub cmdFill_Click()
  287. 'Fill our property list with demo values.
  288. prp.Add "Excalibur PropertyList Control", , , ExPropPropertyHeader
  289. prp.HoldDraw = True
  290. prp.Add "(About)", "", True, ExPropBrowseButton
  291. prp.Add "(Name)", "cmdFill", , ExPropStringValue
  292. prp.Add "Appearance", "1 - 3D", , ExPropCustomValue
  293. prp.Add "BackColor", vbButtonFace, , ExPropOleColor
  294. prp.Add "Cancel", "False", , ExPropBoolValue
  295. prp.Add "Caption", "Load ExPropertyList", , ExPropStringValue
  296. prp.Add "Default", "False", , ExPropBoolValue
  297. prp.Add "DisabledPicture", "(None)", , ExPropBrowseButton
  298. prp.Add "DownPicture", "(None)", , ExPropBrowseButton
  299. prp.Add "DragIcon", "(None)", , ExPropBrowseButton
  300. prp.Add "DragMode", "0 - Manual", , ExPropCustomValue
  301. prp.Add "Enabled", "True", , ExPropBoolValue
  302. prp.Add "Font", "MS Sans Serif", , ExPropBrowseButton
  303. prp.Add "Height", "17", , ExPropNumericValue
  304. prp.Add "HelpContextID", "0", , ExPropStringValue
  305. prp.Add "Index", "0", , ExPropNumericValue
  306. prp.Add "Left", "8", , ExPropNumericValue
  307. prp.Add "MaskColor", &HC0C0C0, , ExPropOleColor
  308. prp.Add "MouseIcon", "(None)", , ExPropBrowseButton
  309. prp.Add "MousePointer", "0 - Default", , ExPropCustomValue
  310. prp.Add "OLEDropMode", "0 - None", , ExPropCustomValue
  311. prp.Add "Picture", "(None)", , ExPropBrowseButton
  312. prp.Add "RightToLeft", "False", , ExPropBoolValue
  313. prp.Add "Style", "0 - Standard", , ExPropCustomValue
  314. prp.Add "TabIndex", "6", , ExPropNumericValue
  315. prp.Add "TabStop", "True", , ExPropBoolValue
  316. prp.Add "Tag", "", , ExPropStringValue
  317. prp.Add "ToolTipText", "", , ExPropStringValue
  318. prp.Add "Top", "224", , ExPropNumericValue
  319. prp.Add "UseMaskColor", "False", , ExPropBoolValue
  320. prp.Add "Visible", "1 - Visible", , ExPropOwnerDraw
  321. prp.Add "WhatsThisHelpID", "0", , ExPropNumericValue
  322. prp.Add "Width", "145", , ExPropNumericValue
  323. prp.HoldDraw = False
  324. End Sub
  325. Private Sub Form_Load()
  326. 'Set the owner-draw sink or the property
  327. 'list will not process correctly when
  328. 'we have owner-drawn items!
  329. 'You don't need to do this unless you
  330. 'plan to use at least one owner-drawn
  331. 'property.
  332. prp.SetOwnerDrawSink Me
  333. End Sub
  334. Private Sub IPropOwnerDrawSink_PropCommitPending(sPropListName As String)
  335. 'Here we commit any pending values in
  336. 'owner-drawn items, if any. Set the
  337. 'Value property of the control to do
  338. 'this. The ValueChanged event will
  339. 'still fire.
  340. End Sub
  341. Private Sub IPropOwnerDrawSink_PropDrawItem(sPropListName As String, ByVal nIndex As Integer, ByVal bDrawActive As Boolean, ByVal DrawDC As Long, ByVal rctLeft As Long, ByVal rctTop As Long, ByVal rctRight As Long, ByVal rctBottom As Long)
  342. 'This method is called when an owner-drawn
  343. 'list item needs to be painted.
  344. 'The device context in DrawDC already has
  345. 'the required font and text color selected
  346. 'into it.
  347. 'NOTE: We must draw both the left and
  348. 'right columns. It is possible to draw over
  349. 'the center line separating the columns
  350. 'if need be.
  351. 'The only owner-drawn item we have is the
  352. ' Visible property, so we don't need to
  353. ' check for index...
  354. Dim nMidPt As Long
  355. Dim rct As RECT 'General-purpose RECT
  356. Dim hBr As Long 'Handle to a brush
  357. Dim CaptionToDraw As String, ValueToDraw As String
  358. CaptionToDraw = prp.Item(nIndex)
  359. ValueToDraw = prp.Value(nIndex)
  360. rct.Left = rctLeft - 2
  361. rct.Top = rctTop - 1
  362. rct.Bottom = rctBottom - 1
  363. 'This is where the line in between columns sits
  364. nMidPt = (prp.LongestItem \ Screen.TwipsPerPixelX) + 2
  365. rct.Right = nMidPt - 1
  366. '===========
  367. 'Draw the first column
  368. '===========
  369. If bDrawActive Then
  370.     'Draw selected state
  371.     hBr = CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT))
  372.     FillRect DrawDC, rct, hBr
  373.     DeleteObject hBr
  374.     SetTextColor DrawDC, GetSysColor(COLOR_HIGHLIGHTTEXT)
  375.     rct.Left = rct.Left + 2
  376.     rct.Top = rct.Top + 1
  377.     BitBlt DrawDC, rct.Left, rct.Top, 16, 13, picOD.hdc, 0, 1, vbSrcCopy
  378.     rct.Left = rct.Left + 17
  379.     DrawText DrawDC, CaptionToDraw, Len(CaptionToDraw), rct, DT_SINGLELINE Or DT_VCENTER
  380.     'Not selected, but give it some
  381.     'individuality with a blue color
  382.     'and a small image.
  383.     rct.Left = rct.Left + 2
  384.     rct.Top = rct.Top + 1
  385.     BitBlt DrawDC, rct.Left, rct.Top, 16, 13, picOD.hdc, 0, 1, vbSrcCopy
  386.     rct.Left = rct.Left + 17
  387.     SetTextColor DrawDC, vbBlue
  388.     DrawText DrawDC, CaptionToDraw, Len(CaptionToDraw), rct, DT_SINGLELINE Or DT_VCENTER
  389. End If
  390. '===========
  391. 'Draw the second column
  392. '===========
  393. rct.Left = nMidPt + 4
  394. rct.Right = rct.Left + 16
  395. rct.Bottom = rct.Bottom - 1
  396. If ValueToDraw = "1 - Visible" Then
  397.     DrawFrameControl DrawDC, rct, DFC_BUTTON, DFCS_BUTTONCHECK Or _
  398.         DFCS_CHECKED
  399.     DrawFrameControl DrawDC, rct, DFC_BUTTON, DFCS_BUTTONCHECK 'Or _
  400.         DFCS_CHECKED
  401. End If
  402. rct.Left = rct.Right + 3
  403. rct.Right = rctRight
  404. SetTextColor DrawDC, vbRed
  405. DrawText DrawDC, ValueToDraw, Len(ValueToDraw), rct, DT_SINGLELINE Or DT_VCENTER
  406. End Sub
  407. Private Sub IPropOwnerDrawSink_PropHideCtrls(sPropListName As String)
  408. 'The property list wants us to hide any
  409. 'controls that we may be using for
  410. 'owner-drawn items.
  411. chkOD.Visible = False
  412. End Sub
  413. Private Sub IPropOwnerDrawSink_PropPlaceCtrl(sPropListName As String, ByVal nIndex As Integer, ByVal rctLeft As Long, ByVal rctTop As Long, ByVal rctWidth As Long, ByVal rctHeight As Long)
  414. 'The property list tells us exactly where to
  415. 'put a control if we want one for this
  416. 'owner-drawn item. Make it visible at this
  417. 'time as well.
  418. chkOD.Caption = prp.Value(nIndex)
  419. If chkOD.Caption = "1 - Visible" Then
  420.     chkOD.Value = 1
  421.     chkOD.Value = 0
  422. End If
  423. chkOD.Move rctLeft, rctTop, rctWidth, rctHeight
  424. chkOD.Visible = True
  425. End Sub
  426. Private Sub prp_Browse(ByVal Name As String, ByVal Index As Integer, FillWith As String)
  427. dlg.Flags = cdlOFNHideReadOnly Or cdlOFNFileMustExist Or _
  428.     cdlCFBoth
  429. If Index = 1 Then 'About
  430.     Dim sMsg As String
  431.     sMsg = "ExPropertyList 1.0 Demo Application." & vbCrLf
  432.     MsgBox sMsg, vbInformation
  433. ElseIf Index = 7 Or Index = 8 Or Index = 9 _
  434. Or Index = 19 Or Index = 22 Then 'All picture properties
  435.     dlg.filename = ""
  436.     dlg.ShowOpen
  437.     If Len(dlg.filename) > 0 Then
  438.         FillWith = "(Bitmap)" 'Although could be icon, etc.
  439.     Else
  440.         FillWith = "(None)"
  441.     End If
  442. ElseIf Index = 13 Then 'Bring up Font dialog
  443.     dlg.FontName = prp.Value(12)
  444.     dlg.ShowFont
  445.     FillWith = dlg.FontName
  446. End If
  447. End Sub
  448. Private Sub prp_DblClick()
  449. 'Change the owner-drawn item?
  450. If prp.ItemType(prp.Selected) = ExPropOwnerDraw Then
  451.     chkOD.Value = Abs(Not -chkOD.Value)
  452. End If
  453. End Sub
  454. Private Sub prp_MouseUp(Button As Integer, Shift As Integer, x As Single, Y As Single)
  455. If x > prp.LongestItem + 45 Then
  456.     'Clicked in the second column
  457.     prp_DblClick
  458. End If
  459. End Sub
  460. Private Sub prp_NeedData(ByVal Index As Integer, ListItems() As String)
  461. If Index = 3 Then 'Appearance
  462.     ReDim ListItems(1) As String
  463.     ListItems(0) = "0 - Flat"
  464.     ListItems(1) = "1 - 3D"
  465. ElseIf Index = 11 Then 'DragMode
  466.     ReDim ListItems(1) As String
  467.     ListItems(0) = "0 - Manual"
  468.     ListItems(1) = "1 - Automatic"
  469. ElseIf Index = 20 Then 'MousePointer
  470.     ReDim ListItems(16)
  471.     ListItems(0) = "0 - Default"
  472.     ListItems(1) = "1 - Arrow"
  473.     ListItems(2) = "2 - Cross"
  474.     ListItems(3) = "3 - I-Beam"
  475.     ListItems(4) = "4 - Icon"
  476.     ListItems(5) = "5 - Size"
  477.     ListItems(6) = "6 - Size NE SW"
  478.     ListItems(7) = "7 - Size N S"
  479.     ListItems(8) = "8 - Size NW SE"
  480.     ListItems(9) = "9 - Size W E"
  481.     ListItems(10) = "10 - Up Arrow"
  482.     ListItems(11) = "11 - Hourglass"
  483.     ListItems(12) = "12 - No Drop"
  484.     ListItems(13) = "13 - Arrow and Hourglass"
  485.     ListItems(14) = "14 - Arrow and Question"
  486.     ListItems(15) = "15 - Size All"
  487.     ListItems(16) = "99 - Custom"
  488. ElseIf Index = 21 Then 'OLEDropMode
  489.     ReDim ListItems(1)
  490.     ListItems(0) = "0 - None"
  491.     ListItems(1) = "1 - Manual"
  492. ElseIf Index = 24 Then 'Style
  493.     ReDim ListItems(1)
  494.     ListItems(0) = "0 - Standard"
  495.     ListItems(1) = "1 - Graphical"
  496. End If
  497. End Sub
  498. Private Sub prp_SelChange(ByVal OldSel As Integer, ByVal NewSel As Integer)
  499. 'Demo of the SelChange event...
  500. lbl.Caption = "Selection changed, OldSel = " & OldSel & _
  501.     ", NewSel = " & NewSel & "."
  502. End Sub
  503. Private Sub prp_ValueChanged(ByVal Name As String, ByVal Index As Integer, ByVal NewValue As String, Cancel As Boolean)
  504. 'Demo of the ValueChanged event - it works... <g>
  505. lbl.Caption = "Property " & Index & " ('" & Name & "') changed to '" & NewValue & "'."
  506. End Sub
  507.