Free Games Forum
Free Games Games Forums Music Forums TV Forums

  Free Games Forum Home FORUM
HOME
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN
Rules & FAQ RULES / FAQ
REPORT SPAM

Free Games Forum: Game Technology: Visual Basic / VB:
[Tut] Custom Command Buttons

 

 


Fire_Of_Hell
Newbie

Apr 3, 2006, 6:48 PM

Post #1 of 1 (326 views)
Shortcut
[Tut] Custom Command Buttons Can't Post

Ok, so first of all, this is not MY tutorial, it is CFJ0's, so don't give me credit unless it is for copying it on to this forum kk?

-Cusom Command Button Tutorial-



1. Making the buttons u want (SAME SIZE) and name them imgNormal, imgOver and imgDown

2. Now lets get started open up an ActiveX Control project (I will be using the windows xp button in the screenshots)
Firstly you wanna make a image and load each of your images (must be named imgNormal, imgOver and imgDown) into, then make a label called lblCaption and a empty image called imgIO last you have to add a timer called tmrCheck and set interval to 1.

3. Now we want to make them in the right order and that is:
1 - lblCaption - on the top of all
2 - imgDown - next on top
3 - imgOver - in the middle
4 - imgNormal - right before under everything
5 - imgIO - behind everything

if your unsure on how to do so heres a screenie of where to click after u rightclick them

Press Send To Front or Send To Back to move em up or down and list em like shown right under step 3

4. You should now have something like this:


5. Now pull all of the files (lblCaption, imgDown, imgOver, imgNormal, imgIO) on top of each other and the button will look like this:


6. Now for the fun part the coding:
View the code and delete everything of code there is so u have a fully white screen and add this:


Code
  
Option Explicit

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long


Private Type POINTAPI
X As Long
Y As Long
End Type

Public Event Click()
Public Event MouseMove()

Private mpoiCursorPos As POINTAPI


Private Sub lblCaption_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Not Enabled Then Exit Sub
imgDown.Visible = True
RaiseEvent Click
End Sub

Private Sub lblCaption_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Not Enabled Then Exit Sub
tmrCheck.Enabled = True
imgOver.Visible = True
RaiseEvent MouseMove
End Sub

Private Sub lblCaption_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Not Enabled Then Exit Sub
imgDown.Visible = False
End Sub

Private Sub tmrCheck_Timer()
'If Not Enabled Then Exit Sub
Dim lonCStat As Long
Dim lonCurrhWnd As Long

lonCStat = GetCursorPos&(mpoiCursorPos)
lonCurrhWnd = WindowFromPoint(mpoiCursorPos.X, mpoiCursorPos.Y)
If lonCurrhWnd = UserControl.hWnd Then
Else
imgDown.Visible = False
imgOver.Visible = False
imgNormal.Visible = True
tmrCheck.Enabled = False
End If

End Sub

Private Sub UserControl_InitProperties()
Caption = Ambient.DisplayName
End Sub

Public Property Get Caption() As String
Caption = lblCaption.Caption
End Property

Public Property Let Caption(ByVal sNewValue As String)
lblCaption.Caption = sNewValue
UserControl.PropertyChanged "Caption"
End Property

Public Property Get FontName() As String
FontName = lblCaption.FontName
End Property

Public Property Let FontName(ByVal sNewValue As String)
lblCaption.FontName = sNewValue
UserControl.PropertyChanged "FontName"
End Property

Private Sub UserControl_Resize()
lblCaption.Top = ((UserControl.Height - lblCaption.Height) / 2) + 20

imgOver.Width = UserControl.Width
imgOver.Height = UserControl.Height
imgNormal.Width = UserControl.Width
imgNormal.Height = UserControl.Height
imgDown.Width = UserControl.Width
imgDown.Height = UserControl.Height
imgIO.Width = UserControl.Width
imgIO.Height = UserControl.Height
lblCaption.Width = UserControl.Width
End Sub

Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
With PropBag
.WriteProperty "Caption", Caption, Ambient.DisplayName
.WriteProperty "FontName", FontName, "Tahoma"
.WriteProperty "Enabled", Enabled, True
End With
End Sub

Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
With PropBag
Caption = .ReadProperty("Caption", Ambient.DisplayName)
FontName = .ReadProperty("FontName", "Tahoma")
Enabled = .ReadProperty("Enabled", True)
End With
End Sub

Private Sub imgio_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Not Enabled Then Exit Sub
imgDown.Visible = True
RaiseEvent Click
End Sub

Private Sub imgio_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Not Enabled Then Exit Sub
tmrCheck.Enabled = True
imgOver.Visible = True
RaiseEvent MouseMove
End Sub

Private Sub imgio_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Not Enabled Then Exit Sub
imgDown.Visible = False
End Sub

Public Property Get Enabled() As Boolean
Enabled = lblCaption.Enabled
End Property

Public Property Let Enabled(ByVal bNewValue As Boolean)
lblCaption.Enabled = bNewValue
End Property

7. Save the ActiveX as MyButton.ctl and load it onto the project u want the button and when the button is used it will look like this:




8. The final ActiveX (for windows xp buttons) can be found here:
http://www.ezupload.org/?w=download&id=13852&name=COOLBUTTON.CTL


-CFJ0-



I hope that helps a couple of people.


 
 
 


Search for (options) Web Design by Web Ideas - Page loaded in: 0.12 s on (CGI/1.1)