home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1995 September / Image.iso / pcplus / handson / vbwrk107 / apimbtn.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-06-09  |  3.3 KB  |  107 lines

  1. VERSION 2.00
  2. Begin Form APIMBtn 
  3.    BackColor       =   &H8000000F&
  4.    BorderStyle     =   0  'None
  5.    ClientHeight    =   588
  6.    ClientLeft      =   36
  7.    ClientTop       =   6480
  8.    ClientWidth     =   936
  9.    ControlBox      =   0   'False
  10.    Height          =   1008
  11.    Left            =   -12
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    MinButton       =   0   'False
  15.    ScaleHeight     =   588
  16.    ScaleWidth      =   936
  17.    Top             =   6108
  18.    Width           =   1032
  19.    Begin PictureBox tbBtnUp 
  20.       AutoSize        =   -1  'True
  21.       BorderStyle     =   0  'None
  22.       Height          =   264
  23.       Left            =   450
  24.       Picture         =   APIMBTN.FRX:0000
  25.       ScaleHeight     =   264
  26.       ScaleWidth      =   288
  27.       TabIndex        =   0
  28.       Top             =   90
  29.       Width           =   288
  30.    End
  31.    Begin PictureBox tbBtnDn 
  32.       AutoSize        =   -1  'True
  33.       BorderStyle     =   0  'None
  34.       Enabled         =   0   'False
  35.       Height          =   264
  36.       Left            =   90
  37.       Picture         =   APIMBTN.FRX:0182
  38.       ScaleHeight     =   264
  39.       ScaleWidth      =   288
  40.       TabIndex        =   1
  41.       Top             =   90
  42.       Width           =   288
  43.    End
  44. Option Explicit
  45. 'API declarations to enable adding a toolbar
  46. 'button to Visual BASIC's toolbar
  47. Declare Function SetParent% Lib "User" (ByVal hWndChild%, ByVal hWndParent%)
  48. Dim result As Integer   'return value from API calls
  49. Sub Form_Load ()
  50. Dim vbtoolbar As Integer    'handle to VB toolbar
  51. 'get handle of VB toolbar
  52. vbtoolbar = FindWindowByClass("wndclass_desked_gsk", 0&)
  53. 'if VB toolbar handle found - add button
  54. If vbtoolbar > 0 Then
  55.     'flag we have added button
  56.     BtnLoaded = True
  57.     'hide buttons during transfer
  58.     tbBtnUp.Visible = False
  59.     tbBtnDn.Visible = False
  60.     'make button images children of VB toolbar
  61.     result = SetParent(tbBtnUp.hWnd, vbtoolbar)
  62.     result = SetParent(tbBtnDn.hWnd, vbtoolbar)
  63.     'position button images after existing VB buttons
  64.     tbBtnUp.Move 5550, 25
  65.     tbBtnDn.Move 5550, 25
  66.     tbBtnUp.ZOrder
  67.     'reveal buttons
  68.     tbBtnUp.Visible = True
  69.     tbBtnDn.Visible = True
  70. End If
  71. End Sub
  72. Sub Form_QueryUnload (Cancel As Integer, UnloadMode As Integer)
  73. If BtnLoaded Then
  74.     'recover button images from VB toolbar
  75.     result = SetParent(tbBtnUp.hWnd, Me.hWnd)
  76.     result = SetParent(tbBtnDn.hWnd, Me.hWnd)
  77.     'clear flag
  78.     BtnLoaded = False
  79. End If
  80. End Sub
  81. Sub tbBtnUp_Click ()
  82. 'activate API Magic - restore if needed
  83. result = FindWindowByTitle(0&, "API Magic")
  84. If result = 0 Then Exit Sub
  85. result = ShowWindow(result, SW_SHOWNOACTIVATE)
  86. AppActivate "API Magic"
  87. DoEvents
  88. End Sub
  89. Sub tbBtnUp_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
  90. 'on mousdown show button depressed
  91. tbBtnDn.ZOrder
  92. End Sub
  93. Sub tbBtnUp_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  94. 'show button depressed only while covered by mouse cursor
  95. If Button Then
  96.     If X <= 0 Or X > tbBtnUp.Width Or Y < 0 Or Y > tbBtnUp.Height Then
  97.         tbBtnUp.ZOrder
  98.     Else
  99.         tbBtnDn.ZOrder
  100.     End If
  101. End If
  102. End Sub
  103. Sub tbBtnUp_MouseUp (Button As Integer, Shift As Integer, X As Single, Y As Single)
  104. 'on mouseup show button released
  105. tbBtnUp.ZOrder
  106. End Sub
  107.