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 / vbpg32 / samples5 / ch05 / btnplay.frm (.txt) next >
Encoding:
Visual Basic Form  |  1997-02-16  |  15.6 KB  |  467 lines

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