hi i will post free codes and activex every week starting now, enjoy.
hi
some of the following codes made by me
and the rest from visualbasic websites.
but any question just ask me.
hope everybody enjoy.
ps: i am posting this codes to make it easy to find what you need
ps: i will post some activex control soon.
1- open and close the cdroom.
VB Code:
Private Declare Function mciSendString Lib "winmm.dll" _
Alias "mciSendStringA" ( _
ByVal lpstrCommand As String, ByVal lpstrReturnString As String, _
ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Public Sub OpenCDDriveDoor(ByVal State As Boolean)
If State = True Then
Call mciSendString("Set CDAudio Door Open", 0&, 0&, 0&)
Else
Call mciSendString("Set CDAudio Door Closed", 0&, 0&, 0&)
End If
End Sub
Private Sub Command1_Click()
OpenCDDriveDoor (True)
End Sub
Private Sub Command2_Click()
OpenCDDriveDoor (False)
End Sub
2- hide the caret In Textbox.
VB Code:
'Add 1 Text Box and 1 Check Box to your form.
'Uncheck the Check Box to hide Text1 Caret. Check it again to return the caret.
'Insert the following code to your form:
Private Declare Function HideCaret Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ShowCaret& Lib "user32" (ByVal hwnd As Long)
Private Sub CheckCaret()
If Check1.Value = vbChecked Then
ShowCaret (Text1.hwnd)
Else
HideCaret (Text1.hwnd)
End If
End Sub
Private Sub Form_Load()
Check1.Value = 1
End Sub
Private Sub Text1_Change()
CheckCaret
End Sub
Private Sub Text1_GotFocus()
CheckCaret
End Sub
3- Add A Picture In Rich Textbox.
VB Code:
'Add 1 Command Button (named Command1),
'1 Rich Text Box (named RichTextBox1) and
'1 Picture Box (named Picture1) to your form.
'Add a picture to the Picture Box.
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_PASTE = &H302
Private Sub Command1_Click()
'the 2 code lines below copy the picture box's picture to the clipboard. if you will omit them,
'the picture that currently found in the clipboard will be copied to the rich text box.
Clipboard.Clear
Clipboard.SetData Picture1.Picture
SendMessage RichTextBox1.hwnd, WM_PASTE, 0, 0
End Sub
4- Add Combobox To Toolbar.
VB Code:
'Add 1 Combo Box and 1 ToolBar to your form.
'Insert the following code to your form:
Private Sub Form_Load()
Dim btnX As Button
Me.Show
Set btnX = Toolbar1.Buttons.Add()
btnX.Style = tbrSeparator
Set btnX = Toolbar1.Buttons.Add()
btnX.Style = tbrPlaceholder
btnX.Key = "combo"
btnX.Width = 2000
With Combo1
.ZOrder 0
.Width = Toolbar1.Buttons("combo").Width
.Top = Toolbar1.Buttons("combo").Top
.Left = Toolbar1.Buttons("combo").Left
End With
End Sub
5- Add Checkbox In Combobox.
VB Code:
'Add 1 Combo Box and 1 Check Box to your form.
'Set CheckBox Width property and Height property to 130.
'Insert this code to the module :
Private Const EC_LEFTMARGIN = &H1
Private Const EC_RIGHTMARGIN = &H2
Private Const EC_USEFONTINFO = &HFFFF&
Private Const EM_SETMARGINS = &HD3&
Private Const EM_GETMARGINS = &HD4&
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal hwndParent As Long, ByVal hwndChildAfter As Long, _
ByVal lpszClass As String, _
ByVal lpszWindow As String) As Long
Private Declare Function SendMessageLong Lib "user32" _ Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
'Insert the following code to your form:
Private Sub AddCheckToCombo(ByRef chkThis As CheckBox, ByRef cboThis As ComboBox)
Dim lhWnd As Long
Dim lMargin As Long
lhWnd = FindWindowEx(cboThis.hwnd, 0, "EDIT", vbNullString)
If (lhWnd <> 0) Then
lMargin = chkThis.Width \ Screen.TwipsPerPixelX + 2
SendMessageLong lhWnd, EM_SETMARGINS, EC_LEFTMARGIN, lMargin
chkThis.BackColor = cboThis.BackColor
chkThis.Move cboThis.Left + 3 * Screen.TwipsPerPixelX, cboThis.Top + 2 * Screen.TwipsPerPixelY, chkThis.Width, cboThis.Height - 4 * Screen.TwipsPerPixelY
chkThis.ZOrder
End If
End Sub
Private Sub Form_Load()
AddCheckToCombo Check1, Combo1
End Sub
6- Showing A Tooltiptext For Each Element In Listbox.
VB Code:
Private Sub List1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim index As Integer
On Error GoTo endList
WordHeight = 195
index = List1.TopIndex + ((y) / WordHeight)
List1.ListIndex = index
List1.ToolTipText = List1.Text
Exit Sub
endList:
List1.ListIndex = List1.ListCount - 1
List1.ToolTipText = List1.Text
End Sub
7- Enable Or Disable All The Controls In The Frame.
VB Code:
Public Sub EnableFrame(InFrame As Frame, ByVal Flag As Boolean)
Dim Contrl As Control
'some controls don't have the Container.Name property, so instead of
'stopping the application with an error message, we ignore them.
On Error Resume Next
'enable or disable the frame that passed as parameter.
InFrame.Enabled = Flag
'passing over all controls
For Each Contrl In InFrame.Parent.Controls
'if the control is found in the frame
If (Contrl.Container.Name = InFrame.Name) Then
'if the control is a frame, and it's not the frame that passed as parameter, i.e.
'other frame that found inside our frame, recursively run this sub with this frame,
'to enable or disable all the controls in it.
If (TypeOf Contrl Is Frame) And Not (Contrl.Name = InFrame.Name) Then
EnableFrame Contrl, Flag
Else
'enable or disable the control
If Not (TypeOf Contrl Is Menu) Then Contrl.Enabled = Flag
End If
End If
Next
End Sub
Private Sub Command1_Click()
EnableFrame Frame1, False
End Sub
Private Sub Command2_Click()
EnableFrame Frame1, True
End Sub
Thats all for today.
see ya
Re: hi i will post free codes and activex every week starting now, enjoy.
Can you post is the VBCODE Tag