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 / samples4 / ch05 / btnplay.frm (.txt) next >
Encoding:
Visual Basic Form  |  1996-02-16  |  15.6 KB  |  468 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. Option Explicit
  276. ' Copyright 
  277.  1996 by Desaware. All Rights Reserved
  278. Dim dl&
  279. Dim fAlignment&
  280. '**********************************
  281. '**  Constant Definitions:
  282. #If Win32 Then
  283. Private Const BS_NULL& = 1
  284. Private Const BS_BOTTOM& = &H800&
  285. Private Const BS_BITMAP& = &H80&
  286. Private Const BS_AUTORADIOBUTTON& = &H9&
  287. Private Const BS_AUTOCHECKBOX& = &H3&
  288. Private Const BS_AUTO3STATE& = &H6&
  289. Private Const BS_3STATE& = &H5&
  290. Private Const BS_CENTER& = &H300&
  291. Private Const BS_CHECKBOX& = &H2&
  292. Private Const BS_DEFPUSHBUTTON& = &H1&
  293. Private Const BS_DIBPATTERN& = 5
  294. Private Const BS_DIBPATTERN8X8& = 8
  295. Private Const BS_DIBPATTERNPT& = 6
  296. Private Const BS_FLAT& = &H8000&
  297. Private Const BS_ICON& = &H40&
  298. Private Const BS_HOLLOW& = BS_NULL
  299. Private Const BS_HATCHED& = 2
  300. Private Const BS_GROUPBOX& = &H7&
  301. Private Const BS_INDEXED& = 4
  302. Private Const BS_LEFT& = &H100&
  303. Private Const BS_LEFTTEXT& = &H20&
  304. Private Const BS_MULTILINE& = &H2000&
  305. Private Const BS_NOTIFY& = &H4000&
  306. Private Const BS_OWNERDRAW& = &HB&
  307. Private Const BS_PATTERN& = 3
  308. Private Const BS_PATTERN8X8& = 7
  309. Private Const BS_PUSHBUTTON& = &H0&
  310. Private Const BS_PUSHLIKE& = &H1000&
  311. Private Const BS_RADIOBUTTON& = &H4&
  312. Private Const BS_RIGHT& = &H200&
  313. Private Const BS_RIGHTBUTTON& = &H20&
  314. Private Const BS_SOLID& = 0
  315. Private Const BS_TEXT& = 0&
  316. Private Const BS_TOP& = &H400&
  317. Private Const BS_USERBUTTON& = &H8&
  318. Private Const BS_VCENTER& = &HC00&
  319. Private Const GWL_EXSTYLE& = (-20)
  320. Private Const GWL_HINSTANCE& = (-6)
  321. Private Const GWL_HWNDPARENT& = (-8)
  322. Private Const GWL_ID& = (-12)
  323. Private Const GWL_STYLE& = (-16)
  324. Private Const GWL_USERDATA& = (-21)
  325. Private Const GWL_WNDPROC& = (-4)
  326. #End If 'WIN32
  327. '**********************************
  328. '**  Function Declarations:
  329. #If Win32 Then
  330. Private Declare Function GetWindowLong& Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long)
  331. Private Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
  332. #End If 'WIN32
  333. '**********************************
  334. '**  Constant Definitions:
  335. #If Win32 Then
  336. Private Const BM_GETCHECK& = &HF0
  337. Private Const BM_SETCHECK& = &HF1
  338. Private Const BM_GETSTATE& = &HF2
  339. Private Const BM_SETSTATE& = &HF3
  340. Private Const BM_SETSTYLE& = &HF4
  341. Private Const BM_GETIMAGE& = &HF6
  342. Private Const BM_SETIMAGE& = &HF7
  343. #End If 'WIN32
  344. '**********************************
  345. '**  Function Declarations:
  346. #If Win32 Then
  347. Private Declare Function SendMessage& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long)
  348. #End If 'WIN32
  349. Private Sub chkLong_Click()
  350.     If chkLong = 1 Then 'Checked
  351.         cmdTest.Caption = "This is a test button"
  352.     Else
  353.         cmdTest.Caption = "Test Button"
  354.     End If
  355.     cmdTest.Refresh
  356. End Sub
  357. Private Sub chkMline_Click()
  358.     If chkMline = 1 Then
  359.         'Add the bit
  360.         dl& = SetWindowLong&(cmdTest.hwnd, GWL_STYLE, GetWindowLong&(cmdTest.hwnd, _
  361.             GWL_STYLE) Or BS_MULTILINE)
  362.     Else
  363.         'Remove the bit
  364.         dl& = SetWindowLong&(cmdTest.hwnd, GWL_STYLE, GetWindowLong&(cmdTest.hwnd, _
  365.             GWL_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.     Else
  376.         dl& = SetWindowLong&(cmdTest.hwnd, GWL_STYLE, GetWindowLong&(cmdTest.hwnd, _
  377.             GWL_STYLE) And Not BS_PUSHLIKE)
  378.     End If
  379.     cmdTest.Refresh
  380. End Sub
  381. Private Sub chkSize_Click()
  382.     If chkSize = 1 Then
  383.         cmdTest.Height = 315  'Small button size (only one line of text high)
  384.     Else
  385.         cmdTest.Height = 615 ' Regular button size
  386.     End If
  387. End Sub
  388. Private Sub chkTxtLeft_Click()
  389.     If chkTxtLeft = 1 Then
  390.         dl& = SetWindowLong&(cmdTest.hwnd, GWL_STYLE, GetWindowLong&(cmdTest.hwnd, _
  391.             GWL_STYLE) Or BS_LEFTTEXT)
  392.     Else
  393.         dl& = SetWindowLong&(cmdTest.hwnd, GWL_STYLE, GetWindowLong&(cmdTest.hwnd, _
  394.             GWL_STYLE) And Not BS_LEFTTEXT)
  395.     End If
  396.     cmdTest.Refresh
  397. End Sub
  398. Private Sub Form_Load()
  399.     fAlignment& = BS_CENTER
  400. End Sub
  401. Private Sub optLR_Click(Index As Integer)
  402.     Dim tmpValue&
  403.     Select Case Index
  404.     Case 0: ' Center
  405.         fAlignment& = BS_CENTER ' Set the flag
  406.         
  407.         'Get the current style and remove the LEFT and RIGHT bits from it
  408.         tmpValue& = GetWindowLong&(cmdTest.hwnd, GWL_STYLE) And Not (BS_LEFT Or BS_RIGHT)
  409.     Case 1: ' Left
  410.         fAlignment& = BS_LEFT
  411.         tmpValue& = GetWindowLong&(cmdTest.hwnd, GWL_STYLE) And Not BS_RIGHT
  412.     Case 2: 'Right
  413.         fAlignment& = BS_RIGHT
  414.         tmpValue& = GetWindowLong&(cmdTest.hwnd, GWL_STYLE) And Not BS_LEFT
  415.     End Select
  416.     'Set the style and Add the fAlignment& bit in
  417.     dl& = SetWindowLong&(cmdTest.hwnd, GWL_STYLE, tmpValue& Or fAlignment&)
  418.     'Repaint the control
  419.     cmdTest.Refresh
  420. End Sub
  421. ' See the comments for optLR for explanation of this procedure
  422. Private Sub optTB_Click(Index As Integer)
  423.    Dim tmpValue&
  424.     Select Case Index
  425.     Case 0: ' Center
  426.         fAlignment& = BS_CENTER
  427.         tmpValue& = GetWindowLong&(cmdTest.hwnd, GWL_STYLE) And Not (BS_TOP Or BS_BOTTOM)
  428.     Case 1: ' Top
  429.         fAlignment& = BS_TOP
  430.         tmpValue& = GetWindowLong&(cmdTest.hwnd, GWL_STYLE) And Not BS_BOTTOM
  431.     Case 2: 'Bottom
  432.         fAlignment& = BS_BOTTOM
  433.         tmpValue& = GetWindowLong&(cmdTest.hwnd, GWL_STYLE) And Not BS_TOP
  434.     End Select
  435.     dl& = SetWindowLong&(cmdTest.hwnd, GWL_STYLE, tmpValue& Or fAlignment&)
  436.     cmdTest.Refresh
  437. End Sub
  438. Private Sub optType_Click(Index As Integer)
  439.     Dim tmpValue&, mskNoStyle&
  440.     'Remove all the style bits from the button
  441.     mskNoStyle& = GetWindowLong&(cmdTest.hwnd, GWL_STYLE) And Not (BS_AUTOCHECKBOX Or _
  442.                         BS_RADIOBUTTON Or BS_3STATE _
  443.                         Or BS_GROUPBOX Or BS_ICON Or BS_PUSHBUTTON)
  444.     Select Case Index
  445.         Case 0: ' Pushbutton
  446.             tmpValue& = BS_PUSHBUTTON
  447.             
  448.         Case 1: ' Option Button
  449.             tmpValue& = BS_RADIOBUTTON
  450.             
  451.         Case 2: 'CheckBox
  452.             tmpValue& = BS_AUTOCHECKBOX
  453.             
  454.         Case 3: '3-State
  455.             tmpValue& = BS_3STATE
  456.             
  457.         Case 4: 'Groupbox
  458.             tmpValue& = BS_GROUPBOX
  459.             
  460.         Case 5: 'ICON
  461.             tmpValue& = BS_ICON
  462.             
  463.     End Select
  464.     'Add the correct style bit to the button
  465.     dl& = SetWindowLong&(cmdTest.hwnd, GWL_STYLE, mskNoStyle& Or tmpValue&)
  466.     cmdTest.Refresh
  467. End Sub
  468.