These codes are all made by me and with a help of two people who has added a little input with two codes...If using these codes please give me a little credit if you want. My email address is
Open a text files to add stuff
How to make a
label count up
How to count the number of entries in a ListBox
How to make a form in the background show an Image everywhere you click
To shutdown th computer in Windows 95
To make a program detect first time run
To Make a Listbox not put two strings in twice
To Find the Windows Directory
Put a simple code like this:
A$ = String$ (255,1)
B = GetWindowsDirectory (A$,255)
Msgbox A$
Declaration:
Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Hexidecimals
0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 A 10 B 11 C 12 D 13 E 14 F 15
Take Off Text From The Left Of A Word
A = Text1.Text
B = Left$ (A,2)
Msgbox B
Summary: What this does is it extract two words from the left of a word You can Switch Left$ with Right$ or Mid$
How to make a Program end after 4 tries
Requirements:
Put this code under the load section of a FORM
retvalue = GetSetting("A", "0", "Runcount")
GD$ = Val(retvalue) + 1
SaveSetting "A", "0", "RunCount", GD$
If GD$ > 3 Then
MsgBox "HeY!!!, Well it's time for you to register this program for now BYE!!!"
Unload me
End If
Counting the Amount of times a program is runned
num = GetSetting("Test", 0, "Run")
num = Val(num) + 1
SaveSetting "Test", 0, "Run", num
Msgbox num
Getting a Window Caption
Code:
GDs$ = String$ (200,150)
AOL% = FindWindow ("AOL FRAME25", VBNULLSTRING)
blabla = GetWindowText(AOL%, GDs$, 100)
Msgbox GDs%
Using LB_SETCURSEL
Summary:
LB_SETCURSEL is used to move from one list index to another it's very easy to use
Code:
Set = SendMessageByNum(HWND%, LB_SETCURSEL, 1, 0)
'This will set the selection on the SECOND index in the listbox in Windows 95 the 0 is the first and 1 is the second
HWND% is the listbox handle
Gaming Movements
This does a special function when something is pressed add it to the KEYDOWN Proc in a form or anything you want:
If keycode = 39 Then
Msgbox "You pressed the right key"
End If
If keycode = 37 Then
Msgbox "You pressed the left key"
End If
If keycode = 38 Then
Msgbox "You pressed the Up arrow key"
End If
If keycode = 40 Then
Msgbox "You pressed the down arrow key"
Picture1.Move Picture1.Top - 100
End If
End Sub
Loading Lists in VB
Dim a As Variant
Dim b As Variant
CMDialog1.DialogTitle = "Load List File" ' set title
CMDialog1.Filter = "Tee (*.txt)|*.txt|All Files (*.*)|*.*|"
CMDialog1.FileName = "*.txt"
CMDialog1.FLAGS = &H1000&
CMDialog1.Action = 1
a = 1
If (CMDialog1.FileTitle <> "") Then
List1.Clear ' clear the list
Open CMDialog1.FileTitle For Input As a
While (EOF(a) = False)
Line Input #a, b
List1.AddItem b
Wend
Close a
End If
Saving a List in VB
Dim b As Variant
CMDialog1.DialogTitle = "Save List File" ' set CMDialog's title bar
CMDialog1.Filter = "Tee (*.txt)|*.txt|All Files (*.*)|*.*|"
CMDialog1.FLAGS = &H1000&
CMDialog1.FileName = "*.txt"
CMDialog1.Action = 2
If (CMDialog1.FileTitle <> "") Then
a = 2
Open CMDialog1.FileName For Output As a
b = 0
Do While b < List1.ListCount
Print #a, List1.List(b)
b = b + 1
Loop
Close a
End If
Moving a form with a titlebar
Summary: What this does is move a form with really a piece of atr or a label and without the original WINDOWS titlebar.
Steps:
1. Make sure the form Border under properties is set to NONE
2. Stick in a piece of art for the titlebar and in the MOUSE_DOWN event of that image put in this simple code:
DoEvents
ReleaseCapture
Returnl% = SendMessage(Form1.hwnd, &HA1, 2, 0)
Declarations:
In a bas file under General_Declarations put this:
Declare Sub ReleaseCapture Lib "User32" ()
Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long
Painting Desktop Image
Source:
a = Form1.hwnd ' Gets the Handle of the form
b = GetDC(a) ' Get's the Device Context of that window
c = PaintDesktop(b) ' Paint the desktop image without the physical icons and images which you added
Declaration:
Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Declare Function PaintDesktop Lib "user32" (ByVal hdc As Long) As Boolean
Playing an MIDI File in VB
Form1.MMControl1.Command = "CLOSE"
Form1.MMControl1.Notify = True
Form1.MMControl1.DeviceType = "Sequencer"
Form1.MMControl1.filename = App.Path + "\" + "mk.mid"
Form1.MMControl1.Command = "Open"
Form1.MMControl1.Command = "PLAY"
Summary: This will play a MID file which you have in the same directory as the project
Note: Please note that you need the MCI Control added in the project for this to work
| Command | Value |
| OK | 1 |
| Cancel | 2 |
| Abort | 3 |
| Retry | 4 |
| Ignore | 5 |
| Yes | 6 |
| No | 7 |
About Box (MS Format)
Declaration:
Declare Function
ShellAbout Lib "shell32.dll" Alias "ShellAboutA" (ByVal hwnd As Long,
ByVal szApp As String, ByVal szOtherStuff As String, ByVal hIcon As Long) As Long
Code:
a =
ShellAbout(Form1.hwnd, "GD's Application", "Made By: GD", 0&)
Input Box
Code:
x = inputbox ("Hi this is GD what's your name?","GD")
msgbox "Your name is " & x,64,"Did you know..."
Note: Most of the time we use InputBox to save space when making the program and it's a lot easier to get the User's input
Blocking Ctrl + Alt + Del
Declare
Function SystemParametersInfo Lib "user32" Alias
"SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByVal
lpvParam As Any, ByVal fuWinIni As Long) As Long
Code:
Sub
GDDis(v As Boolean)
GD = SystemParametersInfo(97, v, CStr(1), 0)
End Sub
Making a circular form
Making a wave file play
from RES
First make a directory called Res
Copy these files into that directory:
RC.exe
RCdll.dll
...also copy any wave file and call it gd.wav
In notepad put in the following text
1 SOUND MOVEABLE PURE "gd.wav"
Then save the file as gd.rc
After that in windows explorer drag and drop gd.rc to rc.exe and it will make gd.res
Then in VB5 click Project-->Add File then add gd.res.
Then download gdplay.bas by clicking here....Add it to your VB
project
Then in a command button put in the following code:
BeginPlaySound 1
And that's how you make a wave file play from memory you no longer need to add the wave
file with your exe program it's compiled into the program :)
Note: GDPlay.bas came from ATM.bas which came with VB5 :)
Opening and Closing CD-Rom Drive
Delcarations:
Declare Function mcisendstring Lib "MMSystem" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal wReturnLength As Integer, ByVal hCallback As Integer) As Long
Code:
gdx = MCISendString("set CDAudio door closed", returnstring, 127, 0) ' 'This is to close it
gdxx = MCISendString("set CDAudio door open", returnstring, 127, 0) ' This is to Open it
Email Address: [email protected]
Copyright � 1996-1998 GD Corp - Zero-Inc. All Rights Reserved.
Main URL: GD.Cjb.Net