home *** CD-ROM | disk | FTP | other *** search
/ Dan Appleman's Visual Bas…s Guide to the Win32 API / Dan.Applmans.Visual.Basic.5.0.Programmers.Guide.To.The.Win32.API.1997.Ziff-Davis.Press.CD / VB5PG32.mdf / classlib / classact / btnplay.frm (.txt) next >
Encoding:
Visual Basic Form  |  1996-01-25  |  16.8 KB  |  486 lines

  1. VERSION 4.00
  2. Begin VB.Form frmButtonPlay 
  3.    Caption         =   "Button Play"
  4.    ClientHeight    =   5295
  5.    ClientLeft      =   1065
  6.    ClientTop       =   1545
  7.    ClientWidth     =   5640
  8.    Height          =   5700
  9.    Icon            =   "btnplay.frx":0000
  10.    Left            =   1005
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   5295
  13.    ScaleWidth      =   5640
  14.    Top             =   1200
  15.    Width           =   5760
  16.    Begin VB.Frame zfGroup 
  17.       Caption         =   "Button Type:"
  18.       Height          =   2475
  19.       Index           =   2
  20.       Left            =   60
  21.       TabIndex        =   13
  22.       Top             =   2700
  23.       Width           =   4755
  24.       Begin VB.OptionButton optType 
  25.          Caption         =   "Icon"
  26.          Height          =   195
  27.          Index           =   5
  28.          Left            =   2040
  29.          TabIndex        =   22
  30.          Top             =   240
  31.          Width           =   1575
  32.       End
  33.       Begin VB.OptionButton optType 
  34.          Caption         =   "Group Box"
  35.          Height          =   195
  36.          Index           =   4
  37.          Left            =   120
  38.          TabIndex        =   21
  39.          Top             =   1200
  40.          Width           =   1575
  41.       End
  42.       Begin VB.CheckBox chkTxtLeft 
  43.          Caption         =   "Text On Left"
  44.          Height          =   255
  45.          Left            =   120
  46.          TabIndex        =   20
  47.          Top             =   2100
  48.          Width           =   1575
  49.       End
  50.       Begin VB.CheckBox chkPushLike 
  51.          Caption         =   "Push-Like"
  52.          Height          =   255
  53.          Left            =   120
  54.          TabIndex        =   19
  55.          Top             =   1800
  56.          Width           =   1275
  57.       End
  58.       Begin VB.CheckBox chkSize 
  59.          Caption         =   "Small  Size  (Checkbox /Option Button)"
  60.          Height          =   255
  61.          Left            =   120
  62.          TabIndex        =   18
  63.          Top             =   1500
  64.          Width           =   3075
  65.       End
  66.       Begin VB.OptionButton optType 
  67.          Caption         =   "3-State Button"
  68.          Height          =   255
  69.          Index           =   3
  70.          Left            =   120
  71.          TabIndex        =   17
  72.          Top             =   960
  73.          Width           =   1575
  74.       End
  75.       Begin VB.OptionButton optType 
  76.          Caption         =   "CheckBox"
  77.          Height          =   255
  78.          Index           =   2
  79.          Left            =   120
  80.          TabIndex        =   16
  81.          Top             =   720
  82.          Width           =   1575
  83.       End
  84.       Begin VB.OptionButton optType 
  85.          Caption         =   "Option Button"
  86.          Height          =   255
  87.          Index           =   1
  88.          Left            =   120
  89.          TabIndex        =   15
  90.          Top             =   480
  91.          Width           =   1575
  92.       End
  93.       Begin VB.OptionButton optType 
  94.          Caption         =   "Command Button"
  95.          Height          =   255
  96.          Index           =   0
  97.          Left            =   120
  98.          TabIndex        =   14
  99.          Top             =   240
  100.          Value           =   -1  'True
  101.          Width           =   1575
  102.       End
  103.       Begin VB.Line zSep 
  104.          BorderColor     =   &H00FFFFFF&
  105.          Index           =   5
  106.          X1              =   0
  107.          X2              =   4740
  108.          Y1              =   1455
  109.          Y2              =   1455
  110.       End
  111.       Begin VB.Line zSep 
  112.          BorderColor     =   &H00808080&
  113.          Index           =   4
  114.          X1              =   0
  115.          X2              =   4740
  116.          Y1              =   1440
  117.          Y2              =   1440
  118.       End
  119.    End
  120.    Begin VB.Frame zfGroup 
  121.       Caption         =   "Text Value:"
  122.       Height          =   795
  123.       Index           =   1
  124.       Left            =   60
  125.       TabIndex        =   10
  126.       Top             =   1860
  127.       Width           =   2955
  128.       Begin VB.CheckBox chkMline 
  129.          Caption         =   "Multi-Line Button"
  130.          Height          =   255
  131.          Left            =   120
  132.          TabIndex        =   12
  133.          Top             =   480
  134.          Value           =   1  'Checked
  135.          Width           =   1815
  136.       End
  137.       Begin VB.CheckBox chkLong 
  138.          Caption         =   "Long Text"
  139.          Height          =   255
  140.          Left            =   120
  141.          TabIndex        =   11
  142.          Top             =   180
  143.          Width           =   1815
  144.       End
  145.    End
  146.    Begin VB.CommandButton cmdTest 
  147.       Caption         =   "Test Button"
  148.       BeginProperty Font 
  149.          name            =   "MS Sans Serif"
  150.          charset         =   0
  151.          weight          =   400
  152.          size            =   9.75
  153.          underline       =   0   'False
  154.          italic          =   0   'False
  155.          strikethrough   =   0   'False
  156.       EndProperty
  157.       Height          =   615
  158.       Left            =   3900
  159.       TabIndex        =   1
  160.       Top             =   480
  161.       Width           =   1575
  162.    End
  163.    Begin VB.Frame zfGroup 
  164.       Caption         =   "Text Alingment:"
  165.       Height          =   1575
  166.       Index           =   0
  167.       Left            =   60
  168.       TabIndex        =   0
  169.       Top             =   180
  170.       Width           =   2955
  171.       Begin VB.PictureBox zGroup 
  172.          Appearance      =   0  'Flat
  173.          BackColor       =   &H00C0C0C0&
  174.          BorderStyle     =   0  'None
  175.          ForeColor       =   &H80000008&
  176.          Height          =   615
  177.          Index           =   0
  178.          Left            =   60
  179.          ScaleHeight     =   615
  180.          ScaleWidth      =   2535
  181.          TabIndex        =   5
  182.          Top             =   900
  183.          Width           =   2535
  184.          Begin VB.OptionButton optTB 
  185.             Caption         =   "Center"
  186.             Height          =   255
  187.             Index           =   0
  188.             Left            =   1020
  189.             TabIndex        =   9
  190.             Top             =   120
  191.             Value           =   -1  'True
  192.             Width           =   795
  193.          End
  194.          Begin VB.OptionButton optTB 
  195.             Caption         =   "Bottom"
  196.             Height          =   255
  197.             Index           =   2
  198.             Left            =   0
  199.             TabIndex        =   7
  200.             Top             =   300
  201.             Width           =   975
  202.          End
  203.          Begin VB.OptionButton optTB 
  204.             Caption         =   "Top"
  205.             Height          =   255
  206.             Index           =   1
  207.             Left            =   0
  208.             TabIndex        =   6
  209.             Top             =   0
  210.             Width           =   795
  211.          End
  212.       End
  213.       Begin VB.PictureBox zGroup 
  214.          Appearance      =   0  'Flat
  215.          BackColor       =   &H00C0C0C0&
  216.          BorderStyle     =   0  'None
  217.          ForeColor       =   &H80000008&
  218.          Height          =   555
  219.          Index           =   1
  220.          Left            =   60
  221.          ScaleHeight     =   555
  222.          ScaleWidth      =   2655
  223.          TabIndex        =   2
  224.          Top             =   240
  225.          Width           =   2655
  226.          Begin VB.OptionButton optLR 
  227.             Caption         =   "Center"
  228.             Height          =   255
  229.             Index           =   0
  230.             Left            =   1020
  231.             TabIndex        =   8
  232.             Top             =   120
  233.             Value           =   -1  'True
  234.             Width           =   795
  235.          End
  236.          Begin VB.OptionButton optLR 
  237.             Caption         =   "Right"
  238.             Height          =   255
  239.             Index           =   2
  240.             Left            =   0
  241.             TabIndex        =   4
  242.             Top             =   300
  243.             Width           =   855
  244.          End
  245.          Begin VB.OptionButton optLR 
  246.             Caption         =   "Left"
  247.             Height          =   255
  248.             Index           =   1
  249.             Left            =   0
  250.             TabIndex        =   3
  251.             Top             =   0
  252.             Width           =   855
  253.          End
  254.       End
  255.       Begin VB.Line zSep 
  256.          BorderColor     =   &H00FFFFFF&
  257.          Index           =   3
  258.          X1              =   0
  259.          X2              =   2940
  260.          Y1              =   855
  261.          Y2              =   855
  262.       End
  263.       Begin VB.Line zSep 
  264.          BorderColor     =   &H00808080&
  265.          Index           =   2
  266.          X1              =   0
  267.          X2              =   2940
  268.          Y1              =   840
  269.          Y2              =   840
  270.       End
  271.    End
  272. Attribute VB_Name = "frmButtonPlay"
  273. Attribute VB_Creatable = False
  274. Attribute VB_Exposed = False
  275. Dim dl&
  276. Dim fAlignment&
  277. '**********************************
  278. '**  Constant Definitions:
  279. #If Win32 Then
  280. Private Const BS_NULL& = 1
  281. Private Const BS_BOTTOM& = &H800&
  282. Private Const BS_BITMAP& = &H80&
  283. Private Const BS_AUTORADIOBUTTON& = &H9&
  284. Private Const BS_AUTOCHECKBOX& = &H3&
  285. Private Const BS_AUTO3STATE& = &H6&
  286. Private Const BS_3STATE& = &H5&
  287. Private Const BS_CENTER& = &H300&
  288. Private Const BS_CHECKBOX& = &H2&
  289. Private Const BS_DEFPUSHBUTTON& = &H1&
  290. Private Const BS_DIBPATTERN& = 5
  291. Private Const BS_DIBPATTERN8X8& = 8
  292. Private Const BS_DIBPATTERNPT& = 6
  293. Private Const BS_FLAT& = &H8000&
  294. Private Const BS_ICON& = &H40&
  295. Private Const BS_HOLLOW& = BS_NULL
  296. Private Const BS_HATCHED& = 2
  297. Private Const BS_GROUPBOX& = &H7&
  298. Private Const BS_INDEXED& = 4
  299. Private Const BS_LEFT& = &H100&
  300. Private Const BS_LEFTTEXT& = &H20&
  301. Private Const BS_MULTILINE& = &H2000&
  302. Private Const BS_NOTIFY& = &H4000&
  303. Private Const BS_OWNERDRAW& = &HB&
  304. Private Const BS_PATTERN& = 3
  305. Private Const BS_PATTERN8X8& = 7
  306. Private Const BS_PUSHBUTTON& = &H0&
  307. Private Const BS_PUSHLIKE& = &H1000&
  308. Private Const BS_RADIOBUTTON& = &H4&
  309. Private Const BS_RIGHT& = &H200&
  310. Private Const BS_RIGHTBUTTON& = &H20&
  311. Private Const BS_SOLID& = 0
  312. Private Const BS_TEXT& = 0&
  313. Private Const BS_TOP& = &H400&
  314. Private Const BS_USERBUTTON& = &H8&
  315. Private Const BS_VCENTER& = &HC00&
  316. Private Const GWL_EXSTYLE& = (-20)
  317. Private Const GWL_HINSTANCE& = (-6)
  318. Private Const GWL_HWNDPARENT& = (-8)
  319. Private Const GWL_ID& = (-12)
  320. Private Const GWL_STYLE& = (-16)
  321. Private Const GWL_USERDATA& = (-21)
  322. Private Const GWL_WNDPROC& = (-4)
  323. #End If 'WIN32
  324. '**********************************
  325. '**  Function Declarations:
  326. #If Win32 Then
  327. 'Private Declare Function GetWindowLong& Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long)
  328. 'Private Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
  329. #End If 'WIN32
  330. '**********************************
  331. '**  Constant Definitions:
  332. #If Win32 Then
  333. Private Const BM_GETCHECK& = &HF0
  334. Private Const BM_SETCHECK& = &HF1
  335. Private Const BM_GETSTATE& = &HF2
  336. Private Const BM_SETSTATE& = &HF3
  337. Private Const BM_SETSTYLE& = &HF4
  338. Private Const BM_GETIMAGE& = &HF6
  339. Private Const BM_SETIMAGE& = &HF7
  340. #End If 'WIN32
  341. '**********************************
  342. '**  Function Declarations:
  343. #If Win32 Then
  344. 'Private Declare Function SendMessage& Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long)
  345. #End If 'WIN32
  346. Private m_wndButton As foWindow
  347. Private Sub chkLong_Click()
  348.     If chkLong = 1 Then 'Checked
  349.         cmdTest.Caption = "This is a test button"
  350.     Else
  351.         cmdTest.Caption = "Test Button"
  352.     End If
  353.     cmdTest.Refresh
  354. End Sub
  355. Private Sub chkMline_Click()
  356.     If chkMline = 1 Then
  357.         'Add the bit
  358.         ' dl& = SetWindowLong&(cmdTest.hWnd, GWL_STYLE, GetWindowLong&(cmdTest.hWnd, _
  359.         '    GWL_STYLE) Or BS_MULTILINE)
  360.         m_wndButton.Style = (m_wndButton.Style Or BS_MULTILINE)
  361.     Else
  362.         'Remove the bit
  363.         ' dl& = SetWindowLong&(cmdTest.hWnd, GWL_STYLE, GetWindowLong&(cmdTest.hWnd, _
  364.         '    GWL_STYLE) And Not BS_MULTILINE)
  365.         m_wndButton.Style = (m_wndButton.Style And Not BS_MULTILINE)
  366.     End If
  367.     'Repaint the control
  368.     cmdTest.Refresh
  369.         
  370. End Sub
  371. Private Sub chkPushLike_Click()
  372.     If chkPushLike = 1 Then
  373.         'dl& = SetWindowLong&(cmdTest.hWnd, GWL_STYLE, GetWindowLong&(cmdTest.hWnd, _
  374.         '    GWL_STYLE) Or BS_PUSHLIKE)
  375.         m_wndButton.Style = (m_wndButton.Style Or BS_PUSHLIKE)
  376.     Else
  377.         'dl& = SetWindowLong&(cmdTest.hWnd, GWL_STYLE, GetWindowLong&(cmdTest.hWnd, _
  378.         '    GWL_STYLE) And Not BS_PUSHLIKE)
  379.         m_wndButton.Style = (m_wndButton.Style And Not BS_PUSHLIKE)
  380.     End If
  381.     cmdTest.Refresh
  382. End Sub
  383. Private Sub chkSize_Click()
  384.     If chkSize = 1 Then
  385.         cmdTest.Height = 315  'Small button size (only one line of text high)
  386.     Else
  387.         cmdTest.Height = 615 ' Regular button size
  388.     End If
  389. End Sub
  390. Private Sub chkTxtLeft_Click()
  391.     If chkTxtLeft = 1 Then
  392.         'dl& = SetWindowLong&(cmdTest.hWnd, GWL_STYLE, GetWindowLong&(cmdTest.hWnd, _
  393.         '    GWL_STYLE) Or BS_LEFTTEXT)
  394.         m_wndButton.Style = (m_wndButton.Style Or BS_LEFTTEXT)
  395.     Else
  396.         'dl& = SetWindowLong&(cmdTest.hWnd, GWL_STYLE, GetWindowLong&(cmdTest.hWnd, _
  397.         '    GWL_STYLE) And Not BS_LEFTTEXT)
  398.         m_wndButton.Style = (m_wndButton.Style And Not BS_LEFTTEXT)
  399.     End If
  400.     cmdTest.Refresh
  401. End Sub
  402. Private Sub Form_Load()
  403.     fAlignment& = BS_CENTER
  404.     Set m_wndButton = New foWindow
  405.     m_wndButton.Attach cmdTest.hWnd
  406. End Sub
  407. Private Sub optLR_Click(Index As Integer)
  408.     Dim tmpValue&
  409.     Select Case Index
  410.     Case 0: ' Center
  411.         fAlignment& = BS_CENTER ' Set the flag
  412.         
  413.         'Get the current style and remove the LEFT and RIGHT bits from it
  414.         'tmpValue& = GetWindowLong&(cmdTest.hWnd, GWL_STYLE) And Not (BS_LEFT Or BS_RIGHT)
  415.         tmpValue& = (m_wndButton.Style And Not (BS_LEFT Or BS_RIGHT))
  416.     Case 1: ' Left
  417.         fAlignment& = BS_LEFT
  418.         'tmpValue& = GetWindowLong&(cmdTest.hWnd, GWL_STYLE) And Not BS_RIGHT
  419.         tmpValue& = (m_wndButton.Style And Not BS_RIGHT)
  420.     Case 2: 'Right
  421.         fAlignment& = BS_RIGHT
  422.         'tmpValue& = GetWindowLong&(cmdTest.hWnd, GWL_STYLE) And Not BS_LEFT
  423.         tmpValue& = (m_wndButton.Style And Not BS_LEFT)
  424.     End Select
  425.     'Set the style and Add the fAlignment& bit in
  426.     'dl& = SetWindowLong&(cmdTest.hWnd, GWL_STYLE, tmpValue& Or fAlignment&)
  427.     m_wndButton.Style = (tmpValue& Or fAlignment&)
  428.     'Repaint the control
  429.     cmdTest.Refresh
  430. End Sub
  431. ' See the comments for optLR for explanation of this procedure
  432. Private Sub optTB_Click(Index As Integer)
  433.    Dim tmpValue&
  434.     Select Case Index
  435.     Case 0: ' Center
  436.         fAlignment& = BS_CENTER
  437.         'tmpValue& = GetWindowLong&(cmdTest.hWnd, GWL_STYLE) And Not (BS_TOP Or BS_BOTTOM)
  438.         tmpValue& = (m_wndButton.Style And Not (BS_TOP Or BS_BOTTOM))
  439.     Case 1: ' Top
  440.         fAlignment& = BS_TOP
  441.         'tmpValue& = GetWindowLong&(cmdTest.hWnd, GWL_STYLE) And Not BS_BOTTOM
  442.         tmpValue& = (m_wndButton.Style And Not BS_BOTTOM)
  443.     Case 2: 'Bottom
  444.         fAlignment& = BS_BOTTOM
  445.         'tmpValue& = GetWindowLong&(cmdTest.hWnd, GWL_STYLE) And Not BS_TOP
  446.         tmpValue& = (m_wndButton.Style And Not BS_TOP)
  447.     End Select
  448.     'dl& = SetWindowLong&(cmdTest.hWnd, GWL_STYLE, tmpValue& Or fAlignment&)
  449.     m_wndButton.Style = (tmpValue& Or fAlignment&)
  450.     cmdTest.Refresh
  451. End Sub
  452. Private Sub optType_Click(Index As Integer)
  453.     Dim tmpValue&, mskNoStyle&
  454.     'Remove all the style bits from the button
  455.     'mskNoStyle& = GetWindowLong&(cmdTest.hWnd, GWL_STYLE) And Not (BS_AUTOCHECKBOX Or _
  456.     '                    BS_RADIOBUTTON Or BS_3STATE _
  457.     '                    Or BS_GROUPBOX Or BS_ICON Or BS_PUSHBUTTON)
  458.     mskNoStyle& = m_wndButton.Style And Not (BS_AUTOCHECKBOX Or _
  459.                         BS_RADIOBUTTON Or BS_3STATE _
  460.                         Or BS_GROUPBOX Or BS_ICON Or BS_PUSHBUTTON)
  461.     Select Case Index
  462.         Case 0: ' Pushbutton
  463.             tmpValue& = BS_PUSHBUTTON
  464.             
  465.         Case 1: ' Option Button
  466.             tmpValue& = BS_RADIOBUTTON
  467.             
  468.         Case 2: 'CheckBox
  469.             tmpValue& = BS_AUTOCHECKBOX
  470.             
  471.         Case 3: '3-State
  472.             tmpValue& = BS_3STATE
  473.             
  474.         Case 4: 'Groupbox
  475.             tmpValue& = BS_GROUPBOX
  476.             
  477.         Case 5: 'ICON
  478.             tmpValue& = BS_ICON
  479.             
  480.     End Select
  481.     'Add the correct style bit to the button
  482.     'dl& = SetWindowLong&(cmdTest.hWnd, GWL_STYLE, mskNoStyle& Or tmpValue&)
  483.     m_wndButton.Style = (mskNoStyle& Or tmpValue&)
  484.     cmdTest.Refresh
  485. End Sub
  486.